Skip to contentSkip to conversation

syscalls/munmap04: Increase target map address in case of EEXIST

PATCH Superseded Ricardo B. Marlière via ltp 1 participant 2 messages Jul 31, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/munmap04: Increase target map address in case of EEXIST

From: Ricardo B. Marlière <[email protected]>

While trying to exhaust the amount of VMAs, the test should bump the address for the next try in case of EEXIST. Otherwise, it might timeout in an infinite loop.

Fixes 7f70db39ec45 ("syscalls/munmap04: Check errno while trying to exhaust VMA count")
---
 testcases/kernel/syscalls/munmap/munmap04.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/munmap/munmap04.c +7 -2
index aeb905286e9d4214ac6423ef26e9570674b60530..106f99e27f813130558f5f51707642f22b1892e2 100644
@@ -28,6 +28,8 @@ static void run(void)
 
 static void setup(void)
 {
+	uintptr_t addr = base;
+
 	page_sz = SAFE_SYSCONF(_SC_PAGESIZE);
 	vma_size = MEMSIZE * page_sz;
 
@@ -36,15 +38,18 @@ static void setup(void)
 		maps[i] = NULL;
 
 	while (1) {
-		void *p = mmap((void *)(base + PAD * vma_size * map_count),
+		void *p = mmap((void *) addr,
 			     vma_size, PROT_NONE,
 			     MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE,
 			     -1, 0);
-		if (p == MAP_FAILED && errno == EEXIST)
+		if (p == MAP_FAILED && errno == EEXIST) {
+			addr += PAD * vma_size;
 			continue;
+		}
 		if (p == MAP_FAILED)
 			break;
 		maps[map_count++] = p;
+		addr += PAD * vma_size;
 	}
 
 	if (map_count == MAP_MAX_COUNT)

---
base-commit: 91fa413eb521fde80d57c79bd3d2fb5cbe4ad3f4
change-id: 20250728-fixes-munmap04-02083c550c6b

Best regards,

Signature · 5 lines
Ricardo B. Marlière <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 28 lines · Ricardo B. Marlière via ltp

From: Ricardo B. Marlière <[email protected]>

While trying to exhaust the amount of VMAs, the test should bump the address for the next try in case of EEXIST. Otherwise, it might timeout in an infinite loop.

Fixes 7f70db39ec45 ("syscalls/munmap04: Check errno while trying to exhaust VMA count")
---
  testcases/kernel/syscalls/munmap/munmap04.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/munmap/munmap04.c +2 -0
index aeb905286e9d4214ac6423ef26e9570674b60530..106f99e27f813130558f5f51707642f22b1892e2 100644
@@ -28,6 +28,8 @@ static void run(void)
 
  static void setup(void)
  {
+	uintptr_t addr = base;
+
  	page_sz = SAFE_SYSCONF(_SC_PAGESIZE);
  	vma_size = MEMSIZE * page_sz;
 
@@ -36,15 +38,18 @@ static void setup(void)
  		maps[i] = NULL;
 

testcases/kernel/syscalls/munmap/munmap04.c static void setup(void) · line 47

Quoted 10 lines
testcases/kernel/syscalls/munmap/munmap04.c +3 -2
  	while (1) {
-		void *p = mmap((void *)(base + PAD * vma_size * map_count),
+		void *p = mmap((void *) addr,
  			     vma_size, PROT_NONE,
  			     MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE,
  			     -1, 0);
-		if (p == MAP_FAILED && errno == EEXIST)
+		if (p == MAP_FAILED && errno == EEXIST) {
+			addr += PAD * vma_size;
  			continue;

Here you can do instead:

goto next_addr;

testcases/kernel/syscalls/munmap/munmap04.c static void setup(void) · line 51

Quoted 4 lines
testcases/kernel/syscalls/munmap/munmap04.c +1 -0
+		}
  		if (p == MAP_FAILED)
  			break;
  		maps[map_count++] = p;

And here we add the goto label, so we won't increment addr variable in the same way in two different places:

next_addr:

Quoted 10 lines
testcases/kernel/syscalls/munmap/munmap04.c +1 -1
+		addr += PAD * vma_size;
  	}
 
  	if (map_count == MAP_MAX_COUNT)
 
---

base-commit: 91fa413eb521fde80d57c79bd3d2fb5cbe4ad3f4
change-id: 20250728-fixes-munmap04-02083c550c6b

Best regards,

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp