All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests 0/4] test GUEST_EFER field and address size controls
@ 2019-09-25 16:14 Paolo Bonzini
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 1/4] x86: vmx_tests: gate load guest PAT tests on the correct bit Paolo Bonzini
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Paolo Bonzini @ 2019-09-25 16:14 UTC (permalink / raw)
  To: kvm; +Cc: Krish Sadhukhan

This series extends the HOST_EFER tests to test the host address size
(patch 2) and adds matching tests for GUEST_EFER (patches 3-4).

Paolo Bonzini (4):
  x86: vmx_tests: gate load guest PAT tests on the correct bit
  x86: vmx_tests: extend HOST_EFER tests
  x86: vmx_tests: prepare for extending guest state area tests
  x86: vmx_tests: add GUEST_EFER tests

 x86/vmx_tests.c | 219 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 145 insertions(+), 74 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH kvm-unit-tests 1/4] x86: vmx_tests: gate load guest PAT tests on the correct bit
  2019-09-25 16:14 [PATCH kvm-unit-tests 0/4] test GUEST_EFER field and address size controls Paolo Bonzini
@ 2019-09-25 16:14 ` Paolo Bonzini
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 2/4] x86: vmx_tests: extend HOST_EFER tests Paolo Bonzini
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2019-09-25 16:14 UTC (permalink / raw)
  To: kvm; +Cc: Krish Sadhukhan

The tests should check the "load PAT" entry control,
not the exit control.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/vmx_tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index a447d39..b404219 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7203,7 +7203,7 @@ static void test_load_guest_pat(void)
 	/*
 	 * "load IA32_PAT" VM-entry control
 	 */
-	if (!(ctrl_exit_rev.clr & ENT_LOAD_PAT)) {
+	if (!(ctrl_enter_rev.clr & ENT_LOAD_PAT)) {
 		printf("\"Load-IA32-PAT\" entry control not supported\n");
 		return;
 	}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH kvm-unit-tests 2/4] x86: vmx_tests: extend HOST_EFER tests
  2019-09-25 16:14 [PATCH kvm-unit-tests 0/4] test GUEST_EFER field and address size controls Paolo Bonzini
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 1/4] x86: vmx_tests: gate load guest PAT tests on the correct bit Paolo Bonzini
@ 2019-09-25 16:14 ` Paolo Bonzini
  2019-11-23  1:40   ` Nadav Amit
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 3/4] x86: vmx_tests: prepare for extending guest state area tests Paolo Bonzini
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 4/4] x86: vmx_tests: add GUEST_EFER tests Paolo Bonzini
  3 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2019-09-25 16:14 UTC (permalink / raw)
  To: kvm; +Cc: Krish Sadhukhan

Extend the tests to cover the host address size bit.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/vmx_tests.c | 126 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 74 insertions(+), 52 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index b404219..8851f64 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -6720,59 +6720,62 @@ static void test_host_ctl_regs(void)
 	vmcs_write(HOST_CR3, cr3_saved);
 }
 
-static void test_efer_bit(u32 fld, const char * fld_name, u32 ctrl_fld,
-			   u64 ctrl_bit, u64 efer_bit,
-			   const char *efer_bit_name)
+static void test_efer_one(u32 fld, const char * fld_name, u64 efer,
+			  u32 ctrl_fld, u64 ctrl,
+			  int i, const char *efer_bit_name)
 {
-	u64 efer_saved = vmcs_read(fld);
-	u32 ctrl_saved = vmcs_read(ctrl_fld);
-	u64 host_addr_size = ctrl_saved & EXI_HOST_64;
-	u64 efer;
+	bool ok;
 
-	vmcs_write(ctrl_fld, ctrl_saved & ~ctrl_bit);
-	efer = efer_saved & ~efer_bit;
-	vmcs_write(fld, efer);
-	report_prefix_pushf("%s bit turned off, %s %lx", efer_bit_name,
-			    fld_name, efer);
-	test_vmx_vmlaunch(0, false);
-	report_prefix_pop();
+	ok = true;
+	if (ctrl & EXI_LOAD_EFER) {
+		if (!!(efer & EFER_LMA) != !!(ctrl & EXI_HOST_64))
+			ok = false;
+		if (!!(efer & EFER_LME) != !!(ctrl & EXI_HOST_64))
+			ok = false;
+	}
 
-	efer = efer_saved | efer_bit;
+	vmcs_write(ctrl_fld, ctrl);
 	vmcs_write(fld, efer);
-	report_prefix_pushf("%s bit turned on, %s %lx", efer_bit_name,
-			    fld_name, efer);
-	test_vmx_vmlaunch(0, false);
-	report_prefix_pop();
+	report_prefix_pushf("%s %s bit turned %s, controls %s",
+			    fld_name, efer_bit_name,
+			    (i & 1) ? "on" : "off",
+			    (i & 2) ? "on" : "off");
 
-	vmcs_write(ctrl_fld, ctrl_saved | ctrl_bit);
-	efer = efer_saved & ~efer_bit;
-	vmcs_write(fld, efer);
-	report_prefix_pushf("%s bit turned off, %s %lx", efer_bit_name,
-			    fld_name, efer);
-	if (host_addr_size)
-		test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
-				  false);
-	else
-		test_vmx_vmlaunch(0, false);
-	report_prefix_pop();
-
-	efer = efer_saved | efer_bit;
-	vmcs_write(fld, efer);
-	report_prefix_pushf("%s bit turned on, %s %lx", efer_bit_name,
-			    fld_name, efer);
-	if (host_addr_size)
+	if (ok)
 		test_vmx_vmlaunch(0, false);
 	else
 		test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
 				  false);
 	report_prefix_pop();
+}
+
+static void test_efer_bit(u32 fld, const char * fld_name,
+			  u32 ctrl_fld, u64 ctrl_bit, u64 efer_bit,
+			  const char *efer_bit_name)
+{
+	u64 efer_saved = vmcs_read(fld);
+	u32 ctrl_saved = vmcs_read(ctrl_fld);
+	int i;
+
+	for (i = 0; i < 4; i++) {
+		u64 efer = efer_saved & ~efer_bit;
+		u64 ctrl = ctrl_saved & ~ctrl_bit;
+
+		if (i & 1)
+			efer |= efer_bit;
+		if (i & 2)
+			ctrl |= ctrl_bit;
+
+		test_efer_one(fld, fld_name, efer, ctrl_fld, ctrl,
+			      i, efer_bit_name);
+	}
 
 	vmcs_write(ctrl_fld, ctrl_saved);
 	vmcs_write(fld, efer_saved);
 }
 
 static void test_efer(u32 fld, const char * fld_name, u32 ctrl_fld,
-		      u64 ctrl_bit)
+		      u64 ctrl_bit1, u64 ctrl_bit2)
 {
 	u64 efer_saved = vmcs_read(fld);
 	u32 ctrl_saved = vmcs_read(ctrl_fld);
@@ -6783,10 +6786,19 @@ static void test_efer(u32 fld, const char * fld_name, u32 ctrl_fld,
 	if (cpu_has_efer_nx())
 		efer_reserved_bits &= ~EFER_NX;
 
+	if (!ctrl_bit1) {
+		printf("\"Load-IA32-EFER\" exit control not supported\n");
+		goto test_entry_exit_mode;
+	}
+
+	report_prefix_pushf("%s %lx", fld_name, efer_saved);
+	test_vmx_vmlaunch(0, false);
+	report_prefix_pop();
+
 	/*
 	 * Check reserved bits
 	 */
-	vmcs_write(ctrl_fld, ctrl_saved & ~ctrl_bit);
+	vmcs_write(ctrl_fld, ctrl_saved & ~ctrl_bit1);
 	for (i = 0; i < 64; i++) {
 		if ((1ull << i) & efer_reserved_bits) {
 			efer = efer_saved | (1ull << i);
@@ -6797,15 +6809,14 @@ static void test_efer(u32 fld, const char * fld_name, u32 ctrl_fld,
 		}
 	}
 
-	vmcs_write(ctrl_fld, ctrl_saved | ctrl_bit);
+	vmcs_write(ctrl_fld, ctrl_saved | ctrl_bit1);
 	for (i = 0; i < 64; i++) {
 		if ((1ull << i) & efer_reserved_bits) {
 			efer = efer_saved | (1ull << i);
 			vmcs_write(fld, efer);
 			report_prefix_pushf("%s %lx", fld_name, efer);
-			test_vmx_vmlaunch(
-				VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
-				false);
+			test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
+					  false);
 			report_prefix_pop();
 		}
 	}
@@ -6816,28 +6827,39 @@ static void test_efer(u32 fld, const char * fld_name, u32 ctrl_fld,
 	/*
 	 * Check LMA and LME bits
 	 */
-	test_efer_bit(fld, fld_name, ctrl_fld, ctrl_bit, EFER_LMA,
+	test_efer_bit(fld, fld_name,
+		      ctrl_fld, ctrl_bit1,
+		      EFER_LMA,
+		      "EFER_LMA");
+	test_efer_bit(fld, fld_name,
+		      ctrl_fld, ctrl_bit1,
+		      EFER_LME,
+		      "EFER_LME");
+
+test_entry_exit_mode:
+	test_efer_bit(fld, fld_name,
+		      ctrl_fld, ctrl_bit2,
+		      EFER_LMA,
 		      "EFER_LMA");
-	test_efer_bit(fld, fld_name, ctrl_fld, ctrl_bit, EFER_LME,
+	test_efer_bit(fld, fld_name,
+		      ctrl_fld, ctrl_bit2,
+		      EFER_LME,
 		      "EFER_LME");
 }
 
 /*
- * If the “load IA32_EFER†VM-exit control is 1, bits reserved in the
+ * If the 'load IA32_EFER' VM-exit control is 1, bits reserved in the
  * IA32_EFER MSR must be 0 in the field for that register. In addition,
  * the values of the LMA and LME bits in the field must each be that of
- * the “host address-space size†VM-exit control.
+ * the 'host address-space size' VM-exit control.
  *
  *  [Intel SDM]
  */
 static void test_host_efer(void)
 {
-	if (!(ctrl_exit_rev.clr & EXI_LOAD_EFER)) {
-		printf("\"Load-IA32-EFER\" exit control not supported\n");
-		return;
-	}
-
-	test_efer(HOST_EFER, "HOST_EFER", EXI_CONTROLS, EXI_LOAD_EFER);
+	test_efer(HOST_EFER, "HOST_EFER", EXI_CONTROLS, 
+		  ctrl_exit_rev.clr & EXI_LOAD_EFER,
+		  EXI_HOST_64);
 }
 
 /*
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH kvm-unit-tests 3/4] x86: vmx_tests: prepare for extending guest state area tests
  2019-09-25 16:14 [PATCH kvm-unit-tests 0/4] test GUEST_EFER field and address size controls Paolo Bonzini
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 1/4] x86: vmx_tests: gate load guest PAT tests on the correct bit Paolo Bonzini
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 2/4] x86: vmx_tests: extend HOST_EFER tests Paolo Bonzini
@ 2019-09-25 16:14 ` Paolo Bonzini
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 4/4] x86: vmx_tests: add GUEST_EFER tests Paolo Bonzini
  3 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2019-09-25 16:14 UTC (permalink / raw)
  To: kvm; +Cc: Krish Sadhukhan

