[LTP] [PATCH] syscalls/munmap04: Stop using MAP_FIXED_NOREPLACE

Cyril Hrubis chrubis@suse.cz
Mon Jul 28 15:39:13 CEST 2025


Hi!
> On some machines, mmap() call might return MAP_FAILED when passed the
> MAP_FIXED_NOREPLACE flag for reasons other than what the test expect: vma
> limit reached. While at it, add a sanity check if no regions were mapped.
> 
> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
> ---
>  testcases/kernel/syscalls/munmap/munmap04.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/munmap/munmap04.c b/testcases/kernel/syscalls/munmap/munmap04.c
> index e046d17a75f8f75c5b11d569c33da41d7adc7d09..f55aa770a99d2facb53234fa593fa3f41a16cb00 100644
> --- a/testcases/kernel/syscalls/munmap/munmap04.c
> +++ b/testcases/kernel/syscalls/munmap/munmap04.c
> @@ -37,8 +37,7 @@ static void setup(void)
>  
>  	while (1) {
>  		void *p = mmap((void *)(base + PAD * vma_size * map_count),
> -			     vma_size, PROT_NONE,
> -			     MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE,
> +			     vma_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,

How do we avoid the adjacent mapping merges without the
MAP_FIXED_NOREPLACE flag? With the flag we force particular addresses
that have padding between then. Without the flag kernel is free to place
the mappings anywhere it wants, e.g. create a big continous mapping in
which case we would effectively have a signle vma in the kernel.



>  			     -1, 0);
>  		if (p == MAP_FAILED)
>  			break;

Sholdn't it be easier to continue; here if errno == EEXIST? that would
mean that we would not map over any mappings that exists in the process
address space and continue retrying with increasing addresses:

	if (p == MAP_FAILED && errno == EEXIST)
		continue;

	if (p == MAP_FAILED)
		break;

	maps[map_count++] = p;

> @@ -46,8 +45,9 @@ static void setup(void)
>  	}
>  
>  	if (map_count == MAP_MAX_COUNT)
> -		tst_brk(TBROK, "Mapped all %d regions, expected less",
> -			map_count);
> +		tst_brk(TBROK, "Mapped all %d regions, expected less", map_count);
> +	if (map_count == 0)
> +		tst_brk(TBROK, "Mapped 0 regions");
>  
>  	tst_res(TINFO, "Mapped %d regions", map_count);
>  }
> 
> ---
> base-commit: 6af619552ce7676171e47b88964ffb5b08499b36
> change-id: 20250728-fixes-munmap04-02083c550c6b
> 
> Best regards,
> -- 
> Ricardo B. Marlière <rbm@suse.com>
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list