diff mbox series

[kvm-unit-tests,4/9] x86/apic: Assert that vCPU0's APIC is enabled at the start of the test

Message ID 20221001011301.2077437-5-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series x86/apic: Cleanups and new tests | expand

Commit Message

Sean Christopherson Oct. 1, 2022, 1:12 a.m. UTC
Assert that vCPU's APIC is fully enabled at the start of the apic test.
The boot code is supposed to do that, but nothing ever actually verifies
the APIC got setup correctly.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 x86/apic.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/x86/apic.c b/x86/apic.c
index 650c1d0..6c555ce 100644
--- a/x86/apic.c
+++ b/x86/apic.c
@@ -15,6 +15,11 @@  static bool is_apic_hw_enabled(void)
 	return rdmsr(MSR_IA32_APICBASE) & APIC_EN;
 }
 
+static bool is_apic_sw_enabled(void)
+{
+	return apic_read(APIC_SPIV) & APIC_SPIV_APIC_ENABLED;
+}
+
 static bool is_x2apic_enabled(void)
 {
 	return (rdmsr(MSR_IA32_APICBASE) & (APIC_EN | APIC_EXTD)) == (APIC_EN | APIC_EXTD);
@@ -691,6 +696,9 @@  static void test_pv_ipi(void)
 
 int main(void)
 {
+	assert_msg(is_apic_hw_enabled() && is_apic_sw_enabled(),
+		   "APIC should be fully enabled by startup code.");
+
 	setup_vm();
 
 	test_lapic_existence();