Re: [RFC][PATCHv4 3/6] printk: introduce per-cpu safe_print seq buffer
From: Sergey Senozhatsky
Date: Wed Nov 30 2016 - 20:08:49 EST
On (11/24/16 17:58), Petr Mladek wrote:
[..]
> > +#ifdef CONFIG_PRINTK
> > +
> > +#define PRINTK_SAFE_CONTEXT_MASK 0x7fffffff
> > +#define PRINTK_SAFE_NMI_CONTEXT_MASK 0x80000000
>
> What about shorter name PRINTK_NMI_CONTEXT_MASK?
ok.
> > diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c
> > index 1f66163..af74d9c 100644
> > --- a/kernel/printk/printk_safe.c
> > +++ b/kernel/printk/printk_safe.c
> > @@ -50,27 +49,26 @@ struct printk_safe_seq_buf {
> > struct irq_work work; /* IRQ work that flushes the buffer */
> > unsigned char buffer[SAFE_LOG_BUF_LEN];
> > };
> > +
> > +static DEFINE_PER_CPU(struct printk_safe_seq_buf, safe_print_seq);
> > +static DEFINE_PER_CPU(int, printk_safe_context);
>
> I would personally use the short name "printk_context". It is a generic
> value. Zero value means that it is a normal context. Also there is
> an idea to add KDB context that would use its own vprintk_kdb()
> implementation and will not use the printk_safe buffer.
ok.
> > - if (len >= sizeof(s->buffer)) {
> > - atomic_inc(&nmi_message_lost);
> > - return 0;
> > - }
> > + if (len >= sizeof(s->buffer))
> > + return -E2BIG;
>
> E2BIG means "argument list too long" and does not fit much here.
> I would suggest to use -ENOSPC. It is not ideal either but it fits
> slightly better.
ok.
> > +/*
> > + * Lockless printk(), to avoid deadlocks should the printk() recurse
> > + * into itself. It uses a per-CPU buffer to store the message, just like
> > + * NMI.
> > + */
> > +static int vprintk_safe(const char *fmt, va_list args)
> > +{
> > + struct printk_safe_seq_buf *s = this_cpu_ptr(&safe_print_seq);
> > +
> > + return printk_safe_log_store(s, fmt, args);
>
> We should return zero if printk_safe_log_store() returns an error.
> I know that it will get fixed in the next patch. But we should do
> some minimum sanity check here because of bisection.
ok.
-ss