Re: [PATCH v2] printk/console: Enable console kthreads only when there is no boot console left

From: Petr Mladek
Date: Tue Jun 21 2022 - 09:55:42 EST


On Tue 2022-06-21 07:45:09, Linus Torvalds wrote:
> On Tue, Jun 21, 2022 at 6:42 AM Daniel Palmer <daniel@xxxxxxxx> wrote:
> >
> > The lockups on boot seem to be gone on my boards with this patch.
>
> Good.
>
> Petr, was this all the reports sorted out? Sounds like we can keep the
> kernel thread model.

Yes, it seems that we fixed all the reports when boot failed or
the console was messed or silent.

There is one more issue, see
https://lore.kernel.org/r/YqyANveL50uxupfQ@xxxxxxxxx
It is about synchronization between messages printed by
userspace and kernel consoles.

The synchronization was never guaranteed. I think that it is
not an argument to remove the kthreads. They are really
needed, especially for huge systems, noisy debugging,
or RT where softlockups really hurts.

My opinion is that we might easily support 3 printk
modes, switched on the command line:

1. Use printk console kthreads when the system is normally
running. It makes printk() predictable and safe. We do
our best to switch to the direct mode when the kthreads
are not reliable, for example, panic, suspend, reboot.

IMHO, it should be default, especially for production
systems.


2. Use an atomic console in fully synchronous mode. It is
inspired by a patch from Peter Zijlstra. It calls
the (serial) console directly from printk() and
uses CPU-reentrant lock to serialize the messages
between CPUs.

AFAIK, Peter and some others use this approach to
debug some nasty bugs in the scheduler, NMI,
early boot when even the legacy code using
console_lock() is not reliable enough.

John Ogness is working on the atomic serial console.
It would allow to integrate this mode a clean
way.

It is not usable for production because printk()
might slow down the entire system.


3. Use the legacy code that tries to call consoles from
printk() via console_trylock(). We need this code
anyway for the early boot, suspend, reboot, panic.

It would be used for debugging nasty bugs like
the 2nd mode for system without serial console.
It will be pretty hard to create lockless
variant for more complicate consoles.


I am not happy that we need more modes. But I think that
they all have a good justification.


Best Regards,
Petr