]> www.infradead.org Git - nvme.git/commit
KVM: guest_memfd: let kvm_gmem_populate() operate only on private gfns
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 11 Jul 2024 22:27:55 +0000 (18:27 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 26 Jul 2024 18:46:15 +0000 (14:46 -0400)
commite4ee5447927377c55777b73fe497a2455a25f948
treea6ffb957b0a7f357327572395b8a08801a9ea0b1
parent4b5f67120a88c713b82907d55a767693382e9e9d
KVM: guest_memfd: let kvm_gmem_populate() operate only on private gfns

This check is currently performed by sev_gmem_post_populate(), but it
applies to all callers of kvm_gmem_populate(): the point of the function
is that the memory is being encrypted and some work has to be done
on all the gfns in order to encrypt them.

Therefore, check the KVM_MEMORY_ATTRIBUTE_PRIVATE attribute prior
to invoking the callback, and stop the operation if a shared page
is encountered.  Because CONFIG_KVM_PRIVATE_MEM in principle does
not require attributes, this makes kvm_gmem_populate() depend on
CONFIG_KVM_GENERIC_PRIVATE_MEM (which does require them).

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