Skip to content

Commit 3426cb4

Browse files
committed
KVM: selftests: Test x2APIC ICR reserved bits
Actually test x2APIC ICR reserved bits instead of deliberately skipping them. The behavior that is observed when IPI virtualization is enabled is the architecturally correct behavior, KVM is the one who was wrong, i.e. KVM was missing reserved bit checks. Fixes: 4b88b1a ("KVM: selftests: Enhance handling WRMSR ICR register in x2APIC mode") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent faf06a2 commit 3426cb4

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

tools/testing/selftests/kvm/x86_64/xapic_state_test.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ static void xapic_guest_code(void)
3131
}
3232
}
3333

34+
#define X2APIC_RSVD_BITS_MASK (GENMASK_ULL(31, 20) | \
35+
GENMASK_ULL(17, 16) | \
36+
GENMASK_ULL(13, 13))
37+
3438
static void x2apic_guest_code(void)
3539
{
3640
asm volatile("cli");
@@ -41,7 +45,10 @@ static void x2apic_guest_code(void)
4145
uint64_t val = x2apic_read_reg(APIC_IRR) |
4246
x2apic_read_reg(APIC_IRR + 0x10) << 32;
4347

44-
x2apic_write_reg(APIC_ICR, val);
48+
if (val & X2APIC_RSVD_BITS_MASK)
49+
x2apic_write_reg_fault(APIC_ICR, val);
50+
else
51+
x2apic_write_reg(APIC_ICR, val);
4552
GUEST_SYNC(val);
4653
} while (1);
4754
}
@@ -72,24 +79,14 @@ static void ____test_icr(struct xapic_vcpu *x, uint64_t val)
7279
(u64)(*((u32 *)&xapic.regs[APIC_ICR2])) << 32;
7380
if (!x->is_x2apic)
7481
val &= (-1u | (0xffull << (32 + 24)));
82+
else if (val & X2APIC_RSVD_BITS_MASK)
83+
return;
7584

7685
TEST_ASSERT_EQ(icr, val & ~APIC_ICR_BUSY);
7786
}
7887

79-
#define X2APIC_RSVED_BITS_MASK (GENMASK_ULL(31,20) | \
80-
GENMASK_ULL(17,16) | \
81-
GENMASK_ULL(13,13))
82-
8388
static void __test_icr(struct xapic_vcpu *x, uint64_t val)
8489
{
85-
if (x->is_x2apic) {
86-
/* Hardware writing vICR register requires reserved bits 31:20,
87-
* 17:16 and 13 kept as zero to avoid #GP exception. Data value
88-
* written to vICR should mask out those bits above.
89-
*/
90-
val &= ~X2APIC_RSVED_BITS_MASK;
91-
}
92-
9390
/*
9491
* The BUSY bit is reserved on both AMD and Intel, but only AMD treats
9592
* it is as _must_ be zero. Intel simply ignores the bit. Don't test

0 commit comments

Comments
 (0)