x86: Remove assumptions on CR4.MCE
PATCH v2 1/1 x86: Remove assumptions on CR4.MCE
CR4.MCE might be set after boot. Remove the assertion that checks that it is clear. Change the test to toggle the bit instead of setting it.
Cc Marc Orr <[email protected]>
Reviewed-by Marc Orr <[email protected]>
Reviewed-by Krish Sadhukhan <[email protected]>
Signed-off-by Nadav Amit <[email protected]>
--- x86/vmx_tests.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
x86/vmx_tests.c +13 -14
@@ -7096,8 +7096,11 @@ static int write_cr4_checking(unsigned long val)static void vmx_cr_load_test (void ) { +unsigned long cr3, cr4, orig_cr3, orig_cr4;struct cpuid _cpuid =cpuid (1 ); -unsigned long cr4 =read_cr4 (), cr3 =read_cr3 (); + + orig_cr4 =read_cr4 (); + orig_cr3 =read_cr3 ();if (!(_cpuid.c &X86_FEATURE_PCID )) {report_skip ("PCID not detected" );
@@ -7108,12 +7111,11 @@ static void vmx_cr_load_test(void)return ; } -TEST_ASSERT (!(cr4 & (X86_CR4_PCIDE |X86_CR4_MCE ))); -TEST_ASSERT (!(cr3 &X86_CR3_PCID_MASK )); +TEST_ASSERT (!(orig_cr3 &X86_CR3_PCID_MASK ));/* Enable PCID for L1. */ - cr4 |=X86_CR4_PCIDE ; - cr3 |=0x1 ; + cr4 = orig_cr4 |X86_CR4_PCIDE ; + cr3 = orig_cr3 |0x1 ;TEST_ASSERT (!write_cr4_checking (cr4));write_cr3 (cr3);
@@ -7126,17 +7128,14 @@ static void vmx_cr_load_test(void)* No exception is expected. * * NB. KVM loads the last guest write to CR4 into CR4 read -* shadow. In order to trigger an exit to KVM, we can set a -* bit that was zero in the above CR4 write and is owned by -* KVM. We choose to set CR4.MCE, which shall have no side -* effect because normally no guest MCE (e.g., as the result -* of bad memory) would happen during this test. +* shadow. In order to trigger an exit to KVM, we can toggle a +* bit that is owned by KVM. */ -TEST_ASSERT (!write_cr4_checking (cr4 |X86_CR4_MCE )); +TEST_ASSERT (!write_cr4_checking (cr4 ^X86_CR4_MCE )); -/* Cleanup L1 state: disable PCID. */ -write_cr3 (cr3 & ~X86_CR3_PCID_MASK ); -TEST_ASSERT (!write_cr4_checking (cr4 & ~X86_CR4_PCIDE )); +/* Cleanup L1 state. */ +write_cr3 (orig_cr3); +TEST_ASSERT (!write_cr4_checking (orig_cr4)); }static void vmx_nm_test_guest (void )
Signature · 1 line
2.17.1