linux-stable/arch/s390
Gerald Schaefer b7cb707c37 s390/smp: fix CPU hotplug deadlock with CPU rescan
smp_rescan_cpus() is called without the device_hotplug_lock, which can lead
to a dedlock when a new CPU is found and immediately set online by a udev
rule.

This was observed on an older kernel version, where the cpu_hotplug_begin()
loop was still present, and it resulted in hanging chcpu and systemd-udev
processes. This specific deadlock will not show on current kernels. However,
there may be other possible deadlocks, and since smp_rescan_cpus() can still
trigger a CPU hotplug operation, the device_hotplug_lock should be held.

For reference, this was the deadlock with the old cpu_hotplug_begin() loop:

        chcpu (rescan)                       systemd-udevd

 echo 1 > /sys/../rescan
 -> smp_rescan_cpus()
 -> (*) get_online_cpus()
    (increases refcount)
 -> smp_add_present_cpu()
    (new CPU found)
 -> register_cpu()
 -> device_add()
 -> udev "add" event triggered -----------> udev rule sets CPU online
                                         -> echo 1 > /sys/.../online
                                         -> lock_device_hotplug_sysfs()
                                            (this is missing in rescan path)
                                         -> device_online()
                                         -> (**) device_lock(new CPU dev)
                                         -> cpu_up()
                                         -> cpu_hotplug_begin()
                                            (loops until refcount == 0)
                                            -> deadlock with (*)
 -> bus_probe_device()
 -> device_attach()
 -> device_lock(new CPU dev)
    -> deadlock with (**)

Fix this by taking the device_hotplug_lock in the CPU rescan path.

Cc: <stable@vger.kernel.org>
Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2019-01-11 17:12:02 +01:00
..
appldata sched: loadavg: consolidate LOAD_INT, LOAD_FRAC, CALC_LOAD 2018-10-26 16:26:32 -07:00
boot s390: avoid vmlinux segments overlap 2018-10-26 10:19:40 +02:00
configs s390: update defconfigs 2018-11-05 15:10:27 +01:00
crypto crypto: drop mask=CRYPTO_ALG_ASYNC from 'cipher' tfm allocations 2018-11-20 14:26:55 +08:00
hypfs s390/hypfs: do not use stack buffers for hardware data 2018-10-09 11:20:53 +02:00
include s390/mm: always force a load of the primary ASCE on context switch 2019-01-11 17:12:02 +01:00
kernel s390/smp: fix CPU hotplug deadlock with CPU rescan 2019-01-11 17:12:02 +01:00
kvm Kconfig updates for v4.21 2018-12-29 13:03:29 -08:00
lib s390/kasan: avoid user access code instrumentation 2018-10-09 11:21:21 +02:00
mm s390 updates for the 4.21 merge window 2019-01-02 18:37:01 -08:00
net s390: bpf: implement jitting of BPF_ALU | BPF_ARSH | BPF_* 2018-12-07 13:30:48 -08:00
numa s390 updates for 4.20-rc2 2018-11-09 06:30:44 -06:00
oprofile 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.21-changes 2019-01-05 17:57:34 -08:00
purgatory s390: clean up stacks setup 2018-09-20 13:20:29 +02:00
scripts s390/build: add *.o.chkbss files to targets list 2018-07-02 12:32:23 +02:00
tools kbuild: use assignment instead of define ... endef for filechk_* rules 2019-01-06 10:22:35 +09:00
defconfig s390: update defconfigs 2018-11-05 15:10:27 +01:00
Kbuild s390/kexec_file: Add purgatory 2018-04-16 09:10:22 +02:00
Kconfig Kconfig file consolidation for v4.21 2018-12-29 13:40:29 -08:00
Kconfig.debug Kconfig: consolidate the "Kernel hacking" menu 2018-08-02 08:06:48 +09:00
Makefile s390/kasan: increase instrumented stack size to 64k 2018-11-02 08:31:57 +01:00