KVM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/3] kvm-unit-tests: nVMX: Test base and limit fields of guest GDTR and IDTR
@ 2020-05-23  0:26 Krish Sadhukhan
  2020-05-23  0:26 ` [PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry of nested guests Krish Sadhukhan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Krish Sadhukhan @ 2020-05-23  0:26 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, jmattson, sean.j.christopherson

Patch# 1: Adds the kvm-unit-tests for the base field of GUEST_BASE_GDTR and
	  GUEST_BASE_IDTR
Patch# 2: Factors out the loops from test_guest_dr7() to a macro
Patch# 3: Adds the kvm-unit-tests for the limit fields of GUEST_BASE_GDTR and
	  GUEST_BASE_IDTR


[PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and
[PATCH 2/3] kvm-unit-tests: nVMX: Optimize test_guest_dr7() by
[PATCH 3/3] kvm-unit-tests: nVMX: Test GUEST_LIMIT_GDTR and

 x86/vmx_tests.c | 52 ++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 36 insertions(+), 16 deletions(-)

Krish Sadhukhan (3):
      kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry 
      kvm-unit-tests: nVMX: Optimize test_guest_dr7() by factoring out the loops
      kvm-unit-tests: nVMX: Test GUEST_LIMIT_GDTR and GUEST_LIMIT_IDTR on vmentr


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

* [PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry of nested guests
  2020-05-23  0:26 [PATCH 0/3] kvm-unit-tests: nVMX: Test base and limit fields of guest GDTR and IDTR Krish Sadhukhan
@ 2020-05-23  0:26 ` Krish Sadhukhan
  2020-05-27  5:17   ` Sean Christopherson
  2020-05-23  0:26 ` [PATCH 2/3] kvm-unit-tests: nVMX: Optimize test_guest_dr7() by factoring out the loops into a macro Krish Sadhukhan
  2020-05-23  0:26 ` [PATCH 3/3] kvm-unit-tests: nVMX: Test GUEST_LIMIT_GDTR and GUEST_LIMIT_IDTR on vmentry of nested guests Krish Sadhukhan
  2 siblings, 1 reply; 5+ messages in thread
From: Krish Sadhukhan @ 2020-05-23  0:26 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, jmattson, sean.j.christopherson

According to section "Checks on Guest Descriptor-Table Registers" in Intel
SDM vol 3C, the following check is performed on the Guest Descriptor-Table
Registers on vmentry of nested guests:

    - On processors that support Intel 64 architecture, the base-address
      fields must contain canonical addresses.

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
---
 x86/vmx_tests.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 68f93d3..fa27d99 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7827,6 +7827,11 @@ static void vmx_guest_state_area_test(void)
 	test_load_guest_perf_global_ctrl();
 	test_load_guest_bndcfgs();
 
+#ifdef __x86_64__
+	test_canonical(GUEST_BASE_GDTR, "GUEST_BASE_GDTR", false);
+	test_canonical(GUEST_BASE_IDTR, "GUEST_BASE_IDTR", false);
+#endif
+
 	/*
 	 * Let the guest finish execution
 	 */
-- 
1.8.3.1


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

* [PATCH 2/3] kvm-unit-tests: nVMX: Optimize test_guest_dr7() by factoring out the loops into a macro
  2020-05-23  0:26 [PATCH 0/3] kvm-unit-tests: nVMX: Test base and limit fields of guest GDTR and IDTR Krish Sadhukhan
  2020-05-23  0:26 ` [PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry of nested guests Krish Sadhukhan
@ 2020-05-23  0:26 ` Krish Sadhukhan
  2020-05-23  0:26 ` [PATCH 3/3] kvm-unit-tests: nVMX: Test GUEST_LIMIT_GDTR and GUEST_LIMIT_IDTR on vmentry of nested guests Krish Sadhukhan
  2 siblings, 0 replies; 5+ messages in thread
From: Krish Sadhukhan @ 2020-05-23  0:26 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, jmattson, sean.j.christopherson

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
---
 x86/vmx_tests.c | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index fa27d99..f400408 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7704,6 +7704,19 @@ static void vmx_host_state_area_test(void)
 	test_load_host_perf_global_ctrl();
 }
 
