linux_dsm_epyc7002/arch/csky/kernel
Valentin Schneider 3c51d82d0b sched/core: Initialize the idle task with preemption disabled
[ Upstream commit f1a0a376ca0c4ef1fc3d24e3e502acbb5b795674 ]

As pointed out by commit

  de9b8f5dcb ("sched: Fix crash trying to dequeue/enqueue the idle thread")

init_idle() can and will be invoked more than once on the same idle
task. At boot time, it is invoked for the boot CPU thread by
sched_init(). Then smp_init() creates the threads for all the secondary
CPUs and invokes init_idle() on them.

As the hotplug machinery brings the secondaries to life, it will issue
calls to idle_thread_get(), which itself invokes init_idle() yet again.
In this case it's invoked twice more per secondary: at _cpu_up(), and at
bringup_cpu().

Given smp_init() already initializes the idle tasks for all *possible*
CPUs, no further initialization should be required. Now, removing
init_idle() from idle_thread_get() exposes some interesting expectations
with regards to the idle task's preempt_count: the secondary startup always
issues a preempt_disable(), requiring some reset of the preempt count to 0
between hot-unplug and hotplug, which is currently served by
idle_thread_get() -> idle_init().

Given the idle task is supposed to have preemption disabled once and never
see it re-enabled, it seems that what we actually want is to initialize its
preempt_count to PREEMPT_DISABLED and leave it there. Do that, and remove
init_idle() from idle_thread_get().

Secondary startups were patched via coccinelle:

  @begone@
  @@

  -preempt_disable();
  ...
  cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);

Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210512094636.2958515-1-valentin.schneider@arm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-07-14 16:55:50 +02:00
..
probes csky: kprobes: Use generic kretprobe trampoline handler 2020-09-08 11:52:33 +02:00
asm-offsets.c csky: Fixup gdbmacros.txt with name sp in thread_struct 2020-05-15 00:16:18 +08:00
atomic.S csky: Set regs->usp to kernel sp, when the exception is from kernel 2020-02-21 15:43:24 +08:00
cpu-probe.c csky: Exception handling and mm-fault 2018-10-25 23:36:19 +08:00
entry.S csky: Add context tracking support 2020-08-01 08:17:51 +00:00
ftrace.c maccess: rename probe_kernel_{read,write} to copy_{from,to}_kernel_nofault 2020-06-17 10:57:41 -07:00
head.S csky: Fixup cpu speculative execution to IO area 2020-04-03 12:40:07 +08:00
irq.c csky: IRQ handling 2018-10-26 00:54:22 +08:00
Makefile csky: Fixup calltrace panic 2020-05-13 17:55:06 +08:00
module.c mm: don't include asm/pgtable.h if linux/mm.h is already included 2020-06-09 09:39:13 -07:00
perf_callchain.c csky: Fixup perf callchain unwind 2020-05-13 17:55:05 +08:00
perf_event.c csky: Move static keyword to the front of declaration 2019-09-30 11:50:49 +08:00
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
power.c csky: Library functions 2018-10-26 00:54:24 +08:00
process.c sched/idle: Fix arch_cpu_idle() vs tracing 2020-11-24 16:47:35 +01:00
ptrace.c csky: Fix a size determination in gpr_get() 2021-03-04 11:38:21 +01:00
setup.c dma-mapping: merge <linux/dma-contiguous.h> into <linux/dma-map-ops.h> 2020-10-06 07:07:04 +02:00
signal.c tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume() 2020-10-17 15:04:36 -06:00
smp.c sched/core: Initialize the idle task with preemption disabled 2021-07-14 16:55:50 +02:00
stacktrace.c kernel: rename show_stack_loglvl() => show_stack() 2020-06-09 09:39:13 -07:00
syscall_table.c csky: System Call 2018-10-25 23:36:19 +08:00
syscall.c csky: System Call 2018-10-25 23:36:19 +08:00
time.c csky: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-02-23 12:48:55 +08:00
traps.c csky: Optimize the trap processing flow 2020-07-31 01:52:22 +00:00
vdso.c mmap locking API: use coccinelle to convert mmap_sem rwsem call sites 2020-06-09 09:39:14 -07:00
vmlinux.lds.S vmlinux.lds.h: Split ELF_DETAILS from STABS_DEBUG 2020-09-01 09:50:35 +02:00