Skip to content

Commit 0fe133a

Browse files
sean-jcbonzini
authored andcommitted
KVM: LoongArch: Mark "struct page" pfns dirty only in "slow" page fault path
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/[email protected] Reviewed-by: Bibo Mao <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Tested-by: Dmitry Osipenko <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-ID: <[email protected]>
1 parent 8b135c7 commit 0fe133a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

arch/loongarch/kvm/mmu.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,13 @@ static int kvm_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa, bool writ
608608
if (kvm_pte_young(changed))
609609
kvm_set_pfn_accessed(pfn);
610610

611-
if (kvm_pte_dirty(changed)) {
612-
mark_page_dirty(kvm, gfn);
613-
kvm_set_pfn_dirty(pfn);
614-
}
615611
if (page)
616612
put_page(page);
617613
}
614+
615+
if (kvm_pte_dirty(changed))
616+
mark_page_dirty(kvm, gfn);
617+
618618
return ret;
619619
out:
620620
spin_unlock(&kvm->mmu_lock);
@@ -915,12 +915,14 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
915915
else
916916
++kvm->stat.pages;
917917
kvm_set_pte(ptep, new_pte);
918+
919+
if (writeable)
920+
kvm_set_pfn_dirty(pfn);
921+
918922
spin_unlock(&kvm->mmu_lock);
919923

920-
if (prot_bits & _PAGE_DIRTY) {
924+
if (prot_bits & _PAGE_DIRTY)
921925
mark_page_dirty_in_slot(kvm, memslot, gfn);
922-
kvm_set_pfn_dirty(pfn);
923-
}
924926

925927
kvm_release_pfn_clean(pfn);
926928
out:

0 commit comments

Comments
 (0)