kernel-ark/arch/mips
Petr Mladek 42a0bb3f71 printk/nmi: generic solution for safe printk in NMI
printk() takes some locks and could not be used a safe way in NMI
context.

The chance of a deadlock is real especially when printing stacks from
all CPUs.  This particular problem has been addressed on x86 by the
commit a9edc88093 ("x86/nmi: Perform a safe NMI stack trace on all
CPUs").

The patchset brings two big advantages.  First, it makes the NMI
backtraces safe on all architectures for free.  Second, it makes all NMI
messages almost safe on all architectures (the temporary buffer is
limited.  We still should keep the number of messages in NMI context at
minimum).

Note that there already are several messages printed in NMI context:
WARN_ON(in_nmi()), BUG_ON(in_nmi()), anything being printed out from MCE
handlers.  These are not easy to avoid.

This patch reuses most of the code and makes it generic.  It is useful
for all messages and architectures that support NMI.

The alternative printk_func is set when entering and is reseted when
leaving NMI context.  It queues IRQ work to copy the messages into the
main ring buffer in a safe context.

__printk_nmi_flush() copies all available messages and reset the buffer.
Then we could use a simple cmpxchg operations to get synchronized with
writers.  There is also used a spinlock to get synchronized with other
flushers.

We do not longer use seq_buf because it depends on external lock.  It
would be hard to make all supported operations safe for a lockless use.
It would be confusing and error prone to make only some operations safe.

The code is put into separate printk/nmi.c as suggested by Steven
Rostedt.  It needs a per-CPU buffer and is compiled only on
architectures that call nmi_enter().  This is achieved by the new
HAVE_NMI Kconfig flag.

The are MN10300 and Xtensa architectures.  We need to clean up NMI
handling there first.  Let's do it separately.

The patch is heavily based on the draft from Peter Zijlstra, see

  https://lkml.org/lkml/2015/6/10/327

[arnd@arndb.de: printk-nmi: use %zu format string for size_t]
[akpm@linux-foundation.org: min_t->min - all types are size_t here]
Signed-off-by: Petr Mladek <pmladek@suse.com>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Jan Kara <jack@suse.cz>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>	[arm part]
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Jiri Kosina <jkosina@suse.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: David Miller <davem@davemloft.net>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-05-20 17:58:30 -07:00
..
alchemy Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2016-05-19 10:02:26 -07:00
ar7
ath25
ath79 MIPS: ath79: fix regression in PCI window initialization 2016-05-17 11:13:28 +02:00
bcm47xx
bcm63xx
bmips
boot MIPS: JZ4740: Probe OHCI platform device via DT 2016-05-13 19:09:24 +02:00
cavium-octeon
cobalt
configs
dec MIPS: DEC: Export `ioasic_ssr_lock' to modules 2016-05-17 11:03:54 +02:00
emma
fw
include Merge branch 'akpm' (patches from Andrew) 2016-05-19 20:00:06 -07:00
jazz
jz4740 MIPS: JZ4740: Probe OHCI platform device via DT 2016-05-13 19:09:24 +02:00
kernel exit_thread: remove empty bodies 2016-05-20 17:58:30 -07:00
kvm Small release overall. 2016-05-19 11:27:09 -07:00
lantiq
lasat
lib MIPS: Print GuestCtl1 on machine check exception 2016-05-13 15:30:25 +02:00
loongson32
loongson64
math-emu MIPS: math-emu: Fix jalr emulation when rd == $0 2016-05-13 14:02:24 +02:00
mm Merge branch 'akpm' (patches from Andrew) 2016-05-19 20:00:06 -07:00
mti-malta MIPS: malta-time: Take seconds into account 2016-05-13 15:30:25 +02:00
mti-sead3
net
netlogic MIPS: Define & use CP0_EBase bit definitions 2016-05-13 15:30:25 +02:00
oprofile MIPS: Add perf counter feature 2016-05-13 15:30:25 +02:00
paravirt
pci
pic32 Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2016-05-19 10:02:26 -07:00
pistachio MIPS: pistachio: Determine SoC revision during boot 2016-05-13 17:47:47 +02:00
pmcs-msp71xx
pnx833x
power
ralink mips: mt7620: fallback to SDRAM when syscfg0 does not have a valid value for the memory type 2016-05-13 15:39:43 +02:00
rb532
sgi-ip22
sgi-ip27
sgi-ip32
sibyte
sni
txx9
vdso MIPS: Fix genvdso error on rebuild 2016-05-13 22:47:39 +02:00
vr41xx
xilfpga
Kbuild
Kbuild.platforms
Kconfig printk/nmi: generic solution for safe printk in NMI 2016-05-20 17:58:30 -07:00
Kconfig.debug
Makefile MIPS: Fix VZ probe gas errors with binutils <2.24 2016-05-17 11:06:04 +02:00