Re: [RFC PATCH v2 3/6] KVM: selftests: Add tests for punch hole on guest_memfd
From: Sean Christopherson
Date: Thu Sep 21 2023 - 17:17:32 EST
On Thu, Sep 21, 2023, isaku.yamahata@xxxxxxxxx wrote:
> From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
>
> Punch hole implies the region is zeroed out. Add tests if the punched
> region has zero.
> Oppertunistically Remove unused member, pattern, in guest_run_test().
Heh, I didn't pretty much all the same stuff, except I opted to have
SET_ATTRIBUTE instead of FALLOCATE_ONLY, e.g. in case we end up with a test that's
wants a thrid flavor (or somehow neither?).
> Signed-off-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
> ---
> .../kvm/x86_64/private_mem_conversions_test.c | 26 ++++++++++++++-----
> 1 file changed, 20 insertions(+), 6 deletions(-)
>
...
> @@ -156,6 +163,10 @@ static void guest_run_test(uint64_t base_gpa, bool do_fallocate)
>
> if (size > PAGE_SIZE) {
> memset((void *)gpa, p2, PAGE_SIZE);
> +
> + /* Test if punch hole results in zeroing page. */
> + guest_punch_hole_private(gpa, PAGE_SIZE);
> + memcmp_g(gpa, 0, PAGE_SIZE);
I added a dedicated sub-test to provide a bit more variety in the tests. I highly
doubt my version will ever find a bug that isn't caught by this approach, but if
nothing else, it's nice to have a completely separate sub-test.