printk: Deadlock in NMI regression
Subsystems (4)
Petr Mladek
maintainerPATCH v2 2/3 printk: Create helper function to queue deferred console handling
In reply to Petr MladekIt is just a preparation step. The patch does not change the existing behavior.
--- kernel/printk/printk.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/printk/printk.c +9 -5
@@ -2887,16 +2887,20 @@ void wake_up_klogd(void)preempt_enable (); } -int vprintk_deferred (const char *fmt,va_list args) +void defer_console (void ) { -int r; - - r =vprintk_emit (0 ,LOGLEVEL_SCHED ,NULL ,0 , fmt, args); -preempt_disable ();__this_cpu_or (printk_pending,PRINTK_PENDING_OUTPUT );irq_work_queue (this_cpu_ptr (&wake_up_klogd_work));preempt_enable (); +} + +int vprintk_deferred (const char *fmt,va_list args) +{ +int r; + + r =vprintk_emit (0 ,LOGLEVEL_SCHED ,NULL ,0 , fmt, args); +defer_console ();return r; }
Signature · 1 line
2.13.7
Petr Mladek
maintainerv2 cover printk: Deadlock in NMI regression
The commit 719f6a7040f1bdaf96 ("printk: Use the main logbuf in NMI when logbuf_lock is available") brought back the possible deadlocks in printk() and NMI.
This is rework of the proposed fix, see
https://lkml.kernel.org/r/[email protected]
I realized that we could rather easily move the check to vprintk_func() and still avoid any race. I believe that this is a win-win solution.
Changes against v1:
+ Move the check from vprintk_emit() to vprintk_func()
+ More straightforward commit message
+ Fix build with CONFIG_PRINTK_NMI disabled
Petr Mladek (3):
printk: Split the code for storing a message into the log buffer
printk: Create helper function to queue deferred console handling printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
include/linux/printk.h | 4 ++++ kernel/printk/internal.h | 9 ++++++- kernel/printk/printk.c | 57 +++++++++++++++++++++++++++----------------- kernel/printk/printk_safe.c | 58 +++++++++++++++++++++++++++++---------------- kernel/trace/trace.c | 4 +++- lib/nmi_backtrace.c | 3 --- 6 files changed, 87 insertions(+), 48 deletions(-)
Signature · 1 line
2.13.7
Petr Mladek
maintainerPATCH v2 1/3 printk: Split the code for storing a message into the log buffer
It is just a preparation step. The patch does not change the existing behavior.
--- kernel/printk/printk.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-)
kernel/printk/printk.c +26 -17
@@ -1824,28 +1824,16 @@ static size_t log_output(int facility, int level, enum log_flags lflags, const creturn log_store (facility, level, lflags,0 , dict, dictlen, text, text_len); } -asmlinkage int vprintk_emit(int facility, int level, -const char *dict,size_t dictlen, -const char *fmt,va_list args) +/* Must be called under logbuf_lock. */ +int vprintk_store (int facility,int level, +const char *dict,size_t dictlen, +const char *fmt,va_list args) {static char textbuf[LOG_LINE_MAX ];char *text = textbuf;size_t text_len;enum log_flags lflags =0 ; -unsigned long flags; -int printed_len; -bool in_sched = false; - -if (level ==LOGLEVEL_SCHED ) { - level =LOGLEVEL_DEFAULT ; - in_sched = true; - } - -boot_delay_msec (level); -printk_delay (); -/* This stops the holder of console_sem just where we want him */ -logbuf_lock_irqsave (flags);/* * The printf needs to come first; we need the syslog * prefix which might be passed-in as a parameter.
@@ -1886,8 +1874,29 @@ asmlinkage int vprintk_emit(int facility, int level,if (dict) lflags |=LOG_PREFIX |LOG_NEWLINE ; - printed_len =log_output (facility, level, lflags, dict, dictlen, text, text_len); +return log_output (facility, level, lflags, + dict, dictlen, text, text_len); +} +asmlinkage int vprintk_emit(int facility, int level, +const char *dict,size_t dictlen, +const char *fmt,va_list args) +{ +int printed_len; +bool in_sched = false; +unsigned long flags; + +if (level ==LOGLEVEL_SCHED ) { + level =LOGLEVEL_DEFAULT ; + in_sched = true; + } + +boot_delay_msec (level); +printk_delay (); + +/* This stops the holder of console_sem just where we want him */ +logbuf_lock_irqsave (flags); + printed_len =vprintk_store (facility, level, dict, dictlen, fmt, args);logbuf_unlock_irqrestore (flags);/* If called from the scheduler, we can not call up(). */
Signature · 1 line
2.13.7
Quoted 11 lines · Petr Mladek
The commit
719f6a7040f1bdaf96("printk: Use the main logbuf in NMI whenlogbuf_lockis available") brought back the possible deadlocks inprintk()and NMI.This is rework of the proposed fix, see
https://lkml.kernel.org/r/[email protected]I realized that we could rather easily move the check to
vprintk_func()and still avoid any race. I believe that this is a win-win solution.
Quoted 5 lines
Changes against v1:
+ Move the check from
vprintk_emit()tovprintk_func()
+ More straightforward commit message
+ Fix build withCONFIG_PRINTK_NMIdisabled
Did I miss out V1?
Quoted 4 lines
Petr Mladek (3):
printk: Split the code for storing a message into the log buffer
printk: Create helper function to queue deferred console handling printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
Patch 3/3 is not in my mailbox, somehow [I checked the spam folder]. I'm not Cc-ed or the message got lost somewhere before it reached my gmail?
-ss
Petr Mladek
maintainerPATCH v2 3/3 printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
In reply to Petr MladekThe commit 719f6a7040f1bdaf96 ("printk: Use the main logbuf in NMI when logbuf_lock is available") brought back the possible deadlocks in printk() and NMI.
The check of logbuf_lock is done only in printk_nmi_enter() to prevent mixed output. But another CPU might take the lock later, enter NMI, and:
+ Both NMIs might be serialized by yet another lock, for example, the one in nmi_cpu_backtrace().
+ The other CPU might get stopped in NMI, see smp_send_stop() in panic().
The only safe solution is to use trylock when storing the message into the main log-buffer. It might cause reordering when some lines go to the main lock buffer directly and others are delayed via the per-CPU buffer. It means that it is not useful in general.
This patch replaces the problematic NMI deferred context with NMI direct context. It can be used to mark a code that might produce many messages in NMI and the risk of losing them is more critical than problems with eventual reordering.
The context is then used when dumping trace buffers on oops. It was the primary motivation for the original fix. Also the reordering is even smaller issue there because some traces have their own time stamps.
Finally, nmi_cpu_backtrace() need not longer be serialized because it will always us the per-CPU buffers again.
--- include/linux/printk.h | 4 ++++ kernel/printk/internal.h | 9 ++++++- kernel/printk/printk_safe.c | 58 +++++++++++++++++++++++++++++---------------- kernel/trace/trace.c | 4 +++- lib/nmi_backtrace.c | 3 --- 5 files changed, 52 insertions(+), 26 deletions(-)
include/linux/printk.h +4 -0
@@ -148,9 +148,13 @@ void early_printk(const char *s, ...) { }#ifdef CONFIG_PRINTK_NMI extern void printk_nmi_enter (void );extern void printk_nmi_exit (void ); +extern void printk_nmi_direct_enter (void ); +extern void printk_nmi_direct_exit (void );#else static inline void printk_nmi_enter (void ) { }static inline void printk_nmi_exit (void ) { } +static inline void printk_nmi_direct_enter (void ) { } +static inline void printk_nmi_direct_exit (void ) { }#endif /* PRINTK_NMI */ #ifdef CONFIG_PRINTK
kernel/printk/internal.h +8 -1
@@ -19,11 +19,16 @@#ifdef CONFIG_PRINTK #define PRINTK_SAFE_CONTEXT_MASK 0x3fffffff -#define PRINTK_NMI_DEFERRED_CONTEXT_MASK 0x40000000 +#define PRINTK_NMI_DIRECT_CONTEXT_MASK 0x40000000#define PRINTK_NMI_CONTEXT_MASK 0x80000000extern raw_spinlock_t logbuf_lock; +__printf(5, 0) +int vprintk_store (int facility,int level, +const char *dict,size_t dictlen, +const char *fmt,va_list args); + __printf(1, 0) int vprintk_default(const char *fmt, va_list args); __printf(1, 0) int vprintk_deferred(const char *fmt, va_list args); __printf(1, 0) int vprintk_func(const char *fmt, va_list args);
@@ -54,6 +59,8 @@ void __printk_safe_exit(void);local_irq_enable (); \ } while (0) +void defer_console(void); +#else __printf(1, 0) int vprintk_func(const char *fmt, va_list args) { return 0; }
kernel/printk/printk_safe.c +37 -21
80 lines not on this page · raw message
kernel/trace/trace.c +3 -1
@@ -8279,6 +8279,7 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)tracing_off ();local_irq_save (flags); +printk_nmi_direct_enter ();/* Simulate the iterator */ trace_init_global_iter (&iter);
@@ -8358,7 +8359,8 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)for_each_tracing_cpu (cpu) {atomic_dec (&per_cpu_ptr (iter.trace_buffer->data, cpu)->disabled); } -atomic_dec (&dump_running); +atomic_dec (&dump_running); +printk_nmi_direct_exit ();local_irq_restore (flags); }EXPORT_SYMBOL_GPL (ftrace_dump);
lib/nmi_backtrace.c +0 -3
@@ -87,11 +87,9 @@ void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,bool nmi_cpu_backtrace (struct pt_regs *regs) { -static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;int cpu =smp_processor_id ();if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { -arch_spin_lock (&lock);if (regs &&cpu_in_idle (instruction_pointer (regs))) {pr_warn ("NMI backtrace for cpu %d skipped: idling at %pS\n" , cpu, (void *)instruction_pointer (regs));
@@ -102,7 +100,6 @@ bool nmi_cpu_backtrace(struct pt_regs *regs)else dump_stack (); } -arch_spin_unlock (&lock);cpumask_clear_cpu (cpu,to_cpumask (backtrace_mask));return true; }
Signature · 1 line
2.13.7
Quoted 8 lines · Sergey Senozhatsky
Quoted 4 lines
Petr Mladek (3):
printk: Split the code for storing a message into the log buffer
printk: Create helper function to queue deferred console handling printk/nmi: Prevent deadlock when accessing the main log buffer in NMIPatch 3/3 is not in my mailbox, somehow [I checked the spam folder]. I'm not Cc-ed or the message got lost somewhere before it reached my gmail?
UPD: 3/3 just arrived, with a 12 minutes delay.
-ss
Petr Mladek
maintainerQuoted 7 lines · Sergey Senozhatsky
Quoted 6 lines · Petr Mladek
The commit
719f6a7040f1bdaf96("printk: Use the main logbuf in NMI whenlogbuf_lockis available") brought back the possible deadlocks inprintk()and NMI.This is rework of the proposed fix, see
https://lkml.kernel.org/r/[email protected]
Grr, the right link is
https://lkml.kernel.org/r/[email protected]
Quoted 11 lines
Quoted 9 lines
I realized that we could rather easily move the check to
vprintk_func()and still avoid any race. I believe that this is a win-win solution.Changes against v1:
+ Move the check from
vprintk_emit()tovprintk_func()
+ More straightforward commit message
+ Fix build withCONFIG_PRINTK_NMIdisabledDid I miss out V1?
It is the above fixed link. I am sorry for the confusion.
Quoted 8 lines
Quoted 4 lines
Petr Mladek (3):
printk: Split the code for storing a message into the log buffer
printk: Create helper function to queue deferred console handling printk/nmi: Prevent deadlock when accessing the main log buffer in NMIPatch 3/3 is not in my mailbox, somehow [I checked the spam folder]. I'm not Cc-ed or the message got lost somewhere before it reached my gmail?
Ah, the following line somehow confused git send-mail and the message had broken list of recipients:
I have sent it once again as you have already noticed.
Best Regards,
Petr
Re: [PATCH v2 1/3] printk: Split the code for storing a message into the log buffer
In reply to Petr MladekOn (06/27/18 16:08), Petr Mladek wrote:
[..]
kernel/printk/printk.c asmlinkage int vprintk_emit(int facility, int level, · line 1879
Quoted 7 lines
kernel/printk/printk.c +3
-1if (dict) lflags |=LOG_PREFIX |LOG_NEWLINE ; - printed_len =log_output (facility, level, lflags, dict, dictlen, text, text_len); +return log_output (facility, level, lflags, + dict, dictlen, text, text_len); +}
YAYY!
-ss
Re: [PATCH v2 2/3] printk: Create helper function to queue deferred console handling
In reply to Petr MladekQuoted 11 lines · Petr Mladek
kernel/printk/printk.c +1
-5-int vprintk_deferred (const char *fmt,va_list args) +void defer_console (void ) { -int r; - - r =vprintk_emit (0 ,LOGLEVEL_SCHED ,NULL ,0 , fmt, args); -preempt_disable ();__this_cpu_or (printk_pending,PRINTK_PENDING_OUTPUT );irq_work_queue (this_cpu_ptr (&wake_up_klogd_work));preempt_enable ();
kernel/printk/printk.c void wake_up_klogd(void) · line 2905
Quoted 10 lines
kernel/printk/printk.c +8
-0+} + +int vprintk_deferred (const char *fmt,va_list args) +{ +int r; + + r =vprintk_emit (0 ,LOGLEVEL_SCHED ,NULL ,0 , fmt, args); +defer_console ();return r;
You can just call vprintk_emit(LOGLEVEL_SCHED) from vprintk_func(), then you don't need to factor out vprintk_deferred() and vprintk_emit(). Any reason for that split?
I'd also may be prefer to have a bit different name. I'm talking about defer_console().
Other than that
-ss
Re: [PATCH v2 2/3] printk: Create helper function to queue deferred console handling
Quoted 4 lines · Sergey Senozhatsky
You can just call
vprintk_emit(LOGLEVEL_SCHED)fromvprintk_func(), then you don't need to factor outvprintk_deferred()andvprintk_emit(). Any reason for that split?
My bad, no you can't. I forgot that for direct_nmi vprintk_func() logbuf_lock is locked at the upper level - vprintk_func().
-ss
Re: [PATCH v2 3/3] printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
In reply to Petr MladekQuoted 5 lines · Petr Mladek
kernel/printk/printk_safe.c +5
-0+/* +* Marks a code that might produce many messages in NMI context +* and the risk of losing them is more critical than eventual +* reordering. +*
kernel/printk/printk_safe.c static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args) · line 333
Quoted 10 lines
kernel/printk/printk_safe.c +10
-0+* It has effect only when called in NMI context. Then printk() +* will try to store the messages into the main logbuf directly +* and use the per-CPU buffers only as a fallback when the lock +* is not available. +*/ +void printk_nmi_direct_enter (void ) +{ +if (this_cpu_read (printk_context) &PRINTK_NMI_CONTEXT_MASK ) +this_cpu_or (printk_context,PRINTK_NMI_DIRECT_CONTEXT_MASK ); +}
A side note: This nesting also handles recursive printk-s for us.
NMI:
printk_nmi_enter
ftrace_dump
printk_nmi_direct_enter
vprintk_func
spin_lock(logbuf_lock)
vprintk_store
vsprintf
WARN_ON
vprintk_func
vprintk_nmi
Quoted 5 lines
__printf(1, 0)intvprintk_func(const char *fmt, va_list args){kernel/printk/printk_safe.c +3
-0+/* +* Try to use the main logbuf even in NMI. But avoid calling console +* drivers that might have their own locks.
kernel/printk/printk_safe.c void __printk_safe_exit(void) · line 387
Quoted 10 lines
kernel/printk/printk_safe.c +10
-0+*/ +if ((this_cpu_read (printk_context) &PRINTK_NMI_DIRECT_CONTEXT_MASK ) && +raw_spin_trylock (&logbuf_lock)) { +int len; + + len =vprintk_store (0 ,LOGLEVEL_DEFAULT ,NULL ,0 , fmt, args); +raw_spin_unlock (&logbuf_lock); +defer_console (); +return len; + }
So, maybe, something a bit better than defer_console().
Otherwise,
-ss
Quoted 3 lines · Petr Mladek
kernel/printk/printk.c | 57 +++++++++++++++++++++++++++----------------- kernel/printk/printk_safe.c | 58 +++++++++++++++++++++++++++++----------------
Shall we just merge these two?
-ss
On (06/27/18 16:34), Petr Mladek wrote:
[..]
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Changes against v1:
+ Move the check from
vprintk_emit()tovprintk_func()
+ More straightforward commit message
+ Fix build withCONFIG_PRINTK_NMIdisabledDid I miss out V1?
It is the above fixed link. I am sorry for the confusion.
Ah, yep.
[..]
Quoted 6 lines
Ah, the following line somehow confused git send-mail and the message had broken list of recipients:
Cc [email protected] # 4.13+I have sent it once again as you have already noticed.
Got it. Happened to me before as well. I asked because I sort of have some suspicion that lkml email deliver has not been completely reliable lately.
-ss
Petr Mladek
maintainerQuoted 6 lines · Sergey Senozhatsky
Quoted 3 lines · Petr Mladek
kernel/printk/printk.c | 57 +++++++++++++++++++++++++++----------------- kernel/printk/printk_safe.c | 58 +++++++++++++++++++++++++++++----------------Shall we just merge these two?
Do you mean to merge files or the patches, please?
I would prefer to keep it as is in both cases.
The printk code could deserve a clean up but I would rather split it into more files than the opposite.
Best Regards,
Petr
Petr Mladek
maintainerRe: [PATCH v2 3/3] printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
In reply to Sergey SenozhatskyQuoted 19 lines · Sergey Senozhatsky
Quoted 5 lines · Petr Mladek
kernel/printk/printk_safe.c +5
-0+/* +* Marks a code that might produce many messages in NMI context +* and the risk of losing them is more critical than eventual +* reordering. +* kernel/printk/printk_safe.c static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args) · line 333
Quoted 10 lines
kernel/printk/printk_safe.c +10
-0+* It has effect only when called in NMI context. Then printk() +* will try to store the messages into the main logbuf directly +* and use the per-CPU buffers only as a fallback when the lock +* is not available. +*/ +void printk_nmi_direct_enter (void ) +{ +if (this_cpu_read (printk_context) &PRINTK_NMI_CONTEXT_MASK ) +this_cpu_or (printk_context,PRINTK_NMI_DIRECT_CONTEXT_MASK ); +}A side note: This nesting also handles recursive printk-s for us.
Quoted 11 lines
NMI:
printk_nmi_enter
ftrace_dump
printk_nmi_direct_enter
vprintk_func
spin_lock(logbuf_lock)
vprintk_store
vsprintf
WARN_ON
vprintk_func
vprintk_nmi
Uff, it seems that the current design is "good" at lest from some points of view.
Quoted 9 lines
Quoted 9 lines
__printf(1, 0)intvprintk_func(const char *fmt, va_list args){kernel/printk/printk_safe.c +7
-0+/* +* Try to use the main logbuf even in NMI. But avoid calling console +* drivers that might have their own locks. +*/ +if ((this_cpu_read (printk_context) &PRINTK_NMI_DIRECT_CONTEXT_MASK ) && +raw_spin_trylock (&logbuf_lock)) { +int len;
Quoted 8 lines
kernel/printk/printk_safe.c void __printk_safe_exit(void) · line 387
Quoted 6 lines
kernel/printk/printk_safe.c +6
-0+ + len =vprintk_store (0 ,LOGLEVEL_DEFAULT ,NULL ,0 , fmt, args); +raw_spin_unlock (&logbuf_lock); +defer_console (); +return len; + }So, maybe, something a bit better than
defer_console().
I am not super happy with the name either. But wakeup_console(), schedule_console(), or queue_console() looked confusing.
Also I thought about poke_console() but I guess that I already suggested this name in the past and people did not like it.
Feel free to suggest anything.
Quoted 2 lines
Otherwise,
Anyway, thanks a lot for review.
Best Regards,
Petr
Re: [PATCH v2 3/3] printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
Quoted 15 lines · Petr Mladek
Quoted 14 lines
A side note: This nesting also handles recursive printk-s for us.
NMI:
printk_nmi_enter
ftrace_dump
printk_nmi_direct_enter
vprintk_func
spin_lock(logbuf_lock)
vprintk_store
vsprintf
WARN_ON
vprintk_func
vprintk_nmi
Quoted 2 lines
Uff, it seems that the current design is "good" at lest from some points of view.
yep yep
Quoted 10 lines
Quoted 7 lines
kernel/printk/printk_safe.c void __printk_safe_exit(void) · line 387
Quoted 5 lines
kernel/printk/printk_safe.c +5
-0+ len =vprintk_store (0 ,LOGLEVEL_DEFAULT ,NULL ,0 , fmt, args); +raw_spin_unlock (&logbuf_lock); +defer_console (); +return len; + }So, maybe, something a bit better than
defer_console().I am not super happy with the name either. But
wakeup_console(),schedule_console(), orqueue_console()looked confusing.
Hmm. defer_console() makes me think that we are dealing with that fbcon=nodefer and deferred console takeover thing here.
So I summon Mr. Rostedt!
Does schedule_console_output() look bad?
What about defer_console_output()?
Any other ideas?
-ss
Quoted 10 lines · Petr Mladek
Quoted 6 lines · Sergey Senozhatsky
Quoted 3 lines · Petr Mladek
kernel/printk/printk.c | 57 +++++++++++++++++++++++++++----------------- kernel/printk/printk_safe.c | 58 +++++++++++++++++++++++++++++----------------Shall we just merge these two?
Do you mean to merge files or the patches, please?
Yeah... dunno. We now lock logbuf spinlock outside of printk.c, and we now have printk.c functions that have that "printk guts, must be called under logbuf lock" requirement and so on. I like when static things are static :)
-ss
Petr Mladek
maintainerRe: [PATCH v2 3/3] printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
In reply to Sergey SenozhatskyQuoted 32 lines · Sergey Senozhatsky
Quoted 15 lines · Petr Mladek
Quoted 14 lines
A side note: This nesting also handles recursive printk-s for us.
NMI:
printk_nmi_enter
ftrace_dump
printk_nmi_direct_enter
vprintk_func
spin_lock(logbuf_lock)
vprintk_store
vsprintf
WARN_ON
vprintk_func
vprintk_nmiQuoted 2 lines
Uff, it seems that the current design is "good" at lest from some points of view.
yep yep
Quoted 10 lines
Quoted 7 lines
kernel/printk/printk_safe.c void __printk_safe_exit(void) · line 387
Quoted 5 lines
kernel/printk/printk_safe.c +5
-0+ len =vprintk_store (0 ,LOGLEVEL_DEFAULT ,NULL ,0 , fmt, args); +raw_spin_unlock (&logbuf_lock); +defer_console (); +return len; + }So, maybe, something a bit better than
defer_console().I am not super happy with the name either. But
wakeup_console(),schedule_console(), orqueue_console()looked confusing.
Quoted 8 lines
Hmm.
defer_console()makes me think that we are dealing with that fbcon=nodefer and deferred console takeover thing here.So I summon Mr. Rostedt!
Does
schedule_console_output()look bad?
What aboutdefer_console_output()?
I am fine with both. I slightly prefer defer_console_output() because I have "schedule" associated with deadlocks in this code path (context) ;-)
Best Regards,
Petr
Re: [PATCH v2 3/3] printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
Quoted 6 lines · Petr Mladek
Quoted 4 lines
So I summon Mr. Rostedt!
Does
schedule_console_output()look bad?
What aboutdefer_console_output()?I am fine with both. I slightly prefer
defer_console_output()
I am fine with defer_console_output().
-ss
Petr Mladek
maintainerQuoted 23 lines · Petr Mladek
The commit
719f6a7040f1bdaf96("printk: Use the main logbuf in NMI whenlogbuf_lockis available") brought back the possible deadlocks inprintk()and NMI.This is rework of the proposed fix, see
https://lkml.kernel.org/r/[email protected]I realized that we could rather easily move the check to
vprintk_func()and still avoid any race. I believe that this is a win-win solution.Changes against v1:
+ Move the check from
vprintk_emit()tovprintk_func()
+ More straightforward commit message
+ Fix build withCONFIG_PRINTK_NMIdisabledPetr Mladek (3):
printk: Split the code for storing a message into the log buffer
printk: Create helper function to queue deferred console handling printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
Quoted 7 lines
include/linux/printk.h | 4 ++++ kernel/printk/internal.h | 9 ++++++- kernel/printk/printk.c | 57 +++++++++++++++++++++++++++----------------- kernel/printk/printk_safe.c | 58 +++++++++++++++++++++++++++++---------------- kernel/trace/trace.c | 4 +++- lib/nmi_backtrace.c | 3 --- 6 files changed, 87 insertions(+), 48 deletions(-)
JFYI, I have renamed the new function defer_console() to defer_console_output() and pushed everything to printk.git, branch for-4.19-nmi.
Best Regards,
Petr