Skip to content

Commit 11362b1

Browse files
committed
KVM: PPC: Book3S HV: Close race with page faults around memslot flushes
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]>
1 parent 3d89c2e commit 11362b1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

arch/powerpc/kvm/book3s_64_mmu_radix.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,11 @@ void kvmppc_radix_flush_memslot(struct kvm *kvm,
11301130
kvm->arch.lpid);
11311131
gpa += PAGE_SIZE;
11321132
}
1133+
/*
1134+
* Increase the mmu notifier sequence number to prevent any page
1135+
* fault that read the memslot earlier from writing a PTE.
1136+
*/
1137+
kvm->mmu_notifier_seq++;
11331138
spin_unlock(&kvm->mmu_lock);
11341139
}
11351140

0 commit comments

Comments
 (0)