The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Re: [PATCH v17 24/24] KVM: selftests: Add guest_memfd testcase to fault-in on !mmap()'d memory
       [not found]     ` <aeJkCGwsrRmuBikT@google.com>
@ 2026-05-12  7:28       ` Zenghui Yu
  2026-05-12 15:53         ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Zenghui Yu @ 2026-05-12  7:28 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Zenghui Yu, Paolo Bonzini, Marc Zyngier, Oliver Upton, kvm,
	linux-arm-kernel, kvmarm, linux-kernel, Ira Weiny, Gavin Shan,
	Shivank Garg, Vlastimil Babka, Xiaoyao Li, David Hildenbrand,
	Fuad Tabba, Ackerley Tng, Tao Chan, James Houghton

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v17 24/24] KVM: selftests: Add guest_memfd testcase to fault-in on !mmap()'d memory
  2026-05-12  7:28       ` [PATCH v17 24/24] KVM: selftests: Add guest_memfd testcase to fault-in on !mmap()'d memory Zenghui Yu
@ 2026-05-12 15:53         ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-05-12 15:53 UTC (permalink / raw)
  To: Zenghui Yu
  Cc: Zenghui Yu, Paolo Bonzini, Marc Zyngier, Oliver Upton, kvm,
	linux-arm-kernel, kvmarm, linux-kernel, Ira Weiny, Gavin Shan,
	Shivank Garg, Vlastimil Babka, Xiaoyao Li, David Hildenbrand,
	Fuad Tabba, Ackerley Tng, Tao Chan, James Houghton

On Tue, May 12, 2026, Zenghui Yu wrote:
> 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);

Gah, the memslot size also needs to be a multiple of the host page size.  I
actually tested on a CONFIG_ARM64_64K_PAGES=y kernel this time, patch incoming...

Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-12 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250729225455.670324-1-seanjc@google.com>
     [not found] ` <20250729225455.670324-25-seanjc@google.com>
     [not found]   ` <0064952b-048c-455d-ad89-e27e5cb82591@linux.dev>
     [not found]     ` <aeJkCGwsrRmuBikT@google.com>
2026-05-12  7:28       ` [PATCH v17 24/24] KVM: selftests: Add guest_memfd testcase to fault-in on !mmap()'d memory Zenghui Yu
2026-05-12 15:53         ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox