alistair23-linux/arch/mips
Paul Burton b63e132b64
MIPS: Use async IPIs for arch_trigger_cpumask_backtrace()
The current MIPS implementation of arch_trigger_cpumask_backtrace() is
broken because it attempts to use synchronous IPIs despite the fact that
it may be run with interrupts disabled.

This means that when arch_trigger_cpumask_backtrace() is invoked, for
example by the RCU CPU stall watchdog, we may:

  - Deadlock due to use of synchronous IPIs with interrupts disabled,
    causing the CPU that's attempting to generate the backtrace output
    to hang itself.

  - Not succeed in generating the desired output from remote CPUs.

  - Produce warnings about this from smp_call_function_many(), for
    example:

    [42760.526910] INFO: rcu_sched detected stalls on CPUs/tasks:
    [42760.535755]  0-...!: (1 GPs behind) idle=ade/140000000000000/0 softirq=526944/526945 fqs=0
    [42760.547874]  1-...!: (0 ticks this GP) idle=e4a/140000000000000/0 softirq=547885/547885 fqs=0
    [42760.559869]  (detected by 2, t=2162 jiffies, g=266689, c=266688, q=33)
    [42760.568927] ------------[ cut here ]------------
    [42760.576146] WARNING: CPU: 2 PID: 1216 at kernel/smp.c:416 smp_call_function_many+0x88/0x20c
    [42760.587839] Modules linked in:
    [42760.593152] CPU: 2 PID: 1216 Comm: sh Not tainted 4.15.4-00373-gee058bb4d0c2 #2
    [42760.603767] Stack : 8e09bd20 8e09bd20 8e09bd20 fffffff0 00000007 00000006 00000000 8e09bca8
    [42760.616937]         95b2b379 95b2b379 807a0080 00000007 81944518 0000018a 00000032 00000000
    [42760.630095]         00000000 00000030 80000000 00000000 806eca74 00000009 8017e2b8 000001a0
    [42760.643169]         00000000 00000002 00000000 8e09baa4 00000008 808b8008 86d69080 8e09bca0
    [42760.656282]         8e09ad50 805e20aa 00000000 00000000 00000000 8017e2b8 00000009 801070ca
    [42760.669424]         ...
    [42760.673919] Call Trace:
    [42760.678672] [<27fde568>] show_stack+0x70/0xf0
    [42760.685417] [<84751641>] dump_stack+0xaa/0xd0
    [42760.692188] [<699d671c>] __warn+0x80/0x92
    [42760.698549] [<68915d41>] warn_slowpath_null+0x28/0x36
    [42760.705912] [<f7c76c1c>] smp_call_function_many+0x88/0x20c
    [42760.713696] [<6bbdfc2a>] arch_trigger_cpumask_backtrace+0x30/0x4a
    [42760.722216] [<f845bd33>] rcu_dump_cpu_stacks+0x6a/0x98
    [42760.729580] [<796e7629>] rcu_check_callbacks+0x672/0x6ac
    [42760.737476] [<059b3b43>] update_process_times+0x18/0x34
    [42760.744981] [<6eb94941>] tick_sched_handle.isra.5+0x26/0x38
    [42760.752793] [<478d3d70>] tick_sched_timer+0x1c/0x50
    [42760.759882] [<e56ea39f>] __hrtimer_run_queues+0xc6/0x226
    [42760.767418] [<e88bbcae>] hrtimer_interrupt+0x88/0x19a
    [42760.775031] [<6765a19e>] gic_compare_interrupt+0x2e/0x3a
    [42760.782761] [<0558bf5f>] handle_percpu_devid_irq+0x78/0x168
    [42760.790795] [<90c11ba2>] generic_handle_irq+0x1e/0x2c
    [42760.798117] [<1b6d462c>] gic_handle_local_int+0x38/0x86
    [42760.805545] [<b2ada1c7>] gic_irq_dispatch+0xa/0x14
    [42760.812534] [<90c11ba2>] generic_handle_irq+0x1e/0x2c
    [42760.820086] [<c7521934>] do_IRQ+0x16/0x20
    [42760.826274] [<9aef3ce6>] plat_irq_dispatch+0x62/0x94
    [42760.833458] [<6a94b53c>] except_vec_vi_end+0x70/0x78
    [42760.840655] [<22284043>] smp_call_function_many+0x1ba/0x20c
    [42760.848501] [<54022b58>] smp_call_function+0x1e/0x2c
    [42760.855693] [<ab9fc705>] flush_tlb_mm+0x2a/0x98
    [42760.862730] [<0844cdd0>] tlb_flush_mmu+0x1c/0x44
    [42760.869628] [<cb259b74>] arch_tlb_finish_mmu+0x26/0x3e
    [42760.877021] [<1aeaaf74>] tlb_finish_mmu+0x18/0x66
    [42760.883907] [<b3fce717>] exit_mmap+0x76/0xea
    [42760.890428] [<c4c8a2f6>] mmput+0x80/0x11a
    [42760.896632] [<a41a08f4>] do_exit+0x1f4/0x80c
    [42760.903158] [<ee01cef6>] do_group_exit+0x20/0x7e
    [42760.909990] [<13fa8d54>] __wake_up_parent+0x0/0x1e
    [42760.917045] [<46cf89d0>] smp_call_function_many+0x1a2/0x20c
    [42760.924893] [<8c21a93b>] syscall_common+0x14/0x1c
    [42760.931765] ---[ end trace 02aa09da9dc52a60 ]---
    [42760.938342] ------------[ cut here ]------------
    [42760.945311] WARNING: CPU: 2 PID: 1216 at kernel/smp.c:291 smp_call_function_single+0xee/0xf8
    ...

