Skip to content

Commit d859b16

Browse files
committed
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. Reviewed-by: Yuan Yao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 6b3dcab commit d859b16

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
@@ -2721,12 +2721,15 @@ bool __kvm_mmu_unprotect_gfn_and_retry(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
27212721
goto out;
27222722
}
27232723

2724-
r = false;
27252724
write_lock(&kvm->mmu_lock);
2726-
for_each_gfn_valid_sp_with_gptes(kvm, sp, gpa_to_gfn(gpa)) {
2727-
r = true;
2725+
for_each_gfn_valid_sp_with_gptes(kvm, sp, gpa_to_gfn(gpa))
27282726
kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list);
2729-
}
2727+
2728+
/*
2729+
* Snapshot the result before zapping, as zapping will remove all list
2730+
* entries, i.e. checking the list later would yield a false negative.
2731+
*/
2732+
r = !list_empty(&invalid_list);
27302733
kvm_mmu_commit_zap_page(kvm, &invalid_list);
27312734
write_unlock(&kvm->mmu_lock);
27322735

0 commit comments

Comments
 (0)