On 7/22/26 2:41 PM, Muhammad Usama Anjum wrote:
> The hole_punch case verifies that guard regions survive MADV_REMOVE and
> that the backing range is punched out.  MADV_REMOVE delegates the hole
> punch to the backing filesystem, which may reject the operation with
> EOPNOTSUPP.
> 
> That result means the test cannot establish the state whose guard
> semantics it intends to validate.  Treating the missing filesystem
> capability as a guard-region failure creates a false regression.
> 
> Unmap the range and skip only when MADV_REMOVE fails with EOPNOTSUPP.
> Preserve the assertion for all other errors so failures on supported
> configurations remain visible.
> 
> Signed-off-by: Muhammad Usama Anjum <[email protected]>

I tested this patch on a QEMU by mounting ramfs over /tmp and then
running guard-regions from /tmp.

Before the patch:

#  RUN           guard_regions.file.hole_punch ...
# guard-regions.c:1947:hole_punch:Expected madvise(&ptr[3 * page_size],
4 * page_size, MADV_REMOVE) (-1) == 0 (0)
# hole_punch: Test terminated by assertion
#          FAIL  guard_regions.file.hole_punch
not ok 84 guard_regions.file.hole_punch

After the patch:

#  RUN           guard_regions.file.hole_punch ...
#      SKIP      MADV_REMOVE not supported by filesystem
#            OK  guard_regions.file.hole_punch
ok 84 guard_regions.file.hole_punch # SKIP MADV_REMOVE not supported by
filesystem

Tested-by: Sarthak Sharma <[email protected]>

> ---
>  tools/testing/selftests/mm/guard-regions.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/guard-regions.c 
> b/tools/testing/selftests/mm/guard-regions.c
> index b21df3040b1c7..5c8ec3ca75d7d 100644
> --- a/tools/testing/selftests/mm/guard-regions.c
> +++ b/tools/testing/selftests/mm/guard-regions.c
> @@ -1912,7 +1912,7 @@ TEST_F(guard_regions, hole_punch)
>  {
>       const unsigned long page_size = self->page_size;
>       char *ptr;
> -     int i;
> +     int i, ret;
>  
>       if (variant->backing == ANON_BACKED)
>               SKIP(return, "Truncation test specific to file-backed");
> @@ -1944,8 +1944,12 @@ TEST_F(guard_regions, hole_punch)
>       }
>  
>       /* Now hole punch the guarded region. */
> -     ASSERT_EQ(madvise(&ptr[3 * page_size], 4 * page_size,
> -                       MADV_REMOVE), 0);
> +     ret = madvise(&ptr[3 * page_size], 4 * page_size, MADV_REMOVE);
> +     if (ret == -1 && errno == EOPNOTSUPP) {
> +             ASSERT_EQ(munmap(ptr, 10 * page_size), 0);
> +             SKIP(return, "MADV_REMOVE not supported by filesystem");
> +     }
> +     ASSERT_EQ(ret, 0);
>  
>       /* Ensure guard regions remain. */
>       for (i = 0; i < 10; i++) {


Reply via email to