Move the test setup and teardown from test_pat to vmx_guest_state_area_test,
so that we can add more tests after test_load_guest_pat.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/vmx_tests.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 8851f64..97aff6e 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -6879,10 +6879,6 @@ static void test_pat(u32 field, const char * field_name, u32 ctrl_field,
 	int error;
 
 	vmcs_clear_bits(ctrl_field, ctrl_bit);
-	if (field == GUEST_PAT) {
-		vmx_set_test_stage(1);
-		test_set_guest(guest_state_test_main);
-	}
 
 	for (i = 0; i < 256; i = (i < PAT_VAL_LIMIT) ? i + 1 : i * 2) {
 		/* Test PAT0..PAT7 fields */
@@ -6942,15 +6938,6 @@ static void test_pat(u32 field, const char * field_name, u32 ctrl_field,
 		}
 	}
 
-	if (field == GUEST_PAT) {
-		/*
-		 * Let the guest finish execution
-		 */
-		vmx_set_test_stage(2);
-		vmcs_write(field, pat_saved);
-		enter_guest();
-	}
-
 	vmcs_write(ctrl_field, ctrl_saved);
 	vmcs_write(field, pat_saved);
 }
@@ -7239,7 +7226,16 @@ static void test_load_guest_pat(void)
  */
 static void vmx_guest_state_area_test(void)
 {
+	vmx_set_test_stage(1);
+	test_set_guest(guest_state_test_main);
+
 	test_load_guest_pat();
+
+	/*
+	 * Let the guest finish execution
+	 */
+	vmx_set_test_stage(2);
+	enter_guest();
 }
 
 static bool valid_vmcs_for_vmentry(void)
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH kvm-unit-tests 4/4] x86: vmx_tests: add GUEST_EFER tests
  2019-09-25 16:14 [PATCH kvm-unit-tests 0/4] test GUEST_EFER field and address size controls Paolo Bonzini
                   ` (2 preceding siblings ...)
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 3/4] x86: vmx_tests: prepare for extending guest state area tests Paolo Bonzini
@ 2019-09-25 16:14 ` Paolo Bonzini
  3 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2019-09-25 16:14 UTC (permalink / raw)
  To: kvm; +Cc: Krish Sadhukhan

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Conflicts:
	x86/vmx_tests.c
