aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrish Sadhukhan <krish.sadhukhan@oracle.com>2020-03-17 19:15:30 +0000
committerPaolo Bonzini <pbonzini@redhat.com>2020-03-18 13:43:56 +0100
commita277760709759237e6ea63702b06b1910c3aef21 (patch)
treedd967644cba92951665663dcf6c0d03b238f09c5
parentba29942c5a35817541a8ba98a7bf4c8ac4fc92ac (diff)
downloadkvm-unit-tests-a277760709759237e6ea63702b06b1910c3aef21.tar.gz
kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests
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> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--x86/vmx_tests.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index c24b2c0..2014e54 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7628,6 +7628,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.
@@ -7648,6 +7692,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