+#define TEST_GUEST_VMCS_FIELD_RESERVED_BITS(start, end, inc, fld, str_name,\
+					    val, msg, xfail)		\
+{									\
+	u64 tmp;							\
+	int i;								\
+									\
+	for (i = start; i <= end; i = i + inc) {			\
+		tmp = val | (1ull << i);				\
+		vmcs_write(fld, tmp);					\
+		test_guest_state(msg, xfail, val, str_name);		\
+	}								\
+}
+
 /*
  * If the "load debug controls" VM-entry control is 1, bits 63:32 in
  * the DR7 field must be 0.
@@ -7714,26 +7727,17 @@ static void test_guest_dr7(void)
 {
 	u32 ent_saved = vmcs_read(ENT_CONTROLS);
 	u64 dr7_saved = vmcs_read(GUEST_DR7);
-	u64 val;
-	int i;
 
 	if (ctrl_enter_rev.set & ENT_LOAD_DBGCTLS) {
-		vmcs_clear_bits(ENT_CONTROLS, ENT_LOAD_DBGCTLS);
-		for (i = 0; i < 64; i++) {
-			val = 1ull << i;
-			vmcs_write(GUEST_DR7, val);
-			test_guest_state("ENT_LOAD_DBGCTLS disabled", false,
-					 val, "GUEST_DR7");
-		}
+		vmcs_write(ENT_CONTROLS, ent_saved & ~ENT_LOAD_DBGCTLS);
+		TEST_GUEST_VMCS_FIELD_RESERVED_BITS(0, 63, 4, GUEST_DR7,
+		    "GUEST_DR7", dr7_saved, "ENT_LOAD_DBGCTLS disabled", false);
 	}
 	if (ctrl_enter_rev.clr & ENT_LOAD_DBGCTLS) {
-		vmcs_set_bits(ENT_CONTROLS, ENT_LOAD_DBGCTLS);
-		for (i = 0; i < 64; i++) {
-			val = 1ull << i;
-			vmcs_write(GUEST_DR7, val);
-			test_guest_state("ENT_LOAD_DBGCTLS enabled", i >= 32,
-					 val, "GUEST_DR7");
-		}
+		vmcs_write(ENT_CONTROLS, ent_saved | ENT_LOAD_DBGCTLS);
+		TEST_GUEST_VMCS_FIELD_RESERVED_BITS(0, 63, 4, GUEST_DR7,
+		    "GUEST_DR7", dr7_saved, "ENT_LOAD_DBGCTLS enabled",
+		    i >= 32);
 	}
 	vmcs_write(GUEST_DR7, dr7_saved);
 	vmcs_write(ENT_CONTROLS, ent_saved);
-- 
1.8.3.1


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

* [PATCH 3/3] kvm-unit-tests: nVMX: Test GUEST_LIMIT_GDTR and GUEST_LIMIT_IDTR on vmentry of nested guests
  2020-05-23  0:26 [PATCH 0/3] kvm-unit-tests: nVMX: Test base and limit fields of guest GDTR and IDTR Krish Sadhukhan
  2020-05-23  0:26 ` [PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry of nested guests Krish Sadhukhan
  2020-05-23  0:26 ` [PATCH 2/3] kvm-unit-tests: nVMX: Optimize test_guest_dr7() by factoring out the loops into a macro Krish Sadhukhan
@ 2020-05-23  0:26 ` Krish Sadhukhan
  2 siblings, 0 replies; 5+ messages in thread
From: Krish Sadhukhan @ 2020-05-23  0:26 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, jmattson, sean.j.christopherson

According to section "Checks on Guest Descriptor-Table Registers" in Intel
SDM vol 3C, the following checks are performed on the Guest Descriptor-Table
Registers on vmentry of nested guests:

    - Bits 31:16 of each limit field must be 0.

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
---
 x86/vmx_tests.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index f400408..7b6205d 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7836,6 +7836,17 @@ static void vmx_guest_state_area_test(void)
 	test_canonical(GUEST_BASE_IDTR, "GUEST_BASE_IDTR", false);
 #endif
 
+	u32 guest_desc_limit_saved = vmcs_read(GUEST_LIMIT_GDTR);
+	TEST_GUEST_VMCS_FIELD_RESERVED_BITS(16, 31, 4, GUEST_LIMIT_GDTR,
+	    "GUEST_LIMIT_GDTR", guest_desc_limit_saved, "GUEST_LIMIT_GDTR",
+	    true);
+	vmcs_write(GUEST_LIMIT_GDTR, guest_desc_limit_saved);
+	guest_desc_limit_saved = vmcs_read(GUEST_LIMIT_IDTR);
+	TEST_GUEST_VMCS_FIELD_RESERVED_BITS(16, 31, 4, GUEST_LIMIT_IDTR,
+	    "GUEST_LIMIT_IDTR", guest_desc_limit_saved, "GUEST_LIMIT_IDTR",
+	    true);
+	vmcs_write(GUEST_LIMIT_IDTR, guest_desc_limit_saved);
+
 	/*
 	 * Let the guest finish execution
 	 */
