mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] linux-4.19.y/printk: Avoid logbuf_lock deadlock in oops_end()
@ 2024-05-28 10:19 Tony W Wang-oc
  2024-05-28 12:47 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Tony W Wang-oc @ 2024-05-28 10:19 UTC (permalink / raw)
  To: tglx, mingo, bp, hpa, x86, jpoimboe, vlovejoy, gregkh, oleg,
	TonyWWang-oc, linux-kernel
  Cc: CobeChen, TimGuo, LeoLiu-oc

A CPU executing vprintk_emit might be interrupted by #PF exception,
this may leads to logbuf_lock deadlock:

CPU x:                            CPU x:
----                              ----
vprintk_emit()
  logbuf_lock_irqsave()
    printk_safe_enter_irqsave()
A:  raw_spin_lock(&logbuf_lock)
  vprintk_store()                 #PF
                                  do_page_fault
                                    ...
                                    oops_end
                                      bust_spinlocks(0)
                                        console_unlock()
                                          ...
                                          printk_safe_enter_irqsave()
B:                                        raw_spin_lock(&logbuf_lock)

logbuf_lock is taken at A and the deadlock happends at B.

Pass 1 to bust_spinlocks() in the oops_end() to avoid this deadlock.

Signed-off-by: Tony W Wang-oc <TonyWWang-oc@zhaoxin.com>
---
 arch/x86/kernel/dumpstack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 7e698c45760c..b4c145ee9536 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -336,7 +336,7 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
 	if (regs && kexec_should_crash(current))
 		crash_kexec(regs);
 
-	bust_spinlocks(0);
+	bust_spinlocks(1);
 	die_owner = -1;
 	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
 	die_nest_count--;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] linux-4.19.y/printk: Avoid logbuf_lock deadlock in oops_end()
  2024-05-28 10:19 [PATCH] linux-4.19.y/printk: Avoid logbuf_lock deadlock in oops_end() Tony W Wang-oc
@ 2024-05-28 12:47 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2024-05-28 12:47 UTC (permalink / raw)
  To: Tony W Wang-oc
  Cc: tglx, mingo, bp, hpa, x86, jpoimboe, vlovejoy, oleg,
	linux-kernel, CobeChen, TimGuo, LeoLiu-oc

On Tue, May 28, 2024 at 06:19:57PM +0800, Tony W Wang-oc wrote:
> A CPU executing vprintk_emit might be interrupted by #PF exception,
> this may leads to logbuf_lock deadlock:
> 
> CPU x:                            CPU x:
> ----                              ----
> vprintk_emit()
>   logbuf_lock_irqsave()
>     printk_safe_enter_irqsave()
> A:  raw_spin_lock(&logbuf_lock)
>   vprintk_store()                 #PF
>                                   do_page_fault
>                                     ...
>                                     oops_end
>                                       bust_spinlocks(0)
>                                         console_unlock()
>                                           ...
>                                           printk_safe_enter_irqsave()
> B:                                        raw_spin_lock(&logbuf_lock)
> 
> logbuf_lock is taken at A and the deadlock happends at B.
> 
> Pass 1 to bust_spinlocks() in the oops_end() to avoid this deadlock.
> 
> Signed-off-by: Tony W Wang-oc <TonyWWang-oc@zhaoxin.com>
> ---
>  arch/x86/kernel/dumpstack.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
> index 7e698c45760c..b4c145ee9536 100644
> --- a/arch/x86/kernel/dumpstack.c
> +++ b/arch/x86/kernel/dumpstack.c
> @@ -336,7 +336,7 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
>  	if (regs && kexec_should_crash(current))
>  		crash_kexec(regs);
>  
> -	bust_spinlocks(0);
> +	bust_spinlocks(1);
>  	die_owner = -1;
>  	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
>  	die_nest_count--;
> -- 
> 2.25.1
> 

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-28 12:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-28 10:19 [PATCH] linux-4.19.y/printk: Avoid logbuf_lock deadlock in oops_end() Tony W Wang-oc
2024-05-28 12:47 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®