linux/arch/m68k
Michael Schmitz da89ce46f0 m68k: Fix spinlock race in kernel thread creation
Context switching does take care to retain the correct lock owner across
the switch from 'prev' to 'next' tasks.  This does rely on interrupts
remaining disabled for the entire duration of the switch.

This condition is guaranteed for normal process creation and context
switching between already running processes, because both 'prev' and
'next' already have interrupts disabled in their saved copies of the
status register.

The situation is different for newly created kernel threads.  The status
register is set to PS_S in copy_thread(), which does leave the IPL at 0.
Upon restoring the 'next' thread's status register in switch_to() aka
resume(), interrupts then become enabled prematurely.  resume() then
returns via ret_from_kernel_thread() and schedule_tail() where run queue
lock is released (see finish_task_switch() and finish_lock_switch()).

A timer interrupt calling scheduler_tick() before the lock is released
in finish_task_switch() will find the lock already taken, with the
current task as lock owner.  This causes a spinlock recursion warning as
reported by Guenter Roeck.

As far as I can ascertain, this race has been opened in commit
533e6903be ("m68k: split ret_from_fork(), simplify kernel_thread()")
but I haven't done a detailed study of kernel history so it may well
predate that commit.

Interrupts cannot be disabled in the saved status register copy for
kernel threads (init will complain about interrupts disabled when
finally starting user space).  Disable interrupts temporarily when
switching the tasks' register sets in resume().

Note that a simple oriw 0x700,%sr after restoring sr is not enough here
- this leaves enough of a race for the 'spinlock recursion' warning to
still be observed.

Tested on ARAnyM and qemu (Quadra 800 emulation).

Fixes: 533e6903be ("m68k: split ret_from_fork(), simplify kernel_thread()")
Reported-by: Guenter Roeck <linux@roeck-us.net>
Closes: https://lore.kernel.org/all/07811b26-677c-4d05-aeb4-996cd880b789@roeck-us.net
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/r/20240411033631.16335-1-schmitzmic@gmail.com
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2024-05-08 17:43:22 +02:00
..
68000 m68knommu: updates and fixes for v6.7 2023-11-02 15:31:01 -10:00
amiga m68k: amiga: Use str_plural() to fix Coccinelle warning 2024-04-29 16:45:53 +02:00
apollo m68k: apollo: Add and use "apollo.h" 2023-10-06 10:03:02 +02:00
atari m68k: atari: Add and use "atari.h" 2023-10-06 10:03:02 +02:00
bvme6000 m68k: Replace GPL 2.0+ README.legal boilerplate with SPDX 2023-10-06 10:03:04 +02:00
coldfire arch: include linux/cpu.h for trap_init() prototype 2023-11-23 11:32:31 +01:00
configs m68k: defconfig: Update defconfigs for v6.8-rc1 2024-02-19 11:11:01 +01:00
emu nfblock: pass queue_limits to blk_mq_alloc_disk 2024-02-19 16:58:23 -07:00
fpsp040 m68k: fpsp040: Fix indentation by 5 spaces 2023-10-16 14:30:40 +02:00
hp300 serial: 8250: Move hp300_setup_serial_console() to <linux/serial_8250.h> 2024-01-27 19:01:39 -08:00
ifpsp060 m68k: Replace GPL 2.0+ README.legal boilerplate with SPDX 2023-10-06 10:03:04 +02:00
include m68k: Calculate THREAD_SIZE from THREAD_SIZE_ORDER 2024-04-02 09:33:21 +02:00
kernel m68k: Fix spinlock race in kernel thread creation 2024-05-08 17:43:22 +02:00
lib m68k: lib: Include <linux/libgcc.h> for __muldi3() 2023-10-16 14:30:40 +02:00
mac m68k: mac: Add and use "mac.h" 2023-10-06 10:03:03 +02:00
math-emu m68k: math-emu: Add missing prototypes 2023-10-06 10:03:01 +02:00
mm m68knommu: updates and fixes for v6.7 2023-11-02 15:31:01 -10:00
mvme16x m68k: Replace GPL 2.0+ README.legal boilerplate with SPDX 2023-10-06 10:03:04 +02:00
mvme147 m68k: Replace GPL 2.0+ README.legal boilerplate with SPDX 2023-10-06 10:03:04 +02:00
q40 m68k: Replace GPL 2.0+ README.legal boilerplate with SPDX 2023-10-06 10:03:04 +02:00
sun3 m68k: sun3: Fix indentation by 5 or 7 spaces 2023-10-16 14:30:39 +02:00
sun3x m68k: sun3/3x: Add and use "sun3.h" 2023-10-06 10:03:04 +02:00
tools/amiga
virt
install.sh
Kbuild
Kconfig m68k: Let GENERIC_IOMAP depend on HAS_IOPORT 2024-05-08 17:43:22 +02:00
Kconfig.bus
Kconfig.cpu arch: define CONFIG_PAGE_SIZE_*KB on all architectures 2024-03-06 19:29:09 +01:00
Kconfig.debug m68k: Remove obsolete config NO_KERNEL_MSG 2023-03-20 15:39:14 +01:00
Kconfig.devices
Kconfig.machine m68knommu: improve config ROM setting defaults 2023-10-23 08:22:22 +10:00
Makefile kbuild: use 4-space indentation when followed by conditionals 2024-02-15 06:05:44 +09:00