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/2 v2] kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests
Date: Tue, 17 Mar 2020 19:15:30 +0000 [thread overview]
Message-ID: <1584472530-31728-3-git-send-email-krish.sadhukhan@oracle.com> (raw)
In-Reply-To: <1584472530-31728-1-git-send-email-krish.sadhukhan@oracle.com>
According to section "Checks on Guest Control Registers, Debug Registers,
and MSRs" in Intel SDM vol 3C, the following checks are performed on
vmentry of nested guests:
If the "load IA32_BNDCFGS" VM-entry control is 1, the following
checks are performed on the field for the IA32_BNDCFGS MSR:
— Bits reserved in the IA32_BNDCFGS MSR must be 0.
— The linear address in bits 63:12 must be canonical.
Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
---
x86/vmx_tests.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 0ae0046..7a37c37 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7606,6 +7606,50 @@ static void test_load_guest_pat(void)
test_pat(GUEST_PAT, "GUEST_PAT", ENT_CONTROLS, ENT_LOAD_PAT);
}
+#define MSR_IA32_BNDCFGS_RSVD_MASK 0x00000ffc
+
+/*
+ * If the “load IA32_BNDCFGS” VM-entry control is 1, the following
+ * checks are performed on the field for the IA32_BNDCFGS MSR:
+ *
+ * — Bits reserved in the IA32_BNDCFGS MSR must be 0.
+ * — The linear address in bits 63:12 must be canonical.
+ *
+ * [Intel SDM]
+ */
+static void test_load_guest_bndcfgs(void)
+{
+ u64 bndcfgs_saved = vmcs_read(GUEST_BNDCFGS);
+ u64 bndcfgs;
+
+ if (!(ctrl_enter_rev.clr & ENT_LOAD_BNDCFGS)) {
+ printf("\"Load-IA32-BNDCFGS\" entry control not supported\n");
+ return;
+ }
+
+ vmcs_clear_bits(ENT_CONTROLS, ENT_LOAD_BNDCFGS);
+
+ vmcs_write(GUEST_BNDCFGS, NONCANONICAL);
+ test_guest_state("ENT_LOAD_BNDCFGS disabled", false,
+ GUEST_BNDCFGS, "GUEST_BNDCFGS");
+ bndcfgs = bndcfgs_saved | MSR_IA32_BNDCFGS_RSVD_MASK;
+ vmcs_write(GUEST_BNDCFGS, bndcfgs);
+ test_guest_state("ENT_LOAD_BNDCFGS disabled", false,
+ GUEST_BNDCFGS, "GUEST_BNDCFGS");
+
+ vmcs_set_bits(ENT_CONTROLS, ENT_LOAD_BNDCFGS);
+
+ vmcs_write(GUEST_BNDCFGS, NONCANONICAL);
+ test_guest_state("ENT_LOAD_BNDCFGS enabled", true,
+ GUEST_BNDCFGS, "GUEST_BNDCFGS");
+ bndcfgs = bndcfgs_saved | MSR_IA32_BNDCFGS_RSVD_MASK;
+ vmcs_write(GUEST_BNDCFGS, bndcfgs);
+ test_guest_state("ENT_LOAD_BNDCFGS enabled", true,
+ GUEST_BNDCFGS, "GUEST_BNDCFGS");
+
+ vmcs_write(GUEST_BNDCFGS, bndcfgs_saved);
+}
+
/*
* Check that the virtual CPU checks the VMX Guest State Area as
* documented in the Intel SDM.
@@ -7626,6 +7670,7 @@ static void vmx_guest_state_area_test(void)
test_load_guest_pat();
test_guest_efer();
test_load_guest_perf_global_ctrl();
+ test_load_guest_bndcfgs();
/*
* Let the guest finish execution
--
1.8.3.1
next prev parent reply other threads:[~2020-03-17 19:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-17 19:15 [PATCH 0/2 v2] kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests Krish Sadhukhan
2020-03-17 19:15 ` [PATCH 1/2 v2] kvm-unit-test: VMX: Add enum for GUEST_BNDCFGS field and LOAD_BNDCFGS vmentry control field Krish Sadhukhan
2020-03-17 19:15 ` Krish Sadhukhan [this message]
2020-03-18 13:07 ` [PATCH 0/2 v2] kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests 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=1584472530-31728-3-git-send-email-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).