Re: [PATCH printk v5 1/1] printk: extend console_lock for per-console locking

From: Petr Mladek
Date: Thu Apr 28 2022 - 10:54:58 EST


On Wed 2022-04-27 18:21:16, John Ogness wrote:
> Hi Marek,
>
> On 2022-04-27, Marek Szyprowski <m.szyprowski@xxxxxxxxxxx> wrote:
> > Here is the full serial console log:
> >
> > https://pastebin.com/E5CDH88L
>
> Here are a few ideas from me:
>
> 3. It looks like the problem happens quite late in the boot process. I
> expect it is due to some userspace process that is running that is
> interacting with printk (either /dev/kmsg or /proc/kmsg) and is causing
> problems.

I did not find an real issue in the code handling /dev/kmsg,
/proc/kmsg, or syslog sycall API. There might be just few
small changes:

1. There is an increased number of spurious wakeups because
log_wait is shared between upstream readers and printk kthreads.
And we newly wake up waiters from both vprintk_emit()
and __console_unlock() code paths.

It might affect especially the pooling APIs: kmsg_pool(),
devkmsg_pool()). They might return 0 more often than before.


2. 4th patch replaced wake_up_interruptible(&log_wait) with
wake_up_interruptible_all(&log_wait). As a result, all
readers are woken at the same time.

It is perfectly fine because the log buffer is lockless.
And all readers should be either independent or synchronized
against each other.


Any of the above changes should not introduce new problems. But
they might make some old problem (race) more visible.

I spent quite some time reviewing the code and testing. But I neither
see any problem nor I am able to reproduce it. Some more clues
from Marek would be needed.

Best Regards,
Petr