kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krish Sadhukhan <krish.sadhukhan@oracle.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com,
	sean.j.christopherson@intel.com
Subject: [PATCH 2/3] kvm-unit-tests: nVMX: Optimize test_guest_dr7() by factoring out the loops into a macro
Date: Fri, 22 May 2020 20:26:02 -0400	[thread overview]
Message-ID: <20200523002603.32450-3-krish.sadhukhan@oracle.com> (raw)
In-Reply-To: <20200523002603.32450-1-krish.sadhukhan@oracle.com>

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


  parent reply	other threads:[~2020-05-23  1:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Krish Sadhukhan [this message]
2020-05-23  0:26 ` [PATCH 3/3] kvm-unit-tests: nVMX: Test GUEST_LIMIT_GDTR and GUEST_LIMIT_IDTR " Krish Sadhukhan

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=20200523002603.32450-3-krish.sadhukhan@oracle.com \
    --to=krish.sadhukhan@oracle.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=sean.j.christopherson@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).