* [PATCH] selftests/mm: mremap_test: Validate the preamble region before mapping it
@ 2026-10-14 18:46 Ricardo B. Marlière (SUSE)
2026-10-15 6:14 ` Sarthak Sharma
0 siblings, 1 reply; 2+ messages in thread
From: Ricardo B. Marlière (SUSE) @ 2026-10-14 18:46 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan
Cc: linux-mm, linux-kselftest, linux-kernel, Ricardo B. Marlière (SUSE)
remap_region() checks that the destination region is free before mapping
it, but not the preamble region placed right before it, so mapping the
preamble can intermittently fail with EEXIST:
# Failed to map dest preamble region: File exists
not ok 15 5MB mremap - Source 1MB-aligned, Dest 1MB-aligned with 40MB Preamble
This happens when the kernel's heap ASLR (arch_randomize_brk()) lands the
process heap inside that unchecked range. Confirmed by correlating
brk(NULL) at startup with pass/fail across 60 runs: every failure had brk
land inside that range.
Fix it by including the preamble in the free-region check.
Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
---
Hi, this sporadic issue has been found in openSUSE CI:
https://openqa.opensuse.org/tests/6270334/logfile?filename=serial_terminal.txt#line-6760
---
tools/testing/selftests/mm/mremap_test.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
index 131d9d6db867..8d4fa3025a9d 100644
--- a/tools/testing/selftests/mm/mremap_test.c
+++ b/tools/testing/selftests/mm/mremap_test.c
@@ -1006,8 +1006,10 @@ static long long remap_region(struct config c, unsigned int threshold_mb,
if (!((unsigned long long) addr & c.dest_alignment))
addr = (void *) ((unsigned long long) addr | c.dest_alignment);
- /* Don't destroy existing mappings unless expected to overlap */
- while (!is_remap_region_valid(addr, c.region_size) && !c.overlapping) {
+ /* Don't destroy existing mappings unless expected to overlap. */
+ while (!is_remap_region_valid(addr - c.dest_preamble_size,
+ c.dest_preamble_size + c.region_size) &&
+ !c.overlapping) {
/* Check for unsigned overflow */
tmp_addr = addr + c.dest_alignment;
if (tmp_addr < addr) {
---
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
change-id: 20261014-selftests-mm-mremap_preamble-5f98ad625f93
Best regards,
--
Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/mm: mremap_test: Validate the preamble region before mapping it
2026-10-14 18:46 [PATCH] selftests/mm: mremap_test: Validate the preamble region before mapping it Ricardo B. Marlière (SUSE)
@ 2026-10-15 6:14 ` Sarthak Sharma
0 siblings, 0 replies; 2+ messages in thread
From: Sarthak Sharma @ 2026-10-15 6:14 UTC (permalink / raw)
To: Ricardo B. Marlière (SUSE),
Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan
Cc: linux-mm, linux-kselftest, linux-kernel
On 10/15/26 12:16 AM, Ricardo B. Marlière (SUSE) wrote:
> remap_region() checks that the destination region is free before mapping
> it, but not the preamble region placed right before it, so mapping the
> preamble can intermittently fail with EEXIST:
>
> # Failed to map dest preamble region: File exists
> not ok 15 5MB mremap - Source 1MB-aligned, Dest 1MB-aligned with 40MB Preamble
>
> This happens when the kernel's heap ASLR (arch_randomize_brk()) lands the
> process heap inside that unchecked range. Confirmed by correlating
> brk(NULL) at startup with pass/fail across 60 runs: every failure had brk
> land inside that range.
>
> Fix it by including the preamble in the free-region check.
>
> Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
> ---
Just wondering, should this have a Fixes: tag as well?
Other than that, LGTM.
Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>
> Hi, this sporadic issue has been found in openSUSE CI:
>
> https://openqa.opensuse.org/tests/6270334/logfile?filename=serial_terminal.txt#line-6760
> ---
> tools/testing/selftests/mm/mremap_test.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
> index 131d9d6db867..8d4fa3025a9d 100644
> --- a/tools/testing/selftests/mm/mremap_test.c
> +++ b/tools/testing/selftests/mm/mremap_test.c
> @@ -1006,8 +1006,10 @@ static long long remap_region(struct config c, unsigned int threshold_mb,
> if (!((unsigned long long) addr & c.dest_alignment))
> addr = (void *) ((unsigned long long) addr | c.dest_alignment);
>
> - /* Don't destroy existing mappings unless expected to overlap */
> - while (!is_remap_region_valid(addr, c.region_size) && !c.overlapping) {
> + /* Don't destroy existing mappings unless expected to overlap. */
> + while (!is_remap_region_valid(addr - c.dest_preamble_size,
> + c.dest_preamble_size + c.region_size) &&
> + !c.overlapping) {
> /* Check for unsigned overflow */
> tmp_addr = addr + c.dest_alignment;
> if (tmp_addr < addr) {
>
> ---
> base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
> change-id: 20261014-selftests-mm-mremap_preamble-5f98ad625f93
>
> Best regards,
> --
> Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-15 6:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-14 18:46 [PATCH] selftests/mm: mremap_test: Validate the preamble region before mapping it Ricardo B. Marlière (SUSE)
2026-10-15 6:14 ` Sarthak Sharma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®