]> www.infradead.org Git - nvme.git/commit
KVM: guest_memfd: move check for already-populated page to common code
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 11 Jul 2024 22:27:52 +0000 (18:27 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 26 Jul 2024 18:46:14 +0000 (14:46 -0400)
commitde80252414f32db31eaa14baef511e9bd96021cd
tree0708540fc05d5bec1ebb28393edde1df750d0337
parent7239ed74677af143857d1a96d402476446a0995a
KVM: guest_memfd: move check for already-populated page to common code

Do not allow populating the same page twice with startup data.  In the
case of SEV-SNP, for example, the firmware does not allow it anyway,
since the launch-update operation is only possible on pages that are
still shared in the RMP.

Even if it worked, kvm_gmem_populate()'s callback is meant to have side
effects such as updating launch measurements, and updating the same
page twice is unlikely to have the desired results.

Races between calls to the ioctl are not possible because
kvm_gmem_populate() holds slots_lock and the VM should not be running.
But again, even if this worked on other confidential computing technology,
it doesn't matter to guest_memfd.c whether this is something fishy
such as missing synchronization in userspace, or rather something
intentional.  One of the racers wins, and the page is initialized by
either kvm_gmem_prepare_folio() or kvm_gmem_populate().

Anyway, out of paranoia, adjust sev_gmem_post_populate() anyway to use
the same errno that kvm_gmem_populate() is using.

Reviewed-by: Michael Roth <michael.roth@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/sev.c
virt/kvm/guest_memfd.c