From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH printk v5 26/30] printk: nbcon: Implement emergency sections
Date: Tue, 21 May 2024 14:37:08 +0200 [thread overview]
Message-ID: <ZkyVdD4alTWw2I_a@pathway.suse.cz> (raw)
In-Reply-To: <87h6fbi5q8.fsf@jogness.linutronix.de>
On Mon 2024-05-06 12:45:59, John Ogness wrote:
> On 2024-05-02, John Ogness <john.ogness@linutronix.de> wrote:
> > diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> > index 8f6b3858ab27..991e2702915c 100644
> > --- a/kernel/printk/nbcon.c
> > +++ b/kernel/printk/nbcon.c
> > +void nbcon_cpu_emergency_exit(void)
> > +{
> > + unsigned int *cpu_emergency_nesting;
> > + bool do_trigger_flush = false;
> > +
> > + cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting();
> > +
> > + /*
> > + * Flush the messages before enabling preemtion to see them ASAP.
> > + *
> > + * Reduce the risk of potential softlockup by using the
> > + * flush_pending() variant which ignores messages added later. It is
> > + * called before decrementing the counter so that the printing context
> > + * for the emergency messages is NBCON_PRIO_EMERGENCY.
> > + */
> > + if (*cpu_emergency_nesting == 1) {
> > + nbcon_atomic_flush_pending();
> > + do_trigger_flush = true;
> > + }
> > +
> > + (*cpu_emergency_nesting)--;
> > +
> > + if (WARN_ON_ONCE(*cpu_emergency_nesting < 0))
> > + *cpu_emergency_nesting = 0;
>
> I see two issues here. First, this is unsigned. kernel test robot
> reported:
>
> > kernel/printk/nbcon.c:1540 nbcon_cpu_emergency_exit() warn: unsigned
> > '*cpu_emergency_nesting' is never less than zero.
>
> Also, in this situation, we are allowing a brief window of activated
> emergency mode by allowing it to become !0 before correcting
> it. Instead, we should avoid illegally decrementing. I suggest:
Great catch!
> void nbcon_cpu_emergency_exit(void)
> {
> unsigned int *cpu_emergency_nesting;
> bool do_trigger_flush = false;
>
> cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting();
>
> /*
> * Flush the messages before enabling preemtion to see them ASAP.
> *
> * Reduce the risk of potential softlockup by using the
> * flush_pending() variant which ignores messages added later. It is
> * called before decrementing the counter so that the printing context
> * for the emergency messages is NBCON_PRIO_EMERGENCY.
> */
> if (*cpu_emergency_nesting == 1) {
> nbcon_atomic_flush_pending();
> do_trigger_flush = true;
> }
>
> if (!WARN_ON_ONCE(*cpu_emergency_nesting == 0))
> (*cpu_emergency_nesting)--;
Looks good.
> preempt_enable();
>
> if (do_trigger_flush)
> printk_trigger_flush();
> }
Best Regards,
Petr
next prev parent reply other threads:[~2024-05-21 12:37 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-02 21:38 [PATCH printk v5 00/30] wire up write_atomic() printing John Ogness
2024-05-02 21:38 ` [PATCH printk v5 01/30] printk: Add notation to console_srcu locking John Ogness
2024-05-07 12:16 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 02/30] printk: Properly deal with nbcon consoles on seq init John Ogness
2024-05-02 21:38 ` [PATCH printk v5 03/30] printk: nbcon: Remove return value for write_atomic() John Ogness
2024-05-02 21:38 ` [PATCH printk v5 04/30] printk: Check printk_deferred_enter()/_exit() usage John Ogness
2024-05-02 21:38 ` [PATCH printk v5 05/30] printk: nbcon: Add detailed doc for write_atomic() John Ogness
2024-05-07 12:26 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 06/30] printk: nbcon: Add callbacks to synchronize with driver John Ogness
2024-05-17 13:31 ` Petr Mladek
2024-05-17 14:00 ` John Ogness
2024-05-17 14:40 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 07/30] printk: nbcon: Use driver synchronization while (un)registering John Ogness
2024-05-06 10:27 ` John Ogness
2024-05-17 13:44 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 08/30] serial: core: Provide low-level functions to lock port John Ogness
2024-05-02 21:38 ` [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
2024-05-03 8:09 ` Théo Lebrun
2024-05-04 16:08 ` Greg Kroah-Hartman
2024-05-17 14:51 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 10/30] console: Improve console_srcu_read_flags() comments John Ogness
2024-05-17 14:55 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 11/30] nbcon: Provide functions for drivers to acquire console for non-printing John Ogness
2024-05-06 10:29 ` John Ogness
2024-05-20 12:13 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 12/30] serial: core: Implement processing in port->lock wrapper John Ogness
2024-05-04 16:08 ` Greg Kroah-Hartman
2024-05-20 12:22 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 13/30] printk: nbcon: Do not rely on proxy headers John Ogness
2024-05-02 21:38 ` [PATCH printk v5 14/30] printk: nbcon: Fix kerneldoc for enums John Ogness
2024-05-02 21:38 ` [PATCH printk v5 15/30] printk: Make console_is_usable() available to nbcon John Ogness
2024-05-02 21:38 ` [PATCH printk v5 16/30] printk: Let console_is_usable() handle nbcon John Ogness
2024-05-02 21:38 ` [PATCH printk v5 17/30] printk: Add @flags argument for console_is_usable() John Ogness
2024-05-02 21:38 ` [PATCH printk v5 18/30] printk: nbcon: Add helper to assign priority based on CPU state John Ogness
2024-05-02 21:38 ` [PATCH printk v5 19/30] printk: nbcon: Provide function to flush using write_atomic() John Ogness
2024-05-20 15:04 ` Petr Mladek
2024-05-21 19:07 ` John Ogness
2024-05-02 21:38 ` [PATCH printk v5 20/30] printk: Track registered boot consoles John Ogness
2024-05-02 21:38 ` [PATCH printk v5 21/30] printk: nbcon: Use nbcon consoles in console_flush_all() John Ogness
2024-05-21 8:41 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 22/30] printk: nbcon: Add unsafe flushing on panic John Ogness
2024-05-02 21:38 ` [PATCH printk v5 23/30] printk: Avoid console_lock dance if no legacy or boot consoles John Ogness
2024-05-02 21:38 ` [PATCH printk v5 24/30] printk: Track nbcon consoles John Ogness
2024-05-02 21:38 ` [PATCH printk v5 25/30] printk: Coordinate direct printing in panic John Ogness
2024-05-02 21:38 ` [PATCH printk v5 26/30] printk: nbcon: Implement emergency sections John Ogness
2024-05-06 10:39 ` John Ogness
2024-05-21 12:37 ` Petr Mladek [this message]
2024-05-21 13:38 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 27/30] panic: Mark emergency section in warn John Ogness
2024-05-02 21:38 ` [PATCH printk v5 28/30] panic: Mark emergency section in oops John Ogness
2024-05-02 21:38 ` [PATCH printk v5 29/30] rcu: Mark emergency sections in rcu stalls John Ogness
2024-05-21 14:03 ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 30/30] lockdep: Mark emergency sections in lockdep splats John Ogness
2024-05-21 15:13 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZkyVdD4alTWw2I_a@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox