Skip to content

Commit

Permalink
Update EPTP02 from EPTP01 if the guest hypervisor is not using EPT
Browse files Browse the repository at this point in the history
  • Loading branch information
lxylxy123456 committed Oct 23, 2022
1 parent 4c1cbb6 commit 226e33c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static vmcs12_info_t *new_active_vmcs12(VCPU * vcpu, gpa_t vmcs_ptr, u32 rev)
(void *)vcpu->vmx_vaddr_msr_area_guest,
vcpu->vmcs.control_VM_entry_MSR_load_count * sizeof(msr_entry_t));
vmcs12_info->guest_ept_enable = 0;
vmcs12_info->guest_ept_root = 0;
vmcs12_info->guest_ept_cache_line = NULL;
vmcs12_info->guest_nmi_exiting = false;
vmcs12_info->guest_virtual_nmis = false;
vmcs12_info->guest_nmi_window_exiting = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ static u32 handle_vmexit20_ept_violation(VCPU * vcpu,
ept02_cache_line_t *cache_line = vmcs12_info->guest_ept_cache_line;
u64 guest2_paddr = __vmx_vmread64(VMCSENC_guest_paddr);
ulong_t qualification = __vmx_vmreadNW(VMCSENC_info_exit_qualification);
HALT_ON_ERRORCOND(cache_line->key == vmcs12_info->guest_ept_root);
HALT_ON_ERRORCOND(cache_line->key ==
vmcs12_info->vmcs12_value.control_EPT_pointer);
#ifdef __DEBUG_QEMU__
/*
* Workaround a KVM bug:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,6 @@ static u32 _vmcs12_to_vmcs02_control_EPT_pointer(ARG10 * arg)
ept02 = xmhf_nested_arch_x86vmx_get_ept02(arg->vcpu, ept12, &cache_hit,
&cache_line);
arg->vmcs12_info->guest_ept_cache_line = cache_line;
arg->vmcs12_info->guest_ept_root = ept12;
#ifdef __DEBUG_QEMU__
_workaround_kvm_216212(arg, cache_line);
#endif /* !__DEBUG_QEMU__ */
Expand All @@ -956,7 +955,7 @@ static void _vmcs02_to_vmcs12_control_EPT_pointer(ARG01 * arg)
u16 encoding = VMCSENC_control_EPT_pointer;
HALT_ON_ERRORCOND(_vmx_hasctl_enable_ept(&arg->vcpu->vmx_caps));
if (_vmx_hasctl_enable_ept(arg->ctls)) {
gpa_t ept12 = arg->vmcs12_info->guest_ept_root;
gpa_t ept12 = arg->vmcs12->control_EPT_pointer;
ept02_cache_line_t *cache_line;
bool cache_hit;
ept02 = xmhf_nested_arch_x86vmx_get_ept02(arg->vcpu, ept12, &cache_hit,
Expand All @@ -970,6 +969,28 @@ static void _vmcs02_to_vmcs12_control_EPT_pointer(ARG01 * arg)
(void)_vmcs02_to_vmcs12_control_EPT_pointer_unused;
}

static void _rewalk_ept01_control_EPT_pointer(ARG10 * arg)
{
spa_t ept02;
if (arg->vmcs12_info->guest_ept_enable) {
ept02_cache_line_t *cache_line;
bool cache_hit;
gpa_t ept12 = arg->vmcs12->control_EPT_pointer;
ept02 = xmhf_nested_arch_x86vmx_get_ept02(arg->vcpu, ept12, &cache_hit,
&cache_line);
HALT_ON_ERRORCOND(!cache_hit);
arg->vmcs12_info->guest_ept_cache_line = cache_line;
__vmx_vmwrite64(VMCSENC_control_EPT_pointer, ept02);
#ifdef __DEBUG_QEMU__
_workaround_kvm_216212(arg, cache_line);
#endif /* !__DEBUG_QEMU__ */
} else {
ept02 = arg->vcpu->vmcs.control_EPT_pointer;
_update_pae_pdpte(arg);
}
__vmx_vmwrite64(VMCSENC_control_EPT_pointer, ept02);
}

/*
* 64-Bit Read-Only Data Field
*/
Expand Down Expand Up @@ -1701,22 +1722,7 @@ void xmhf_nested_arch_x86vmx_rewalk_ept01(VCPU * vcpu,
#include "nested-x86vmx-vmcs12-fields.h"

/* Special handling for EPT02 */
if (vmcs12_info->guest_ept_enable) {
ept02_cache_line_t *cache_line;
bool cache_hit;
gpa_t ept12 = vmcs12_info->guest_ept_root;
spa_t ept02 = xmhf_nested_arch_x86vmx_get_ept02(vcpu, ept12, &cache_hit,
&cache_line);
HALT_ON_ERRORCOND(!cache_hit);
vmcs12_info->guest_ept_cache_line = cache_line;
__vmx_vmwrite64(VMCSENC_control_EPT_pointer, ept02);
#ifdef __DEBUG_QEMU__
_workaround_kvm_216212(&arg, cache_line);
#endif /* !__DEBUG_QEMU__ */
__vmx_vmwrite64(VMCSENC_control_EPT_pointer, ept02);
} else {
_update_pae_pdpte(&arg);
}
_rewalk_ept01_control_EPT_pointer(&arg);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ typedef struct vmcs12_info {
* it when accessing.
*/
ept02_cache_line_t *guest_ept_cache_line;
/* When guest_ept_enable, pointer to EPT12 root */
gpa_t guest_ept_root;
/* "NMI exiting" in VMCS */
bool guest_nmi_exiting;
/* "Virtual NMIs" in VMCS */
Expand Down

0 comments on commit 226e33c

Please sign in to comment.