---
 x86/vmx_tests.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 70 insertions(+), 17 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 97aff6e..dba61a3 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -5030,19 +5030,23 @@ static void guest_state_test_main(void)
 	asm volatile("fnop");
 }
 
+static void advance_guest_state_test(void)
+{
+	u32 reason = vmcs_read(EXI_REASON);
+	if (! (reason & 0x80000000)) {
+		u64 guest_rip = vmcs_read(GUEST_RIP);
+		u32 insn_len = vmcs_read(EXI_INST_LEN);
+		vmcs_write(GUEST_RIP, guest_rip + insn_len);
+	}
+}
+
 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, %s %lx", reason == xreason, test, field_name, field);
-
-	guest_rip = vmcs_read(GUEST_RIP);
-	insn_len = vmcs_read(EXI_INST_LEN);
-	if (! (reason & 0x80000021))
-		vmcs_write(GUEST_RIP, guest_rip + insn_len);
+	advance_guest_state_test();
 }
 
 /*
@@ -6720,6 +6724,25 @@ static void test_host_ctl_regs(void)
 	vmcs_write(HOST_CR3, cr3_saved);
 }
 
+static void test_efer_vmlaunch(u32 fld, bool ok)
+{
+	if (fld == HOST_EFER) {
+		if (ok)
+			test_vmx_vmlaunch(0, false);
+		else
+			test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD, false);
+	} else {
+		if (ok) {
+			enter_guest();
+			report("vmlaunch succeeds", vmcs_read(EXI_REASON) == VMX_VMCALL);
+		} else {
+			enter_guest_with_invalid_guest_state();
+			report("vmlaunch fails", vmcs_read(EXI_REASON) == (VMX_ENTRY_FAILURE | VMX_FAIL_STATE));
+		}
+		advance_guest_state_test();
+	}
+}
+
 static void test_efer_one(u32 fld, const char * fld_name, u64 efer,
 			  u32 ctrl_fld, u64 ctrl,
 			  int i, const char *efer_bit_name)
@@ -6727,12 +6750,27 @@ static void test_efer_one(u32 fld, const char * fld_name, u64 efer,
 	bool ok;
 
 	ok = true;
-	if (ctrl & EXI_LOAD_EFER) {
+	if (ctrl_fld == EXI_CONTROLS && (ctrl & EXI_LOAD_EFER)) {
 		if (!!(efer & EFER_LMA) != !!(ctrl & EXI_HOST_64))
 			ok = false;
 		if (!!(efer & EFER_LME) != !!(ctrl & EXI_HOST_64))
 			ok = false;
 	}
+	if (ctrl_fld == ENT_CONTROLS && (ctrl & ENT_LOAD_EFER)) {
+		/* Check LMA too since CR0.PG is set.  */
+		if (!!(efer & EFER_LMA) != !!(ctrl & ENT_GUEST_64))
+			ok = false;
+		if (!!(efer & EFER_LME) != !!(ctrl & ENT_GUEST_64))
+			ok = false;
+	}
+
+	/*
+	 * Skip the test if it would enter the guest in 32-bit mode.
+	 * Perhaps write the test in assembly and make sure it
+	 * can be run in either mode?
+	 */
+	if (fld == GUEST_EFER && ok && !(ctrl & ENT_GUEST_64))
+		return;
 
 	vmcs_write(ctrl_fld, ctrl);
 	vmcs_write(fld, efer);
