On Fri 2021-02-19 15:45:21, John Ogness wrote:
> On 2021-02-19, Petr Mladek <pmla...@suse.com> wrote:
> >> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> >> index 20c21a25143d..401df370832b 100644
> >> --- a/kernel/printk/printk.c
> >> +++ b/kernel/printk/printk.c
> >> +/* Return a consistent copy of @syslog_seq. */
> >> +static u64 read_syslog_seq_irq(void)
> >> +{
> >> +  u64 seq;
> >> +
> >> +  raw_spin_lock_irq(&syslog_lock);
> >> +  seq = syslog_seq;
> >> +  raw_spin_unlock_irq(&syslog_lock);
> >
> > Is there any particular reason to disable interrupts here?
> >
> > It would make sense only when the lock could be taken in IRQ
> > context. Then we would need to always disable interrupts when
> > the lock is taken. And if it is taken in IRQ context, we would
> > need to safe flags.
> 
> All other instances of locking @syslog_lock are done with interrupts
> disabled. And we have:
> 
> register_console()
>   logbuf_lock_irqsave()
>     raw_spin_lock(&syslog_lock)

I see. We should revisit this after removing logbuf_lock and
printk_safe context.

> Looking back through history, I found that locking of the "console lock"
> in register_console() was changed from spin_lock_irq() to
> spin_lock_irqsave() for 2.3.15pre1 [0]. The only reason I can find why
> that was done is because sparc64 was regstering its console in a PROM
> callback (the comments there: "Pretty sick eh?").

Note that console_lock was a spinlock in 2.3.15.pre1. I see it defined
in kernel/printk.c as:

spinlock_t console_lock = SPIN_LOCK_UNLOCKED;

But it is a sleeping semaphore these days. As a result,
register_console(), as it is now, must not be called in an interrupt context.

Best Regards,
Petr

Reply via email to