Skip to content

Commit eebed24

Browse files
committed
kvm: nVMX: Add support for fast unprotection of nested guest page tables
This is the same as commit 1472775 ("kvm: svm: Add support for additional SVM NPF error codes", 2016-11-23), but for Intel processors. In this case, the exit qualification field's bit 8 says whether the EPT violation occurred while translating the guest's final physical address or rather while translating the guest page tables. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 64531a3 commit eebed24

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ enum {
204204
#define PFERR_GUEST_PAGE_MASK (1ULL << PFERR_GUEST_PAGE_BIT)
205205

206206
#define PFERR_NESTED_GUEST_PAGE (PFERR_GUEST_PAGE_MASK | \
207-
PFERR_USER_MASK | \
208207
PFERR_WRITE_MASK | \
209208
PFERR_PRESENT_MASK)
210209

arch/x86/kvm/mmu.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4836,12 +4836,9 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code,
48364836
* This can occur when using nested virtualization with nested
48374837
* paging in both guests. If true, we simply unprotect the page
48384838
* and resume the guest.
4839-
*
4840-
* Note: AMD only (since it supports the PFERR_GUEST_PAGE_MASK used
4841-
* in PFERR_NEXT_GUEST_PAGE)
48424839
*/
48434840
if (vcpu->arch.mmu.direct_map &&
4844-
error_code == PFERR_NESTED_GUEST_PAGE) {
4841+
(error_code & PFERR_NESTED_GUEST_PAGE) == PFERR_NESTED_GUEST_PAGE) {
48454842
kvm_mmu_unprotect_page(vcpu->kvm, gpa_to_gfn(cr2));
48464843
return 1;
48474844
}

arch/x86/kvm/vmx.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6358,7 +6358,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
63586358
{
63596359
unsigned long exit_qualification;
63606360
gpa_t gpa;
6361-
u32 error_code;
6361+
u64 error_code;
63626362

63636363
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
63646364

@@ -6390,6 +6390,9 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
63906390
EPT_VIOLATION_EXECUTABLE))
63916391
? PFERR_PRESENT_MASK : 0;
63926392

6393+
error_code |= (exit_qualification & 0x100) != 0 ?
6394+
PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK;
6395+
63936396
vcpu->arch.gpa_available = true;
63946397
vcpu->arch.exit_qualification = exit_qualification;
63956398

0 commit comments

Comments
 (0)