selftests/mm: fix thuge-gen test bugs
authorRyan Roberts <ryan.roberts@arm.com>
Mon, 24 Jul 2023 08:25:18 +0000 (09:25 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 18 Aug 2023 17:12:42 +0000 (10:12 -0700)
thuge-gen was previously only munmapping part of the mmapped buffer, which
caused us to run out of 1G huge pages for a later part of the test.  Fix
this by munmapping the whole buffer.  Based on the code, it looks like a
typo rather than an intention to keep some of the buffer mapped.

thuge-gen was also calling mmap with SHM_HUGETLB flag (bit 11 set), which
is actually MAP_DENYWRITE in mmap context.  The man page says this flag is
ignored in modern kernels.  I'm pretty sure from the context that the
author intended to pass the MAP_HUGETLB flag so I've fixed that up too.

Link: https://lkml.kernel.org/r/20230724082522.1202616-5-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Cc: Florent Revest <revest@chromium.org>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/thuge-gen.c

index 380ab5f0a5340ef12a042ba9c29aac86c942e8f8..16ed4dfa7359839ad55d8115350d42a3603e49b8 100644 (file)
@@ -139,7 +139,7 @@ void test_mmap(unsigned long size, unsigned flags)
                before, after, before - after, size);
        assert(size == getpagesize() || (before - after) == NUM_PAGES);
        show(size);
-       err = munmap(map, size);
+       err = munmap(map, size * NUM_PAGES);
        assert(!err);
 }
 
@@ -222,7 +222,7 @@ int main(void)
                test_mmap(ps, MAP_HUGETLB | arg);
        }
        printf("Testing default huge mmap\n");
-       test_mmap(default_hps, SHM_HUGETLB);
+       test_mmap(default_hps, MAP_HUGETLB);
 
        puts("Testing non-huge shmget");
        test_shmget(getpagesize(), 0);