Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: PPC: Book3S: Mark "struct page" pfns dirty/accessed after installing PTE

Mark pages/folios dirty/accessed after installing a PTE, and more
specifically after acquiring mmu_lock and checking for an mmu_notifier
invalidation. 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.

This will also allow converting Book3S to kvm_release_faultin_page(),
which requires that mmu_lock be held (for the aforementioned reason).

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-64-seanjc@google.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
2b26d6b7 dac09f61

+5 -5
+5 -5
arch/powerpc/kvm/book3s_64_mmu_host.c
··· 121 121 122 122 vpn = hpt_vpn(orig_pte->eaddr, map->host_vsid, MMU_SEGSIZE_256M); 123 123 124 - kvm_set_pfn_accessed(pfn); 125 124 if (!orig_pte->may_write || !writable) 126 125 rflags |= PP_RXRX; 127 - else { 126 + else 128 127 mark_page_dirty(vcpu->kvm, gfn); 129 - kvm_set_pfn_dirty(pfn); 130 - } 131 128 132 129 if (!orig_pte->may_execute) 133 130 rflags |= HPTE_R_N; ··· 199 202 } 200 203 201 204 out_unlock: 205 + if (!orig_pte->may_write || !writable) 206 + kvm_release_pfn_clean(pfn); 207 + else 208 + kvm_release_pfn_dirty(pfn); 202 209 spin_unlock(&kvm->mmu_lock); 203 - kvm_release_pfn_clean(pfn); 204 210 if (cpte) 205 211 kvmppc_mmu_hpte_cache_free(cpte); 206 212