[PATCH v17 24/24] KVM: selftests: Add guest_memfd testcase to fault-in on !mmap()'d memory

Zenghui Yu yuzenghui at huawei.com
Tue May 12 00:28:15 PDT 2026


Hi Sean,

On 2026/4/18 0:47, Sean Christopherson wrote:
> 
> Does this fix things for you?  If so, I'll send a proper patch.
> 
> diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
> index ec7644aae999..c682bda722f9 100644
> --- a/tools/testing/selftests/kvm/guest_memfd_test.c
> +++ b/tools/testing/selftests/kvm/guest_memfd_test.c
> @@ -510,9 +510,15 @@ static void test_guest_memfd_guest(void)
>                     "Default VM type should support INIT_SHARED, supported flags = 0x%x",
>                     vm_check_cap(vm, KVM_CAP_GUEST_MEMFD_FLAGS));
>  
> +       /*
> +        * Use the guest's page size for all accesses, e.g. to avoid having to
> +        * map multiple pages, but create the guest_memfd instance with the max
> +        * of the host or guest page size, as KVM requires gmem files to be
> +        * aligned to the host page size.
> +        */
>         size = vm->page_size;
> -       fd = vm_create_guest_memfd(vm, size, GUEST_MEMFD_FLAG_MMAP |
> -                                            GUEST_MEMFD_FLAG_INIT_SHARED);
> +       fd = vm_create_guest_memfd(vm, max(size, page_size), GUEST_MEMFD_FLAG_MMAP |
> +                                                            GUEST_MEMFD_FLAG_INIT_SHARED);
>         vm_set_user_memory_region2(vm, slot, KVM_MEM_GUEST_MEMFD, gpa, size, NULL, fd, 0);
>  
>         mem = kvm_mmap(size, PROT_READ | PROT_WRITE, MAP_SHARED, fd);

This results in another failure at

|	vm_set_user_memory_region2(vm, slot, KVM_MEM_GUEST_MEMFD, gpa, size,
NULL, fd, 0);

# ./guest_memfd_test
Random seed: 0x6b8b4567
__vm_create: mode='PA-bits:40,  VA-bits:48,  4K pages' type='0', pages='672'
==== Test Assertion Failure ====
  lib/kvm_util.c:974: !ret
  pid=284539 tid=284539 errno=22 - Invalid argument
     1	0x00000000004008fb: test_guest_memfd_guest at guest_memfd_test.c:522
     2	 (inlined by) main at guest_memfd_test.c:561
     3	0x0000000000417623: __libc_start_call_main at libc-start.o:?
     4	0x000000000041796b: __libc_start_main_impl at ??:?
     5	0x0000000000400cef: _start at ??:?
  KVM_SET_USER_MEMORY_REGION2 failed, errno = 22 (Invalid argument)

Thanks,
Zenghui



More information about the linux-arm-kernel mailing list