Re: [PATCH v13 13/22] KVM: selftests: Set first memory region as shared if guest_memfd
From: Xiaoyao Li
Date: Wed Jul 01 2026 - 10:11:34 EST
On 7/1/2026 2:18 AM, Ackerley Tng wrote:
GUEST_MEMFD_FLAG_INIT_SHARED was introduced before guest_memfd in-placeI think this patch should fully buy into in-place conversions, so weGUEST_MEMFD_FLAG_INIT_SHARED is valid only when the memory attributes is
need to also set GUEST_MEMFD_FLAG_MMAP:
@@ -483,6 +483,7 @@ struct kvm_vm *__vm_create(struct vm_shape shape,
u32 nr_runnable_vcpus,
{
u64 nr_pages = vm_nr_pages_required(shape.mode, nr_runnable_vcpus,
nr_extra_pages);
+ enum vm_mem_backing_src_type src_type = VM_MEM_SRC_ANONYMOUS;
struct userspace_mem_region *slot0;
u64 gmem_flags = 0;
struct kvm_vm *vm;
@@ -503,10 +504,16 @@ struct kvm_vm *__vm_create(struct vm_shape
shape, u32 nr_runnable_vcpus,
*/
if (is_guest_memfd_required(shape)) {
flags |= KVM_MEM_GUEST_MEMFD;
- gmem_flags |= GUEST_MEMFD_FLAG_INIT_SHARED;
+ gmem_flags |= GUEST_MEMFD_FLAG_INIT_SHARED | GUEST_MEMFD_FLAG_MMAP;
per-gmem.
conversions, so I think it's orthogonal to whether memory attributes is
per-gmem.
But before gmem in-place conversion, i.e., per-gmem attribute, GUEST_MEMFD_FLAG_INIT_SHARED is not supported/valid for Coco VMs.
we need to check KVM_CAP_GUEST_MEMFD_FLAGS or kvm_has_gmem_attributes.I think we do want to deprecate the non-in-place-conversions setup, so
how about inserting a TEST_REQIRE(kvm_has_gmem_attributes) here?
Well, then all the TDX and SNP selftest will be skipped on the kernel with gmem_in_place_conversion=false.
I don't object it. But we still need to get Sean's answer.