This patch fix 3 bugs in VMX framework and EPT framework
1. Fix bug of setting default value of CPU_SECONDARY
2. Fix bug of reading MSR_IA32_VMX_PROCBASED_CTLS2 and
MSR_IA32_VMX_EPT_VPID_CAP
3. For EPT violation and misconfiguration reduced vmexit, vmcs field
"VM-exit instruction length" is not used and will return unexpected
value when read.

Signed-off-by: Arthur Chunqi Li <[email protected]>
---
 x86/vmx.c       |   13 ++++++++++---
 x86/vmx_tests.c |    2 --
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/x86/vmx.c b/x86/vmx.c
index 87d1d55..9db4ef4 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -304,7 +304,8 @@ static void init_vmcs_ctrl(void)
        /* Disable VMEXIT of IO instruction */
        vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu[0]);
        if (ctrl_cpu_rev[0].set & CPU_SECONDARY) {
-               ctrl_cpu[1] |= ctrl_cpu_rev[1].set & ctrl_cpu_rev[1].clr;
+               ctrl_cpu[1] = (ctrl_cpu[1] | ctrl_cpu_rev[1].set) &
+                       ctrl_cpu_rev[1].clr;
                vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu[1]);
        }
        vmcs_write(CR3_TARGET_COUNT, 0);
@@ -489,8 +490,14 @@ static void init_vmx(void)
                        : MSR_IA32_VMX_ENTRY_CTLS);
        ctrl_cpu_rev[0].val = rdmsr(basic.ctrl ? MSR_IA32_VMX_TRUE_PROC
                        : MSR_IA32_VMX_PROCBASED_CTLS);
-       ctrl_cpu_rev[1].val = rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2);
-       ept_vpid.val = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
+       if ((ctrl_cpu_rev[0].clr & CPU_SECONDARY) != 0)
+               ctrl_cpu_rev[1].val = rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2);
+       else
+               ctrl_cpu_rev[1].val = 0;
+       if ((ctrl_cpu_rev[1].clr & (CPU_EPT | CPU_VPID)) != 0)
+               ept_vpid.val = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
+       else
+               ept_vpid.val = 0;
 
        write_cr0((read_cr0() & fix_cr0_clr) | fix_cr0_set);
        write_cr4((read_cr4() & fix_cr4_clr) | fix_cr4_set | X86_CR4_VMXE);
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 6d972c0..e891a9f 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -1075,7 +1075,6 @@ static int ept_exit_handler()
                        print_vmexit_info();
                        return VMX_TEST_VMEXIT;
                }
-               vmcs_write(GUEST_RIP, guest_rip + insn_len);
                return VMX_TEST_RESUME;
        case VMX_EPT_VIOLATION:
                switch(get_stage()) {
@@ -1100,7 +1099,6 @@ static int ept_exit_handler()
                        print_vmexit_info();
                        return VMX_TEST_VMEXIT;
                }
-               vmcs_write(GUEST_RIP, guest_rip + insn_len);
                return VMX_TEST_RESUME;
        default:
                printf("Unknown exit reason, %d\n", reason);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to