1
0
Fork 0
alistair23-linux/arch/sparc/kernel
Nicholas Piggin 2eab8974ae sparc64: remove mm_cpumask clearing to fix kthread_use_mm race
[ Upstream commit bafb056ce2 ]

The de facto (and apparently uncommented) standard for using an mm had,
thanks to this code in sparc if nothing else, been that you must have a
reference on mm_users *and that reference must have been obtained with
mmget()*, i.e., from a thread with a reference to mm_users that had used
the mm.

The introduction of mmget_not_zero() in commit d2005e3f41
("userfaultfd: don't pin the user memory in userfaultfd_file_create()")
allowed mm_count holders to aoperate on user mappings asynchronously
from the actual threads using the mm, but they were not to load those
mappings into their TLB (i.e., walking vmas and page tables is okay,
kthread_use_mm() is not).

io_uring 2b188cc1bb ("Add io_uring IO interface") added code which
does a kthread_use_mm() from a mmget_not_zero() refcount.

The problem with this is code which previously assumed mm == current->mm
and mm->mm_users == 1 implies the mm will remain single-threaded at
least until this thread creates another mm_users reference, has now
broken.

arch/sparc/kernel/smp_64.c:

    if (atomic_read(&mm->mm_users) == 1) {
        cpumask_copy(mm_cpumask(mm), cpumask_of(cpu));
        goto local_flush_and_out;
    }

vs fs/io_uring.c

    if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL) ||
                 !mmget_not_zero(ctx->sqo_mm)))
        return -EFAULT;
    kthread_use_mm(ctx->sqo_mm);

mmget_not_zero() could come in right after the mm_users == 1 test, then
kthread_use_mm() which sets its CPU in the mm_cpumask. That update could
be lost if cpumask_copy() occurs afterward.

I propose we fix this by allowing mmget_not_zero() to be a first-class
reference, and not have this obscure undocumented and unchecked
restriction.

