1
0
Fork 0
alistair23-linux/include
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
..
acpi * Stratix10 SDRAM support to altera_edac (Thor Thayer) 2018-06-06 15:36:13 -07:00
asm-generic Kbuild updates for v4.18 2018-06-06 11:00:15 -07:00
clocksource ARM: SoC platform updates for 4.17 2018-04-05 21:21:08 -07:00
crypto Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2018-06-05 15:51:21 -07:00
drm drm for v4.18-rc1 2018-06-06 08:16:33 -07:00
dt-bindings sound updates for 4.18 2018-06-06 09:08:38 -07:00
keys
kvm KVM: arm/arm64: vgic: Fix source vcpu issues for GICv2 SGI 2018-04-27 12:39:09 +01:00
linux printk/nmi: Prevent deadlock when accessing the main log buffer in NMI 2018-07-09 14:10:40 +02:00
math-emu
media MAINTAINERS & files: Canonize the e-mails I use at files 2018-05-04 06:21:06 -04:00
memory
misc
net Merge branch 'work.aio-1' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2018-06-04 13:57:43 -07:00
pcmcia
ras
rdma IB/uverbs: Fix uverbs_attr_get_obj 2018-05-23 15:25:53 -06:00
scsi block: rename BLK_EH_NOT_HANDLED to BLK_EH_DONE 2018-05-29 08:59:21 -06:00
soc soc: bcm2835: Make !RASPBERRYPI_FIRMWARE dummies return failure 2018-04-16 15:15:23 -07:00
sound sound updates for 4.18 2018-06-06 09:08:38 -07:00
target
trace sound updates for 4.18 2018-06-06 09:08:38 -07:00
uapi sound updates for 4.18 2018-06-06 09:08:38 -07:00
video
xen xen/sndif: Sync up with the canonical definition in Xen 2018-04-17 08:26:33 -04:00