Re: [PATCH 2/7] printk: Use consoles_suspended flag when suspending/resuming all consoles

Petr Mladek
2025-06-24T08:41:04Z

On Fri 2025-06-20 16:49:07, John Ogness wrote:
> On 2025-06-13, Petr Mladek <pmladek@suse.com> wrote:
> >> diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> >> index fd12efcc4aeda8883773d9807bc215f6e5cdf71a..72de12396e6f1bc5234acfdf6dcc393acf88d216 100644
> >> --- a/kernel/printk/nbcon.c
> >> +++ b/kernel/printk/nbcon.c
> >> @@ -1147,7 +1147,7 @@ static bool nbcon_kthread_should_wakeup(struct console *con, struct nbcon_contex
> >> cookie = console_srcu_read_lock();
> >>
> >> flags = console_srcu_read_flags(con);
> >> - if (console_is_usable(con, flags, false)) {
> >> + if (console_is_usable(con, flags, false, consoles_suspended)) {
> >
> > The new global console_suspended value has the be synchronized the
> > same way as the current CON_SUSPENDED per-console flag.
> > It means that the value must be:
> >
> > + updated only under console_list_lock together with
> > synchronize_rcu().
> >
> > + read using READ_ONCE() under console_srcu_read_lock()
>
> Yes.
>
> > I am going to propose more solutions because no one is obviously
> > the best one.
>
> [...]
>
> > Variant C:
> > ==========
> >
> > Remove even @flags parameter from console_is_usable() and read both
> > values there directly.
> >
> > Many callers read @flags only because they call console_is_usable().
> > The change would simplify the code.
> >
> > But there are few exceptions:
> >
> > 2. Another exception is __pr_flush() where console_is_usable() is
> > called twice with @use_atomic set "true" and "false".
> >
> > We would want to read "con->flags" only once here. A solution
> > would be to add a parameter to check both con->write_atomic
> > and con->write_thread in a single call.
>
> Or it could become a bitmask of printing types to check:
>
> #define ATOMIC_PRINTING 0x1
> #define NONATOMIC_PRINTING 0x2
>
> and then __pr_flush() looks like:
>
> if (!console_is_usable(c, flags, ATOMIC_PRINTING|NONATOMIC_PRINTING)

I like this. It will help even in all other cases when one mode is needed.
I mean that, for example:

console_is_usable(c, flags, ATOMIC_PRINTING)

is more self-explaining than

console_is_usable(c, flags, true)

Best Regards,
Petr