[LTP] [PATCH v8] mremap07.c: New test for mremap() with MREMAP_DONTUNMAP

Wei Gao wegao@suse.com
Tue Apr 21 10:20:57 CEST 2026


On Mon, Apr 20, 2026 at 06:12:19PM +0800, Li Wang wrote:
> Hi Wei,
> 
> This is an excellent test design, but still few places need
> refactoring in my opinion.
> 
> Wei Gao via ltp <ltp@lists.linux.it> wrote:
> 
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -46,6 +46,7 @@ AC_CHECK_DECLS([MADV_MERGEABLE],,,[#include <sys/mman.h>])
> >  AC_CHECK_DECLS([NFTA_CHAIN_ID, NFTA_VERDICT_CHAIN_ID],,,[#include <linux/netfilter/nf_tables.h>])
> >  AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ],,,[#include <sys/prctl.h>])
> >  AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
> > +AC_CHECK_DECLS([MREMAP_DONTUNMAP],,,[#include <linux/mman.h>])
> 
> I didn't go through all the previous discussion, but can we define
> MREMAP_DONTUNMAP in the lapi/mmap.h then remove the .min_kver
> and TST_TEST_TCONF?

To handle older kernels without using .min_kver and TST_TEST_TCONF, 
we'd need to implement extra logic. Would it look something like the following?

-	if (new_remap_addr == MAP_FAILED)
+	if (new_remap_addr == MAP_FAILED) {
+		if (errno == EINVAL)
+			tst_brk(TCONF | TERRNO, "mremap() with MREMAP_DONTUNMAP not supported");
+
 		tst_brk(TBROK | TERRNO, "mremap failed");
+	}

Test on old kernel if not using .min_kver/TST_TEST_TCONF?.

susetest:~/ltp/testcases/kernel/syscalls/mremap # uname -r
4.12.14-122.231-default
susetest:~/ltp/testcases/kernel/syscalls/mremap # ./mremap07 
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_tmpdir.c:309: TINFO: Using /tmp/LTP_mreVVHzVk as tmpdir (btrfs filesystem)
tst_test.c:2059: TINFO: LTP version: 20260130-147-g19c9b694c
tst_test.c:2062: TINFO: Tested kernel: 4.12.14-122.231-default #1 SMP Wed Oct 2 17:30:21 UTC 2024 (5f0ddca) x86_64
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:714: TINFO: CONFIG_FAULT_INJECTION kernel option detected which might slow the execution
tst_test.c:1889: TINFO: Overall timeout per run is 0h 02m 00s
mremap07.c:88: TINFO: Original mapping created at 0x7f19f2edb000
mremap07.c:121: TBROK: mremap failed: EINVAL (22)



More information about the ltp mailing list