]> Git Repo - linux.git/commitdiff
KVM: PPC: Book3S HV: Close race with page faults around memslot flushes
authorPaul Mackerras <[email protected]>
Thu, 28 May 2020 00:56:42 +0000 (10:56 +1000)
committerPaul Mackerras <[email protected]>
Thu, 28 May 2020 00:56:42 +0000 (10:56 +1000)
There is a potential race condition between hypervisor page faults
and flushing a memslot.  It is possible for a page fault to read the
memslot before a memslot is updated and then write a PTE to the
partition-scoped page tables after kvmppc_radix_flush_memslot has
completed.  (Note that this race has never been explicitly observed.)

To close this race, it is sufficient to increment the MMU sequence
number while the kvm->mmu_lock is held.  That will cause
mmu_notifier_retry() to return true, and the page fault will then
return to the guest without inserting a PTE.

Signed-off-by: Paul Mackerras <[email protected]>
arch/powerpc/kvm/book3s_64_mmu_radix.c

index bc3f795252fdf2bf1adb5188955e21b3f4a1b4e9..aa41183d2a975755a41aa34c0b46ca53da54a682 100644 (file)
@@ -1130,6 +1130,11 @@ void kvmppc_radix_flush_memslot(struct kvm *kvm,
                                         kvm->arch.lpid);
                gpa += PAGE_SIZE;
        }
+       /*
+        * Increase the mmu notifier sequence number to prevent any page
+        * fault that read the memslot earlier from writing a PTE.
+        */
+       kvm->mmu_notifier_seq++;
        spin_unlock(&kvm->mmu_lock);
 }
 
This page took 0.066255 seconds and 4 git commands to generate.