x86/vmx: Add some FRED tests
cover x86/vmx: Add some FRED tests
This patch series add tests to:
1) verify that FRED MSRs are correctly handled during VM-Exit.
2) verify that attempting a VM entry with a reserved bit set in the host FRED_CONFIG MSR correctly triggers a VM-entry failure.
3) validate #GP injection for EFER.LME clear with FRED enabled.
While adding tests to verify FRED MSR behaviors controlled by VM-Exit FRED controls, add similar tests to verify EFER/PAT/RTIT/CET MSRs are correctly handled by their corresponding VM-Exit controls to improve test coverage (especially the nested code coverage).
Xin Li (11):
x86/vmx: Support the nested exception bit in VMX_BASIC MSR x86/vmx: Allow bit 13 of VM-entry injection info to be set x86/vmx: Simplify msr_bmp_init()
x86/vmx: Fix a typo
x86/vmx: Validate FRED MSR handling during VM-Exit x86/vmx: Validate the EFER MSR handling during VM-Exit x86/vmx: Validate the PAT MSR handling during VM-Exit x86/vmx: Validate the RTIT control MSR handling during VM-Exit x86/vmx: Validate CET MSR handling during VM-Exit x86/vmx: Validate FRED state checking during VM-Entry x86/vmx: Validate #GP injection for EFER.LME clear with FRED enabled
lib/x86/msr.h | 13 + lib/x86/processor.h | 2 + x86/vmx.c | 95 ++++++- x86/vmx.h | 118 ++++++++- x86/vmx_tests.c | 631 +++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 845 insertions(+), 14 deletions(-)
base-commit: 1da1819e49fc4938985edca67df669099b4c87a7
Signature · 1 line
2.54.0
PATCH 1/11 x86/vmx: Support the nested exception bit in VMX_BASIC MSR
Bit 58 in the VMX_BASIC MSR is used to enumerate VMX nested-exception support, thus it's no longer a reserved bit, and can be read as 1.
--- x86/vmx.c | 3 ++- x86/vmx.h | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
x86/vmx.c +2 -1
@@ -1573,7 +1573,8 @@ static void test_vmx_caps(void)report ((basic_msr.revision & (1ul <<31 )) ==0 && basic_msr.size >0 && basic_msr.size <=4096 && (basic_msr.type ==0 || basic_msr.type ==6 ) && - basic_msr.reserved1 ==0 && basic_msr.reserved2 ==0 , + basic_msr.reserved1 ==0 && basic_msr.reserved2 ==0 && + basic_msr.reserved3 ==0 ,"MSR_IA32_VMX_BASIC" ); val =rdmsr (MSR_IA32_VMX_MISC );
x86/vmx.h +4 -2
@@ -114,14 +114,16 @@ union vmx_basic_msr {struct {u32 revision;u32 size:13 , - reserved1:3 , + reserved1:3 , width:1 , dual:1 , type:4 , insouts:1 , ctrl:1 , no_hw_errcode_cc:1 , - reserved2:7 ; + reserved2:1 , + nested_exception:1 , + reserved3:5 ; }; };
Signature · 1 line
2.54.0
PATCH 2/11 x86/vmx: Allow bit 13 of VM-entry injection info to be set
In reply to Xin LiWith the introduction of VMX nested-exception support, bit 13 of the VM-entry interruption-information field (Nested Exception) must be set when injecting a nested hardware exception.
A CPU supporting FRED relaxes the Intel SDM's conventional VM-entry validation checks: if the event type is a hardware exception (bits 10:8 set to 3), bit 13 is permitted to be 1, regardless of whether FRED transitions are actively enabled following the VM-entry.
Update the event injection test logic to allow this bit to be set to prevent spurious test failures on FRED-capable hardware.
--- x86/vmx_tests.c | 9 +++++++++ 1 file changed, 9 insertions(+)
x86/vmx_tests.c +9 -0
@@ -4708,6 +4708,15 @@ skip_unrestricted_guest:/* Reserved bits in the field (30:12) are 0. */ report_prefix_push ("reserved bits clear" );for (cnt =12 ; cnt <=30 ; cnt++) { +/* +* Regardless of whether FRED transitions would be enabled +* following VM entry, if event type (bits 10:8) is 3 +* (hardware exception), bit 13 may have value 1 (indicating +* a nested exception). +*/ +if (cnt ==13 ) +continue ; + ent_intr_info = ent_intr_info_base |INTR_INFO_DELIVER_CODE_MASK | INTR_TYPE_HARD_EXCEPTION | GP_VECTOR |
Signature · 1 line
2.54.0
PATCH 3/11 x86/vmx: Simplify msr_bmp_init()
In reply to Xin LiUse the helper vmcs_set_bits() to update CPU_EXEC_CTRL0.
--- x86/vmx_tests.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
x86/vmx_tests.c +2 -8
@@ -369,14 +369,8 @@ static void vmx_pae_free_page_tables_cb(void *pdpt_)static void msr_bmp_init (void ) { -void *msr_bitmap; -u32 ctrl_cpu0; - - msr_bitmap =alloc_page (); - ctrl_cpu0 =vmcs_read (CPU_EXEC_CTRL0 ); - ctrl_cpu0 |=CPU_MSR_BITMAP ; -vmcs_write (CPU_EXEC_CTRL0 , ctrl_cpu0); -vmcs_write (MSR_BITMAP , (u64 )msr_bitmap); +vmcs_set_bits (CPU_EXEC_CTRL0 ,CPU_MSR_BITMAP ); +vmcs_write (MSR_BITMAP , (u64 )alloc_page ()); }static void *get_msr_bitmap (void )
Signature · 1 line
2.54.0
PATCH 4/11 x86/vmx: Fix a typo
In reply to Xin LiThis should be GUEST_EFER rather than GUEST_PAT.
--- x86/vmx_tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/vmx_tests.c +1 -1
@@ -537,7 +537,7 @@ static int test_ctrl_efer_exit_handler(union exit_reason exit_reason)report (rdmsr (MSR_EFER ) == (ia32_efer ^EFER_NX ),"Exit load EFER" ); } -vmcs_write (GUEST_PAT , ia32_efer); +vmcs_write (GUEST_EFER , ia32_efer);vmcs_write (GUEST_RIP , guest_rip +3 );return VMX_TEST_RESUME ;default :
Signature · 1 line
2.54.0
PATCH 5/11 x86/vmx: Validate FRED MSR handling during VM-Exit
In reply to Xin LiAdd tests to verify that FRED MSRs are correctly handled during VM-Exit.
The following behaviors are verified:
1. FRED MSRs are saved to VMCS during VM exit iff the "Save FRED" VM-Exit control is set.
2. FRED MSRs are not saved to VMCS during VM exit iff the "Save FRED" VM-Exit control is cleared.
3. FRED MSRs are loaded with values from VMCS host FRED MSR fields iff the "Load FRED" VM-Exit control is set.
4. FRED MSRs are retained iff the "Load FRED" VM-Exit control is cleared.
--- lib/x86/msr.h | 13 ++++++ x86/vmx.h | 25 +++++++++- x86/vmx_tests.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-)
lib/x86/msr.h +13 -0
@@ -302,9 +302,22 @@#define MSR_IA32_TSC_ADJUST 0x0000003b#define MSR_IA32_U_CET 0x000006a0#define MSR_IA32_S_CET 0x000006a2 +#define MSR_IA32_PL0_SSP 0x000006a4#define MSR_IA32_PL3_SSP 0x000006a7#define MSR_IA32_PKRS 0x000006e1 +/* FRED MSRs */ +#define MSR_IA32_FRED_RSP0 0x000001cc +#define MSR_IA32_FRED_RSP1 0x000001cd +#define MSR_IA32_FRED_RSP2 0x000001ce +#define MSR_IA32_FRED_RSP3 0x000001cf +#define MSR_IA32_FRED_STKLVLS 0x000001d0 +#define MSR_IA32_FRED_SSP0 MSR_IA32_PL0_SSP +#define MSR_IA32_FRED_SSP1 0x000001d1 +#define MSR_IA32_FRED_SSP2 0x000001d2 +#define MSR_IA32_FRED_SSP3 0x000001d3 +#define MSR_IA32_FRED_CONFIG 0x000001d4 +#define FEATURE_CONTROL_LOCKED (1<<0)#define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1<<1)#define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2)
x86/vmx.h +24 -1
@@ -221,7 +221,7 @@ enum Encoding {EOI_EXIT_BITMAP3 =0x2022ul ,PMLADDR =0x200eul ,PMLADDR_HI =0x200ful , - +EXI_CTRL1 =0x2044ul ,/* 64-Bit Readonly Data Field */ INFO_PHYS_ADDR = 0x2400ul,
@@ -236,11 +236,27 @@ enum Encoding {GUEST_PERF_GLOBAL_CTRL =0x2808ul ,GUEST_PDPTE =0x280aul ,GUEST_BNDCFGS =0x2812ul , +GUEST_FRED_CONFIG =0x281aul , +GUEST_FRED_RSP1 =0x281cul , +GUEST_FRED_RSP2 =0x281eul , +GUEST_FRED_RSP3 =0x2820ul , +GUEST_FRED_STKLVLS =0x2822ul , +GUEST_FRED_SSP1 =0x2824ul , +GUEST_FRED_SSP2 =0x2826ul , +GUEST_FRED_SSP3 =0x2828ul ,/* 64-Bit Host State */ HOST_PAT =0x2c00ul ,HOST_EFER =0x2c02ul ,HOST_PERF_GLOBAL_CTRL =0x2c04ul , +HOST_FRED_CONFIG =0x2c08ul , +HOST_FRED_RSP1 =0x2c0aul , +HOST_FRED_RSP2 =0x2c0cul , +HOST_FRED_RSP3 =0x2c0eul , +HOST_FRED_STKLVLS =0x2c10ul , +HOST_FRED_SSP1 =0x2c12ul , +HOST_FRED_SSP2 =0x2c14ul , +HOST_FRED_SSP3 =0x2c16ul ,/* 32-Bit Control Fields */ PIN_CONTROLS = 0x4000ul,
@@ -433,6 +449,12 @@ enum Ctrl_exi {EXI_LOAD_EFER =1UL <<21 ,EXI_SAVE_PREEMPT =1UL <<22 ,EXI_LOAD_CET =1UL <<28 , + EXI_ACTIVATE_CTRL1 = 1UL << 31, +}; + +enum Ctrl1_exi { +EXI_SAVE_FRED =1UL <<0 , +EXI_LOAD_FRED =1UL <<1 , }; enum Ctrl_ent {
@@ -443,6 +465,7 @@ enum Ctrl_ent {ENT_LOAD_EFER =1UL <<15 ,ENT_LOAD_BNDCFGS =1UL <<16 ,ENT_LOAD_CET =1UL <<20 , + ENT_LOAD_FRED = 1UL << 23, }; enum Ctrl_pin {
x86/vmx_tests.c +119 -0
130 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH 6/11 x86/vmx: Validate the EFER MSR handling during VM-Exit
In reply to Xin LiAdd tests to verify that the EFER MSR is correctly handled during VM-Exit.
The following behaviors are verified:
1. The EFER MSR is saved to VMCS during VM-Exit iff the "Save EFER" VM-Exit control is set.
2. The EFER MSR is not saved to VMCS during VM-Exit iff the "Save EFER" VM-Exit control is cleared.
3. The EFER MSR is loaded with the value from VMCS host EFER MSR field iff the "Load EFER" VM-Exit control is set.
4. The EFER MSR is retained iff the "Load EFER" VM-Exit control is cleared.
--- x86/vmx_tests.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+)
x86/vmx_tests.c +126 -0
@@ -12195,6 +12195,131 @@ static void vmx_exit_control_fred_test(void)test_set_guest_finished (); } +#define GUEST_INIT_EFER (EFER_SCE | EFER_LME | EFER_LMA) +#define GUEST_SET_EFER (EFER_LME | EFER_LMA | EFER_NX) + +static void vmx_exit_control_efer_test_guest (void ) +{ +wrmsr (MSR_EFER ,GUEST_SET_EFER ); + +vmcall (); +} + +static void vmx_exit_control_efer_test (void ) +{ +bool entry_not_load_efer_tested = false; +u64 host_efer =rdmsr (MSR_EFER ); + +if (!(ctrl_exit_rev.clr &EXI_SAVE_EFER )) { +report_skip ("Save EFER exit control is not available" ); +return ; + } + +if (!(ctrl_exit_rev.clr &EXI_LOAD_EFER )) { +report_skip ("Load EFER exit control is not available" ); +return ; + } + +if (!(ctrl_enter_rev.clr &ENT_LOAD_EFER )) { +report_skip ("Load EFER entry control is not available" ); +return ; + } + +/* Allow the guest to read the EFER MSR directly */ +msr_bmp_init (); + +vmcs_set_bits (ENT_CONTROLS ,ENT_LOAD_EFER ); +vmcs_write (HOST_EFER , host_efer); + +test_again: +/* +* Case 1: +* +* The EFER MSR is not saved to VMCS during VM-Exit if the "Save EFER" +* VM-Exit control is cleared. +* +* The EFER MSR is retained if the "Load EFER" VM-Exit control is +* cleared. +*/ +vmcs_clear_bits (EXI_CONTROLS ,EXI_SAVE_EFER |EXI_LOAD_EFER ); +if (entry_not_load_efer_tested) +test_override_guest (vmx_exit_control_efer_test_guest); +else +test_set_guest (vmx_exit_control_efer_test_guest); +vmcs_write (GUEST_EFER ,GUEST_INIT_EFER ); + +enter_guest (); +report (rdmsr (MSR_EFER ) ==GUEST_SET_EFER ,"The EFER MSR is retained at VM Exit" ); +report (vmcs_read (GUEST_EFER ) ==GUEST_INIT_EFER ,"VMCS guest EFER is not saved at VM Exit" ); + +wrmsr (MSR_EFER , host_efer); + +/* +* Case 2: +* +* The EFER MSR is not saved to VMCS during VM-Exit if the "Save EFER" +* VM-Exit control is cleared. +* +* The EFER MSR is loaded with the value from VMCS host EFER MSR field +* if the "Load EFER" VM-Exit control is set. +*/ +vmcs_clear_bits (EXI_CONTROLS ,EXI_SAVE_EFER ); +vmcs_set_bits (EXI_CONTROLS ,EXI_LOAD_EFER ); +test_override_guest (vmx_exit_control_efer_test_guest); +vmcs_write (GUEST_EFER ,GUEST_INIT_EFER ); + +enter_guest (); +report (rdmsr (MSR_EFER ) == host_efer,"VMCS host EFER is loaded at VM Exit" ); +report (vmcs_read (GUEST_EFER ) ==GUEST_INIT_EFER ,"VMCS guest EFER is not saved at VM Exit" ); + +/* +* Case 3: +* +* The EFER MSR is saved to VMCS during VM-Exit if the "Save EFER" +* VM-Exit control is set. +* +* The EFER MSR is retained if the "Load EFER" VM-Exit control is +* cleared. +*/ +vmcs_set_bits (EXI_CONTROLS ,EXI_SAVE_EFER ); +vmcs_clear_bits (EXI_CONTROLS ,EXI_LOAD_EFER ); +test_override_guest (vmx_exit_control_efer_test_guest); +vmcs_write (GUEST_EFER ,GUEST_INIT_EFER ); + +enter_guest (); +report (rdmsr (MSR_EFER ) ==GUEST_SET_EFER ,"The EFER MSR is retained at VM Exit" ); +report (vmcs_read (GUEST_EFER ) ==GUEST_SET_EFER ,"VMCS guest EFER is saved at VM Exit" ); + +wrmsr (MSR_EFER , host_efer); + +/* +* Case 4: +* +* The EFER MSR is saved to VMCS during VM-Exit if the "Save EFER" +* VM-Exit control is set. +* +* The EFER MSR is loaded with the value from VMCS host EFER MSR field +* if the "Load EFER" VM-Exit control is set. +*/ +vmcs_set_bits (EXI_CONTROLS ,EXI_SAVE_EFER |EXI_LOAD_EFER ); +test_override_guest (vmx_exit_control_efer_test_guest); +vmcs_write (GUEST_EFER ,GUEST_INIT_EFER ); + +enter_guest (); +report (rdmsr (MSR_EFER ) == host_efer,"VMCS host EFER is loaded at VM Exit" ); +report (vmcs_read (GUEST_EFER ) ==GUEST_SET_EFER ,"VMCS guest EFER is saved at VM Exit" ); + +if (!entry_not_load_efer_tested) { + entry_not_load_efer_tested = true; + +/* Clear ENT_LOAD_EFER and run tests again */ +vmcs_clear_bits (ENT_CONTROLS ,ENT_LOAD_EFER ); + goto test_again; + } + +test_set_guest_finished (); +} +#define TEST (name) { #name, .v2 = name }/* name/init/guest_main/exit_handler/vmfail_handler */
@@ -12314,5 +12439,6 @@ struct vmx_test vmx_tests[] = {/* "Load CET" VM-entry/exit controls tests. */ TEST (vmx_cet_test),TEST (vmx_exit_control_fred_test), +TEST (vmx_exit_control_efer_test), { NULL, NULL, NULL, NULL }, };
Signature · 1 line
2.54.0
PATCH 7/11 x86/vmx: Validate the PAT MSR handling during VM-Exit
In reply to Xin LiAdd tests to verify that the PAT MSR is correctly handled during VM-Exit.
The following behaviors are verified:
1. The PAT MSR is saved to VMCS during VM-Exit iff the "Save PAT" VM-Exit control is set.
2. The PAT MSR is not saved to VMCS during VM-Exit iff the "Save PAT" VM-Exit control is cleared.
3. The PAT MSR is loaded with the value from VMCS host PAT MSR field iff the "Load PAT" VM-Exit control is set.
4. The PAT MSR is retained iff the "Load PAT" VM-Exit control is cleared.
--- x86/vmx_tests.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+)
x86/vmx_tests.c +119 -0
@@ -12320,6 +12320,124 @@ test_again:test_set_guest_finished (); } +static void vmx_exit_control_pat_test_guest (void ) +{ +wrmsr (MSR_IA32_CR_PAT ,0x0506 ); + +vmcall (); +} + +static void vmx_exit_control_pat_test (void ) +{ +bool entry_not_load_pat_tested = false; +u64 host_pat =rdmsr (MSR_IA32_CR_PAT ); + +if (!(ctrl_exit_rev.clr &EXI_SAVE_PAT )) { +report_skip ("Save PAT exit control is not available" ); +return ; + } + +if (!(ctrl_exit_rev.clr &EXI_LOAD_PAT )) { +report_skip ("Load PAT exit control is not available" ); +return ; + } + +if (!(ctrl_enter_rev.clr &ENT_LOAD_PAT )) { +report_skip ("Load PAT entry control is not available" ); +return ; + } + +/* Allow the guest to read the PAT MSR directly */ +msr_bmp_init (); + +vmcs_set_bits (ENT_CONTROLS ,ENT_LOAD_PAT ); +vmcs_write (HOST_PAT , host_pat); + +test_again: +/* +* Case 1: +* +* The PAT MSR is not saved to VMCS during VM-Exit if the "Save PAT" +* VM-Exit control is cleared. +* +* The PAT MSR is retained if the "Load PAT" VM-Exit control is cleared. +*/ +vmcs_clear_bits (EXI_CONTROLS ,EXI_SAVE_PAT |EXI_LOAD_PAT ); +if (entry_not_load_pat_tested) +test_override_guest (vmx_exit_control_pat_test_guest); +else +test_set_guest (vmx_exit_control_pat_test_guest); +vmcs_write (GUEST_PAT ,0x0606 ); + +enter_guest (); +report (rdmsr (MSR_IA32_CR_PAT ) ==0x0506 ,"The PAT MSR is retained at VM Exit" ); +report (vmcs_read (GUEST_PAT ) ==0x0606 ,"VMCS guest PAT is not saved at VM Exit" ); + +wrmsr (MSR_IA32_CR_PAT , host_pat); + +/* +* Case 2: +* +* The PAT MSR is not saved to VMCS during VM-Exit if the "Save PAT" +* VM-Exit control is cleared. +* +* The PAT MSR is loaded with the value from VMCS host PAT MSR field +* if the "Load PAT" VM-Exit control is set. +*/ +vmcs_clear_bits (EXI_CONTROLS ,EXI_SAVE_PAT ); +vmcs_set_bits (EXI_CONTROLS ,EXI_LOAD_PAT ); +test_override_guest (vmx_exit_control_pat_test_guest); +vmcs_write (GUEST_PAT ,0x0606 ); + +enter_guest (); +report (rdmsr (MSR_IA32_CR_PAT ) == host_pat,"VMCS host PAT is loaded at VM Exit" ); +report (vmcs_read (GUEST_PAT ) ==0x0606 ,"VMCS guest PAT is not saved at VM Exit" ); + +/* +* Case 3: +* +* The PAT MSR is saved to VMCS during VM-Exit if the "Save PAT" VM-Exit +* control is set. +* +* The PAT MSR is retained if the "Load PAT" VM-Exit control is cleared. +*/ +vmcs_set_bits (EXI_CONTROLS ,EXI_SAVE_PAT ); +vmcs_clear_bits (EXI_CONTROLS ,EXI_LOAD_PAT ); +test_override_guest (vmx_exit_control_pat_test_guest); +vmcs_write (GUEST_PAT ,0x0606 ); + +enter_guest (); +report (rdmsr (MSR_IA32_CR_PAT ) ==0x0506 ,"The PAT MSR is retained at VM Exit" ); +report (vmcs_read (GUEST_PAT ) ==0x0506 ,"VMCS guest PAT is saved at VM Exit" ); + +wrmsr (MSR_IA32_CR_PAT , host_pat); + +/* +* Case 4: +* +* The PAT MSR is saved to VMCS during VM-Exit if the "Save PAT" VM-Exit +* control is set. +* +* The PAT MSR is loaded with the value from VMCS host PAT MSR field if +* the "Load PAT" VM-Exit control is set. +*/ +vmcs_set_bits (EXI_CONTROLS ,EXI_SAVE_PAT |EXI_LOAD_PAT ); +test_override_guest (vmx_exit_control_pat_test_guest); +vmcs_write (GUEST_PAT ,0x0606 ); + +enter_guest (); +report (rdmsr (MSR_IA32_CR_PAT ) == host_pat,"VMCS host PAT is loaded at VM Exit" ); +report (vmcs_read (GUEST_PAT ) ==0x0506 ,"VMCS guest PAT is saved at VM Exit" ); + +if (!entry_not_load_pat_tested) { + entry_not_load_pat_tested = true; +vmcs_clear_bits (ENT_CONTROLS ,ENT_LOAD_PAT ); + goto test_again; + } + +test_set_guest_finished (); +} +#define TEST (name) { #name, .v2 = name }/* name/init/guest_main/exit_handler/vmfail_handler */
@@ -12440,5 +12558,6 @@ struct vmx_test vmx_tests[] = {TEST (vmx_cet_test),TEST (vmx_exit_control_fred_test),TEST (vmx_exit_control_efer_test), +TEST (vmx_exit_control_pat_test), { NULL, NULL, NULL, NULL }, };
Signature · 1 line
2.54.0
PATCH 8/11 x86/vmx: Validate the RTIT control MSR handling during VM-Exit
In reply to Xin LiAdd tests to verify that the RTIT control MSR is correctly handled during VM-Exit.
The following behaviors are verified:
1. The RTIT control MSR is cleared iff the "Clear RTIT control MSR" VM-Exit control is set.
2. The RTIT control MSR is retained iff the "Clear RTIT control MSR" VM-Exit control is cleared.
--- x86/vmx.h | 3 +++ x86/vmx_tests.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
x86/vmx.h +3 -0
@@ -236,6 +236,7 @@ enum Encoding {GUEST_PERF_GLOBAL_CTRL =0x2808ul ,GUEST_PDPTE =0x280aul ,GUEST_BNDCFGS =0x2812ul , +GUEST_RTIT_CTL =0x2814ul ,GUEST_FRED_CONFIG =0x281aul ,GUEST_FRED_RSP1 =0x281cul , GUEST_FRED_RSP2 = 0x281eul,
@@ -448,6 +449,7 @@ enum Ctrl_exi {EXI_SAVE_EFER =1UL <<20 ,EXI_LOAD_EFER =1UL <<21 ,EXI_SAVE_PREEMPT =1UL <<22 , +EXI_CLEAR_RTIT_CTL =1UL <<25 ,EXI_LOAD_CET =1UL <<28 , EXI_ACTIVATE_CTRL1 = 1UL << 31, };
@@ -464,6 +466,7 @@ enum Ctrl_ent {ENT_LOAD_PAT =1UL <<14 ,ENT_LOAD_EFER =1UL <<15 ,ENT_LOAD_BNDCFGS =1UL <<16 , +ENT_LOAD_RTIT_CTL =1UL <<18 ,ENT_LOAD_CET =1UL <<20 , ENT_LOAD_FRED = 1UL << 23, };
x86/vmx_tests.c +49 -0
60 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH 9/11 x86/vmx: Validate CET MSR handling during VM-Exit
In reply to Xin LiAdd tests to verify that CET MSRs are correctly handled during VM-Exit.
The following behaviors are verified:
1. The CET MSRs are loaded with the values from VMCS host CET MSR fields iff the "Load CET" VM-Exit control is set.
2. The CET MSRs are retained iff the "Load CET" VM-Exit control is cleared.
--- x86/vmx_tests.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
x86/vmx_tests.c +50 -0
@@ -12486,6 +12486,55 @@ static void vmx_exit_control_rtit_test(void)test_set_guest_finished (); } +static void vmx_exit_control_cet_test_guest (void ) +{ +wrmsr (MSR_IA32_S_CET ,2 ); + +vmcall (); +} + +static void vmx_exit_control_cet_test (void ) +{ +if (!(ctrl_exit_rev.clr &EXI_LOAD_CET )) { +report_skip ("Load CET state exit control is not available" ); +return ; + } + +if (!(ctrl_enter_rev.clr &ENT_LOAD_CET )) { +report_skip ("Load CET state entry control is not available" ); +return ; + } + +/* Allow the guest to read CET MSRs directly */ +msr_bmp_init (); + +vmcs_set_bits (ENT_CONTROLS ,ENT_LOAD_CET ); +vmcs_write (HOST_S_CET ,6 ); +wrmsr (MSR_IA32_S_CET ,6 ); + +/* Case 1: */ +vmcs_clear_bits (EXI_CONTROLS ,EXI_LOAD_CET ); +vmcs_write (GUEST_S_CET ,8 ); +test_set_guest (vmx_exit_control_cet_test_guest); + +enter_guest (); +report (rdmsr (MSR_IA32_S_CET ) ==2 ,"The IA32_S_CET MSR is retained at VM Exit" ); +report (vmcs_read (GUEST_S_CET ) ==2 ,"VMCS guest IA32_S_CET MSR is saved at VM Exit" ); + +wrmsr (MSR_IA32_S_CET ,6 ); + +/* Case 2: */ +vmcs_set_bits (EXI_CONTROLS ,EXI_LOAD_CET ); +vmcs_write (GUEST_S_CET ,8 ); +test_override_guest (vmx_exit_control_cet_test_guest); + +enter_guest (); +report (rdmsr (MSR_IA32_S_CET ) ==6 ,"The IA32_S_CET MSR is loaded at VM Exit" ); +report (vmcs_read (GUEST_S_CET ) ==2 ,"VMCS guest RTIT control MSR is saved at VM Exit" ); + +test_set_guest_finished (); +} +#define TEST (name) { #name, .v2 = name }/* name/init/guest_main/exit_handler/vmfail_handler */
@@ -12608,5 +12657,6 @@ struct vmx_test vmx_tests[] = {TEST (vmx_exit_control_efer_test),TEST (vmx_exit_control_pat_test),TEST (vmx_exit_control_rtit_test), +TEST (vmx_exit_control_cet_test), { NULL, NULL, NULL, NULL }, };
Signature · 1 line
2.54.0
PATCH 10/11 x86/vmx: Validate FRED state checking during VM-Entry
In reply to Xin LiAdd a test to verify that attempting a VM entry with a reserved bit set in the host FRED_CONFIG MSR correctly triggers a VM-entry failure.
More similar tests can be added later.
--- x86/vmx_tests.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
x86/vmx_tests.c +39 -0
@@ -12535,6 +12535,44 @@ static void vmx_exit_control_cet_test(void)test_set_guest_finished (); } +static void vmx_entry_fred_test_guest (void ) +{ +vmcall (); +} + +static void vmx_entry_fred_test (void ) +{ +struct vmcs *curr; + +if (!(ctrl_enter_rev.clr &ENT_LOAD_FRED )) { +report_skip ("Load FRED state entry control is not available" ); +return ; + } + +/* Allow the guest to read FRED MSRs directly */ +msr_bmp_init (); + +vmcs_set_bits (ENT_CONTROLS ,ENT_LOAD_FRED ); +vmcs_set_bits (EXI_CONTROLS ,EXI_ACTIVATE_CTRL1 ); +vmcs_set_bits (EXI_CTRL1 ,EXI_SAVE_FRED |EXI_LOAD_FRED ); + +wrmsr (MSR_IA32_FRED_CONFIG ,0x4000 ); +vmcs_write (HOST_FRED_CONFIG ,0x4000 ); +vmcs_write (GUEST_FRED_CONFIG ,0x400000 ); +test_set_guest (vmx_entry_fred_test_guest); + +/* Following test_vmx_vmlaunch() needs a "not launched" VMCS */ +vmcs_save (&curr); +vmcs_clear (curr); +make_vmcs_current (curr); + +/* Bit 2 of FRED_CONFIG is reserved; setting it will result in a VM entry failure */ +vmcs_write (HOST_FRED_CONFIG ,0x1004 ); +test_vmx_vmlaunch (VMXERR_ENTRY_INVALID_HOST_STATE_FIELD ); + +test_set_guest_finished (); +} +#define TEST (name) { #name, .v2 = name }/* name/init/guest_main/exit_handler/vmfail_handler */
@@ -12658,5 +12696,6 @@ struct vmx_test vmx_tests[] = {TEST (vmx_exit_control_pat_test),TEST (vmx_exit_control_rtit_test),TEST (vmx_exit_control_cet_test), +TEST (vmx_entry_fred_test), { NULL, NULL, NULL, NULL }, };
Signature · 1 line
2.54.0
PATCH 11/11 x86/vmx: Validate #GP injection for EFER.LME clear with FRED enabled
In reply to Xin LiThe FRED specification mandates that FRED be disabled prior to leaving long mode. Add two test cases, one for L1 guest and the other for L2 guest, to validate if KVM correctly injects #GP when a vCPU attempts to disable long mode with FRED active.
--- lib/x86/processor.h | 2 + x86/vmx.c | 92 +++++++++++++++++++++++++++++++++++++ x86/vmx.h | 84 ++++++++++++++++++++++++++++++++++ x86/vmx_tests.c | 108 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 285 insertions(+), 1 deletion(-)
lib/x86/processor.h +2 -0
@@ -139,6 +139,8 @@ static inline u64 get_non_canonical(u64 addr, u64 mask)#define X86_CR4_PKS BIT(X86_CR4_PKS_BIT)#define X86_CR4_LAM_SUP_BIT (28)#define X86_CR4_LAM_SUP BIT(X86_CR4_LAM_SUP_BIT) +#define X86_CR4_FRED_BIT (32) +#define X86_CR4_FRED BIT(X86_CR4_FRED_BIT)#define X86_EFLAGS_CF_BIT (0)#define X86_EFLAGS_CF BIT(X86_EFLAGS_CF_BIT)
x86/vmx.c +92 -0
98 lines not on this page · raw message
x86/vmx.h +84 -0
94 lines not on this page · raw message
x86/vmx_tests.c +107 -1
125 lines not on this page · raw message
Signature · 1 line
2.54.0