Skip to content

Commit

Permalink
sched,init: Fix DEBUG_PREEMPT vs early boot
Browse files Browse the repository at this point in the history
Extend 8fb1215 ("init: Pin init task to the boot CPU, initially")
to cover the new PF_NO_SETAFFINITY requirement.

While there, move wait_for_completion(&kthreadd_done) into kernel_init()
to make it absolutely clear it is the very first thing done by the init
thread.

Fixes: 570a752 ("lib/smp_processor_id: Use is_percpu_thread() instead of nr_cpus_allowed")
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Valentin Schneider <[email protected]>
Tested-by: Valentin Schneider <[email protected]>
Tested-by: Borislav Petkov <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
Peter Zijlstra committed Jun 1, 2021
1 parent 7b419f4 commit 15faafc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ noinline void __ref rest_init(void)
*/
rcu_read_lock();
tsk = find_task_by_pid_ns(pid, &init_pid_ns);
tsk->flags |= PF_NO_SETAFFINITY;
set_cpus_allowed_ptr(tsk, cpumask_of(smp_processor_id()));
rcu_read_unlock();

Expand Down Expand Up @@ -1440,6 +1441,11 @@ static int __ref kernel_init(void *unused)
{
int ret;

/*
* Wait until kthreadd is all set-up.
*/
wait_for_completion(&kthreadd_done);

kernel_init_freeable();
/* need to finish all async __init code before freeing the memory */
async_synchronize_full();
Expand Down Expand Up @@ -1520,11 +1526,6 @@ void __init console_on_rootfs(void)

static noinline void __init kernel_init_freeable(void)
{
/*
* Wait until kthreadd is all set-up.
*/
wait_for_completion(&kthreadd_done);

/* Now the scheduler is fully set up and can do blocking allocations */
gfp_allowed_mask = __GFP_BITS_MASK;

Expand Down
1 change: 1 addition & 0 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -8862,6 +8862,7 @@ void __init sched_init_smp(void)
/* Move init over to a non-isolated CPU */
if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
BUG();
current->flags &= ~PF_NO_SETAFFINITY;
sched_init_granularity();

init_sched_rt_class();
Expand Down

0 comments on commit 15faafc

Please sign in to comment.