: Test "load IA32_PERF_GLOBAL_CONTROL" VM-entry control on vmentry of nested guests
PATCH 2/4 : Rename report_guest_pat_test to report_guest_state_test
In reply to Krish Sadhukhan...so that it can be re-used by other tests.
--- x86/vmx_tests.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
x86/vmx_tests.c +13 -9
@@ -5007,13 +5007,14 @@ static void guest_state_test_main(void) asmvolatile ("fnop" ); } -static void report_guest_pat_test (const char *test,u32 xreason,u64 guest_pat) +static void report_guest_state_test (const char *test,u32 xreason, +u64 field,const char * field_name) {u32 reason =vmcs_read (EXI_REASON );u64 guest_rip;u32 insn_len; -report ("%s, GUEST_PAT %lx" , reason == xreason, test, guest_pat); +report ("%s, %s %lx" , reason == xreason, test, field_name, field); guest_rip =vmcs_read (GUEST_RIP ); insn_len =vmcs_read (EXI_INST_LEN );
@@ -5112,8 +5113,9 @@ static void test_pat(u32 fld, const char * fld_name, u32 ctrl_fld, u64 ctrl_bit) }else {// GUEST_PAT __enter_guest (ABORT_ON_EARLY_VMENTRY_FAIL ); -report_guest_pat_test ("ENT_LOAD_PAT enabled" , -VMX_VMCALL , val); +report_guest_state_test ("ENT_LOAD_PAT enabled" , +VMX_VMCALL , val, +"GUEST_PAT" ); } } }
@@ -5139,17 +5141,19 @@ static void test_pat(u32 fld, const char * fld_name, u32 ctrl_fld, u64 ctrl_bit) }else {// GUEST_PAT if (i ==0x2 || i ==0x3 || i ==0x8 ) {__enter_guest (ABORT_ON_EARLY_VMENTRY_FAIL ); -report_guest_pat_test ("ENT_LOAD_PAT " -"enabled" , +report_guest_state_test ("ENT_LOAD_PAT " +"enabled" ,VMX_FAIL_STATE |VMX_ENTRY_FAILURE , - val); + val, +"GUEST_PAT" ); }else {__enter_guest (ABORT_ON_EARLY_VMENTRY_FAIL ); -report_guest_pat_test ("ENT_LOAD_PAT " +report_guest_state_test ("ENT_LOAD_PAT " "enabled" ,VMX_VMCALL , - val); + val, +"GUEST_PAT" ); } }
Signature · 1 line
2.20.1
PATCH 3/4 : Add #define for "load IA32_PERF_GLOBAL_CONTROL" bit
In reply to Krish Sadhukhan--- x86/vmx.h | 1 + 1 file changed, 1 insertion(+)
x86/vmx.h +1 -0
@@ -370,6 +370,7 @@ enum Ctrl_exi {enum Ctrl_ent {ENT_LOAD_DBGCTLS =1UL <<2 ,ENT_GUEST_64 =1UL <<9 , +ENT_LOAD_PERF =1UL <<13 ,ENT_LOAD_PAT =1UL <<14 ,ENT_LOAD_EFER =1UL <<15 , };
Signature · 1 line
2.20.1
cover : Test "load IA32_PERF_GLOBAL_CONTROL" VM-entry control on vmentry of nested guests
This set contains the unit test, and related changes, for the "load IA32_PERF_GLOBAL_CONTROL" VM-entry control that was enabled in my previous patchset titled:
[KVM nVMX]: Check "load IA32_PERF_GLOBAL_CTRL" on vmentry of nested guests
[PATCH 1/4][kvm-unit-test nVMX]: Rename guest_pat_main to guest_state_test_main [PATCH 2/4][kvm-unit-test nVMX]: Rename report_guest_pat_test to [PATCH 3/4][kvm-unit-test nVMX]: Add #define for "load IA32_PERF_GLOBAL_CONTROL" bit [PATCH 4/4][kvm-unit-test nVMX]: Test "load IA32_PERF_GLOBAL_CONTROL" VM-entry
x86/vmx.h | 1 + x86/vmx_tests.c | 108 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 22 deletions(-)
Krish Sadhukhan (4):
nVMX: Rename guest_pat_main to guest_state_test_main
nVMX: Rename report_guest_pat_test to report_guest_state_test
nVMX: Add #define for "load IA32_PERF_GLOBAL_CONTROL" bit
nVMX: Test "load IA32_PERF_GLOBAL_CONTROL" VM-entry control on vmentry of nested guests
PATCH 1/4 : Rename guest_pat_main to guest_state_test_main
...so that it can be re-used by other tests.
--- x86/vmx_tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
x86/vmx_tests.c +2 -2
@@ -4995,7 +4995,7 @@ static void test_sysenter_field(u32 field, const char *name)vmcs_write (field, addr_saved); } -static void guest_pat_main (void ) +static void guest_state_test_main (void ) {while (1 ) {if (vmx_get_test_stage () !=2 )
@@ -5097,7 +5097,7 @@ static void test_pat(u32 fld, const char * fld_name, u32 ctrl_fld, u64 ctrl_bit)vmcs_clear_bits (ctrl_fld, ctrl_bit);if (fld ==GUEST_PAT ) {vmx_set_test_stage (1 ); -test_set_guest (guest_pat_main); +test_set_guest (guest_state_test_main); }for (i =0 ; i <256 ; i = (i <PAT_VAL_LIMIT ) ? i +1 : i *2 ) {
Signature · 1 line
2.20.1
PATCH 4/4 : Test "load IA32_PERF_GLOBAL_CONTROL" VM-entry control on vmentry of nested guests
In reply to Krish Sadhukhan ..to verify KVM performs the appropriate consistency checks for loading
IA32_PERF_GLOBAL_CONTROL as part of running a nested guest.
According to section "Checking and Loading Guest State" in Intel SDM vol 3C, the following check is performed on vmentry:
If the "load IA32_PERF_GLOBAL_CTRL" VM-exit control is 1, bits reserved in the IA32_PERF_GLOBAL_CTRL MSR must be 0 in the field for that register.
--- x86/vmx_tests.c | 82 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 11 deletions(-)
x86/vmx_tests.c +71 -11
@@ -5031,29 +5031,69 @@ static void test_perf_global_ctl(u32 field, const char * field_name,u64 perf_global_saved =vmcs_read (field);u64 i, val; +if (field ==GUEST_PERF_GLOBAL_CTRL ) { +vmx_set_test_stage (1 ); +test_set_guest (guest_state_test_main); + } +vmcs_write (ctrl_field, ctrl_saved & ~ctrl_bit);for (i =0 ; i <64 ; i++) { val =1ull << i;vmcs_write (field, val); -report_prefix_pushf ("\"load IA32_PERF_GLOBAL_CTRL\" " -"VM-exit control is off, HOST_PERF_GLOBAL_CTRL %lx" , val); -test_vmx_vmlaunch (0 , false); -report_prefix_pop (); +if (field ==HOST_PERF_GLOBAL_CTRL ) { +report_prefix_pushf ("\"load IA32_PERF_GLOBAL_CTRL\" " +"VM-exit control is off, " +"HOST_PERF_GLOBAL_CTRL %lx" , val); +test_vmx_vmlaunch (0 , false); +report_prefix_pop (); + }else {// GUEST_PERF_GLOBAL_CTRL +enter_guest (); +report_guest_state_test ("ENT_LOAD_PERF disabled" , +VMX_VMCALL , val, +"GUEST_PERF_GLOBAL_CTRL" ); + } }vmcs_write (ctrl_field, ctrl_saved | ctrl_bit);for (i =0 ; i <64 ; i++) { val =1ull << i;vmcs_write (field, val); -report_prefix_pushf ("\"load IA32_PERF_GLOBAL_CTRL\" " -"VM-exit control is on, HOST_PERF_GLOBAL_CTRL %lx" , val); -if (PERF_GLOBAL_CTRL_VALID_BITS & (1ull << i)) { -test_vmx_vmlaunch (0 , false); - }else { -test_vmx_vmlaunch (VMXERR_ENTRY_INVALID_HOST_STATE_FIELD , - false); +if (field ==HOST_PERF_GLOBAL_CTRL ) { +report_prefix_pushf ("\"load IA32_PERF_GLOBAL_CTRL\" " +"VM-exit control is on, HOST_PERF_GLOBAL_CTRL %lx" , + val); +if (PERF_GLOBAL_CTRL_VALID_BITS & (1ull << i)) { +test_vmx_vmlaunch (0 , false); + }else { +test_vmx_vmlaunch ( +VMXERR_ENTRY_INVALID_HOST_STATE_FIELD , + false); }report_prefix_pop (); + }else {// GUEST_PERF_GLOBAL_CTRL +enter_guest (); +if (PERF_GLOBAL_CTRL_VALID_BITS & (1ull << i)) { +report_guest_state_test ("ENT_LOAD_PERF enabled" , +VMX_FAIL_STATE | +VMX_ENTRY_FAILURE , + val, +"GUEST_PERF_GLOBAL_CTRL" ); + }else { +report_guest_state_test ("ENT_LOAD_PERF enabled" , +VMX_VMCALL , + val, +"GUEST_PERF_GLOBAL_CTRL" ); + } + } + } + +if (field ==GUEST_PERF_GLOBAL_CTRL ) { +/* +* Let the guest finish execution +*/ +vmx_set_test_stage (2 ); +vmcs_write (field, perf_global_saved); +enter_guest (); }vmcs_write (ctrl_field, ctrl_saved);
@@ -5079,6 +5119,25 @@ static void test_host_perf_global_ctl(void) EXI_CONTROLS, EXI_LOAD_PERF); } +/* +* If the "load IA32_PERF_GLOBAL_CTRL" VM-entry control is 1, bits reserved +* in the IA32_PERF_GLOBAL_CTRL MSR must be 0 in the field for that +* register. +* +* [Intel SDM] +*/ +static void test_guest_perf_global_ctl (void ) +{ +if (!(ctrl_exit_rev.clr &ENT_LOAD_PERF )) { +printf ("\"load IA32_PERF_GLOBAL_CTRL\" VM-entry control not " +"supported\n" ); +return ; + } + +test_perf_global_ctl (GUEST_PERF_GLOBAL_CTRL ,"GUEST_PERF_GLOBAL_CTRL" , +ENT_CONTROLS ,ENT_LOAD_PERF ); +} +/* * PAT values higher than 8 are uninteresting since they're likely lumped * in with "8". We only test values above 8 one bit at a time,
@@ -5243,6 +5302,7 @@ static void test_load_guest_pat(void)*/ static void vmx_guest_state_area_test (void ) { +test_guest_perf_global_ctl ();test_load_guest_pat (); }
Signature · 1 line
2.20.1
Paolo Bonzini
maintainerQuoted 16 lines · Krish Sadhukhan
This set contains the unit test, and related changes, for the "load
IA32_PERF_GLOBAL_CONTROL" VM-entry control that was enabled in my previous patchset titled:[KVM nVMX]: Check "load
IA32_PERF_GLOBAL_CTRL" on vmentry of nested guests[PATCH 1/4][kvm-unit-test nVMX]: Rename
guest_pat_maintoguest_state_test_main[PATCH 2/4][kvm-unit-test nVMX]: Renamereport_guest_pat_testto [PATCH 3/4][kvm-unit-test nVMX]: Add #define for "loadIA32_PERF_GLOBAL_CONTROL" bit [PATCH 4/4][kvm-unit-test nVMX]: Test "loadIA32_PERF_GLOBAL_CONTROL" VM-entryx86/vmx.h | 1 + x86/vmx_tests.c | 108 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 22 deletions(-)
Quoted 6 lines
Krish Sadhukhan (4):
nVMX: Renameguest_pat_maintoguest_state_test_main
nVMX: Renamereport_guest_pat_testtoreport_guest_state_test
nVMX: Add #define for "loadIA32_PERF_GLOBAL_CONTROL" bit
nVMX: Test "loadIA32_PERF_GLOBAL_CONTROL" VM-entry control on vmentry of nested guests
Queued 1-3, but patch 4 does not apply. It seems like you have another patch that this sits on top of?
Paolo
Quoted 17 lines · Paolo Bonzini
Quoted 16 lines · Krish Sadhukhan
This set contains the unit test, and related changes, for the "load
IA32_PERF_GLOBAL_CONTROL" VM-entry control that was enabled in my previous patchset titled:[KVM nVMX]: Check "load
IA32_PERF_GLOBAL_CTRL" on vmentry of nested guests[PATCH 1/4][kvm-unit-test nVMX]: Rename
guest_pat_maintoguest_state_test_main[PATCH 2/4][kvm-unit-test nVMX]: Renamereport_guest_pat_testto [PATCH 3/4][kvm-unit-test nVMX]: Add #define for "loadIA32_PERF_GLOBAL_CONTROL" bit [PATCH 4/4][kvm-unit-test nVMX]: Test "loadIA32_PERF_GLOBAL_CONTROL" VM-entryx86/vmx.h | 1 + x86/vmx_tests.c | 108 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 22 deletions(-)
Quoted 8 lines
Quoted 6 lines
Krish Sadhukhan (4):
nVMX: Renameguest_pat_maintoguest_state_test_main
nVMX: Renamereport_guest_pat_testtoreport_guest_state_test
nVMX: Add #define for "loadIA32_PERF_GLOBAL_CONTROL" bit
nVMX: Test "loadIA32_PERF_GLOBAL_CONTROL" VM-entry control on vmentry of nested guestsQueued 1-3, but patch 4 does not apply. It seems like you have another patch that this sits on top of?
Yes, the following patchset:
[KVM nVMX]: Check "load IA32_PERF_GLOBAL_CTRL" on vmentry of nested guests
I need to send out v2 of that set and patch# 4 of this set builds on top of that.
You don't need to pull 1-3 out because they are independent of the pending patchset. I will attach patch# 4 of this set to the v2 of the pending set.
Quoted 2 lines
Paolo