From 9461c70fcdcda933185659bfa60e4e89452dd7fe Mon Sep 17 00:00:00 2001 From: hujun5 Date: Tue, 11 Feb 2025 17:41:19 +0800 Subject: [PATCH] x86_64: fix bootup problem in SMP We need to initialize the per - CPU registers as early as possible. Signed-off-by: hujun5 --- arch/x86_64/src/intel64/intel64_cpu.c | 15 +-------------- arch/x86_64/src/intel64/intel64_cpustart.c | 3 +-- arch/x86_64/src/intel64/intel64_irq.c | 6 ++++++ 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/arch/x86_64/src/intel64/intel64_cpu.c b/arch/x86_64/src/intel64/intel64_cpu.c index d1650da176f..f93289ae789 100644 --- a/arch/x86_64/src/intel64/intel64_cpu.c +++ b/arch/x86_64/src/intel64/intel64_cpu.c @@ -366,14 +366,7 @@ bool x86_64_cpu_ready_get(uint8_t cpu) uint8_t x86_64_cpu_count_get(void) { - irqstate_t flags; - uint8_t count; - - flags = spin_lock_irqsave(&g_ap_boot); - count = g_cpu_count; - spin_unlock_irqrestore(&g_ap_boot, flags); - - return count; + return g_cpu_count; } /**************************************************************************** @@ -425,10 +418,4 @@ void x86_64_cpu_priv_set(uint8_t cpu) write_msr(MSR_FMASK, X86_64_RFLAGS_IF | X86_64_RFLAGS_DF); #endif - -#ifdef CONFIG_SMP - /* Attach TLB shootdown handler */ - - irq_attach(SMP_IPI_TLBSHOOTDOWN_IRQ, x86_64_tlb_handler, NULL); -#endif } diff --git a/arch/x86_64/src/intel64/intel64_cpustart.c b/arch/x86_64/src/intel64/intel64_cpustart.c index baaf87ae995..3cb9854c3b0 100644 --- a/arch/x86_64/src/intel64/intel64_cpustart.c +++ b/arch/x86_64/src/intel64/intel64_cpustart.c @@ -154,6 +154,7 @@ void x86_64_ap_boot(void) tcb = current_task(cpu); UNUSED(tcb); + up_update_task(tcb); #ifdef CONFIG_SCHED_THREAD_LOCAL /* Make sure that FS_BASE is not null */ @@ -212,8 +213,6 @@ void x86_64_ap_boot(void) x86_64_hwdebug_init(); #endif - up_update_task(tcb); - /* Then transfer control to the IDLE task */ nx_idle_trampoline(); diff --git a/arch/x86_64/src/intel64/intel64_irq.c b/arch/x86_64/src/intel64/intel64_irq.c index 4934113278d..0d1470476f2 100644 --- a/arch/x86_64/src/intel64/intel64_irq.c +++ b/arch/x86_64/src/intel64/intel64_irq.c @@ -544,6 +544,12 @@ void up_irqinitialize(void) irq_attach(ISR13, x86_64_fault_panic_isr, NULL); irq_attach(ISR14, x86_64_fault_panic_isr, NULL); irq_attach(ISR16, x86_64_fault_kill_isr, NULL); + +#ifdef CONFIG_SMP + /* Attach TLB shootdown handler */ + + irq_attach(SMP_IPI_TLBSHOOTDOWN_IRQ, x86_64_tlb_handler, NULL); +#endif } /****************************************************************************