[PATCH] init/main: Clear boot task idle flag

From: Liam R. Howlett
Date: Tue Sep 12 2023 - 13:45:29 EST


Initial booting was setting the task flag to idle (PF_IDLE) by the call
path sched_init() -> init_idle(). Having the task idle and calling
call_rcu() in kernel/rcu/tiny.c means that TIF_NEED_RESCHED will be
enabled. Subsequent calls to any cond_resched() will enable IRQs,
potentially earlier than the enabling of IRQs.

This causes a warning later in start_kernel() as interrupts are enabled
before the are fully set up.

Fix this issue by clearing the PF_IDLE flag on return from sched_init()
and restore the flag in rest_init().

Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx>
---
init/main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index ad920fac325c..46b35be8f00a 100644
--- a/init/main.c
+++ b/init/main.c
@@ -696,7 +696,7 @@ noinline void __ref __noreturn rest_init(void)
*/
rcu_read_lock();
tsk =3D find_task_by_pid_ns(pid, &init_pid_ns);
- tsk->flags |=3D PF_NO_SETAFFINITY;
+ tsk->flags |=3D PF_NO_SETAFFINITY | PF_IDLE;
set_cpus_allowed_ptr(tsk, cpumask_of(smp_processor_id()));
rcu_read_unlock();
=20
@@ -938,6 +938,7 @@ void start_kernel(void)
* time - but meanwhile we still have a functioning scheduler.
*/
sched_init();
+ current->flags &=3D ~PF_IDLE;
=20
if (WARN(!irqs_disabled(),
"Interrupts were enabled *very* early, fixing it\n"))
--=20
2.39.2


--5aqidbzt6oq7a3jx--