Skip to content

Commit 7aac9dc

Browse files
committed
KVM: x86/mmu: Fold mmu_spte_age() into kvm_rmap_age_gfn_range()
Fold mmu_spte_age() into its sole caller now that aging and testing for young SPTEs is handled in a common location, i.e. doesn't require more helpers. Opportunistically remove the use of mmu_spte_get_lockless(), as mmu_lock is held (for write!), and marking SPTEs for access tracking outside of mmu_lock is unsafe (at least, as written). I.e. using the lockless accessor is quite misleading. No functional change intended. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent c17f150 commit 7aac9dc

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -614,32 +614,6 @@ static u64 mmu_spte_get_lockless(u64 *sptep)
614614
return __get_spte_lockless(sptep);
615615
}
616616

617-
/* Returns the Accessed status of the PTE and resets it at the same time. */
618-
static bool mmu_spte_age(u64 *sptep)
619-
{
620-
u64 spte = mmu_spte_get_lockless(sptep);
621-
622-
if (!is_accessed_spte(spte))
623-
return false;
624-
625-
if (spte_ad_enabled(spte)) {
626-
clear_bit((ffs(shadow_accessed_mask) - 1),
627-
(unsigned long *)sptep);
628-
} else {
629-
/*
630-
* Capture the dirty status of the page, so that it doesn't get
631-
* lost when the SPTE is marked for access tracking.
632-
*/
633-
if (is_writable_pte(spte))
634-
kvm_set_pfn_dirty(spte_to_pfn(spte));
635-
636-
spte = mark_spte_for_access_track(spte);
637-
mmu_spte_update_no_track(sptep, spte);
638-
}
639-
640-
return true;
641-
}
642-
643617
static inline bool is_tdp_mmu_active(struct kvm_vcpu *vcpu)
644618
{
645619
return tdp_mmu_enabled && vcpu->arch.mmu->root_role.direct;
@@ -1641,10 +1615,30 @@ static bool kvm_rmap_age_gfn_range(struct kvm *kvm,
16411615
for_each_slot_rmap_range(range->slot, PG_LEVEL_4K, KVM_MAX_HUGEPAGE_LEVEL,
16421616
range->start, range->end - 1, &iterator) {
16431617
for_each_rmap_spte(iterator.rmap, &iter, sptep) {
1644-
if (test_only && is_accessed_spte(*sptep))
1618+
u64 spte = *sptep;
1619+
1620+
if (!is_accessed_spte(spte))
1621+
continue;
1622+
1623+
if (test_only)
16451624
return true;
16461625

1647-
young = mmu_spte_age(sptep);
1626+
if (spte_ad_enabled(spte)) {
1627+
clear_bit((ffs(shadow_accessed_mask) - 1),
1628+
(unsigned long *)sptep);
1629+
} else {
1630+
/*
1631+
* Capture the dirty status of the page, so that
1632+
* it doesn't get lost when the SPTE is marked
1633+
* for access tracking.
1634+
*/
1635+
if (is_writable_pte(spte))
1636+
kvm_set_pfn_dirty(spte_to_pfn(spte));
1637+
1638+
spte = mark_spte_for_access_track(spte);
1639+
mmu_spte_update_no_track(sptep, spte);
1640+
}
1641+
young = true;
16481642
}
16491643
}
16501644
return young;

0 commit comments

Comments
 (0)