Skip to content

Commit 20c80ea

Browse files
zhenggenlijinxia
authored andcommitted
HV: bug fix on emulating msi message from guest
Current code has a mistake associating destination with redirectionhint. So just use the destination mode to work out destination mode. When injecting the msi interrupt to vcpu in hypervisor layer, current code ingnores the redirection hint(RH) bit of msi address message from guest, and just use the destination mode and destination ID. So correctly before injecting, check the RH bit, if set, choose the vcpu that has lowest priority to inject msi. Signed-off-by: Zheng, Gen <gen.zheng@intel.com> Reviewed-by: Zhao, Yakui <yakui.zhao@intel.com> Reviewed-by: Yin, Fengwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 9695d3b commit 20c80ea

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

hypervisor/arch/x86/assign.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ static void ptdev_build_physical_msi(struct vm *vm, struct ptdev_msi_info *info,
200200

201201
/* get physical destination cpu mask */
202202
dest = (info->vmsi_addr >> 12) & 0xffU;
203-
phys = ((info->vmsi_addr &
204-
(MSI_ADDR_RH | MSI_ADDR_LOG)) !=
205-
(MSI_ADDR_RH | MSI_ADDR_LOG));
203+
phys = ((info->vmsi_addr & MSI_ADDR_LOG) != MSI_ADDR_LOG);
204+
206205
calcvdest(vm, &vdmask, dest, phys);
207206
pdmask = vcpumask2pcpumask(vm, vdmask);
208207

hypervisor/arch/x86/guest/vioapic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ vioapic_send_intr(struct vioapic *vioapic, uint8_t pin)
9393

9494
vector = rte.u.lo_32 & IOAPIC_RTE_LOW_INTVEC;
9595
dest = (uint32_t)(rte.full >> IOAPIC_RTE_DEST_SHIFT);
96-
vlapic_deliver_intr(vioapic->vm, level, dest, phys, delmode, vector);
96+
vlapic_deliver_intr(vioapic->vm, level, dest, phys, delmode, vector, false);
9797
}
9898

9999
static void

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ vlapic_set_apicbase(struct vlapic *vlapic, uint64_t new)
16541654

16551655
void
16561656
vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest, bool phys,
1657-
uint32_t delmode, uint32_t vec)
1657+
uint32_t delmode, uint32_t vec, bool rh)
16581658
{
16591659
bool lowprio;
16601660
uint16_t vcpu_id;
@@ -1668,7 +1668,7 @@ vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest, bool phys,
16681668
"vlapic intr invalid delmode %#x", delmode);
16691669
return;
16701670
}
1671-
lowprio = (delmode == IOAPIC_RTE_DELLOPRI);
1671+
lowprio = (delmode == IOAPIC_RTE_DELLOPRI) || rh;
16721672

16731673
/*
16741674
* We don't provide any virtual interrupt redirection hardware so
@@ -1856,7 +1856,7 @@ vlapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg)
18561856
{
18571857
uint32_t delmode, vec;
18581858
uint32_t dest;
1859-
bool phys;
1859+
bool phys, rh;
18601860

18611861
dev_dbg(ACRN_DBG_LAPIC, "lapic MSI addr: %#lx msg: %#lx", addr, msg);
18621862

@@ -1877,15 +1877,16 @@ vlapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg)
18771877
* physical otherwise.
18781878
*/
18791879
dest = (uint32_t)(addr >> 12U) & 0xffU;
1880-
phys = ((addr & (MSI_ADDR_RH | MSI_ADDR_LOG)) !=
1881-
(MSI_ADDR_RH | MSI_ADDR_LOG));
1880+
phys = ((addr & MSI_ADDR_LOG) != MSI_ADDR_LOG);
1881+
rh = ((addr & MSI_ADDR_RH) == MSI_ADDR_RH);
1882+
18821883
delmode = (uint32_t)msg & APIC_DELMODE_MASK;
18831884
vec = (uint32_t)msg & 0xffU;
18841885

18851886
dev_dbg(ACRN_DBG_LAPIC, "lapic MSI %s dest %#x, vec %u",
18861887
phys ? "physical" : "logical", dest, vec);
18871888

1888-
vlapic_deliver_intr(vm, LAPIC_TRIG_EDGE, dest, phys, delmode, vec);
1889+
vlapic_deliver_intr(vm, LAPIC_TRIG_EDGE, dest, phys, delmode, vec, rh);
18891890
return 0;
18901891
}
18911892

hypervisor/include/arch/x86/guest/vlapic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id, uint32_t vector);
9696
int vlapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg);
9797

9898
void vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest,
99-
bool phys, uint32_t delmode, uint32_t vec);
99+
bool phys, uint32_t delmode, uint32_t vec, bool rh);
100100

101101
/* Reset the trigger-mode bits for all vectors to be edge-triggered */
102102
void vlapic_reset_tmr(struct vlapic *vlapic);

0 commit comments

Comments
 (0)