Skip to content

Commit 1bd9dfe

Browse files
ssuthiku-amdbonzini
authored andcommitted
KVM: x86: Do not block APIC write for non ICR registers
The commit 5413bcb ("KVM: x86: Add support for vICR APIC-write VM-Exits in x2APIC mode") introduces logic to prevent APIC write for offset other than ICR in kvm_apic_write_nodecode() function. This breaks x2AVIC support, which requires KVM to trap and emulate x2APIC MSR writes. Therefore, removes the warning and modify to logic to allow MSR write. Fixes: 5413bcb ("KVM: x86: Add support for vICR APIC-write VM-Exits in x2APIC mode") Cc: Zeng Guang <[email protected]> Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Suravee Suthikulpanit <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0a8735a commit 1bd9dfe

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

arch/x86/kvm/lapic.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static bool lapic_timer_advance_dynamic __read_mostly;
6969
/* step-by-step approximation to mitigate fluctuation */
7070
#define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8
7171
static int kvm_lapic_msr_read(struct kvm_lapic *apic, u32 reg, u64 *data);
72+
static int kvm_lapic_msr_write(struct kvm_lapic *apic, u32 reg, u64 data);
7273

7374
static inline void __kvm_lapic_set_reg(char *regs, int reg_off, u32 val)
7475
{
@@ -2283,21 +2284,20 @@ void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset)
22832284
struct kvm_lapic *apic = vcpu->arch.apic;
22842285
u64 val;
22852286

2286-
if (apic_x2apic_mode(apic)) {
2287-
/*
2288-
* When guest APIC is in x2APIC mode and IPI virtualization
2289-
* is enabled, accessing APIC_ICR may cause trap-like VM-exit
2290-
* on Intel hardware. Other offsets are not possible.
2291-
*/
2292-
if (WARN_ON_ONCE(offset != APIC_ICR))
2293-
return;
2294-
2287+
if (apic_x2apic_mode(apic))
22952288
kvm_lapic_msr_read(apic, offset, &val);
2289+
else
2290+
val = kvm_lapic_get_reg(apic, offset);
2291+
2292+
/*
2293+
* ICR is a single 64-bit register when x2APIC is enabled. For legacy
2294+
* xAPIC, ICR writes need to go down the common (slightly slower) path
2295+
* to get the upper half from ICR2.
2296+
*/
2297+
if (apic_x2apic_mode(apic) && offset == APIC_ICR) {
22962298
kvm_apic_send_ipi(apic, (u32)val, (u32)(val >> 32));
22972299
trace_kvm_apic_write(APIC_ICR, val);
22982300
} else {
2299-
val = kvm_lapic_get_reg(apic, offset);
2300-
23012301
/* TODO: optimize to just emulate side effect w/o one more write */
23022302
kvm_lapic_reg_write(apic, offset, (u32)val);
23032303
}

0 commit comments

Comments
 (0)