Re: syslog: was: [PATCH next v2 3/3] printk: remove logbuf_lock, add syslog_lock

From: Petr Mladek
Date: Mon Dec 07 2020 - 05:02:34 EST


On Sun 2020-12-06 22:12:21, John Ogness wrote:
> On 2020-12-04, Petr Mladek <pmladek@xxxxxxxx> wrote:
> > On Tue 2020-12-01 21:59:41, John Ogness wrote:
> >> Since the ringbuffer is lockless, there is no need for it to be
> >> protected by @logbuf_lock. Remove @logbuf_lock.
> >>
> >> --- a/kernel/printk/printk.c
> >> +++ b/kernel/printk/printk.c
> >> @@ -2809,11 +2856,7 @@ void register_console(struct console *newcon)
> >> nr_ext_console_drivers++;
> >>
> >> if (newcon->flags & CON_PRINTBUFFER) {
> >> - /*
> >> - * console_unlock(); will print out the buffered messages
> >> - * for us.
> >> - */
> >> - logbuf_lock_irqsave(flags);
> >> + spin_lock_irqsave(&syslog_lock, flags);
> >
> > We should take the lock only around assigning syslog_seq. And add a
> > comment that it guarantees atomic update.
>
> OK. So you just want "exclusive_console = newcon;" moved outside the
> critical section.

Exactly, I would like to make it clear that it synchronizes only the
single assignment. Otherwise, people might get wrong assumption.

I know that there is a comment describing the scope of each lock.
But people might miss it or do not search for it at all.

Best Regards,
Petr