Skip to content

Commit 5982a53

Browse files
shvipinsean-jc
authored andcommitted
KVM: x86/mmu: Use kvm_ad_enabled() to determine if TDP MMU SPTEs need wrprot
Use the constant-after-module-load kvm_ad_enabled() to check if SPTEs in the TDP MMU need to be write-protected when clearing accessed/dirty status instead of manually checking every SPTE. The per-SPTE A/D enabling is specific to nested EPT MMUs, i.e. when KVM is using EPT A/D bits but L1 is not, and so cannot happen in the TDP MMU (which is non-nested only). Keep the original code as sanity checks buried under MMU_WARN_ON(). MMU_WARN_ON() is more or less useless at the moment, but there are plans to change that. Link: https://lore.kernel.org/all/Yz4Qi7cn7TWTWQjj@google.com Signed-off-by: Vipin Sharma <vipinsh@google.com> [sean: split to separate patch, apply to dirty path, write changelog] Link: https://lore.kernel.org/r/20230321220021.2119033-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 41e0766 commit 5982a53

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,10 @@ static bool clear_dirty_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
16211621
if (!is_shadow_present_pte(iter.old_spte))
16221622
continue;
16231623

1624-
if (spte_ad_need_write_protect(iter.old_spte)) {
1624+
MMU_WARN_ON(kvm_ad_enabled() &&
1625+
spte_ad_need_write_protect(iter.old_spte));
1626+
1627+
if (!kvm_ad_enabled()) {
16251628
if (is_writable_pte(iter.old_spte))
16261629
new_spte = iter.old_spte & ~PT_WRITABLE_MASK;
16271630
else
@@ -1685,13 +1688,16 @@ static void clear_dirty_pt_masked(struct kvm *kvm, struct kvm_mmu_page *root,
16851688
if (!mask)
16861689
break;
16871690

1691+
MMU_WARN_ON(kvm_ad_enabled() &&
1692+
spte_ad_need_write_protect(iter.old_spte));
1693+
16881694
if (iter.level > PG_LEVEL_4K ||
16891695
!(mask & (1UL << (iter.gfn - gfn))))
16901696
continue;
16911697

16921698
mask &= ~(1UL << (iter.gfn - gfn));
16931699

1694-
if (wrprot || spte_ad_need_write_protect(iter.old_spte)) {
1700+
if (wrprot || !kvm_ad_enabled()) {
16951701
if (is_writable_pte(iter.old_spte))
16961702
new_spte = iter.old_spte & ~PT_WRITABLE_MASK;
16971703
else

0 commit comments

Comments
 (0)