Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/mm: ksm_tests should only MADV_HUGEPAGE valid memory

ksm_tests was previously mmapping a region of memory, aligning the
returned pointer to a PMD boundary, then setting MADV_HUGEPAGE, but was
setting it past the end of the mmapped area due to not taking the pointer
alignment into consideration. Fix this behaviour.

Up until commit efa7df3e3bb5 ("mm: align larger anonymous mappings on THP
boundaries"), this buggy behavior was (usually) masked because the
alignment difference was always less than PMD-size. But since the
mentioned commit, `ksm_tests -H -s 100` started failing.

Link: https://lkml.kernel.org/r/20240122120554.3108022-1-ryan.roberts@arm.com
Fixes: 325254899684 ("selftests: vm: add KSM huge pages merging time test")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Cc: Pedro Demarchi Gomes <pedrodemargomes@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ryan Roberts and committed by
Andrew Morton
d021b442 6f9dc684

+1 -1
+1 -1
tools/testing/selftests/mm/ksm_tests.c
··· 566 566 if (map_ptr_orig == MAP_FAILED) 567 567 err(2, "initial mmap"); 568 568 569 - if (madvise(map_ptr, len + HPAGE_SIZE, MADV_HUGEPAGE)) 569 + if (madvise(map_ptr, len, MADV_HUGEPAGE)) 570 570 err(2, "MADV_HUGEPAGE"); 571 571 572 572 pagemap_fd = open("/proc/self/pagemap", O_RDONLY);