Skip to content

Commit 4d8fdc5

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Detect if unprotect will do anything based on invalid_list
Explicitly query the list of to-be-zapped shadow pages when checking to see if unprotecting a gfn for retry has succeeded, i.e. if KVM should retry the faulting instruction. Add a comment to explain why the list needs to be checked before zapping, which is the primary motivation for this change. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 710d485 commit 4d8fdc5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,12 +2731,15 @@ bool __kvm_mmu_unprotect_gfn_and_retry(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
27312731
goto out;
27322732
}
27332733

2734-
r = false;
27352734
write_lock(&kvm->mmu_lock);
2736-
for_each_gfn_valid_sp_with_gptes(kvm, sp, gpa_to_gfn(gpa)) {
2737-
r = true;
2735+
for_each_gfn_valid_sp_with_gptes(kvm, sp, gpa_to_gfn(gpa))
27382736
kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list);
2739-
}
2737+
2738+
/*
2739+
* Snapshot the result before zapping, as zapping will remove all list
2740+
* entries, i.e. checking the list later would yield a false negative.
2741+
*/
2742+
r = !list_empty(&invalid_list);
27402743
kvm_mmu_commit_zap_page(kvm, &invalid_list);
27412744
write_unlock(&kvm->mmu_lock);
27422745

0 commit comments

Comments
 (0)