diff options
author | Sean Christopherson <sean.j.christopherson@intel.com> | 2020-03-12 16:27:40 -0700 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-03-14 11:33:11 +0100 |
commit | 11a6e3d5913442e6797cf15e547bdc6038d7d189 (patch) | |
tree | dbca6cea9c6ff62c0873927d966241e1e44fd174 | |
parent | 0e0ea94bc3756fa209eaf5193b2efaf1bf1603a4 (diff) | |
download | kvm-unit-tests-11a6e3d5913442e6797cf15e547bdc6038d7d189.tar.gz |
nVMX: Consolidate non-canonical code in test_canonical()
Refactor test_canonical() to provide a single flow for the non-canonical
path. Practically speaking, its extremely unlikely the field being
tested already has a non-canonical address, and even less likely that
it's anything other than NONCANONICAL. I.e. the added complexity
doesn't come with added coverage.
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | x86/vmx_tests.c | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 8c4b24a..3fda00c 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -7411,6 +7411,11 @@ static void test_canonical(u64 field, const char * field_name, bool host) { u64 addr_saved = vmcs_read(field); + /* + * Use the existing value if possible. Writing a random canonical + * value is not an option as doing so would corrupt the field being + * tested and likely hose the test. + */ if (is_canonical(addr_saved)) { if (host) { report_prefix_pushf("%s %lx", field_name, addr_saved); @@ -7422,33 +7427,22 @@ static void test_canonical(u64 field, const char * field_name, bool host) VMX_VMCALL, addr_saved, field_name); } + } - vmcs_write(field, NONCANONICAL); - - if (host) { - report_prefix_pushf("%s %llx", field_name, NONCANONICAL); - test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); - report_prefix_pop(); - } else { - enter_guest_with_invalid_guest_state(); - report_guest_state_test("Test canonical address", - VMX_FAIL_STATE | VMX_ENTRY_FAILURE, - NONCANONICAL, field_name); - } + vmcs_write(field, NONCANONICAL); - vmcs_write(field, addr_saved); + if (host) { + report_prefix_pushf("%s %llx", field_name, NONCANONICAL); + test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); + report_prefix_pop(); } else { - if (host) { - report_prefix_pushf("%s %llx", field_name, NONCANONICAL); - test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); - report_prefix_pop(); - } else { - enter_guest_with_invalid_guest_state(); - report_guest_state_test("Test canonical address", - VMX_FAIL_STATE | VMX_ENTRY_FAILURE, - NONCANONICAL, field_name); - } + enter_guest_with_invalid_guest_state(); + report_guest_state_test("Test non-canonical address", + VMX_FAIL_STATE | VMX_ENTRY_FAILURE, + NONCANONICAL, field_name); } + + vmcs_write(field, addr_saved); } #define TEST_RPL_TI_FLAGS(reg, name) \ |