]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: MIPS: Mark "struct page" pfns dirty only in "slow" page fault path
authorSean Christopherson <seanjc@google.com>
Thu, 10 Oct 2024 18:24:11 +0000 (11:24 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 25 Oct 2024 17:00:49 +0000 (13:00 -0400)
Mark pages/folios dirty only the slow page fault path, i.e. only when
mmu_lock is held and the operation is mmu_notifier-protected, as marking a
page/folio dirty after it has been written back can make some filesystems
unhappy (backing KVM guests will such filesystem files is uncommon, and
the race is minuscule, hence the lack of complaints).

See the link below for details.

Link: https://lore.kernel.org/all/cover.1683044162.git.lstoakes@gmail.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20241010182427.1434605-70-seanjc@google.com>

arch/mips/kvm/mmu.c

index c17157e700c034567cb25ec62ebbd01cc49469fa..4da9ce4eb54dbe5c433c43cec052d95c57f87748 100644 (file)
@@ -514,7 +514,6 @@ static int _kvm_mips_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa,
                set_pte(ptep, pte_mkdirty(*ptep));
                pfn = pte_pfn(*ptep);
                mark_page_dirty(kvm, gfn);
-               kvm_set_pfn_dirty(pfn);
        }
 
        if (out_entry)
@@ -628,7 +627,6 @@ retry:
                if (write_fault) {
                        prot_bits |= __WRITEABLE;
                        mark_page_dirty(kvm, gfn);
-                       kvm_set_pfn_dirty(pfn);
                }
        }
        entry = pfn_pte(pfn, __pgprot(prot_bits));
@@ -642,6 +640,9 @@ retry:
        if (out_buddy)
                *out_buddy = *ptep_buddy(ptep);
 
+       if (writeable)
+               kvm_set_pfn_dirty(pfn);
+
        spin_unlock(&kvm->mmu_lock);
        kvm_release_pfn_clean(pfn);
        kvm_set_pfn_accessed(pfn);