From 65e5f2cdd458278b2fff8d23cac133396e339c07 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 20 Jan 2020 17:23:03 +0000 Subject: [PATCH] x86: Wait for curthread to be set up as an indicator that the boot stack is no longer used. pc_curthread is set by cpu_switch after it stopped using the old thread (or boot) stack. This makes the smp_after_idle_runnable() function not dependent on the internals of the scheduler operations. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D23276 --- sys/x86/x86/mp_x86.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index efe221c86f2..e4354c08f06 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -1092,13 +1092,12 @@ init_secondary_tail(void) static void smp_after_idle_runnable(void *arg __unused) { - struct thread *idle_td; + struct pcpu *pc; int cpu; for (cpu = 1; cpu < mp_ncpus; cpu++) { - idle_td = pcpu_find(cpu)->pc_idlethread; - while (atomic_load_int(&idle_td->td_lastcpu) == NOCPU && - atomic_load_int(&idle_td->td_oncpu) == NOCPU) + pc = pcpu_find(cpu); + while (atomic_load_ptr(&pc->pc_curthread) == (uintptr_t)NULL) cpu_spinwait(); kmem_free((vm_offset_t)bootstacks[cpu], kstack_pages * PAGE_SIZE);