Re: [Kernel Bug] INFO: task hung in show_cons_active
From: Greg KH
Date: Tue Jun 30 2026 - 10:26:13 EST
On Tue, Jun 30, 2026 at 08:30:39PM +0800, Longxing Li wrote:
> Dear maintainers,
>
> Here's my fix and patch of the bug.
>
> Fix Summary:
>
> The deadlock occurs because unregister_console() holds console_list_lock
> while __pr_flush() blocks on console_sem. show_cons_active() has the same
> lock -> sem ordering (holds mutex, waits for sem), creating a potential
> ABBA when any printer path needs the mutex.
>
> Fix: restructure unregister_console() into three phases:
>
> Phase 1 (list lock): Disable console (clear CON_ENABLED).
> Phase 2 (NO lock): __pr_flush() waits for pending output.
> Safe because console is already disabled.
> Phase 3 (list lock): Remove from list + cleanup.
>
> This ensures __pr_flush() is never called while holding console_list_lock,
> eliminating the lock inversion.
>
> Full patch is as follows and also attached in the link.
>
> =====================================================
> From: Longxing Li <coregee2000@xxxxxxxxx>
> Date: Tue, 30 Jun 2026
> Subject: [PATCH] printk: fix potential deadlock in unregister_console()
>
> unregister_console() holds console_list_lock while calling __pr_flush(),
> which blocks on console_sem. show_cons_active() holds console_mutex (the
> same lock) while also waiting for console_sem. This creates a potential
> ABBA deadlock when any console output path needs console_mutex.
>
> Fix by restructuring unregister_console() so __pr_flush() is called WITHOUT
> holding console_list_lock:
>
> Phase 1 (list lock): Disable console (clear CON_ENABLED).
> Phase 2 (no lock): __pr_flush() drains pending output.
> Phase 3 (list lock): Remove from list + cleanup.
>
> Reported-by: Longxing Li
You are the author, noneed for a reported-by
> Suggested-by: Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx>
I did?
> Signed-off-by: Longxing Li <coregee2000@xxxxxxxxx>
> ---
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -4235,28 +4235,15 @@
> struct console *c;
> int res;
>
> lockdep_assert_console_list_lock_held();
>
> - con_printk(KERN_INFO, console, "disabled\n");
> -
Patch is corruupted and can not be applied :(