On 25/02/2019 08:53, Anton Kuchin wrote:
Add hunk that was acceped but lost during merge
Fixes: 1868c05a (Check Host Control Registers on vmentry of L2 guests)
Signed-off-by: Krish Sadhukhan <krish.sadhukhan@xxxxxxxxxx>
Signed-off-by: Anton Kuchin <antonkuchin@xxxxxxxxxxxxxx>
Reviewed-by: Liam Merwick <liam.merwick@xxxxxxxxxx>
Tested-by: Liam Merwick <liam.merwick@xxxxxxxxxx>
---
x86/vmx_tests.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 239cb74..3b2f4f0 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -5089,6 +5089,57 @@ static void vmx_controls_test(void)
test_vm_entry_ctls();
}
+static void test_ctl_reg(const char *cr_name, u64 cr, u64 fixed0, u64 fixed1)
+{
+ u64 val;
+ u64 cr_saved = vmcs_read(cr);
+ int i;
+
+ val = fixed0 & fixed1;
+ if (cr == HOST_CR4)
+ vmcs_write(cr, val | X86_CR4_PAE);
+ else
+ vmcs_write(cr, val);
+ report_prefix_pushf("%s %lx", cr_name, val);
+ if (val == fixed0)
+ test_vmx_vmlaunch(0, false);
+ else
+ test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
+ false);
+ report_prefix_pop();
+
+ for (i = 0; i < 64; i++) {
+
+ /* Set a bit when the corresponding bit in fixed1 is 0 */
+ if ((fixed1 & (1ull << i)) == 0) {
+ if (cr == HOST_CR4 && ((1ull << i) & X86_CR4_SMEP ||
+ (1ull << i) & X86_CR4_SMAP))
+ continue;
+
+ vmcs_write(cr, cr_saved | (1ull << i));
+ report_prefix_pushf("%s %llx", cr_name,
+ cr_saved | (1ull << i));
+ test_vmx_vmlaunch(
+ VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
+ false);
+ report_prefix_pop();
+ }
+
+ /* Unset a bit when the corresponding bit in fixed0 is 1 */
+ if (fixed0 & (1ull << i)) {
+ vmcs_write(cr, cr_saved & ~(1ull << i));
+ report_prefix_pushf("%s %llx", cr_name,
+ cr_saved & ~(1ull << i));
+ test_vmx_vmlaunch(
+ VMXERR_ENTRY_INVALID_HOST_STATE_FIELD,
+ false);
+ report_prefix_pop();
+ }
+ }
+
+ vmcs_write(cr, cr_saved);
+}
+
/*
* 1. The CR0 field must not set any bit to a value not supported in VMX
* operation.