Re: [PATCH next v3 3/3] printk: remove logbuf_lock protection for ringbuffer

From: John Ogness
Date: Tue Dec 08 2020 - 02:46:32 EST


On 2020-12-07, John Ogness <john.ogness@xxxxxxxxxxxxx> wrote:
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index e1f068677a74..f3c0fcc3163f 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
[...]
> int vprintk_store(int facility, int level,
> const struct dev_printk_info *dev_info,
> const char *fmt, va_list args)
> {
> const u32 caller_id = printk_caller_id();
> - static char textbuf[LOG_LINE_MAX];
> struct prb_reserved_entry e;
> enum log_flags lflags = 0;
> struct printk_record r;
> u16 trunc_msg_len = 0;
> - char *text = textbuf;
> + char prefix_buf[8];
> + va_list args2;
> u16 text_len;
> + int ret = 0;
> u64 ts_nsec;
>
> /*
> @@ -1884,35 +1951,21 @@ int vprintk_store(int facility, int level,
> */
> ts_nsec = local_clock();
>
> + va_copy(args2, args);
> +
> /*
> * The printf needs to come first; we need the syslog
> * prefix which might be passed-in as a parameter.
> */
> - text_len = vscnprintf(text, sizeof(textbuf), fmt, args);
> + text_len = vsnprintf(&prefix_buf[0], sizeof(prefix_buf), fmt, args) + 1;
> + if (text_len > CONSOLE_LOG_MAX)
> + text_len = CONSOLE_LOG_MAX;

LOG_LINE_MAX should be the limit. That was the size of the static
@textbuf.

John Ogness