From 17f4cd18a305b1067d51323d160b7fdc7f440f1d Mon Sep 17 00:00:00 2001 From: "Yan, Like" Date: Thu, 31 Jan 2019 15:53:28 +0800 Subject: [PATCH] hv: fix dest of IPI for CPU with lapic_pt With lapic_pt based on vlapic, guest always see vitual apic_id. We need to convert the virtual apic_id from guest to physical apic_id before writing ICR. SMP for VM with lapic_pt is supported with this fix. Tracked-On: #2351 Signed-off-by: Yan, Like Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vlapic.c | 11 ++++++++--- hypervisor/arch/x86/guest/vmcs.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hypervisor/arch/x86/guest/vlapic.c b/hypervisor/arch/x86/guest/vlapic.c index db4779e93..07b1a2875 100644 --- a/hypervisor/arch/x86/guest/vlapic.c +++ b/hypervisor/arch/x86/guest/vlapic.c @@ -2075,7 +2075,7 @@ static inline uint32_t x2apic_msr_to_regoff(uint32_t msr) static int32_t vlapic_x2apic_pt_icr_access(struct acrn_vm *vm, uint64_t val) { - uint32_t apic_id = (uint32_t)(val >> 32U); + uint32_t papic_id, vapic_id = (uint32_t)(val >> 32U); uint32_t icr_low = (uint32_t)val; uint32_t mode = icr_low & APIC_DELMODE_MASK; uint16_t vcpu_id; @@ -2092,7 +2092,7 @@ vlapic_x2apic_pt_icr_access(struct acrn_vm *vm, uint64_t val) not supported in ICR forpartition mode\n"); ret = -1; } else { - vcpu_id = vm_apicid2vcpu_id(vm, apic_id); + vcpu_id = vm_apicid2vcpu_id(vm, vapic_id); target_vcpu = vcpu_from_vid(vm, vcpu_id); if (target_vcpu != NULL) { @@ -2104,7 +2104,12 @@ vlapic_x2apic_pt_icr_access(struct acrn_vm *vm, uint64_t val) vlapic_process_init_sipi(target_vcpu, mode, icr_low, vcpu_id); break; default: - msr_write(MSR_IA32_EXT_APIC_ICR, (((uint64_t)apic_id) << 32U) | icr_low); + /* convert the dest from virtual apic_id to physical apic_id */ + papic_id = per_cpu(lapic_id, target_vcpu->pcpu_id); + dev_dbg(ACRN_DBG_LAPICPT, + "%s vapic_id: 0x%08lx papic_id: 0x%08lx icr_low:0x%08lx", + __func__, vapic_id, papic_id, icr_low); + msr_write(MSR_IA32_EXT_APIC_ICR, (((uint64_t)papic_id) << 32U) | icr_low); break; } } diff --git a/hypervisor/arch/x86/guest/vmcs.c b/hypervisor/arch/x86/guest/vmcs.c index 9be16735d..cf2e45abe 100644 --- a/hypervisor/arch/x86/guest/vmcs.c +++ b/hypervisor/arch/x86/guest/vmcs.c @@ -564,6 +564,7 @@ void switch_apicv_mode_x2apic(struct acrn_vcpu *vcpu) { uint32_t value32; if (is_lapic_pt(vcpu->vm)) { + dev_dbg(ACRN_DBG_LAPICPT, "%s: switching to x2apic and passthru", __func__); /* * Disable external interrupt exiting and irq ack * Disable posted interrupt processing