Re: [linux-next:master] [printk] 8fc5f5fc7f: WARNING:at_kernel/printk/printk.c:#console_flush_all
From: Petr Mladek
Date: Wed Nov 30 2022 - 13:12:41 EST
On Thu 2022-12-01 00:57:06, kernel test robot wrote:
> Greeting,
>
> FYI, we noticed WARNING:at_kernel/printk/printk.c:#console_flush_all due to commit (built with clang-14):
>
> commit: 8fc5f5fc7f52a733fcc8b3939d172b9248e63871 ("printk: introduce console_list_lock")
> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git master
>
> in testcase: boot
>
> on test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 16G
>
> caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):
>
>
> [ 0.000000][ T0] ------------[ cut here ]------------
> [ 0.000000][ T0] WARNING: CPU: 0 PID: 0 at kernel/printk/printk.c:116 console_flush_all (printk.c:?)
When I checked out the commit 8fc5f5fc7f52a733fcc8b3939d172b9248e63871
("printk: introduce console_list_lock") then
kernel/printk/printk.c:116 is:
114 void lockdep_assert_console_list_lock_held(void)
115 {
116 lockdep_assert_held(&console_mutex);
117 }
118 EXPORT_SYMBOL(lockdep_assert_console_list_lock_held);
It is used in
#define for_each_console(con) \
lockdep_assert_console_list_lock_held(); \
hlist_for_each_entry(con, &console_list, node)
that is used in
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handover)
{
[...]
for_each_console(con) {
that is called without console_list_lock().
Hmm, we could not take console_list_lock() here. It would violate lock
ordering. console_flush_all() is called under console_lock(). And
console_list_lock() is taken outside of console_lock() in register_console().
Fortunately, we do not have to do it. for_each_console() is still safe
under console_lock() at this stage. And later patches will switch
it to for_each_console_srcu() that will not require
console_list_lock().
So, the solution is to remove the assert in for_each_console() in
the commit 8fc5f5fc7f52a733fcc8b3939d172b9248e63871 ("printk:
introduce console_list_lock").
We need to add the assert later when removing the console_lock()
synchronization of @console_list in register_console().
Best Regards,
Petr