Skip to content

Commit 64531a3

Browse files
codomaniabonzini
authored andcommitted
KVM: SVM: Limit PFERR_NESTED_GUEST_PAGE error_code check to L1 guest
Commit 1472775 ("kvm: svm: Add support for additional SVM NPF error codes", 2016-11-23) added a new error code to aid nested page fault handling. The commit unprotects (kvm_mmu_unprotect_page) the page when we get a NPF due to guest page table walk where the page was marked RO. However, if an L0->L2 shadow nested page table can also be marked read-only when a page is read only in L1's nested page table. If such a page is accessed by L2 while walking page tables it can cause a nested page fault (page table walks are write accesses). However, after kvm_mmu_unprotect_page we may get another page fault, and again in an endless stream. To cover this use case, we qualify the new error_code check with vcpu->arch.mmu_direct_map so that the error_code check would run on L1 guest, and not the L2 guest. This avoids hitting the above scenario. Fixes: 1472775 Cc: [email protected] Cc: Paolo Bonzini <[email protected]> Cc: Radim Krčmář <[email protected]> Cc: Thomas Lendacky <[email protected]> Signed-off-by: Brijesh Singh <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent bbeac28 commit 64531a3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arch/x86/kvm/mmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4840,7 +4840,8 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code,
48404840
* Note: AMD only (since it supports the PFERR_GUEST_PAGE_MASK used
48414841
* in PFERR_NEXT_GUEST_PAGE)
48424842
*/
4843-
if (error_code == PFERR_NESTED_GUEST_PAGE) {
4843+
if (vcpu->arch.mmu.direct_map &&
4844+
error_code == PFERR_NESTED_GUEST_PAGE) {
48444845
kvm_mmu_unprotect_page(vcpu->kvm, gpa_to_gfn(cr2));
48454846
return 1;
48464847
}

0 commit comments

Comments
 (0)