From 6137347411b5481fc92e09d420349afba50ca333 Mon Sep 17 00:00:00 2001 From: Li Fei1 Date: Mon, 19 Apr 2021 11:12:58 +0800 Subject: [PATCH] hv: smp: fix an isuue about SMP sync Now BSP may launch VMs before APs have not done its initilization, for example, sched_control for per-cpu. However, when we initilize the vcpu thread data, it will access the object (scheduler) of the sched_control of APs. As a result, it will trigger the PF. This patch would waits each physical has done its initilization before to continue to execute. Tracked-On: #5929 Signed-off-by: Li Fei1 --- hypervisor/arch/x86/cpu.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index ef804463f..76e59a808 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -259,6 +259,7 @@ void init_pcpu_post(uint16_t pcpu_id) */ reserve_buffer_for_ept_pages(); + pcpu_sync = ALL_CPUS_MASK; /* Start all secondary cores */ startup_paddr = prepare_trampoline(); if (!start_pcpus(AP_MASK)) { @@ -276,9 +277,6 @@ void init_pcpu_post(uint16_t pcpu_id) timer_init(); ptdev_init(); - - /* Wait for boot processor to signal all secondary cores to continue */ - wait_sync_change(&pcpu_sync, 0UL); } if (!init_software_sram(pcpu_id == BSP_CPU_ID)) { @@ -296,6 +294,10 @@ void init_pcpu_post(uint16_t pcpu_id) enable_smap(); init_keylocker(); + + bitmap_clear_lock(pcpu_id, &pcpu_sync); + /* Waiting for each pCPU has done its initialization before to continue */ + wait_sync_change(&pcpu_sync, 0UL); } static uint16_t get_pcpu_id_from_lapic_id(uint32_t lapic_id) @@ -362,10 +364,6 @@ bool start_pcpus(uint64_t mask) uint16_t pcpu_id = get_pcpu_id(); uint64_t expected_start_mask = mask; - /* secondary cpu start up will wait for pcpu_sync -> 0UL */ - pcpu_sync = 1UL; - cpu_write_memory_barrier(); - i = ffs64(expected_start_mask); while (i != INVALID_BIT_INDEX) { bitmap_clear_nolock(i, &expected_start_mask); @@ -378,9 +376,6 @@ bool start_pcpus(uint64_t mask) i = ffs64(expected_start_mask); } - /* Trigger event to allow secondary CPUs to continue */ - pcpu_sync = 0UL; - return ((pcpu_active_bitmap & mask) == mask); }