All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org
Subject: [kvm-unit-tests PATCH 3/8] nVMX: Consolidate non-canonical code in test_canonical()
Date: Thu, 12 Mar 2020 16:27:40 -0700	[thread overview]
Message-ID: <20200312232745.884-4-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20200312232745.884-1-sean.j.christopherson@intel.com>

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>
---
 x86/vmx_tests.c | 40 +++++++++++++++++-----------------------
 1 file changed, 17 insertions(+), 23 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index c4077b1..ac02b9d 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);
+	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, 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)				\
-- 
2.24.1


  parent reply	other threads:[~2020-03-12 23:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12 23:27 [kvm-unit-tests PATCH 0/8] nVMX: Clean up __enter_guest() and co Sean Christopherson
2020-03-12 23:27 ` [kvm-unit-tests PATCH 1/8] nVMX: Eliminate superfluous entry_failure_handler() wrapper Sean Christopherson
2020-03-12 23:27 ` [kvm-unit-tests PATCH 2/8] nVMX: Refactor VM-Entry "failure" struct into "result" Sean Christopherson
2020-03-18 23:40   ` Krish Sadhukhan
2020-03-19  9:56     ` Paolo Bonzini
2020-03-12 23:27 ` Sean Christopherson [this message]
2020-03-12 23:27 ` [kvm-unit-tests PATCH 4/8] nVMX: Drop redundant check for guest termination Sean Christopherson
2020-03-12 23:27 ` [kvm-unit-tests PATCH 5/8] nVMX: Expose __enter_guest() and consolidate guest state test code Sean Christopherson
2020-03-12 23:27 ` [kvm-unit-tests PATCH 6/8] nVMX: Pass exit reason union to v1 exit handlers Sean Christopherson
2020-03-12 23:27 ` [kvm-unit-tests PATCH 7/8] nVMX: Pass exit reason union to is_hypercall() Sean Christopherson
2020-03-12 23:27 ` [kvm-unit-tests PATCH 8/8] nVMX: Pass exit reason enum to print_vmexit_info() Sean Christopherson
2020-03-14 10:35 ` [kvm-unit-tests PATCH 0/8] nVMX: Clean up __enter_guest() and co Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200312232745.884-4-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.