Skip to contentSkip to conversation

kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests

PATCH Applied Krish Sadhukhan 2 participants 4 messages Mar 17, 2020 – Mar 18, 2020 KVM

lore
Share & tools
lore
#0 lore raw

v2 cover kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests

v1 -> v2:
Rebased to the latest Upstream repo. No other changes.

Patch# 1: Adds the required enum values to the header file Patch# 2: Adds the test code

[PATCH 1/2 v2] kvm-unit-test: VMX: Add enum for GUEST_BNDCFGS field and LOAD_BNDCFGS [PATCH 2/2 v2] kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of

 x86/vmx.h       |  2 ++
 x86/vmx_tests.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

Krish Sadhukhan (2):
VMX: Add enum for GUEST_BNDCFGS field and LOAD_BNDCFGS vmentry control fie
nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests

#1 lore raw

PATCH v2 1/2 kvm-unit-test: VMX: Add enum for GUEST_BNDCFGS field and LOAD_BNDCFGS vmentry control field

---
 x86/vmx.h | 2 ++
 1 file changed, 2 insertions(+)
x86/vmx.h +2 -0
index e6ee776..2e28ecb 100644
@@ -198,6 +198,7 @@ enum Encoding {
 	GUEST_PAT		= 0x2804ul,
 	GUEST_PERF_GLOBAL_CTRL	= 0x2808ul,
 	GUEST_PDPTE		= 0x280aul,
+	GUEST_BNDCFGS		= 0x2812ul,
 
 	/* 64-Bit Host State */
 	HOST_PAT		= 0x2c00ul,
@@ -400,6 +401,7 @@ enum Ctrl_ent {
 	ENT_LOAD_PERF		= 1UL << 13,
 	ENT_LOAD_PAT		= 1UL << 14,
 	ENT_LOAD_EFER		= 1UL << 15,
+	ENT_LOAD_BNDCFGS	= 1UL << 16
 };
 
 enum Ctrl_pin {
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v2 2/2 kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests

In reply to Krish Sadhukhan

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.

---
 x86/vmx_tests.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
x86/vmx_tests.c +45 -0
index 0ae0046..7a37c37 100644
@@ -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
Signature · 1 line
1.8.3.1
maintainer Applied
#3 lore raw
In reply to Krish Sadhukhan
Quoted 10 lines · Krish Sadhukhan

v1 -> v2:
Rebased to the latest Upstream repo. No other changes.

Patch# 1: Adds the required enum values to the header file Patch# 2: Adds the test code

[PATCH 1/2 v2] kvm-unit-test: VMX: Add enum for GUEST_BNDCFGS field and LOAD_BNDCFGS [PATCH 2/2 v2] kvm-unit-test: nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of

Quoted 8 lines
 x86/vmx.h       |  2 ++
 x86/vmx_tests.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

Krish Sadhukhan (2):
VMX: Add enum for GUEST_BNDCFGS field and LOAD_BNDCFGS vmentry control fie
nVMX: Test GUEST_BNDCFGS VM-Entry control on vmentry of nested guests

Queued, thanks.

Paolo