@@ -6741,11 +6779,7 @@ static void test_efer_one(u32 fld, const char * fld_name, u64 efer,
 			    (i & 1) ? "on" : "off",
 			    (i & 2) ? "on" : "off");
 
-	if (ok)
-		test_vmx_vmlaunch(0, false);
-	else
-		test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
-				  false);
+	test_efer_vmlaunch(fld, ok);
 	report_prefix_pop();
 }
 
@@ -6792,7 +6826,7 @@ static void test_efer(u32 fld, const char * fld_name, u32 ctrl_fld,
 	}
 
 	report_prefix_pushf("%s %lx", fld_name, efer_saved);
-	test_vmx_vmlaunch(0, false);
+	test_efer_vmlaunch(fld, true);
 	report_prefix_pop();
 
 	/*
@@ -6804,7 +6838,7 @@ static void test_efer(u32 fld, const char * fld_name, u32 ctrl_fld,
 			efer = efer_saved | (1ull << i);
 			vmcs_write(fld, efer);
 			report_prefix_pushf("%s %lx", fld_name, efer);
-			test_vmx_vmlaunch(0, false);
+			test_efer_vmlaunch(fld, true);
 			report_prefix_pop();
 		}
 	}
@@ -6815,8 +6849,7 @@ static void test_efer(u32 fld, const char * fld_name, u32 ctrl_fld,
 			efer = efer_saved | (1ull << i);
 			vmcs_write(fld, efer);
 			report_prefix_pushf("%s %lx", fld_name, efer);
-			test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
-					  false);
+			test_efer_vmlaunch(fld, false);
 			report_prefix_pop();
 		}
 	}
@@ -6863,6 +6896,25 @@ static void test_host_efer(void)
 }
 
 /*
+ * If the 'load IA32_EFER' VM-enter control is 1, bits reserved in the
+ * IA32_EFER MSR must be 0 in the field for that register. In addition,
+ * the values of the LMA and LME bits in the field must each be that of
+ * the 'IA32e-mode guest' VM-exit control.
+ */
+static void test_guest_efer(void)
+{
+	if (!(ctrl_enter_rev.clr & ENT_LOAD_EFER)) {
+		printf("\"Load-IA32-EFER\" entry control not supported\n");
+		return;
+	}
+
+	vmcs_write(GUEST_EFER, rdmsr(MSR_EFER));
+	test_efer(GUEST_EFER, "GUEST_EFER", ENT_CONTROLS,
+		  ctrl_enter_rev.clr & ENT_LOAD_EFER,
+		  ENT_GUEST_64);
+}
+
+/*
  * 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,
  * in order to reduce the number of VM-Entries and keep the runtime reasonable.
@@ -7230,6 +7282,7 @@ static void vmx_guest_state_area_test(void)
 	test_set_guest(guest_state_test_main);
 
 	test_load_guest_pat();
+	test_guest_efer();
 
 	/*
 	 * Let the guest finish execution
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH kvm-unit-tests 2/4] x86: vmx_tests: extend HOST_EFER tests
  2019-09-25 16:14 ` [PATCH kvm-unit-tests 2/4] x86: vmx_tests: extend HOST_EFER tests Paolo Bonzini
@ 2019-11-23  1:40   ` Nadav Amit
  2019-11-23 10:22     ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: Nadav Amit @ 2019-11-23  1:40 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Krish Sadhukhan



> On Sep 25, 2019, at 9:14 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> Extend the tests to cover the host address size bit.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> x86/vmx_tests.c | 126 +++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 74 insertions(+), 52 deletions(-)

I get the following results with this test on Skylake bare-metal:

PASS: HOST_EFER EFER_LMA bit turned off, controls off: vmlaunch succeeds
PASS: HOST_EFER EFER_LMA bit turned on, controls off: vmlaunch succeeds
PASS: HOST_EFER EFER_LMA bit turned off, controls on: vmlaunch fails
PASS: HOST_EFER EFER_LMA bit turned off, controls on: VMX inst error is 8 (actual 8)
PASS: HOST_EFER EFER_LMA bit turned on, controls on: vmlaunch succeeds
PASS: HOST_EFER EFER_LME bit turned off, controls off: vmlaunch succeeds
PASS: HOST_EFER EFER_LME bit turned on, controls off: vmlaunch succeeds
PASS: HOST_EFER EFER_LME bit turned off, controls on: vmlaunch fails
PASS: HOST_EFER EFER_LME bit turned off, controls on: VMX inst error is 8 (actual 8)
PASS: HOST_EFER EFER_LME bit turned on, controls on: vmlaunch succeeds
PASS: HOST_EFER EFER_LMA bit turned off, controls off: vmlaunch fails
FAIL: HOST_EFER EFER_LMA bit turned off, controls off: VMX inst error is 8 (actual 7)
PASS: HOST_EFER EFER_LMA bit turned on, controls off: vmlaunch fails
FAIL: HOST_EFER EFER_LMA bit turned on, controls off: VMX inst error is 8 (actual 7)
PASS: HOST_EFER EFER_LMA bit turned off, controls on: vmlaunch fails
PASS: HOST_EFER EFER_LMA bit turned off, controls on: VMX inst error is 8 (actual 8)
PASS: HOST_EFER EFER_LMA bit turned on, controls on: vmlaunch succeeds
PASS: HOST_EFER EFER_LME bit turned off, controls off: vmlaunch fails
FAIL: HOST_EFER EFER_LME bit turned off, controls off: VMX inst error is 8 (actual 7)
PASS: HOST_EFER EFER_LME bit turned on, controls off: vmlaunch fails
FAIL: HOST_EFER EFER_LME bit turned on, controls off: VMX inst error is 8 (actual 7)
PASS: HOST_EFER EFER_LME bit turned off, controls on: vmlaunch fails
PASS: HOST_EFER EFER_LME bit turned off, controls on: VMX inst error is 8 (actual 8)
PASS: HOST_EFER EFER_LME bit turned on, controls on: vmlaunch succeeds

Apparently, turning the controls off, causes some “VM entry with invalid
control field” (7) instead of “VM-entry with invalid host-state field”.

According to the SDM, checks of control fields and host field are not ordered.
But I do not know what exactly causes the failure.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH kvm-unit-tests 2/4] x86: vmx_tests: extend HOST_EFER tests
  2019-11-23  1:40   ` Nadav Amit
@ 2019-11-23 10:22     ` Paolo Bonzini
  0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2019-11-23 10:22 UTC (permalink / raw)
  To: Nadav Amit; +Cc: kvm, Krish Sadhukhan

On 23/11/19 02:40, Nadav Amit wrote:
> 
> 
>> On Sep 25, 2019, at 9:14 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> Extend the tests to cover the host address size bit.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>> x86/vmx_tests.c | 126 +++++++++++++++++++++++++++++++++-----------------------
>> 1 file changed, 74 insertions(+), 52 deletions(-)
> 
> I get the following results with this test on Skylake bare-metal:
> 
> PASS: HOST_EFER EFER_LMA bit turned off, controls off: vmlaunch succeeds
> PASS: HOST_EFER EFER_LMA bit turned on, controls off: vmlaunch succeeds
> PASS: HOST_EFER EFER_LMA bit turned off, controls on: vmlaunch fails
> PASS: HOST_EFER EFER_LMA bit turned off, controls on: VMX inst error is 8 (actual 8)
> PASS: HOST_EFER EFER_LMA bit turned on, controls on: vmlaunch succeeds
> PASS: HOST_EFER EFER_LME bit turned off, controls off: vmlaunch succeeds
> PASS: HOST_EFER EFER_LME bit turned on, controls off: vmlaunch succeeds
> PASS: HOST_EFER EFER_LME bit turned off, controls on: vmlaunch fails
> PASS: HOST_EFER EFER_LME bit turned off, controls on: VMX inst error is 8 (actual 8)
> PASS: HOST_EFER EFER_LME bit turned on, controls on: vmlaunch succeeds
> PASS: HOST_EFER EFER_LMA bit turned off, controls off: vmlaunch fails
> FAIL: HOST_EFER EFER_LMA bit turned off, controls off: VMX inst error is 8 (actual 7)
> PASS: HOST_EFER EFER_LMA bit turned on, controls off: vmlaunch fails
> FAIL: HOST_EFER EFER_LMA bit turned on, controls off: VMX inst error is 8 (actual 7)
> PASS: HOST_EFER EFER_LMA bit turned off, controls on: vmlaunch fails
> PASS: HOST_EFER EFER_LMA bit turned off, controls on: VMX inst error is 8 (actual 8)
> PASS: HOST_EFER EFER_LMA bit turned on, controls on: vmlaunch succeeds
> PASS: HOST_EFER EFER_LME bit turned off, controls off: vmlaunch fails
> FAIL: HOST_EFER EFER_LME bit turned off, controls off: VMX inst error is 8 (actual 7)
> PASS: HOST_EFER EFER_LME bit turned on, controls off: vmlaunch fails
> FAIL: HOST_EFER EFER_LME bit turned on, controls off: VMX inst error is 8 (actual 7)
> PASS: HOST_EFER EFER_LME bit turned off, controls on: vmlaunch fails
> PASS: HOST_EFER EFER_LME bit turned off, controls on: VMX inst error is 8 (actual 8)
> PASS: HOST_EFER EFER_LME bit turned on, controls on: vmlaunch succeeds
> 
> Apparently, turning the controls off, causes some “VM entry with invalid
> control field” (7) instead of “VM-entry with invalid host-state field”.
> 
> According to the SDM, checks of control fields and host field are not ordered.
> But I do not know what exactly causes the failure.

The failure happens when checking the VM-exit host address size bit
against EFER.LMA.  26.2.2 puts that check under "Checks on Host Control
Registers and MSRs", so technically it would be wrong to return error 7
instead of 8.  However we can relax the test, it's not a big deal.

Paolo


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-23 10:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25 16:14 [PATCH kvm-unit-tests 0/4] test GUEST_EFER field and address size controls Paolo Bonzini
2019-09-25 16:14 ` [PATCH kvm-unit-tests 1/4] x86: vmx_tests: gate load guest PAT tests on the correct bit Paolo Bonzini
2019-09-25 16:14 ` [PATCH kvm-unit-tests 2/4] x86: vmx_tests: extend HOST_EFER tests Paolo Bonzini
2019-11-23  1:40   ` Nadav Amit
2019-11-23 10:22     ` Paolo Bonzini
2019-09-25 16:14 ` [PATCH kvm-unit-tests 3/4] x86: vmx_tests: prepare for extending guest state area tests Paolo Bonzini
2019-09-25 16:14 ` [PATCH kvm-unit-tests 4/4] x86: vmx_tests: add GUEST_EFER tests Paolo Bonzini

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.