-- 
1.8.3.1


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

* Re: [PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry of nested guests
  2020-05-23  0:26 ` [PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry of nested guests Krish Sadhukhan
@ 2020-05-27  5:17   ` Sean Christopherson
  0 siblings, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2020-05-27  5:17 UTC (permalink / raw)
  To: Krish Sadhukhan; +Cc: kvm, pbonzini, jmattson

On Fri, May 22, 2020 at 08:26:01PM -0400, Krish Sadhukhan wrote:
> According to section "Checks on Guest Descriptor-Table Registers" in Intel
> SDM vol 3C, the following check is performed on the Guest Descriptor-Table
> Registers on vmentry of nested guests:
> 
>     - On processors that support Intel 64 architecture, the base-address
>       fields must contain canonical addresses.
> 
> Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> ---
>  x86/vmx_tests.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index 68f93d3..fa27d99 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -7827,6 +7827,11 @@ static void vmx_guest_state_area_test(void)
>  	test_load_guest_perf_global_ctrl();
>  	test_load_guest_bndcfgs();
>  
> +#ifdef __x86_64__

Aren't the VMX tests 64-bit only?

> +	test_canonical(GUEST_BASE_GDTR, "GUEST_BASE_GDTR", false);
> +	test_canonical(GUEST_BASE_IDTR, "GUEST_BASE_IDTR", false);
> +#endif
> +
>  	/*
>  	 * Let the guest finish execution
>  	 */
> -- 
> 1.8.3.1
> 

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23  0:26 [PATCH 0/3] kvm-unit-tests: nVMX: Test base and limit fields of guest GDTR and IDTR Krish Sadhukhan
2020-05-23  0:26 ` [PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry of nested guests Krish Sadhukhan
2020-05-27  5:17   ` Sean Christopherson
2020-05-23  0:26 ` [PATCH 2/3] kvm-unit-tests: nVMX: Optimize test_guest_dr7() by factoring out the loops into a macro Krish Sadhukhan
2020-05-23  0:26 ` [PATCH 3/3] kvm-unit-tests: nVMX: Test GUEST_LIMIT_GDTR and GUEST_LIMIT_IDTR on vmentry of nested guests Krish Sadhukhan

KVM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvm/0 kvm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvm kvm/ https://lore.kernel.org/kvm \
		kvm@vger.kernel.org
	public-inbox-index kvm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.kvm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git