This patch switches MIPS' arch_trigger_cpumask_backtrace() to use async
IPIs & smp_call_function_single_async() in order to resolve this
problem. We ensure use of the pre-allocated call_single_data_t
structures is serialized by maintaining a cpumask indicating that
they're busy, and refusing to attempt to send an IPI when a CPU's bit is
set in this mask. This should only happen if a CPU hasn't responded to a
previous backtrace IPI - ie. if it's hung - and we print a warning to
the console in this case.

I've marked this for stable branches as far back as v4.9, to which it
applies cleanly. Strictly speaking the faulty MIPS implementation can be
traced further back to commit 856839b768 ("MIPS: Add
arch_trigger_all_cpu_backtrace() function") in v3.19, but kernel
versions v3.19 through v4.8 will require further work to backport due to
the rework performed in commit 9a01c3ed5c ("nmi_backtrace: add more
trigger_*_cpu_backtrace() methods").

Signed-off-by: Paul Burton <paul.burton@mips.com>
Patchwork: https://patchwork.linux-mips.org/patch/19597/
Cc: James Hogan <jhogan@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Huacai Chen <chenhc@lemote.com>
Cc: linux-mips@linux-mips.org
Cc: stable@vger.kernel.org # v4.9+
Fixes: 856839b768 ("MIPS: Add arch_trigger_all_cpu_backtrace() function")
Fixes: 9a01c3ed5c ("nmi_backtrace: add more trigger_*_cpu_backtrace() methods")
2018-06-28 14:14:41 -07:00
..
alchemy Merge branch 'i2c/for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux 2018-06-14 16:21:46 +09:00
ar7 MIPS: AR7: Constify gpio_led 2018-02-19 10:55:36 +00:00
ath25 MIPS: ath25: Check for kzalloc allocation failure 2018-02-23 09:35:54 +00:00
ath79 MIPS: pb44: Fix i2c-gpio GPIO descriptor table 2018-06-18 22:19:50 +01:00
bcm47xx MIPS: BCM47XX: Enable 74K Core ExternalSync for PCIe erratum 2018-06-18 22:19:50 +01:00
bcm63xx MIPS: BCM63XX: kconfig: Remove blank help text 2018-02-02 23:53:10 +09:00
bmips treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
boot MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
cavium-octeon swiotlb: move the SWIOTLB config symbol to lib/Kconfig 2018-05-09 06:58:01 +02:00
cobalt
configs MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
crypto MIPS: crypto: Add crc32 and crc32c hw accelerated module 2018-02-19 20:50:36 +00:00
dec MIPS: Convert update_persistent_clock() to update_persistent_clock64() 2018-05-14 23:58:23 +01:00
emma MIPS: Avoid old-style declaration 2017-01-25 02:51:11 +01:00
fw License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
generic MIPS: xilfpga: Actually include FDT in fitImage 2018-05-14 23:54:25 +01:00
include MIPS: Wire up io_pgetevents syscall 2018-06-19 21:14:29 -07:00
jazz MIPS: Set I/O port resource types correctly 2017-12-18 23:07:45 -06:00
jz4740 MIPS: JZ4740: Drop old platform reset code 2018-05-14 23:58:23 +01:00
kernel MIPS: Use async IPIs for arch_trigger_cpumask_backtrace() 2018-06-28 14:14:41 -07:00
kvm Small update for KVM. 2018-06-12 11:34:04 -07:00
lantiq MIPS: lantiq: ase: Enable MFD_SYSCON 2018-03-21 21:57:35 +00:00
lasat MIPS: Convert update_persistent_clock() to update_persistent_clock64() 2018-05-14 23:58:23 +01:00
lib MIPS: memset.S: Reinstate delay slot indentation 2018-05-21 16:01:15 +01:00
loongson32 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
loongson64 MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
math-emu MIPS: math-emu: Mark fall throughs in switch statements with a comment 2017-12-12 17:20:20 +01:00
mm MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
mti-malta MIPS: Convert read_persistent_clock() to read_persistent_clock64() 2018-05-14 23:58:23 +01:00
net bpf, mips: remove unused function 2018-05-14 19:11:45 -07:00
netlogic scatterlist: move the NEED_SG_DMA_LENGTH config symbol to lib/Kconfig 2018-05-09 06:55:59 +02:00
oprofile MIPS: perf: More robustly probe for the presence of per-tc counters 2018-05-15 15:16:16 +01:00
paravirt License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pci pci-v4.18-changes 2018-06-07 12:45:58 -07:00
pic32 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pistachio License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pmcs-msp71xx License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pnx833x mtd: nand: Rename nand.h into rawnand.h 2017-08-13 10:11:49 +02:00
power License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ralink MIPS: ralink: Fix booting on MT7621 2018-03-22 00:06:30 +00:00
rb532 MIPS: RB532: Avoid undefined mac_pton without GENERIC_NET_UTILS 2018-01-10 16:39:03 +01:00
sgi-ip22 Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2017-11-13 17:56:58 -08:00
sgi-ip27 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sgi-ip32 mips: ip22/32: Convert timers to use timer_setup() 2017-11-02 15:50:36 -07:00
sibyte MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
sni MIPS: sni: Remove the read_persistent_clock() 2018-05-14 23:58:25 +01:00
tools Update MIPS email addresses 2017-11-03 09:02:30 -07:00
txx9 treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
vdso MIPS: VDSO: Replace __mips_isa_rev with MIPS_ISA_REV 2018-03-09 11:22:48 +00:00
vr41xx License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Kbuild MIPS: Disable Werror when W= is set 2017-04-10 11:56:07 +02:00
Kbuild.platforms MIPS: Xilfpga: Switch to using generic defconfigs 2017-11-08 22:54:14 +00:00
Kconfig MIPS: Add support for restartable sequences 2018-06-19 21:13:17 -07:00
Kconfig.debug MIPS: Fix CPS SMP NS16550 UART defaults 2018-01-10 16:44:49 +01:00
Makefile kbuild: add machine size to CHECKFLAGS 2018-06-01 11:36:58 +09:00
Makefile.postlink License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00