Skip to content

Commit 4557033

Browse files
lifeixwenlingz
authored andcommitted
hv: vlapic: minor fix about vlapic write
1) In x2apic mode, when read ICR, we want to read a 64-bits value. 2) In x2apic mode, write self-IPI will trap out through MSR write when VID isn't enabled. Tracked-On: #1842 Signed-off-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent fa8fa37 commit 4557033

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ apicv_set_intr_ready(struct acrn_vlapic *vlapic, uint32_t vector);
9292

9393
static void apicv_post_intr(uint16_t dest_pcpu_id);
9494

95+
static void vlapic_x2apic_self_ipi_handler(struct acrn_vlapic *vlapic);
96+
9597
/*
9698
* Post an interrupt to the vcpu running on 'hostcpu'. This will use a
9799
* hardware assist if available (e.g. Posted Interrupt) or fall back to
@@ -1530,6 +1532,9 @@ vlapic_read(struct acrn_vlapic *vlapic, uint32_t offset_arg, uint64_t *data)
15301532
break;
15311533
case APIC_OFFSET_ICR_LOW:
15321534
*data = lapic->icr_lo.v;
1535+
if (is_x2apic_enabled(vlapic)) {
1536+
*data |= ((uint64_t)lapic->icr_hi.v) << 32U;
1537+
}
15331538
break;
15341539
case APIC_OFFSET_ICR_HI:
15351540
*data = lapic->icr_hi.v;
@@ -1568,8 +1573,7 @@ vlapic_read(struct acrn_vlapic *vlapic, uint32_t offset_arg, uint64_t *data)
15681573
}
15691574
}
15701575

1571-
dev_dbg(ACRN_DBG_LAPIC,
1572-
"vlapic read offset %#x, data %#lx", offset, *data);
1576+
dev_dbg(ACRN_DBG_LAPIC, "vlapic read offset %#x, data %#llx", offset, *data);
15731577
return 0;
15741578
}
15751579

@@ -1610,10 +1614,8 @@ vlapic_write(struct acrn_vlapic *vlapic, uint32_t offset, uint64_t data)
16101614
case APIC_OFFSET_ICR_LOW:
16111615
if (is_x2apic_enabled(vlapic)) {
16121616
lapic->icr_hi.v = (uint32_t)(data >> 32U);
1613-
lapic->icr_lo.v = data32;
1614-
} else {
1615-
lapic->icr_lo.v = data32;
16161617
}
1618+
lapic->icr_lo.v = data32;
16171619
retval = vlapic_icrlo_write_handler(vlapic);
16181620
break;
16191621
case APIC_OFFSET_ICR_HI:
@@ -1643,7 +1645,6 @@ vlapic_write(struct acrn_vlapic *vlapic, uint32_t offset, uint64_t data)
16431645
lapic->dcr_timer.v = data32;
16441646
vlapic_dcr_write_handler(vlapic);
16451647
break;
1646-
16471648
case APIC_OFFSET_ESR:
16481649
vlapic_esr_write_handler(vlapic);
16491650
break;
@@ -1660,7 +1661,17 @@ vlapic_write(struct acrn_vlapic *vlapic, uint32_t offset, uint64_t data)
16601661
*/
16611662
case APIC_OFFSET_TIMER_CCR:
16621663
break;
1664+
1665+
case APIC_OFFSET_SELF_IPI:
1666+
if (is_x2apic_enabled(vlapic)) {
1667+
lapic->self_ipi.v = data32;
1668+
vlapic_x2apic_self_ipi_handler(vlapic);
1669+
break;
1670+
}
1671+
/* falls through */
1672+
16631673
default:
1674+
retval = -EACCES;
16641675
/* Read only */
16651676
break;
16661677
}
@@ -2344,14 +2355,13 @@ static void vlapic_x2apic_self_ipi_handler(struct acrn_vlapic *vlapic)
23442355
int32_t apic_write_vmexit_handler(struct acrn_vcpu *vcpu)
23452356
{
23462357
uint64_t qual;
2347-
int32_t error, handled;
2358+
int32_t err = 0;
23482359
uint32_t offset;
23492360
struct acrn_vlapic *vlapic = NULL;
23502361

23512362
qual = vcpu->arch.exit_qualification;
23522363
offset = (uint32_t)(qual & 0xFFFUL);
23532364

2354-
handled = 1;
23552365
vcpu_retain_rip(vcpu);
23562366
vlapic = vcpu_vlapic(vcpu);
23572367

@@ -2375,10 +2385,7 @@ int32_t apic_write_vmexit_handler(struct acrn_vcpu *vcpu)
23752385
vlapic_esr_write_handler(vlapic);
23762386
break;
23772387
case APIC_OFFSET_ICR_LOW:
2378-
error = vlapic_icrlo_write_handler(vlapic);
2379-
if (error != 0) {
2380-
handled = 0;
2381-
}
2388+
err = vlapic_icrlo_write_handler(vlapic);
23822389
break;
23832390
case APIC_OFFSET_CMCI_LVT:
23842391
case APIC_OFFSET_TIMER_LVT:
@@ -2398,17 +2405,18 @@ int32_t apic_write_vmexit_handler(struct acrn_vcpu *vcpu)
23982405
case APIC_OFFSET_SELF_IPI:
23992406
if (is_x2apic_enabled(vlapic)) {
24002407
vlapic_x2apic_self_ipi_handler(vlapic);
2408+
break;
24012409
}
2402-
break;
2410+
/* falls through */
24032411
default:
2404-
handled = 0;
2412+
err = -EACCES;
24052413
pr_err("Unhandled APIC-Write, offset:0x%x", offset);
24062414
break;
24072415
}
24082416

24092417
TRACE_2L(TRACE_VMEXIT_APICV_WRITE, offset, 0UL);
24102418

2411-
return handled;
2419+
return err;
24122420
}
24132421

24142422
int32_t tpr_below_threshold_vmexit_handler(__unused struct acrn_vcpu *vcpu)

0 commit comments

Comments
 (0)