Skip to content

Commit b7e9488

Browse files
committed
KVM: x86/mmu: Don't try to unprotect an INVALID_GPA
If getting the gpa for a gva fails, e.g. because the gva isn't mapped in the guest page tables, don't try to unprotect the invalid gfn. This is mostly a performance fix (avoids unnecessarily taking mmu_lock), as for_each_gfn_valid_sp_with_gptes() won't explode on garbage input, it's simply pointless. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 2df354e commit b7e9488

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2729,8 +2729,11 @@ bool kvm_mmu_unprotect_gfn_and_retry(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa)
27292729
if (!READ_ONCE(vcpu->kvm->arch.indirect_shadow_pages))
27302730
return false;
27312731

2732-
if (!vcpu->arch.mmu->root_role.direct)
2732+
if (!vcpu->arch.mmu->root_role.direct) {
27332733
gpa = kvm_mmu_gva_to_gpa_write(vcpu, cr2_or_gpa, NULL);
2734+
if (gpa == INVALID_GPA)
2735+
return false;
2736+
}
27342737

27352738
r = kvm_mmu_unprotect_page(vcpu->kvm, gpa_to_gfn(gpa));
27362739
if (r) {
@@ -2749,6 +2752,8 @@ static int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva)
27492752
return 0;
27502753

27512754
gpa = kvm_mmu_gva_to_gpa_read(vcpu, gva, NULL);
2755+
if (gpa == INVALID_GPA)
2756+
return 0;
27522757

27532758
r = kvm_mmu_unprotect_page(vcpu->kvm, gpa >> PAGE_SHIFT);
27542759

0 commit comments

Comments
 (0)