Re: [PATCH] selftests/mm: merge: reserve the far mremap() targets
From: Gregory Price (Meta)
Date: Tue Oct 20 2026 - 22:54:52 EST
On 2026-10-20 20:19 -0500, Danish Khateeb wrote:
> The merge tests map their areas at fixed addresses within a 30-page
> PROT_NONE carveout. Several mremap() tests move an area 1000 or 2000
> pages away to separate it from the others, but those targets are outside
> the carveout, and MREMAP_FIXED unmaps whatever is mapped there.
>
> Under virtme-ng, the shared libraries are packed right above the
> carveout and the dynamic linker starts about 4 MiB above it. The moves
> then replace part of its text with an anonymous mapping, and the test
> crashes in its next lazily bound call:
>
> merge[6980]: segfault at 7f7ebb3c1e60 ip 00007f7ebb3c1e60 sp 00007ffd35fbaec8 error 14
>
> Two to four of the mremap() tests then fail with "Test terminated
> unexpectedly by signal 11", depending on the exact layout. On a host
> where libc is mapped at a 2 MiB aligned address, the targets happen to
> land above the dynamic linker and the tests pass.
>
> Make the carveout large enough to contain the targets.
>
> Fixes: 4e25f85b9f85 ("tools/testing/selftests: add mremap() unfaulted/faulted test cases")
> Signed-off-by: Danish Khateeb <danishkhateeb03@xxxxxxxxx>
A better improvement would be to tweak the tests so they don't use
magic numbers like (page_size * 1000) and it matches more statically
to what the mmap'd region size is. Otherwise it'll get copy/pasted
again later.
(e.g. please don't just update the mmap, please update the tests as
well)
~Gregory
--
Gregory Price (Meta) <gourry@xxxxxxxxxx>