The basic fix for sparc64 is to remove its mm_cpumask clearing code. The
optimisation could be effectively restored by sending IPIs to mm_cpumask
members and having them remove themselves from mm_cpumask. This is more
tricky so I leave it as an exercise for someone with a sparc64 SMP.
powerpc has a (currently similarly broken) example.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200914045219.3736466-4-npiggin@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-11-05 11:43:13 +01:00
..
syscalls arch: mark syscall number 435 reserved for clone3 2019-07-15 00:39:33 +02:00
.gitignore sparc: gitignore a few files 2008-12-04 09:17:15 -08:00
Makefile jump_label: move 'asm goto' support test to Kconfig 2019-01-06 09:46:51 +09:00
adi_64.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 482 2019-06-19 17:09:52 +02:00
apc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
asm-offsets.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
audit.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
auxio_32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
auxio_64.c sparc: Use of_node_name_eq for node name comparisons 2018-11-18 13:35:21 -08:00
btext.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
central.c sparc: Use of_node_name_eq for node name comparisons 2018-11-18 13:35:21 -08:00
cherrs.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
chmc.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
compat_audit.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cpu.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cpumap.c sparc: use struct_size() in kzalloc() 2019-05-09 14:26:16 -07:00
cpumap.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
devices.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ds.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
dtlb_miss.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
dtlb_prot.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ebus.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
entry.S sparc: get rid of asm wrapper for nis_syscall() 2018-03-20 12:05:17 -04:00
entry.h sparc64: Add support for ADI register fields, ASIs and traps 2018-03-18 07:38:45 -07:00
etrap_32.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
etrap_64.S sparc64: Add support for ADI (Application Data Integrity) 2018-03-18 07:38:48 -07:00
fpu_traps.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ftrace.c sparc/function_graph: Simplify with function_graph_enter() 2018-11-27 20:31:46 -05:00
getsetcc.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
head_32.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
head_64.S sparc64: Add support for ADI register fields, ASIs and traps 2018-03-18 07:38:45 -07:00
helpers.S treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
hvapi.c sparc64: Oracle DAX infrastructure 2018-01-22 08:17:15 -08:00
hvcalls.S sparc64: Oracle DAX infrastructure 2018-01-22 08:17:15 -08:00
hvtramp.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
idprom.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
iommu-common.c iommu-common: move to arch/sparc 2018-05-09 06:54:27 +02:00
iommu.c sparc64/iommu: allow large DMA masks 2019-02-20 07:28:58 -07:00
iommu_common.h sparc: remove the mapping_error dma_map_ops method 2018-12-06 06:56:40 -08:00
ioport.c dma-mapping: zero memory returned from dma_alloc_* 2018-12-20 08:13:52 +01:00
irq.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
irq_32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
irq_64.c sparc: Use of_node_name_eq for node name comparisons 2018-11-18 13:35:21 -08:00
itlb_miss.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ivec.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
jump_label.c jump_label: move 'asm goto' support test to Kconfig 2019-01-06 09:46:51 +09:00
kernel.h sparc64: refactor the ali DMA quirk 2019-02-20 07:28:53 -07:00
kgdb_32.c kgdb/treewide: constify struct kgdb_arch arch_kgdb_ops 2018-12-30 08:33:06 +00:00
kgdb_64.c kgdb/treewide: constify struct kgdb_arch arch_kgdb_ops 2018-12-30 08:33:06 +00:00
kprobes.c bpf/error-inject/kprobes: Clear current_kprobe and enable preempt in kprobe 2018-06-21 12:33:19 +02:00
kstack.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ktlb.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ldc.c iommu-common: move to arch/sparc 2018-05-09 06:54:27 +02:00
led.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
leon_kernel.c sparc: Remove unused leon_trans_init 2018-11-18 13:35:22 -08:00
leon_pci.c sparc/PCI: Use dev_printk() when possible 2018-05-22 07:54:06 -05:00
leon_pci_grpci1.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
leon_pci_grpci2.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
leon_pmc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
leon_smp.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mdesc.c mdesc: fix a missing-check bug in get_vdev_port_node_info() 2019-06-02 22:15:35 -07:00
misctrap.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
module.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nmi.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
of_device_32.c sparc: Use DT node full_name instead of name for resources 2018-11-18 13:35:22 -08:00
of_device_64.c sparc: Use DT node full_name instead of name for resources 2018-11-18 13:35:22 -08:00
of_device_common.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
of_device_common.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pci.c sparc64: refactor the ali DMA quirk 2019-02-20 07:28:53 -07:00
pci_common.c sparc/PCI: Use dev_printk() when possible 2018-05-22 07:54:06 -05:00
pci_fire.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
pci_impl.h sparc/PCI: Support arbitrary host bridge address offset 2018-02-15 15:07:30 -06:00
pci_msi.c sparc/PCI: Use dev_printk() when possible 2018-05-22 07:54:06 -05:00
pci_psycho.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pci_sabre.c sparc: Use of_node_name_eq for node name comparisons 2018-11-18 13:35:21 -08:00
pci_schizo.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
pci_sun4v.c sparc64/pci_sun4v: fix ATU checks for large DMA masks 2019-04-10 21:42:04 +02:00
pci_sun4v.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pci_sun4v_asm.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pcic.c sparc/PCI: Use dev_printk() when possible 2018-05-22 07:54:06 -05:00
pcr.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
perf_event.c sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD 2019-06-02 22:16:33 -07:00
pmc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
power.c sparc: Convert to using %pOFn instead of device_node.name 2018-11-18 13:35:20 -08:00
process_32.c sparc: Use device_type helpers to access the node type 2018-11-18 13:35:21 -08:00
process_64.c signal: Remove the task parameter from force_sig_fault 2019-05-29 09:31:43 -05:00
prom.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
prom_32.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
prom_64.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
prom_common.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
prom_irqtrans.c sparc: Use device_type helpers to access the node type 2018-11-18 13:35:21 -08:00
psycho_common.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
psycho_common.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ptrace_32.c fix a braino in "sparc32: fix register window handling in genregs32_[gs]et()" 2020-06-30 15:36:47 -04:00
ptrace_64.c sparc64: fix misuses of access_process_vm() in genregs32_[sg]et() 2020-06-22 09:31:21 +02:00
reboot.c sparc: Use device_type helpers to access the node type 2018-11-18 13:35:21 -08:00
rtrap_32.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rtrap_64.S sparc64: Make corrupted user stacks more debuggable. 2018-10-26 15:04:41 -07:00
sbus.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
setup_32.c Merge branch 'mount.part1' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-01-05 13:25:58 -08:00
setup_64.c sparc: add checks for the return value of memblock_alloc*() 2019-03-12 10:04:02 -07:00
signal32.c signal: Remove task parameter from force_sig 2019-05-27 09:36:28 -05:00
signal_32.c signal: Remove task parameter from force_sig 2019-05-27 09:36:28 -05:00
signal_64.c signal: Remove task parameter from force_sig 2019-05-27 09:36:28 -05:00
sigutil.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sigutil_32.c Remove 'type' argument from access_ok() function 2019-01-03 18:57:57 -08:00
sigutil_64.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
smp_32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
smp_64.c sparc64: remove mm_cpumask clearing to fix kthread_use_mm race 2020-11-05 11:43:13 +01:00
sparc_ksyms.c sparc: move exports to definitions 2016-08-07 23:55:43 -04:00
spiterrs.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sstate.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
stacktrace.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
starfire.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sun4d_irq.c sparc: Use of_node_name_eq for node name comparisons 2018-11-18 13:35:21 -08:00
sun4d_smp.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sun4m_irq.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sun4m_smp.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sun4v_ivec.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sun4v_mcd.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 482 2019-06-19 17:09:52 +02:00
sun4v_tlb_miss.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sys32.S sparc: get rid of remaining SIGN... wrappers 2018-03-20 12:01:23 -04:00
sys_sparc32.c Merge branch 'misc.sparc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2018-04-07 14:30:28 -07:00
sys_sparc_32.c signal: Remove the task parameter from force_sig_fault 2019-05-29 09:31:43 -05:00
sys_sparc_64.c ipc: fix sparc64 ipc() wrapper 2019-09-07 21:42:25 +02:00
syscalls.S sparc: get rid of asm wrapper for nis_syscall() 2018-03-20 12:05:17 -04:00
sysfs.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
systbls.h sparc: get rid of asm wrapper for nis_syscall() 2018-03-20 12:05:17 -04:00
systbls_32.S sparc: generate uapi header and system call table files 2018-11-18 18:52:22 -08:00
systbls_64.S sparc: generate uapi header and system call table files 2018-11-18 18:52:22 -08:00
time_32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
time_64.c cpufreq: Call transition notifier only once for each policy 2019-05-10 12:20:36 +02:00
trampoline_32.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trampoline_64.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
traps_32.c signal: Remove the task parameter from force_sig_fault 2019-05-29 09:31:43 -05:00
traps_64.c Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2019-07-08 21:48:15 -07:00
tsb.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ttable_32.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ttable_64.S sparc64: Add support for ADI register fields, ASIs and traps 2018-03-18 07:38:45 -07:00
una_asm_32.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
una_asm_64.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
unaligned_32.c Remove 'type' argument from access_ok() function 2019-01-03 18:57:57 -08:00
unaligned_64.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
uprobes.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 13 2019-05-21 11:28:45 +02:00
urtt_fill.S sparc64: Add support for ADI (Application Data Integrity) 2018-03-18 07:38:48 -07:00
utrap.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
vdso.c vDSO for sparc 2017-11-15 14:21:03 +09:00
vio.c sparc: Use device_type helpers to access the node type 2018-11-18 13:35:21 -08:00
viohs.c sparc64: viohs: Remove VLA usage 2018-10-07 22:42:00 -07:00
visemul.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
vmlinux.lds.S sparc: Add .exit.data section. 2020-02-24 08:36:27 +01:00
windows.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
winfixup.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
wof.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
wuf.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00