[LTP] [PATCH] hugemmap13: use MMAP_GRANULARITY instead of page size

Hongchen Zhang zhanghongchen@loongson.cn
Tue Dec 5 08:37:21 CET 2023


For some architectures like LoongArch, mmap(MAP_FIXED | MAP_SHARED)
has to be aligned to SHMLBA. So use MMAP_GRANULARITY instead of
page size when mmap, otherwise the test will fail.

Suggested-by: Huacai Chen <chenhuacai@kernel.org>
Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
index f8c36640d61d..42b80064ef36 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
@@ -21,6 +21,7 @@
 #include <limits.h>
 #include <sys/param.h>
 #include <sys/types.h>
+#include <lapi/mmap.h>
 
 #include "hugetlb.h"
 
@@ -62,15 +63,15 @@ static void run_test(void)
 	memset(p, 0, hpage_size);
 
 	/* Test just below 4GB to check for off-by-one errors */
-	lowaddr = FOURGB - page_size;
-	q = mmap((void *)lowaddr, page_size, PROT_READ|PROT_WRITE,
+	lowaddr = FOURGB - MMAP_GRANULARITY;
+	q = mmap((void *)lowaddr, MMAP_GRANULARITY, PROT_READ|PROT_WRITE,
 		 MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0);
 	if (q == MAP_FAILED) {
-		below_start = FOURGB - page_size;
+		below_start = FOURGB - MMAP_GRANULARITY;
 		above_end = FOURGB;
 
 		if (range_is_mapped(below_start, above_end) == 1) {
-			tst_res(TINFO|TERRNO, "region (4G-page)-4G is not free & "
+			tst_res(TINFO|TERRNO, "region (4G-MMAP_GRANULARITY)-4G is not free & "
 					"mmap() failed expected");
 			tst_res(TPASS, "Successful but inconclusive");
 		} else
-- 
2.33.0



More information about the ltp mailing list