OrangePi_CM5/arch/riscv/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
..
vdso riscv: vdso: fix and clean-up Makefile 2021-06-10 13:39:22 +02:00
.gitignore
…
Makefile RISC-V: Add EFI runtime services 2020-10-02 14:31:28 -07:00
asm-offsets.c
…
cacheinfo.c riscv: cacheinfo: Fix using smp_processor_id() in preemptible 2021-01-27 11:55:00 +01:00
cpu-hotplug.c
…
cpu.c
…
cpu_ops.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
cpu_ops_sbi.c
…
cpu_ops_spinwait.c
…
cpufeature.c
…
efi-header.S RISC-V: Add PE/COFF header for EFI stub 2020-10-02 14:31:16 -07:00
efi.c RISC-V: Add EFI runtime services 2020-10-02 14:31:28 -07:00
entry.S riscv,entry: fix misaligned base for excp_vect_table 2021-04-16 11:43:21 +02:00
fpu.S
…
ftrace.c risc-v: kernel: ftrace: Fixes improper SPDX comment style 2020-11-04 13:28:20 -08:00
head.S riscv: Set text_offset correctly for M-Mode 2020-11-05 17:32:27 -08:00
head.h RISC-V: Move DT mapping outof fixmap 2020-10-02 14:30:57 -07:00
image-vars.h RISC-V: Add PE/COFF header for EFI stub 2020-10-02 14:31:16 -07:00
irq.c
…
jump_label.c
…
kgdb.c
…
mcount-dyn.S
…
mcount.S riscv: Workaround mcount name prior to clang-13 2021-05-22 11:40:53 +02:00
module-sections.c
…
module.c
…
patch.c
…
perf_callchain.c
…
perf_event.c
…
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
process.c sched/idle: Fix arch_cpu_idle() vs tracing 2020-11-24 16:47:35 +01:00
ptrace.c
…
reset.c
…
riscv_ksyms.c
…
sbi.c RISC-V: Add mechanism to provide custom IPI operations 2020-08-20 10:55:40 -07:00
setup.c RISC-V: Add missing jump label initialization 2020-11-25 09:44:25 -08:00
signal.c tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume() 2020-10-17 15:04:36 -06:00
smp.c RISC-V: Fix error code returned by riscv_hartid_to_cpuid() 2021-05-19 10:13:06 +02:00
smpboot.c sched/core: Initialize the idle task with preemption disabled 2021-07-14 16:55:50 +02:00
soc.c
…
stacktrace.c
…
sys_riscv.c
…
syscall_table.c
…
time.c riscv: Fix kernel time_init() 2021-01-27 11:54:59 +01:00
traps.c
…
traps_misaligned.c
…
vdso.c riscv: Fixup CONFIG_GENERIC_TIME_VSYSCALL 2021-01-19 18:27:20 +01:00
vmlinux.lds.S RISC-V Patches for the 5.10 Merge Window, Part 1 2020-10-19 18:18:30 -07:00