From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Chenggang Wang <wangchenggang@vivo.com>,
Petr Mladek <pmladek@suse.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/2] printk: Move and rename maximum printk output line length defines
Date: Tue, 19 May 2020 12:42:34 -0700 [thread overview]
Message-ID: <f37c12c0df59b876236827fcd05b518e28d11a6c.1589916689.git.joe@perches.com> (raw)
In-Reply-To: <cover.1589916689.git.joe@perches.com>
Make the printk maximum line length globally available.
Miscellanea:
o Prefix the defines with PRINTK_
Signed-off-by: Joe Perches <joe@perches.com>
---
include/linux/printk.h | 18 ++++++++++++++++++
kernel/printk/printk.c | 28 ++++++++++------------------
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 38beb97e7018..850dc4d4356f 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -43,6 +43,24 @@ static inline const char *printk_skip_headers(const char *buffer)
#define CONSOLE_EXT_LOG_MAX 8192
+/* Maximum length of a single printk */
+
+#ifdef CONFIG_PRINTK
+
+#ifdef CONFIG_PRINTK_CALLER
+#define PRINTK_PREFIX_MAX 48
+#else
+#define PRINTK_PREFIX_MAX 32
+#endif
+#define PRINTK_LOG_LINE_MAX (1024 - PRINTK_PREFIX_MAX)
+
+#else
+
+#define PRINTK_PREFIX_MAX 0
+#define PRINTK_LOG_LINE_MAX 0
+
+#endif
+
/* printk's without a loglevel use this.. */
#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 4f1cc4acef41..fc22a494ef0c 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -443,13 +443,6 @@ static u64 exclusive_console_stop_seq;
static u64 clear_seq;
static u32 clear_idx;
-#ifdef CONFIG_PRINTK_CALLER
-#define PREFIX_MAX 48
-#else
-#define PREFIX_MAX 32
-#endif
-#define LOG_LINE_MAX (1024 - PREFIX_MAX)
-
#define LOG_LEVEL(v) ((v) & 0x07)
#define LOG_FACILITY(v) ((v) >> 3 & 0xff)
@@ -825,7 +818,7 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from)
size_t len = iov_iter_count(from);
ssize_t ret = len;
- if (!user || len > LOG_LINE_MAX)
+ if (!user || len > PRINTK_LOG_LINE_MAX)
return -EINVAL;
/* Ignore when user logging is disabled. */
@@ -1341,7 +1334,7 @@ static size_t msg_print_text(const struct printk_log *msg, bool syslog,
const char *text = log_text(msg);
size_t text_size = msg->text_len;
size_t len = 0;
- char prefix[PREFIX_MAX];
+ char prefix[PRINTK_PREFIX_MAX];
const size_t prefix_len = print_prefix(msg, syslog, time, prefix);
do {
@@ -1382,7 +1375,7 @@ static int syslog_print(char __user *buf, int size)
struct printk_log *msg;
int len = 0;
- text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
+ text = kmalloc(PRINTK_LOG_LINE_MAX + PRINTK_PREFIX_MAX, GFP_KERNEL);
if (!text)
return -ENOMEM;
@@ -1412,7 +1405,7 @@ static int syslog_print(char __user *buf, int size)
skip = syslog_partial;
msg = log_from_idx(syslog_idx);
n = msg_print_text(msg, true, syslog_time, text,
- LOG_LINE_MAX + PREFIX_MAX);
+ PRINTK_LOG_LINE_MAX + PRINTK_PREFIX_MAX);
if (n - syslog_partial <= size) {
/* message fits into buffer, move forward */
syslog_idx = log_next(syslog_idx);
@@ -1454,7 +1447,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
u32 idx;
bool time;
- text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
+ text = kmalloc(PRINTK_LOG_LINE_MAX + PRINTK_PREFIX_MAX, GFP_KERNEL);
if (!text)
return -ENOMEM;
@@ -1492,7 +1485,8 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
while (len >= 0 && seq < next_seq) {
struct printk_log *msg = log_from_idx(idx);
int textlen = msg_print_text(msg, true, time, text,
- LOG_LINE_MAX + PREFIX_MAX);
+ PRINTK_LOG_LINE_MAX +
+ PRINTK_PREFIX_MAX);
idx = log_next(idx);
seq++;
@@ -1845,7 +1839,7 @@ static inline u32 printk_caller_id(void)
* reached the console in case of a kernel crash.
*/
static struct cont {
- char buf[LOG_LINE_MAX];
+ char buf[PRINTK_LOG_LINE_MAX];
size_t len; /* length == 0 means unused buffer */
u32 caller_id; /* printk_caller_id() of first print */
u64 ts_nsec; /* time of first print */
@@ -1931,7 +1925,7 @@ int vprintk_store(int facility, int level,
const char *dict, size_t dictlen,
const char *fmt, va_list args)
{
- static char textbuf[LOG_LINE_MAX];
+ static char textbuf[PRINTK_LOG_LINE_MAX];
char *text = textbuf;
size_t text_len;
enum log_flags lflags = 0;
@@ -2088,8 +2082,6 @@ EXPORT_SYMBOL(printk);
#else /* CONFIG_PRINTK */
-#define LOG_LINE_MAX 0
-#define PREFIX_MAX 0
#define printk_time false
static u64 syslog_seq;
@@ -2396,7 +2388,7 @@ static inline int can_use_console(void)
void console_unlock(void)
{
static char ext_text[CONSOLE_EXT_LOG_MAX];
- static char text[LOG_LINE_MAX + PREFIX_MAX];
+ static char text[PRINTK_LOG_LINE_MAX + PRINTK_PREFIX_MAX];
unsigned long flags;
bool do_cond_resched, retry;
--
2.25.1
next prev parent reply other threads:[~2020-05-19 19:42 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 3:29 [PATCH] init/main.c: Print all command line when boot 王程刚
2020-05-19 3:44 ` Andrew Morton
2020-05-19 5:09 ` Joe Perches
2020-05-19 14:34 ` Arvind Sankar
2020-05-19 19:42 ` [RFC PATCH 0/2] printk/init: multi-line kernel command line logging Joe Perches
2020-05-19 19:42 ` Joe Perches [this message]
2020-05-21 13:49 ` [RFC PATCH 1/2] printk: Move and rename maximum printk output line length defines Petr Mladek
2020-05-19 19:42 ` [RFC PATCH 2/2] init: Allow multi-line output of kernel command line Joe Perches
2020-05-20 4:41 ` Sergey Senozhatsky
2020-05-20 4:58 ` Joe Perches
2020-05-20 12:10 ` Sergey Senozhatsky
2020-05-20 20:36 ` Joe Perches
2020-05-21 1:00 ` Andrew Morton
2020-05-21 2:09 ` Joe Perches
2020-05-21 4:36 ` Sergey Senozhatsky
2020-05-21 4:40 ` Andrew Morton
2020-05-21 12:31 ` Petr Mladek
2020-05-21 15:08 ` Arvind Sankar
2020-05-21 12:48 ` Sergey Senozhatsky
2020-05-21 4:32 ` Sergey Senozhatsky
2020-05-21 13:46 ` Petr Mladek
2020-05-21 15:59 ` Arvind Sankar
2020-05-21 16:09 ` Joe Perches
2020-06-03 8:48 ` [init] d0bcc26c0d: BUG:kernel_hang_in_early-boot_stage,last_printk:early_console_in_setup_code kernel test robot
2020-05-21 18:40 ` [PATCH] printk: Move and rename maximum printk output line length defines Joe Perches
2020-05-25 8:38 ` Sergey Senozhatsky
2020-05-20 14:01 ` [PATCH] init/main.c: Print all command line when boot Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f37c12c0df59b876236827fcd05b518e28d11a6c.1589916689.git.joe@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
--cc=wangchenggang@vivo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).