[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <diqzwm5h1pz1.fsf@google.com>
Date: Mon, 29 Sep 2025 11:02:26 +0000
From: Ackerley Tng <ackerleytng@...gle.com>
To: Sean Christopherson <seanjc@...gle.com>, Paolo Bonzini <pbonzini@...hat.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>, Janosch Frank <frankja@...ux.ibm.com>,
Claudio Imbrenda <imbrenda@...ux.ibm.com>
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
David Hildenbrand <david@...hat.com>, Fuad Tabba <tabba@...gle.com>,
Sean Christopherson <seanjc@...gle.com>, Lisa Wang <wyihan@...gle.com>
Subject: Re: [PATCH 3/6] KVM: selftests: Create a new guest_memfd for each testcase
Sean Christopherson <seanjc@...gle.com> writes:
> Refactor the guest_memfd selftest to improve test isolation by creating a
> a new guest_memfd for each testcase. Currently, the test reuses a single
> guest_memfd instance for all testcases, and thus creates dependencies
> between tests, e.g. not truncating folios from the guest_memfd instance
> at the end of a test could lead to unexpected results (see the PUNCH_HOLE
> purging that needs to done by in-flight the NUMA testcases[1]).
>
Lisa and I ran into this recently while working on testing
memory_failure() handling for guest_memfd too.
> Invoke each test via a macro wrapper to create and close a guest_memfd
> to cut down on the boilerplate copy+paste needed to create a test.
>
I introduced a wrapper function but a macro is a better idea since it
also parametrizes the test name.
Reviewed-by: Ackerley Tng <ackerleytng@...gle.com>
> Link: https://lore.kernel.org/all/20250827175247.83322-10-shivankg@amd.com
> Reported-by: Ackerley Tng <ackerleytng@...gle.com>
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> ---
> .../testing/selftests/kvm/guest_memfd_test.c | 31 ++++++++++---------
> 1 file changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
> index 8251d019206a..60c6dec63490 100644
> --- a/tools/testing/selftests/kvm/guest_memfd_test.c
> +++ b/tools/testing/selftests/kvm/guest_memfd_test.c
> @@ -26,7 +26,7 @@
>
> static size_t page_size;
>
> -static void test_file_read_write(int fd)
> +static void test_file_read_write(int fd, size_t total_size)
> {
> char buf[64];
>
> @@ -259,14 +259,18 @@ static void test_guest_memfd_flags(struct kvm_vm *vm, uint64_t valid_flags)
> }
> }
>
> +#define gmem_test(__test, __vm, __flags) \
> +do { \
> + int fd = vm_create_guest_memfd(__vm, page_size * 4, __flags); \
> + \
> + test_##__test(fd, page_size * 4); \
> + close(fd); \
> +} while (0)
> +
>
> [...snip...]
>
Powered by blists - more mailing lists