1
0
Fork 0
alistair23-linux/kernel/trace
Petr Mladek 03fc7f9c99 printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
The commit 719f6a7040 ("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.

Fixes: 719f6a7040 ("printk: Use the main logbuf in NMI when logbuf_lock is available")
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/20180627142028.11259-1-pmladek@suse.com
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
2018-07-09 14:10:40 +02:00
..
Kconfig tracing: Add inter-event blurb to HIST_TRIGGERS config option 2018-03-10 16:06:05 -05:00
Makefile Tracing updates for 4.15: 2017-11-17 14:58:01 -08:00
blktrace.c blktrace: fix trace mutex deadlock 2017-11-27 12:03:58 -07:00
bpf_trace.c bpf/tracing: fix a deadlock in perf_event_detach_bpf_prog 2018-04-11 01:01:40 +02:00
ftrace.c ftrace: Have set_graph_* files have normal file modes 2018-05-03 11:55:31 -04:00
power-traces.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ring_buffer.c ring-buffer: Add set/clear_current_oom_origin() during allocations 2018-04-06 08:56:52 -04:00
ring_buffer_benchmark.c ring-buffer: Have ring_buffer_alloc_read_page() return error on offline CPU 2017-08-02 14:23:02 -04:00
rpm-traces.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace.c printk/nmi: Prevent deadlock when accessing the main log buffer in NMI 2018-07-09 14:10:40 +02:00
trace.h tracing: Make the snapshot trigger work with instances 2018-05-28 12:49:32 -04:00
trace_benchmark.c rcu: Rename cond_resched_rcu_qs() to cond_resched_tasks_rcu_qs() 2018-05-15 10:27:29 -07:00
trace_benchmark.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_branch.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_clock.c tracing: Hide global trace clock from lockdep 2018-04-06 08:56:52 -04:00
trace_entries.h tracing: Fix missing tab for hwlat_detector print format 2018-04-25 10:28:46 -04:00
trace_event_perf.c perf/core: Fix perf_uprobe_init() 2018-04-10 07:33:10 +02:00
trace_events.c tracing: Make sure the parsed string always terminates with '\0' 2018-01-23 15:57:28 -05:00
trace_events_filter.c tracing: Fix regex_match_front() to not over compare the test string 2018-05-11 10:56:42 -04:00
trace_events_filter_test.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_events_hist.c tracing: Add field modifier parsing hist error for hist triggers 2018-04-26 21:39:58 -04:00
trace_events_trigger.c tracing: Make the snapshot trigger work with instances 2018-05-28 12:49:32 -04:00
trace_export.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_functions.c tracing: Update stack trace skipping for ORC unwinder 2018-01-23 15:57:00 -05:00
trace_functions_graph.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_hwlat.c trace: make trace_hwlat timestamp y2038 safe 2017-05-08 17:15:15 -07:00
trace_irqsoff.c tracing: Add support for preempt and irq enable/disable events 2017-10-10 18:58:43 -04:00
trace_kdb.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_kprobe.c trace_kprobe: Remove warning message "Could not insert probe at..." 2018-04-17 07:54:57 +02:00
trace_mmiotrace.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_nop.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_output.c sched/debug: Rename task-state printing helpers 2017-10-10 11:43:29 +02:00
trace_output.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_printk.c treewide: Align function definition open/close braces 2018-03-26 11:13:09 +02:00
trace_probe.c tracing: probeevent: Fix to support minus offset from symbol 2018-03-23 12:02:37 -04:00
trace_probe.h Merge branch 'perf/urgent' into perf/core 2018-03-29 16:03:48 +02:00
trace_sched_switch.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_sched_wakeup.c Merge branch 'linus' into sched/core, to pick up fixes 2017-11-08 10:17:15 +01:00
trace_selftest.c Tracing updates for 4.15: 2017-11-17 14:58:01 -08:00
trace_selftest_dynamic.c ftrace: Mark function tracer test functions noinline/noclone 2018-01-23 15:57:29 -05:00
trace_seq.c tracing: use %*pb[l] to print bitmaps including cpumasks and nodemasks 2015-02-13 21:21:37 -08:00
trace_stack.c tracing: Fix the file mode of stack tracer 2018-05-03 11:58:05 -04:00
trace_stat.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_stat.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_syscalls.c Tracing updates for 4.15: 2017-11-17 14:58:01 -08:00
trace_uprobe.c tracing: Fix bad use of igrab in trace_uprobe.c 2018-04-26 14:49:55 -04:00
tracing_map.c tracing: Add per-element variable support to tracing_map 2018-03-10 16:05:53 -05:00
tracing_map.h tracing: Add per-element variable support to tracing_map 2018-03-10 16:05:53 -05:00