kvm-unit-tests: VMX: Fix some nested EPT related bugs
PATCH 1/1 kvm-unit-tests: VMX: Fix some nested EPT related bugs
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.
--- x86/vmx.c | 13 ++++++++++--- x86/vmx_tests.c | 2 -- 2 files changed, 10 insertions(+), 5 deletions(-)
x86/vmx.c +10 -3
@@ -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 );
x86/vmx_tests.c +0 -2
@@ -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);
Signature · 1 line
1.7.9.5
Paolo Bonzini
maintainerIl 09/09/2013 17:55, Arthur Chunqi Li ha scritto:
Quoted 59 lines
This patch fix 3 bugs in VMX framework and EPT framework
1. Fix bug of setting default value ofCPU_SECONDARY
2. Fix bug of readingMSR_IA32_VMX_PROCBASED_CTLS2andMSR_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(-)x86/vmx.c +10
-3@@ -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 );x86/vmx_tests.c +0
-1@@ -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 ()) {
x86/vmx_tests.c static int ept_exit_handler() · line 1104
Quoted 7 lines
x86/vmx_tests.c +0
-1@@ -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);
Looks good, thanks!
Paolo