Skip to content

Commit f2e91e8

Browse files
committed
KVM: selftests: Add x86 helpers to play nice with x2APIC MSR #GPs
Add helpers to allow and expect #GP on x2APIC MSRs, and opportunistically have the existing helper spit out a more useful error message if an unexpected exception occurs. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent ed24ba6 commit f2e91e8

File tree

1 file changed

+20
-1
lines changed
  • tools/testing/selftests/kvm/include/x86_64

1 file changed

+20
-1
lines changed

tools/testing/selftests/kvm/include/x86_64/apic.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <stdint.h>
1212

1313
#include "processor.h"
14+
#include "ucall_common.h"
1415

1516
#define APIC_DEFAULT_GPA 0xfee00000ULL
1617

@@ -93,9 +94,27 @@ static inline uint64_t x2apic_read_reg(unsigned int reg)
9394
return rdmsr(APIC_BASE_MSR + (reg >> 4));
9495
}
9596

97+
static inline uint8_t x2apic_write_reg_safe(unsigned int reg, uint64_t value)
98+
{
99+
return wrmsr_safe(APIC_BASE_MSR + (reg >> 4), value);
100+
}
101+
96102
static inline void x2apic_write_reg(unsigned int reg, uint64_t value)
97103
{
98-
wrmsr(APIC_BASE_MSR + (reg >> 4), value);
104+
uint8_t fault = x2apic_write_reg_safe(reg, value);
105+
106+
__GUEST_ASSERT(!fault, "Unexpected fault 0x%x on WRMSR(%x) = %lx\n",
107+
fault, APIC_BASE_MSR + (reg >> 4), value);
99108
}
100109

110+
static inline void x2apic_write_reg_fault(unsigned int reg, uint64_t value)
111+
{
112+
uint8_t fault = x2apic_write_reg_safe(reg, value);
113+
114+
__GUEST_ASSERT(fault == GP_VECTOR,
115+
"Wanted #GP on WRMSR(%x) = %lx, got 0x%x\n",
116+
APIC_BASE_MSR + (reg >> 4), value, fault);
117+
}
118+
119+
101120
#endif /* SELFTEST_KVM_APIC_H */

0 commit comments

Comments
 (0)