]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: arm64: Enable support for guest_memfd backed memory
authorFuad Tabba <tabba@google.com>
Tue, 29 Jul 2025 22:54:51 +0000 (15:54 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 27 Aug 2025 08:36:50 +0000 (04:36 -0400)
Now that the infrastructure is in place, enable guest_memfd for arm64.

* Select CONFIG_KVM_GUEST_MEMFD in KVM/arm64 Kconfig.

* Enforce KVM_MEMSLOT_GMEM_ONLY for guest_memfd on arm64: Ensure that
  guest_memfd-backed memory slots on arm64 are only supported if they
  are intended for shared memory use cases (i.e.,
  kvm_memslot_is_gmem_only() is true). This design reflects the current
  arm64 KVM ecosystem where guest_memfd is primarily being introduced
  for VMs that support shared memory.

Reviewed-by: James Houghton <jthoughton@google.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Acked-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20250729225455.670324-21-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/arm64/kvm/Kconfig
arch/arm64/kvm/mmu.c

index 713248f240e03d505ac17085b3b2f70054ff1102..bff62e75d68142f84988b288fbbd338cdda3c7b4 100644 (file)
@@ -37,6 +37,7 @@ menuconfig KVM
        select HAVE_KVM_VCPU_RUN_PID_CHANGE
        select SCHED_INFO
        select GUEST_PERF_EVENTS if PERF_EVENTS
+       select KVM_GUEST_MEMFD
        help
          Support hosting virtualized guest machines.
 
index 5d73abc9bebc48b0680d573d21979df67b4267aa..a36426ccd9b5ee2a183dc770b0f21e98ef1a4742 100644 (file)
@@ -2302,6 +2302,13 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
        if ((new->base_gfn + new->npages) > (kvm_phys_size(&kvm->arch.mmu) >> PAGE_SHIFT))
                return -EFAULT;
 
+       /*
+        * Only support guest_memfd backed memslots with mappable memory, since
+        * there aren't any CoCo VMs that support only private memory on arm64.
+        */
+       if (kvm_slot_has_gmem(new) && !kvm_memslot_is_gmem_only(new))
+               return -EINVAL;
+
        hva = new->userspace_addr;
        reg_end = hva + (new->npages << PAGE_SHIFT);