Re: [PATCH] printk: queue wake_up_klogd irq_work only if per-CPU areas are ready

From: Sergey Senozhatsky
Date: Tue Mar 03 2020 - 05:28:00 EST


On (20/03/03 10:18), Petr Mladek wrote:
[..]
> > static void queue_flush_work(struct printk_safe_seq_buf *s)
> > {
> > - if (printk_safe_irq_ready)
> > + if (printk_percpu_data_ready())
> > irq_work_queue(&s->work);
>
> This is not safe. printk_percpu_data_ready() returns true even before
> s->work gets initialized by printk_safe_init().

Good catch! I'll move printk_safe_init() call from init/main.c to
set_percpu_data_ready().

> Solution would be to call printk_safe_init() from
> setup_log_buf() before calling set_percpu_data_ready().

I'll move the init call. But printk_safe/nmi called too-early
will still write to no-yet-initialised per-cpu data.

-ss