Skip to content

Commit 45a61eb

Browse files
dmatlacksean-jc
authored andcommitted
KVM: x86/mmu: Check for leaf SPTE when clearing dirty bit in the TDP MMU
Re-check that the given SPTE is still a leaf and present SPTE after a failed cmpxchg in clear_dirty_gfn_range(). clear_dirty_gfn_range() intends to only operate on present leaf SPTEs, but that could change after a failed cmpxchg. A check for present was added in commit 3354ef5 ("KVM: x86/mmu: Check for present SPTE when clearing dirty bit in TDP MMU") but the check for leaf is still buried in tdp_root_for_each_leaf_pte() and does not get rechecked on retry. Fixes: a6a0b05 ("kvm: x86/mmu: Support dirty logging for the TDP MMU") Signed-off-by: David Matlack <dmatlack@google.com> Link: https://lore.kernel.org/r/20231027172640.2335197-3-dmatlack@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 1aa4bb9 commit 45a61eb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,12 +1522,13 @@ static bool clear_dirty_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
15221522

15231523
rcu_read_lock();
15241524

1525-
tdp_root_for_each_leaf_pte(iter, root, start, end) {
1525+
tdp_root_for_each_pte(iter, root, start, end) {
15261526
retry:
1527-
if (tdp_mmu_iter_cond_resched(kvm, &iter, false, true))
1527+
if (!is_shadow_present_pte(iter.old_spte) ||
1528+
!is_last_spte(iter.old_spte, iter.level))
15281529
continue;
15291530

1530-
if (!is_shadow_present_pte(iter.old_spte))
1531+
if (tdp_mmu_iter_cond_resched(kvm, &iter, false, true))
15311532
continue;
15321533

15331534
KVM_MMU_WARN_ON(kvm_ad_enabled() &&

0 commit comments

Comments
 (0)