Re: [PATCH v2 3/5] KVM: Add a dedicated API for setting KVM-internal memslots

Christoph Schlameuss
2025-01-20T14:44:48Z

On Sat Jan 11, 2025 at 1:20 AM CET, Sean Christopherson wrote:
> Add a dedicated API for setting internal memslots, and have it explicitly
> disallow setting userspace memslots. Setting a userspace memslots without
> a direct command from userspace would result in all manner of issues.
>
> No functional change intended.
>
> Cc: Tao Su <tao1.su@linux.intel.com>
> Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/x86.c | 2 +-
> include/linux/kvm_host.h | 4 ++--
> virt/kvm/kvm_main.c | 15 ++++++++++++---
> 3 files changed, 15 insertions(+), 6 deletions(-)

[...]

> +int kvm_set_internal_memslot(struct kvm *kvm,
> + const struct kvm_userspace_memory_region2 *mem)
> +{
> + if (WARN_ON_ONCE(mem->slot < KVM_USER_MEM_SLOTS))
> + return -EINVAL;
> +

Looking at Claudios changes I found that this is missing to acquire the
slots_lock here.

guard(mutex)(&kvm->slots_lock);

> + return __kvm_set_memory_region(kvm, mem);
> +}
> +EXPORT_SYMBOL_GPL(kvm_set_internal_memslot);
>
> static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
> struct kvm_userspace_memory_region2 *mem)