Re: [PATCH printk v5 06/17] printk: nbcon: Introduce printer kthreads

From: Petr Mladek
Date: Mon Sep 02 2024 - 10:19:43 EST


On Fri 2024-08-30 17:35:05, John Ogness wrote:
> From: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>
> Provide the main implementation for running a printer kthread
> per nbcon console that is takeover/handover aware. This
> includes:
>
> - new mandatory write_thread() callback
> - kthread creation
> - kthread main printing loop
> - kthread wakeup mechanism
> - kthread shutdown

I have found one more small problem.

> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -1036,6 +1042,225 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt, bool use_a
[...]
> +/**
> + * nbcon_kthreads_wake - Wake up printing threads using irq_work
> + */
> +void nbcon_kthreads_wake(void)
> +{
> + struct console *con;
> + int cookie;
> +
> + if (!printk_kthreads_running)
> + return;
> +
> + cookie = console_srcu_read_lock();
> + for_each_console_srcu(con) {
> + /*
> + * Only schedule irq_work if the printing thread is
> + * actively waiting. If not waiting, the thread will
> + * notice by itself that it has work to do.
> + */
> + if (rcuwait_has_sleeper(&con->rcuwait))

This is called for all consoles but con->rcuwait is initialized
only for nbcon consoles.

I would add above this check:

+ if (!(console_srcu_read_flags(con) & CON_NBCON))
+ continue;

> + irq_work_queue(&con->irq_work);
> + }
> + console_srcu_read_unlock(cookie);
> +}
> +

With the added check:

Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>

Best Regards,
Petr