Re: [patch RFC 28/29] printk: Provide functions for atomic write enforcement

From: John Ogness
Date: Tue Sep 27 2022 - 10:51:30 EST


Below is a fix that was used for the LPC2022 demo so that after a
warning, the atomic printing context is not responsible for printing any
non-emergency backlog that came after the warning.

On 2022-09-11, Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
> --- a/kernel/printk/printk_nobkl.c
> +++ b/kernel/printk/printk_nobkl.c
> + * cons_atomic_flush_one - Flush one console in atomic mode
> + * @con: The console to flush
> + * @prio: The priority of the current context
> + */
> +static void cons_atomic_flush_one(struct console *con, enum cons_prio prio)
> +{
> + struct cons_write_context *wctxt = cons_get_wctxt(con, prio);
> + struct cons_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
> +
> + if (!cons_atomic_try_acquire(con, ctxt, prio))
> + return;
> +
> + do {
> + /*
> + * cons_emit_record() returns false when the console was
> + * handed over or taken over. In both cases the context is
> + * not longer valid.
> + */
> + if (!cons_emit_record(wctxt))
> + return;

If the CPU is no longer in an elevated priority and kthreads are
available, abort the atomic printing and let the kthreads take over. Add
the following break condition here:

/*
* If the CPU is no longer in an elevated priority, let the
* kthreads take over, if they are available.
*/
if (prio <= CONS_PRIO_NORMAL && con->kthread)
break;


> + } while (ctxt->backlog);
> +
> + cons_release(ctxt);
> +}

John Ogness