linux/arch/powerpc
David Gibson 9765ad134a powerpc/mm: Ensure IRQs are off in switch_mm()
powerpc expects IRQs to already be (soft) disabled when switch_mm() is
called, as made clear in the commit message of 9c1e105238 ("powerpc: Allow
perf_counters to access user memory at interrupt time").

Aside from any race conditions that might exist between switch_mm() and an IRQ,
there is also an unconditional hard_irq_disable() in switch_slb(). If that isn't
followed at some point by an IRQ enable then interrupts will remain disabled
until we return to userspace.

It is true that when switch_mm() is called from the scheduler IRQs are off, but
not when it's called by use_mm(). Looking closer we see that last year in commit
f98db6013c ("sched/core: Add switch_mm_irqs_off() and use it in the scheduler")
this was made more explicit by the addition of switch_mm_irqs_off() which is now
called by the scheduler, vs switch_mm() which is used by use_mm().

Arguably it is a bug in use_mm() to call switch_mm() in a different context than
it expects, but fixing that will take time.

This was discovered recently when vhost started throwing warnings such as:

  BUG: sleeping function called from invalid context at kernel/mutex.c:578
  in_atomic(): 0, irqs_disabled(): 1, pid: 10768, name: vhost-10760
  no locks held by vhost-10760/10768.
  irq event stamp: 10
  hardirqs last  enabled at (9):  _raw_spin_unlock_irq+0x40/0x80
  hardirqs last disabled at (10): switch_slb+0x2e4/0x490
  softirqs last  enabled at (0):  copy_process+0x5e8/0x1260
  softirqs last disabled at (0):  (null)
  Call Trace:
    show_stack+0x88/0x390 (unreliable)
    dump_stack+0x30/0x44
    __might_sleep+0x1c4/0x2d0
    mutex_lock_nested+0x74/0x5c0
    cgroup_attach_task_all+0x5c/0x180
    vhost_attach_cgroups_work+0x58/0x80 [vhost]
    vhost_worker+0x24c/0x3d0 [vhost]
    kthread+0xec/0x100
    ret_from_kernel_thread+0x5c/0xd4

Prior to commit 04b96e5528 ("vhost: lockless enqueuing") (Aug 2016) the
vhost_worker() would do a spin_unlock_irq() not long after calling use_mm(),
which had the effect of reenabling IRQs. Since that commit removed the locking
in vhost_worker() the body of the vhost_worker() loop now runs with interrupts
off causing the warnings.

This patch addresses the problem by making the powerpc code mirror the x86 code,
ie. we disable interrupts in switch_mm(), and optimise the scheduler case by
defining switch_mm_irqs_off().

Cc: stable@vger.kernel.org # v4.7+
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
[mpe: Flesh out/rewrite change log, add stable]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-04-25 00:24:59 +10:00
..
boot powerpc/boot: Fix zImage TOC alignment 2017-03-08 10:39:32 +11:00
configs powerpc/configs: Re-enable POWER8 crc32c 2017-03-28 10:52:04 +11:00
crypto crypto: powerpc - Fix initialisation of crc32c context 2017-03-08 14:01:08 +08:00
include powerpc/mm: Ensure IRQs are off in switch_mm() 2017-04-25 00:24:59 +10:00
kernel powerpc/sysfs: Fix reference leak of cpu device_nodes present at boot 2017-04-25 00:24:59 +10:00
kvm Merge branch 'topic/xive' (early part) into next 2017-04-12 22:31:37 +10:00
lib powerpc/kprobes: Convert __kprobes to NOKPROBE_SYMBOL() 2017-04-23 20:32:25 +10:00
math-emu Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
mm powerpc/mm: Add support for runtime configuration of ASLR limits 2017-04-21 22:57:55 +10:00
net powerpc updates for 4.11 part 1. 2017-02-22 10:30:38 -08:00
oprofile ktime: Cleanup ktime_set() usage 2016-12-25 17:21:22 +01:00
perf powerpc/perf: Add Power8 mem_access event to sysfs 2017-04-19 20:00:23 +10:00
platforms powerpc/pseries: Fix of_node_put() underflow during DLPAR remove 2017-04-25 00:24:59 +10:00
purgatory kexec, x86/purgatory: Unbreak it and clean it up 2017-03-10 20:55:09 +01:00
scripts powerpc/ftrace: Add Kconfig & Make glue for mprofile-kernel 2016-03-07 14:53:56 +11:00
sysdev powerpc/xive: Fix missing check of rc != OPAL_BUSY 2017-04-20 14:43:19 +10:00
xmon powerpc/xmon: Deindent the SLB dumping logic 2017-04-25 00:24:59 +10:00
Kconfig Merge branch 'topic/kprobes' into next 2017-04-25 00:24:04 +10:00
Kconfig.debug powerpc/xmon: Enable disassembly files (compilation changes) 2017-02-15 20:02:42 +11:00
Makefile powerpc: Fix compiling a BE kernel with a powerpc64le toolchain 2017-03-03 11:24:50 +11:00
relocs_check.sh powerpc/64: whitelist unresolved modversions CRCs 2016-09-22 14:46:31 +02:00