Hi all,
This patch series addresses false positives in the generic mm selftests and skips tests that cannot run correctly due to missing features or system limitations.
v3: https://lore.kernel.org/all/20250729053403.1071807-1-aboorvad@linux.ibm.com/
Changes in v4:
- Rebased onto the latest mm-new branch, top commit of the base is commit 916e1f041670 ("drivers/base: move memory_block_add_nid() into the caller"). Dropped the v3 patches that had already been merged and re-applied them to the mm-new branch. - Only Patch 4 is updated to address review comments, all other patches remain unchanged from v3.
---
v2: https://lore.kernel.org/all/20250703060656.54345-1-aboorvad@linux.ibm.com/
Changes in v3:
- Rebased onto the latest mm-new branch, top commit of the base is commit 0709ddf8951f ("mm: add zblock allocator"). - Minor refactor based on the review comments. - Included the tags from the previous version.
---
v1: https://lore.kernel.org/all/20250616160632.35250-1-aboorvad@linux.ibm.com/
Changes in v2:
- Rebased onto the mm-new branch, top commit of the base is commit 3b4a8ad89f7e ("mm: add zblock allocator"). - Split some patches for clarity. - Updated virtual_address_range test to support testing 4PB VA on PPC64. - Added proper Fixes: tags. - Included a patch to skip a failing userfaultfd test when unsupported, instead of reporting a failure.
---
Please let us know if you have any further comments.
Thanks, Aboorva
Aboorva Devarajan (3): selftests/mm: fix child process exit codes in ksm_functional_tests selftests/mm: skip thuge-gen test if system is not setup properly selftests/mm: skip hugepage-mremap test if userfaultfd unavailable
Donet Tom (4): mm/selftests: Fix incorrect pointer being passed to mark_range() selftests/mm: Add support to test 4PB VA on PPC64 selftest/mm: Fix ksm_funtional_test failures mm/selftests: Fix split_huge_page_test failure on systems with 64KB page size
tools/testing/selftests/mm/cow.c | 5 ---- tools/testing/selftests/mm/hugepage-mremap.c | 16 +++++++++-- .../selftests/mm/ksm_functional_tests.c | 28 +++++++++++++------ .../selftests/mm/split_huge_page_test.c | 22 +++++++++------ tools/testing/selftests/mm/thuge-gen.c | 11 +++++--- tools/testing/selftests/mm/uffd-wp-mremap.c | 5 ---- .../selftests/mm/virtual_address_range.c | 13 ++++++++- tools/testing/selftests/mm/vm_util.h | 5 ++++ 8 files changed, 71 insertions(+), 34 deletions(-)
From: Donet Tom donettom@linux.ibm.com
In main(), the high address is stored in hptr, but for mark_range(), the address passed is ptr, not hptr. Fixed this by changing ptr[i] to hptr[i] in mark_range() function call.
Fixes: b2a79f62133a ("selftests/mm: virtual_address_range: unmap chunks after validation") Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Acked-by: David Hildenbrand david@redhat.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Donet Tom donettom@linux.ibm.com --- tools/testing/selftests/mm/virtual_address_range.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index 3c21d136962c..e7ef6759baa1 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -227,7 +227,7 @@ int main(void) if (hptr[i] == MAP_FAILED) break;
- mark_range(ptr[i], MAP_CHUNK_SIZE); + mark_range(hptr[i], MAP_CHUNK_SIZE); validate_addr(hptr[i], 1); } hchunks = i;
On Sat, Aug 16, 2025 at 09:31:07AM +0530, Aboorva Devarajan wrote:
From: Donet Tom donettom@linux.ibm.com
In main(), the high address is stored in hptr, but for mark_range(), the address passed is ptr, not hptr. Fixed this by changing ptr[i] to hptr[i] in mark_range() function call.
Fixes: b2a79f62133a ("selftests/mm: virtual_address_range: unmap chunks after validation") Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Acked-by: David Hildenbrand david@redhat.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Donet Tom donettom@linux.ibm.com
Reviewed-by: Wei Yang richard.weiyang@gmail.com
From: Donet Tom donettom@linux.ibm.com
PowerPC64 supports a 4PB virtual address space, but this test was previously limited to 512TB. This patch extends the coverage up to the full 4PB VA range on PowerPC64.
Memory from 0 to 128TB is allocated without an address hint, while allocations from 128TB to 4PB use a hint address.
Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Acked-by: David Hildenbrand david@redhat.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Donet Tom donettom@linux.ibm.com --- tools/testing/selftests/mm/virtual_address_range.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index e7ef6759baa1..1de62f6cadc7 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -44,12 +44,18 @@ * On Arm64 the address space is 256TB and support for * high mappings up to 4PB virtual address space has * been added. + * + * On PowerPC64, the address space up to 128TB can be + * mapped without a hint. Addresses beyond 128TB, up to + * 4PB, can be mapped with a hint. + * */
#define NR_CHUNKS_128TB ((128 * SZ_1TB) / MAP_CHUNK_SIZE) /* Number of chunks for 128TB */ #define NR_CHUNKS_256TB (NR_CHUNKS_128TB * 2UL) #define NR_CHUNKS_384TB (NR_CHUNKS_128TB * 3UL) #define NR_CHUNKS_3840TB (NR_CHUNKS_128TB * 30UL) +#define NR_CHUNKS_3968TB (NR_CHUNKS_128TB * 31UL)
#define ADDR_MARK_128TB (1UL << 47) /* First address beyond 128TB */ #define ADDR_MARK_256TB (1UL << 48) /* First address beyond 256TB */ @@ -59,6 +65,11 @@ #define HIGH_ADDR_SHIFT 49 #define NR_CHUNKS_LOW NR_CHUNKS_256TB #define NR_CHUNKS_HIGH NR_CHUNKS_3840TB +#elif defined(__PPC64__) +#define HIGH_ADDR_MARK ADDR_MARK_128TB +#define HIGH_ADDR_SHIFT 48 +#define NR_CHUNKS_LOW NR_CHUNKS_128TB +#define NR_CHUNKS_HIGH NR_CHUNKS_3968TB #else #define HIGH_ADDR_MARK ADDR_MARK_128TB #define HIGH_ADDR_SHIFT 48
On Sat, Aug 16, 2025 at 09:31:08AM +0530, Aboorva Devarajan wrote:
From: Donet Tom donettom@linux.ibm.com
PowerPC64 supports a 4PB virtual address space, but this test was previously limited to 512TB. This patch extends the coverage up to the full 4PB VA range on PowerPC64.
Memory from 0 to 128TB is allocated without an address hint, while allocations from 128TB to 4PB use a hint address.
Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Acked-by: David Hildenbrand david@redhat.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Donet Tom donettom@linux.ibm.com
Reviewed-by: Wei Yang richard.weiyang@gmail.com
From: Donet Tom donettom@linux.ibm.com
This patch fixed 2 issues.
1) After fork() in test_prctl_fork, the child process uses the file descriptors from the parent process to read ksm_stat and ksm_merging_pages. This results in incorrect values being read (parent process ksm_stat and ksm_merging_pages will be read in child), causing the test to fail.
This patch calls init_global_file_handles() in the child process to ensure that the current process's file descriptors are used to read ksm_stat and ksm_merging_pages.
2) All tests currently call ksm_merge to trigger page merging. To ensure the system remains in a consistent state for subsequent tests, it is better to call ksm_unmerge during the test cleanup phase
In the test_prctl_fork test, after a fork(), reading ksm_merging_pages in the child process returns a non-zero value because a previous test performed a merge, and the child's memory state is inherited from the parent.
Although the child process calls ksm_unmerge, the ksm_merging_pages counter in the parent is reset to zero, while the child's counter remains unchanged. This discrepancy causes the test to fail.
To avoid this issue, each test should call ksm_unmerge during cleanup to ensure the counter is reset and the system is in a clean state for subsequent tests.
execv argument is an array of pointers to null-terminated strings. In this patch we also added NULL in the execv argument.
Fixes: 6c47de3be3a0 ("selftest/mm: ksm_functional_tests: extend test case for ksm fork/exec") Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com --- tools/testing/selftests/mm/ksm_functional_tests.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c index d8bd1911dfc0..996dc6645570 100644 --- a/tools/testing/selftests/mm/ksm_functional_tests.c +++ b/tools/testing/selftests/mm/ksm_functional_tests.c @@ -46,6 +46,8 @@ static int ksm_use_zero_pages_fd; static int pagemap_fd; static size_t pagesize;
+static void init_global_file_handles(void); + static bool range_maps_duplicates(char *addr, unsigned long size) { unsigned long offs_a, offs_b, pfn_a, pfn_b; @@ -274,6 +276,7 @@ static void test_unmerge(void) ksft_test_result(!range_maps_duplicates(map, size), "Pages were unmerged\n"); unmap: + ksm_unmerge(); munmap(map, size); }
@@ -338,6 +341,7 @@ static void test_unmerge_zero_pages(void) ksft_test_result(!range_maps_duplicates(map, size), "KSM zero pages were unmerged\n"); unmap: + ksm_unmerge(); munmap(map, size); }
@@ -366,6 +370,7 @@ static void test_unmerge_discarded(void) ksft_test_result(!range_maps_duplicates(map, size), "Pages were unmerged\n"); unmap: + ksm_unmerge(); munmap(map, size); }
@@ -452,6 +457,7 @@ static void test_unmerge_uffd_wp(void) close_uffd: close(uffd); unmap: + ksm_unmerge(); munmap(map, size); } #endif @@ -515,6 +521,7 @@ static int test_child_ksm(void) else if (map == MAP_MERGE_SKIP) return -3;
+ ksm_unmerge(); munmap(map, size); return 0; } @@ -548,6 +555,7 @@ static void test_prctl_fork(void)
child_pid = fork(); if (!child_pid) { + init_global_file_handles(); exit(test_child_ksm()); } else if (child_pid < 0) { ksft_test_result_fail("fork() failed\n"); @@ -595,7 +603,7 @@ static void test_prctl_fork_exec(void) return; } else if (child_pid == 0) { char *prg_name = "./ksm_functional_tests"; - char *argv_for_program[] = { prg_name, FORK_EXEC_CHILD_PRG_NAME }; + char *argv_for_program[] = { prg_name, FORK_EXEC_CHILD_PRG_NAME, NULL };
execv(prg_name, argv_for_program); return; @@ -644,6 +652,7 @@ static void test_prctl_unmerge(void) ksft_test_result(!range_maps_duplicates(map, size), "Pages were unmerged\n"); unmap: + ksm_unmerge(); munmap(map, size); }
@@ -677,6 +686,7 @@ static void test_prot_none(void) ksft_test_result(!range_maps_duplicates(map, size), "Pages were unmerged\n"); unmap: + ksm_unmerge(); munmap(map, size); }
On Sat, Aug 16, 2025 at 09:31:09AM +0530, Aboorva Devarajan wrote:
From: Donet Tom donettom@linux.ibm.com
This patch fixed 2 issues.
- After fork() in test_prctl_fork, the child process uses the file
descriptors from the parent process to read ksm_stat and ksm_merging_pages. This results in incorrect values being read (parent process ksm_stat and ksm_merging_pages will be read in child), causing the test to fail.
This patch calls init_global_file_handles() in the child process to ensure that the current process's file descriptors are used to read ksm_stat and ksm_merging_pages.
- All tests currently call ksm_merge to trigger page merging.
To ensure the system remains in a consistent state for subsequent tests, it is better to call ksm_unmerge during the test cleanup phase
In the test_prctl_fork test, after a fork(), reading ksm_merging_pages in the child process returns a non-zero value because a previous test performed a merge, and the child's memory state is inherited from the parent.
Although the child process calls ksm_unmerge, the ksm_merging_pages counter in the parent is reset to zero, while the child's counter remains unchanged. This discrepancy causes the test to fail.
To avoid this issue, each test should call ksm_unmerge during cleanup to ensure the counter is reset and the system is in a clean state for subsequent tests.
execv argument is an array of pointers to null-terminated strings. In this patch we also added NULL in the execv argument.
Fixes: 6c47de3be3a0 ("selftest/mm: ksm_functional_tests: extend test case for ksm fork/exec") Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com
Reviewed-by: Wei Yang richard.weiyang@gmail.com
From: Donet Tom donettom@linux.ibm.com
The split_huge_page_test fails on systems with a 64KB base page size. This is because the order of a 2MB huge page is different:
On 64KB systems, the order is 5.
On 4KB systems, it's 9.
The test currently assumes a maximum huge page order of 9, which is only valid for 4KB base page systems. On systems with 64KB pages, attempting to split huge pages beyond their actual order (5) causes the test to fail.
In this patch, we calculate the huge page order based on the system's base page size. With this change, the tests now run successfully on both 64KB and 4KB page size systems.
Fixes: fa6c02315f745 ("mm: huge_memory: a new debugfs interface for splitting THP tests") Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Donet Tom donettom@linux.ibm.com --- tools/testing/selftests/mm/cow.c | 5 ----- .../selftests/mm/split_huge_page_test.c | 22 ++++++++++++------- tools/testing/selftests/mm/uffd-wp-mremap.c | 5 ----- tools/testing/selftests/mm/vm_util.h | 5 +++++ 4 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index 90ee5779662f..e742d9313798 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -41,11 +41,6 @@ static size_t hugetlbsizes[10]; static int gup_fd; static bool has_huge_zeropage;
-static int sz2ord(size_t size) -{ - return __builtin_ctzll(size / pagesize); -} - static int detect_thp_sizes(size_t sizes[], int max) { int count = 0; diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index eadbeb820d71..7cbeaebc9d71 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -523,6 +523,9 @@ int main(int argc, char **argv) const char *fs_loc; bool created_tmp; int offset; + unsigned int max_order; + unsigned int nr_pages; + unsigned int tests;
ksft_print_header();
@@ -534,35 +537,38 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1];
- ksft_set_plan(1+8+1+9+9+8*4+2); - pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; pmd_pagesize = read_pmd_pagesize(); if (!pmd_pagesize) ksft_exit_fail_msg("Reading PMD pagesize failed\n");
+ nr_pages = pmd_pagesize / pagesize; + max_order = sz2ord(pmd_pagesize); + tests = 2 + (max_order - 1) + (2 * max_order) + (max_order - 1) * 4 + 2; + ksft_set_plan(tests); + fd_size = 2 * pmd_pagesize;
split_pmd_zero_pages();
- for (i = 0; i < 9; i++) + for (i = 0; i < max_order; i++) if (i != 1) split_pmd_thp_to_order(i);
split_pte_mapped_thp(); - for (i = 0; i < 9; i++) + for (i = 0; i < max_order; i++) split_file_backed_thp(i);
created_tmp = prepare_thp_fs(optional_xfs_path, fs_loc_template, &fs_loc); - for (i = 8; i >= 0; i--) + for (i = max_order - 1; i >= 0; i--) split_thp_in_pagecache_to_order_at(fd_size, fs_loc, i, -1);
- for (i = 0; i < 9; i++) + for (i = 0; i < max_order; i++) for (offset = 0; - offset < pmd_pagesize / pagesize; - offset += MAX(pmd_pagesize / pagesize / 4, 1 << i)) + offset < nr_pages; + offset += MAX(nr_pages / 4, 1 << i)) split_thp_in_pagecache_to_order_at(fd_size, fs_loc, i, offset); cleanup_thp_fs(fs_loc, created_tmp);
diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c index 13ceb5628970..7140b2f9c452 100644 --- a/tools/testing/selftests/mm/uffd-wp-mremap.c +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c @@ -19,11 +19,6 @@ static size_t thpsizes[20]; static int nr_hugetlbsizes; static size_t hugetlbsizes[10];
-static int sz2ord(size_t size) -{ - return __builtin_ctzll(size / pagesize); -} - static int detect_thp_sizes(size_t sizes[], int max) { int count = 0; diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 1843ad48d32b..85f7dae9a0c1 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -127,6 +127,11 @@ static inline void log_test_result(int result) ksft_test_result_report(result, "%s\n", test_name); }
+static inline int sz2ord(size_t size) +{ + return __builtin_ctzll(size / getpagesize()); +} + void *sys_mremap(void *old_address, unsigned long old_size, unsigned long new_size, int flags, void *new_address);
On Sat, Aug 16, 2025 at 09:31:10AM +0530, Aboorva Devarajan wrote:
From: Donet Tom donettom@linux.ibm.com
The split_huge_page_test fails on systems with a 64KB base page size. This is because the order of a 2MB huge page is different:
On 64KB systems, the order is 5.
On 4KB systems, it's 9.
The test currently assumes a maximum huge page order of 9, which is only valid for 4KB base page systems. On systems with 64KB pages, attempting to split huge pages beyond their actual order (5) causes the test to fail.
In this patch, we calculate the huge page order based on the system's base page size. With this change, the tests now run successfully on both 64KB and 4KB page size systems.
Fixes: fa6c02315f745 ("mm: huge_memory: a new debugfs interface for splitting THP tests") Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Donet Tom donettom@linux.ibm.com
Reviewed-by: Wei Yang richard.weiyang@gmail.com
Nit below:
tools/testing/selftests/mm/cow.c | 5 ----- .../selftests/mm/split_huge_page_test.c | 22 ++++++++++++------- tools/testing/selftests/mm/uffd-wp-mremap.c | 5 ----- tools/testing/selftests/mm/vm_util.h | 5 +++++ 4 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index 90ee5779662f..e742d9313798 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -41,11 +41,6 @@ static size_t hugetlbsizes[10]; static int gup_fd; static bool has_huge_zeropage;
-static int sz2ord(size_t size) -{
- return __builtin_ctzll(size / pagesize);
-}
static int detect_thp_sizes(size_t sizes[], int max) { int count = 0; diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index eadbeb820d71..7cbeaebc9d71 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -523,6 +523,9 @@ int main(int argc, char **argv) const char *fs_loc; bool created_tmp; int offset;
unsigned int max_order;
unsigned int nr_pages;
unsigned int tests;
ksft_print_header();
@@ -534,35 +537,38 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1];
- ksft_set_plan(1+8+1+9+9+8*4+2);
- pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; pmd_pagesize = read_pmd_pagesize(); if (!pmd_pagesize) ksft_exit_fail_msg("Reading PMD pagesize failed\n");
- nr_pages = pmd_pagesize / pagesize;
- max_order = sz2ord(pmd_pagesize);
^ extra space here
tests = 2 + (max_order - 1) + (2 * max_order) + (max_order - 1) * 4 + 2;
ksft_set_plan(tests);
fd_size = 2 * pmd_pagesize;
split_pmd_zero_pages();
On Sat, 2025-08-16 at 14:31 +0000, Wei Yang wrote:
On Sat, Aug 16, 2025 at 09:31:10AM +0530, Aboorva Devarajan wrote:
From: Donet Tom donettom@linux.ibm.com
The split_huge_page_test fails on systems with a 64KB base page size. This is because the order of a 2MB huge page is different:
On 64KB systems, the order is 5.
On 4KB systems, it's 9.
The test currently assumes a maximum huge page order of 9, which is only valid for 4KB base page systems. On systems with 64KB pages, attempting to split huge pages beyond their actual order (5) causes the test to fail.
In this patch, we calculate the huge page order based on the system's base page size. With this change, the tests now run successfully on both 64KB and 4KB page size systems.
Fixes: fa6c02315f745 ("mm: huge_memory: a new debugfs interface for splitting THP tests") Co-developed-by: Aboorva Devarajan aboorvad@linux.ibm.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Donet Tom donettom@linux.ibm.com
Reviewed-by: Wei Yang richard.weiyang@gmail.com
Nit below:
tools/testing/selftests/mm/cow.c | 5 ----- .../selftests/mm/split_huge_page_test.c | 22 ++++++++++++----
tools/testing/selftests/mm/uffd-wp-mremap.c | 5 ----- tools/testing/selftests/mm/vm_util.h | 5 +++++ 4 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index 90ee5779662f..e742d9313798 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -41,11 +41,6 @@ static size_t hugetlbsizes[10]; static int gup_fd; static bool has_huge_zeropage;
-static int sz2ord(size_t size) -{
- return __builtin_ctzll(size / pagesize);
-}
static int detect_thp_sizes(size_t sizes[], int max) { int count = 0; diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index eadbeb820d71..7cbeaebc9d71 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -523,6 +523,9 @@ int main(int argc, char **argv) const char *fs_loc; bool created_tmp; int offset;
unsigned int max_order;
unsigned int nr_pages;
unsigned int tests;
ksft_print_header();
@@ -534,35 +537,38 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1];
- ksft_set_plan(1+8+1+9+9+8*4+2);
- pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; pmd_pagesize = read_pmd_pagesize(); if (!pmd_pagesize) ksft_exit_fail_msg("Reading PMD pagesize
failed\n");
- nr_pages = pmd_pagesize / pagesize;
- max_order = sz2ord(pmd_pagesize);
^ extra space here
Hi Wei,
Thanks for the review. I’ve sent a fixup patch for this: https://lore.kernel.org/all/20250819041239.167537-1-aboorvad@linux.ibm.com/
Andrew,
Could you please apply the above fixup patch?
Regards, Aboorva
- tests = 2 + (max_order - 1) + (2 * max_order) + (max_order
- 4 + 2;
ksft_set_plan(tests);
fd_size = 2 * pmd_pagesize;
split_pmd_zero_pages();
Removed an extra space in split_huge_page_test that was introduced by commit 4b76e221794b ("mm/selftests: fix split_huge_page_test failure on systems with 64KB page size").
Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com --- tools/testing/selftests/mm/split_huge_page_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 54e86f00aabc..faf7e1f88743 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -544,7 +544,7 @@ int main(int argc, char **argv) ksft_exit_fail_msg("Reading PMD pagesize failed\n");
nr_pages = pmd_pagesize / pagesize; - max_order = sz2ord(pmd_pagesize, pagesize); + max_order = sz2ord(pmd_pagesize, pagesize); tests = 2 + (max_order - 1) + (2 * max_order) + (max_order - 1) * 4 + 2; ksft_set_plan(tests);
On 19.08.25 06:12, Aboorva Devarajan wrote:
Removed an extra space in split_huge_page_test that was introduced by commit 4b76e221794b ("mm/selftests: fix split_huge_page_test failure on systems with 64KB page size").
Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com
tools/testing/selftests/mm/split_huge_page_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 54e86f00aabc..faf7e1f88743 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -544,7 +544,7 @@ int main(int argc, char **argv) ksft_exit_fail_msg("Reading PMD pagesize failed\n"); nr_pages = pmd_pagesize / pagesize;
- max_order = sz2ord(pmd_pagesize, pagesize);
- max_order = sz2ord(pmd_pagesize, pagesize); tests = 2 + (max_order - 1) + (2 * max_order) + (max_order - 1) * 4 + 2; ksft_set_plan(tests);
Please just comment next time one the respective patch as review comment.
On 19.08.25 09:25, David Hildenbrand wrote:
On 19.08.25 06:12, Aboorva Devarajan wrote:
Removed an extra space in split_huge_page_test that was introduced by commit 4b76e221794b ("mm/selftests: fix split_huge_page_test failure on systems with 64KB page size").
Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com
tools/testing/selftests/mm/split_huge_page_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 54e86f00aabc..faf7e1f88743 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -544,7 +544,7 @@ int main(int argc, char **argv) ksft_exit_fail_msg("Reading PMD pagesize failed\n"); nr_pages = pmd_pagesize / pagesize;
- max_order = sz2ord(pmd_pagesize, pagesize);
- max_order = sz2ord(pmd_pagesize, pagesize); tests = 2 + (max_order - 1) + (2 * max_order) + (max_order - 1) * 4 + 2; ksft_set_plan(tests);
Please just comment next time one the respective patch as review comment.
To clarify what I mean is something like this:
https://lkml.kernel.org/r/3dca2de4-9a6a-4efe-a86c-83f9509831fc@gmail.com
Gives more context when the subject directly highlights to which patch you are replying.
On Tue, 2025-08-19 at 09:28 +0200, David Hildenbrand wrote:
On 19.08.25 09:25, David Hildenbrand wrote:
On 19.08.25 06:12, Aboorva Devarajan wrote:
Removed an extra space in split_huge_page_test that was introduced by commit 4b76e221794b ("mm/selftests: fix split_huge_page_test failure on systems with 64KB page size").
Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com
tools/testing/selftests/mm/split_huge_page_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 54e86f00aabc..faf7e1f88743 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -544,7 +544,7 @@ int main(int argc, char **argv) ksft_exit_fail_msg("Reading PMD pagesize failed\n"); nr_pages = pmd_pagesize / pagesize;
- max_order = sz2ord(pmd_pagesize, pagesize);
- max_order = sz2ord(pmd_pagesize, pagesize);
tests = 2 + (max_order - 1) + (2 * max_order) + (max_order - 1) * 4 + 2; ksft_set_plan(tests);
Please just comment next time one the respective patch as review comment.
To clarify what I mean is something like this:
https://lkml.kernel.org/r/3dca2de4-9a6a-4efe-a86c-83f9509831fc@gmail.com
Gives more context when the subject directly highlights to which patch you are replying.
Hi David,
Thanks for pointing this out. I’ll make sure to follow this.
Regards, Aboorva
In ksm_functional_tests, test_child_ksm() returned negative values to indicate errors. However, when passed to exit(), these were interpreted as large unsigned values (e.g, -2 became 254), leading to incorrect handling in the parent process. As a result, some tests appeared to be skipped or silently failed.
This patch changes test_child_ksm() to return positive error codes (1, 2, 3) and updates test_child_ksm_err() to interpret them correctly. Additionally, test_prctl_fork_exec() now uses exit(4) after a failed execv() to clearly signal exec failures. This ensures the parent accurately detects and reports child process failures.
-------------- Before patch: -------------- - [RUN] test_unmerge ok 1 Pages were unmerged ... - [RUN] test_prctl_fork - No pages got merged - [RUN] test_prctl_fork_exec ok 7 PR_SET_MEMORY_MERGE value is inherited ... Bail out! 1 out of 8 tests failed - Planned tests != run tests (9 != 8) - Totals: pass:7 fail:1 xfail:0 xpass:0 skip:0 error:0
-------------- After patch: -------------- - [RUN] test_unmerge ok 1 Pages were unmerged ... - [RUN] test_prctl_fork - No pages got merged not ok 7 Merge in child failed - [RUN] test_prctl_fork_exec ok 8 PR_SET_MEMORY_MERGE value is inherited ... Bail out! 2 out of 9 tests failed - Totals: pass:7 fail:2 xfail:0 xpass:0 skip:0 error:0
Fixes: 6c47de3be3a0 ("selftest/mm: ksm_functional_tests: extend test case for ksm fork/exec") Co-developed-by: Donet Tom donettom@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com Acked-by: David Hildenbrand david@redhat.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com --- .../testing/selftests/mm/ksm_functional_tests.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c index 996dc6645570..534aa405cac7 100644 --- a/tools/testing/selftests/mm/ksm_functional_tests.c +++ b/tools/testing/selftests/mm/ksm_functional_tests.c @@ -512,14 +512,14 @@ static int test_child_ksm(void)
/* Test if KSM is enabled for the process. */ if (prctl(PR_GET_MEMORY_MERGE, 0, 0, 0, 0) != 1) - return -1; + return 1;
/* Test if merge could really happen. */ map = __mmap_and_merge_range(0xcf, size, PROT_READ | PROT_WRITE, KSM_MERGE_NONE); if (map == MAP_MERGE_FAIL) - return -2; + return 2; else if (map == MAP_MERGE_SKIP) - return -3; + return 3;
ksm_unmerge(); munmap(map, size); @@ -528,12 +528,14 @@ static int test_child_ksm(void)
static void test_child_ksm_err(int status) { - if (status == -1) + if (status == 1) ksft_test_result_fail("unexpected PR_GET_MEMORY_MERGE result in child\n"); - else if (status == -2) + else if (status == 2) ksft_test_result_fail("Merge in child failed\n"); - else if (status == -3) + else if (status == 3) ksft_test_result_skip("Merge in child skipped\n"); + else if (status == 4) + ksft_test_result_fail("Binary not found\n"); }
/* Verify that prctl ksm flag is inherited. */ @@ -606,7 +608,7 @@ static void test_prctl_fork_exec(void) char *argv_for_program[] = { prg_name, FORK_EXEC_CHILD_PRG_NAME, NULL };
execv(prg_name, argv_for_program); - return; + exit(4); }
if (waitpid(child_pid, &status, 0) > 0) {
On Sat, Aug 16, 2025 at 09:31:11AM +0530, Aboorva Devarajan wrote:
In ksm_functional_tests, test_child_ksm() returned negative values to indicate errors. However, when passed to exit(), these were interpreted as large unsigned values (e.g, -2 became 254), leading to incorrect handling in the parent process. As a result, some tests appeared to be skipped or silently failed.
This is because "the least significant 8 bits" is returned to parent, right?
This patch changes test_child_ksm() to return positive error codes (1, 2, 3) and updates test_child_ksm_err() to interpret them correctly. Additionally, test_prctl_fork_exec() now uses exit(4) after a failed execv() to clearly signal exec failures. This ensures the parent accurately detects and reports child process failures.
Before patch:
- [RUN] test_unmerge
ok 1 Pages were unmerged ...
- [RUN] test_prctl_fork
- No pages got merged
- [RUN] test_prctl_fork_exec
ok 7 PR_SET_MEMORY_MERGE value is inherited ... Bail out! 1 out of 8 tests failed
- Planned tests != run tests (9 != 8)
- Totals: pass:7 fail:1 xfail:0 xpass:0 skip:0 error:0
After patch:
- [RUN] test_unmerge
ok 1 Pages were unmerged ...
- [RUN] test_prctl_fork
- No pages got merged
not ok 7 Merge in child failed
- [RUN] test_prctl_fork_exec
ok 8 PR_SET_MEMORY_MERGE value is inherited ... Bail out! 2 out of 9 tests failed
- Totals: pass:7 fail:2 xfail:0 xpass:0 skip:0 error:0
Fixes: 6c47de3be3a0 ("selftest/mm: ksm_functional_tests: extend test case for ksm fork/exec") Co-developed-by: Donet Tom donettom@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com Acked-by: David Hildenbrand david@redhat.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com
If so:
Reviewed-by: Wei Yang richard.weiyang@gmail.com
Thanks, I am afraid to make the same mistake if you don't point out.
On Sat, 2025-08-16 at 14:43 +0000, Wei Yang wrote:
Hi Wei,
On Sat, Aug 16, 2025 at 09:31:11AM +0530, Aboorva Devarajan wrote:
In ksm_functional_tests, test_child_ksm() returned negative values to indicate errors. However, when passed to exit(), these were interpreted as large unsigned values (e.g, -2 became 254), leading to incorrect handling in the parent process. As a result, some tests appeared to be skipped or silently failed.
This is because "the least significant 8 bits" is returned to parent, right?
Yes, that's right. As per the WEXITSTATUS(wstatus) manual:
WEXITSTATUS: returns the exit status of the child. This consists of the least significant 8 bits of the status argument that the child specified in a call to exit(3) or _exit(2) or as the argument for a return statement in main(). This macro should only be employed if WIFEXITED returned true.
Since only the least significant 8 bits are preserved, negative return values can appear as large unsigned codes, so using small positive exit codes ensures the parent interprets the error code correctly.
This patch changes test_child_ksm() to return positive error codes (1, 2, 3) and updates test_child_ksm_err() to interpret them correctly. Additionally, test_prctl_fork_exec() now uses exit(4) after a failed execv() to clearly signal exec failures. This ensures the parent accurately detects and reports child process failures.
Before patch:
- [RUN] test_unmerge
ok 1 Pages were unmerged ...
- [RUN] test_prctl_fork
- No pages got merged
- [RUN] test_prctl_fork_exec
ok 7 PR_SET_MEMORY_MERGE value is inherited ... Bail out! 1 out of 8 tests failed
- Planned tests != run tests (9 != 8)
- Totals: pass:7 fail:1 xfail:0 xpass:0 skip:0 error:0
After patch:
- [RUN] test_unmerge
ok 1 Pages were unmerged ...
- [RUN] test_prctl_fork
- No pages got merged
not ok 7 Merge in child failed
- [RUN] test_prctl_fork_exec
ok 8 PR_SET_MEMORY_MERGE value is inherited ... Bail out! 2 out of 9 tests failed
- Totals: pass:7 fail:2 xfail:0 xpass:0 skip:0 error:0
Fixes: 6c47de3be3a0 ("selftest/mm: ksm_functional_tests: extend test case for ksm fork/exec") Co-developed-by: Donet Tom donettom@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com Acked-by: David Hildenbrand david@redhat.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com
If so:
Reviewed-by: Wei Yang richard.weiyang@gmail.com
Thanks, I am afraid to make the same mistake if you don't point out.
Thanks, Aboorva
Make thuge-gen skip instead of fail when it can't run due to system settings. If shmmax is too small or no 1G huge pages are available, the test now prints a warning and is marked as skipped.
------------------- Before Patch: ------------------- ~ running ./thuge-gen ~ Bail out! Please do echo 262144 > /proc/sys/kernel/shmmax ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 ~ [FAIL] not ok 28 thuge-gen ~ exit=1
------------------- After Patch: ------------------- ~ running ./thuge-gen ~ ~ WARNING: shmmax is too small to run this test. ~ ~ Please run the following command to increase shmmax: ~ ~ echo 262144 > /proc/sys/kernel/shmmax ~ 1..0 ~ SKIP Test skipped due to insufficient shmmax value. ~ [SKIP] ok 29 thuge-gen ~ SKIP
Co-developed-by: Donet Tom donettom@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Acked-by: David Hildenbrand david@redhat.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com --- tools/testing/selftests/mm/thuge-gen.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c index 8e2b08dc5762..4f5e290ff1a6 100644 --- a/tools/testing/selftests/mm/thuge-gen.c +++ b/tools/testing/selftests/mm/thuge-gen.c @@ -177,13 +177,16 @@ void find_pagesizes(void) globfree(&g);
read_sysfs("/proc/sys/kernel/shmmax", &shmmax_val); - if (shmmax_val < NUM_PAGES * largest) - ksft_exit_fail_msg("Please do echo %lu > /proc/sys/kernel/shmmax", - largest * NUM_PAGES); + if (shmmax_val < NUM_PAGES * largest) { + ksft_print_msg("WARNING: shmmax is too small to run this test.\n"); + ksft_print_msg("Please run the following command to increase shmmax:\n"); + ksft_print_msg("echo %lu > /proc/sys/kernel/shmmax\n", largest * NUM_PAGES); + ksft_exit_skip("Test skipped due to insufficient shmmax value.\n"); + }
#if defined(__x86_64__) if (largest != 1U<<30) { - ksft_exit_fail_msg("No GB pages available on x86-64\n" + ksft_exit_skip("No GB pages available on x86-64\n" "Please boot with hugepagesz=1G hugepages=%d\n", NUM_PAGES); } #endif
On Sat, Aug 16, 2025 at 09:31:12AM +0530, Aboorva Devarajan wrote:
Make thuge-gen skip instead of fail when it can't run due to system settings. If shmmax is too small or no 1G huge pages are available, the test now prints a warning and is marked as skipped.
Before Patch:
~ running ./thuge-gen ~ Bail out! Please do echo 262144 > /proc/sys/kernel/shmmax ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 ~ [FAIL] not ok 28 thuge-gen ~ exit=1
After Patch:
~ running ./thuge-gen ~ ~ WARNING: shmmax is too small to run this test. ~ ~ Please run the following command to increase shmmax: ~ ~ echo 262144 > /proc/sys/kernel/shmmax ~ 1..0 ~ SKIP Test skipped due to insufficient shmmax value. ~ [SKIP] ok 29 thuge-gen ~ SKIP
Co-developed-by: Donet Tom donettom@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com Reviewed-by: Dev Jain dev.jain@arm.com Acked-by: David Hildenbrand david@redhat.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com
Reviewed-by: Wei Yang richard.weiyang@gmail.com
Gracefully skip test if userfaultfd is not supported (ENOSYS) or not permitted (EPERM), instead of failing. This avoids misleading failures with clear skip messages.
-------------- Before Patch -------------- ~ running ./hugepage-mremap ... ~ Bail out! userfaultfd: Function not implemented ~ Planned tests != run tests (1 != 0) ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 ~ [FAIL] not ok 4 hugepage-mremap # exit=1
-------------- After Patch -------------- ~ running ./hugepage-mremap ... ~ ok 2 # SKIP userfaultfd is not supported/not enabled. ~ 1 skipped test(s) detected. ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 ~ [SKIP] ok 4 hugepage-mremap # SKIP
Co-developed-by: Donet Tom donettom@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com Acked-by: David Hildenbrand david@redhat.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com --- tools/testing/selftests/mm/hugepage-mremap.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/mm/hugepage-mremap.c b/tools/testing/selftests/mm/hugepage-mremap.c index c463d1c09c9b..2bd1dac75c3f 100644 --- a/tools/testing/selftests/mm/hugepage-mremap.c +++ b/tools/testing/selftests/mm/hugepage-mremap.c @@ -65,10 +65,20 @@ static void register_region_with_uffd(char *addr, size_t len) struct uffdio_api uffdio_api;
/* Create and enable userfaultfd object. */ - uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); - if (uffd == -1) - ksft_exit_fail_msg("userfaultfd: %s\n", strerror(errno)); + if (uffd == -1) { + switch (errno) { + case EPERM: + ksft_exit_skip("Insufficient permissions, try running as root.\n"); + break; + case ENOSYS: + ksft_exit_skip("userfaultfd is not supported/not enabled.\n"); + break; + default: + ksft_exit_fail_msg("userfaultfd failed with %s\n", strerror(errno)); + break; + } + }
uffdio_api.api = UFFD_API; uffdio_api.features = 0;
On Sat, Aug 16, 2025 at 09:31:13AM +0530, Aboorva Devarajan wrote:
Gracefully skip test if userfaultfd is not supported (ENOSYS) or not permitted (EPERM), instead of failing. This avoids misleading failures with clear skip messages.
Before Patch
~ running ./hugepage-mremap ... ~ Bail out! userfaultfd: Function not implemented ~ Planned tests != run tests (1 != 0) ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 ~ [FAIL] not ok 4 hugepage-mremap # exit=1
After Patch
~ running ./hugepage-mremap ... ~ ok 2 # SKIP userfaultfd is not supported/not enabled. ~ 1 skipped test(s) detected. ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 ~ [SKIP] ok 4 hugepage-mremap # SKIP
Co-developed-by: Donet Tom donettom@linux.ibm.com Signed-off-by: Donet Tom donettom@linux.ibm.com Acked-by: David Hildenbrand david@redhat.com Reviewed-by: Zi Yan ziy@nvidia.com Signed-off-by: Aboorva Devarajan aboorvad@linux.ibm.com
Reviewed-by: Wei Yang richard.weiyang@gmail.com
linux-kselftest-mirror@lists.linaro.org