Skip to contentSkip to conversation

selftests/mm: hugetlb_madv_vs_map: add underflow test

PATCH Applied Guillaume Morin 5 participants 5 messages Sep 14 – Oct 6

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 selftests/mm: hugetlb_madv_vs_map: add underflow test

Add a test that checks for underflows when a parent unmaps the page first. Also check that when the child exits the reserve count is correct.

---
v5: address Mike and Breno's comments
v4: address Mike's comments
v3: address Mike's comments
v2: refactor tests into 2 functions

 .../testing/selftests/mm/hugepage_settings.c  |   9 ++
 .../testing/selftests/mm/hugepage_settings.h  |   1 +
 .../selftests/mm/hugetlb_madv_vs_map.c        | 141 +++++++++++++++---
 3 files changed, 130 insertions(+), 21 deletions(-)
tools/testing/selftests/mm/hugepage_settings.c +9 -0
index d7917dce3aba..584054736ce9 100644
@@ -449,6 +449,15 @@ unsigned long hugetlb_free_pages(unsigned long size)
 	return read_num(path);
 }
 
+unsigned long hugetlb_nr_resv_pages(unsigned long size)
+{
+	char path[PATH_MAX];
+
+	hugetlb_sysfs_path(path, sizeof(path), size, "resv_hugepages");
+
+	return read_num(path);
+}
+
 static bool __hugetlb_setup(unsigned long size, unsigned long nr)
 {
 	unsigned long free = hugetlb_free_pages(size);
tools/testing/selftests/mm/hugepage_settings.h +1 -0
index 726c73c43c05..548e9d288d1d 100644
@@ -98,6 +98,7 @@ unsigned long default_huge_page_size(void);
 unsigned long hugetlb_nr_pages(unsigned long size);
 void hugetlb_set_nr_pages(unsigned long size, unsigned long nr);
 unsigned long hugetlb_free_pages(unsigned long size);
+unsigned long hugetlb_nr_resv_pages(unsigned long size);
 
 static inline void hugetlb_save_settings(void)
 {
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +120 -21

176 lines not on this page · raw message

Signature · 4 lines
2.39.1

-- 
Guillaume Morin <[email protected]>
#1 lore raw

PATCH 1/1 selftests/mm: hugetlb_madv_vs_map: fix TAP plan mismatches

The plan was raised from 1 to 3, but the HugeTLB setup check that may call ksft_exit_skip() still runs after ksft_set_plan(), so a setup failure reports one result against a plan of 3. Move ksft_set_plan() below the setup check.

Also, when the underflow check fails, or munmap() fails, test_underflow() jumps to err_cleanup and exits without reporting the remaining results. Report the munmap() failure as a test result and skip the final HugePages_Rsvd check in err_cleanup, so the output always contains the planned 3 results.

Fixes 827149aad495 ("selftests/mm: hugetlb_madv_vs_map: add underflow test")
Assisted-by LLM
---
 tools/testing/selftests/mm/hugetlb_madv_vs_map.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +4 -1
index 1d111f42dd59..5dc44ff0a377 100644
@@ -169,6 +169,7 @@ void test_underflow(void)
 	/* First unmap, this will close the vma */
 	if (munmap(huge_ptr, mmap_size) != 0) {
 		ksft_perror("munmap failed");
+		ksft_test_result_fail("munmap failed\n");
 		goto err_cleanup;
 	}
 
@@ -203,18 +204,20 @@ void test_underflow(void)
 	if (waitpid(pid, NULL, 0) <= 0)
 		ksft_exit_fail_perror("waitpid failed");
 
+	ksft_test_result_skip("HugePages_Rsvd check after child exit\n");
 	ksft_exit_fail();
 }
 
 int main(void)
 {
 	ksft_print_header();
-	ksft_set_plan(3);
 
 	if (!hugetlb_setup_default_exact(1))
 		ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
 			       hugetlb_free_default_pages());
 
+	ksft_set_plan(3);
+
 	test_madv_vs_map();
 	test_underflow();
 
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#2 lore raw

Re: [PATCH] selftests/mm: hugetlb_madv_vs_map: fix TAP plan mismatches

Quoted 11 lines · Jaeyeon Lee

The plan was raised from 1 to 3, but the HugeTLB setup check that may call ksft_exit_skip() still runs after ksft_set_plan(), so a setup failure reports one result against a plan of 3. Move ksft_set_plan() below the setup check.

Also, when the underflow check fails, or munmap() fails, test_underflow() jumps to err_cleanup and exits without reporting the remaining results. Report the munmap() failure as a test result and skip the final HugePages_Rsvd check in err_cleanup, so the output always contains the planned 3 results.

Quoted 4 lines
Fixes 827149aad495 ("selftests/mm: hugetlb_madv_vs_map: add underflow test")
Assisted-by LLM

---

Signature · 3 lines
Cheers,

David
#3 lore raw

Re: [PATCH] selftests/mm: hugetlb_madv_vs_map: fix TAP plan mismatches

In reply to Jaeyeon Lee

Hi Jaeyeon!

Quoted 23 lines · Jaeyeon Lee

The plan was raised from 1 to 3, but the HugeTLB setup check that may call ksft_exit_skip() still runs after ksft_set_plan(), so a setup failure reports one result against a plan of 3. Move ksft_set_plan() below the setup check.

Also, when the underflow check fails, or munmap() fails, test_underflow() jumps to err_cleanup and exits without reporting the remaining results. Report the munmap() failure as a test result and skip the final HugePages_Rsvd check in err_cleanup, so the output always contains the planned 3 results.

Fixes 827149aad495 ("selftests/mm: hugetlb_madv_vs_map: add underflow test")
Assisted-by LLM
---
 tools/testing/selftests/mm/hugetlb_madv_vs_map.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +0 -0
index 1d111f42dd59..5dc44ff0a377 100644

tools/testing/selftests/mm/hugetlb_madv_vs_map.c void test_underflow(void) · line 172

Quoted 4 lines
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +1 -0
@@ -169,6 +169,7 @@ void test_underflow(void)
 	/* First unmap, this will close the vma */
 	if (munmap(huge_ptr, mmap_size) != 0) {
 		ksft_perror("munmap failed");
+		ksft_test_result_fail("munmap failed\n");

This is duplicating the "munmap failed" message. Can we simply put a ksft_test_result_fail("munmap failed: %s (%d)\n", strerror(errno), errno) here?

Also, please send your patch in a new thread instead of replying on another thread from next time onwards :)

Quoted 25 lines
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +3 -1
 		goto err_cleanup;
 	}
 
@@ -203,18 +204,20 @@ void test_underflow(void)
 	if (waitpid(pid, NULL, 0) <= 0)
 		ksft_exit_fail_perror("waitpid failed");
 
+	ksft_test_result_skip("HugePages_Rsvd check after child exit\n");
 	ksft_exit_fail();
 }
 
 int main(void)
 {
 	ksft_print_header();
-	ksft_set_plan(3);
 
 	if (!hugetlb_setup_default_exact(1))
 		ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
 			       hugetlb_free_default_pages());
 
+	ksft_set_plan(3);
+
 	test_madv_vs_map();
 	test_underflow();
 
Tested-by on v5 1/1
#4 lore raw
In reply to Guillaume Morin
Quoted 11 lines · Guillaume Morin

Add a test that checks for underflows when a parent unmaps the page first. Also check that when the child exits the reserve count is correct.