Skip to content

Commit 694556d

Browse files
Marc Zyngierchristofferdall-arm
authored andcommitted
KVM: arm/arm64: Clean dcache to PoC when changing PTE due to CoW
When triggering a CoW, we unmap the RO page via an MMU notifier (invalidate_range_start), and then populate the new PTE using another one (change_pte). In the meantime, we'll have copied the old page into the new one. The problem is that the data for the new page is sitting in the cache, and should the guest have an uncached mapping to that page (or its MMU off), following accesses will bypass the cache. In a way, this is similar to what happens on a translation fault: We need to clean the page to the PoC before mapping it. So let's just do that. This fixes a KVM unit test regression observed on a HiSilicon platform, and subsequently reproduced on Seattle. Fixes: a9c0e12 ("KVM: arm/arm64: Only clean the dcache on translation fault") Cc: [email protected] # v4.16+ Reported-by: Mike Galbraith <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Christoffer Dall <[email protected]>
1 parent 5b394b2 commit 694556d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

virt/kvm/arm/mmu.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1860,13 +1860,20 @@ static int kvm_set_spte_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data
18601860
void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte)
18611861
{
18621862
unsigned long end = hva + PAGE_SIZE;
1863+
kvm_pfn_t pfn = pte_pfn(pte);
18631864
pte_t stage2_pte;
18641865

18651866
if (!kvm->arch.pgd)
18661867
return;
18671868

18681869
trace_kvm_set_spte_hva(hva);
1869-
stage2_pte = pfn_pte(pte_pfn(pte), PAGE_S2);
1870+
1871+
/*
1872+
* We've moved a page around, probably through CoW, so let's treat it
1873+
* just like a translation fault and clean the cache to the PoC.
1874+
*/
1875+
clean_dcache_guest_page(pfn, PAGE_SIZE);
1876+
stage2_pte = pfn_pte(pfn, PAGE_S2);
18701877
handle_hva_to_gpa(kvm, hva, end, &kvm_set_spte_handler, &stage2_pte);
18711878
}
18721879

0 commit comments

Comments
 (0)