* + selftests-mm-test-mremap-with-an-old-size-of-0.patch added to mm-new branch
@ 2026-11-06 1:27 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-11-06 1:27 UTC (permalink / raw)
To: mm-commits, vbabka, sarthak.sharma, pfalcato, osalvador,
muchun.song, ljs, liam, jannh, david, azpijr, josef, akpm
The patch titled
Subject: selftests/mm: test mremap() with an old size of 0
has been added to the -mm mm-new branch. Its filename is
selftests-mm-test-mremap-with-an-old-size-of-0.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-test-mremap-with-an-old-size-of-0.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Josef Bacik <josef@toxicpanda.com>
Subject: selftests/mm: test mremap() with an old size of 0
Date: Thu, 05 Nov 2026 14:02:07 +0000
mremap() with an old size of 0 duplicates a shared mapping, and
mremap_test has no case for it.
Duplicate a shared anonymous mapping, once from its start and once from
the middle. Check that the source and the duplicate are mapped by one VMA
each and that they show the same pages.
Link: https://lore.kernel.org/20261105-b4-mremap-pre-split-v3-5-f8789de76849@toxicpanda.com
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Jann Horn <jannh@google.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Sarthak Sharma <sarthak.sharma@arm.com>
---
tools/testing/selftests/mm/mremap_test.c | 51 ++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
--- a/tools/testing/selftests/mm/mremap_test.c~selftests-mm-test-mremap-with-an-old-size-of-0
+++ a/tools/testing/selftests/mm/mremap_test.c
@@ -604,6 +604,53 @@ out:
inplace ? " [inplace]" : "");
}
+/*
+ * An old size of 0 duplicates a shared mapping: the pages show up at a second
+ * address, and the mapping they were taken from stays as it is.
+ */
+static void mremap_duplicate_shared(FILE *maps_fp, unsigned long page_size,
+ unsigned long offset)
+{
+ char *test_name = "mremap duplicate shared mapping";
+ const size_t size = 3 * page_size;
+ const size_t dup_size = size - offset;
+ char *dup = MAP_FAILED;
+ bool success = false;
+ char *ptr;
+
+ ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANON, -1, 0);
+ if (ptr == MAP_FAILED) {
+ ksft_perror("mmap");
+ goto out;
+ }
+ memset(ptr, 'a', size);
+
+ dup = mremap(ptr + offset, 0, dup_size, MREMAP_MAYMOVE);
+ if (dup == MAP_FAILED) {
+ ksft_perror("mremap");
+ goto out_unmap;
+ }
+
+ /* Both are mapped, each by a single VMA. */
+ if (!is_ptr_mapped(maps_fp, ptr, size) ||
+ !is_ptr_mapped(maps_fp, dup, dup_size))
+ goto out_unmap;
+
+ /* They show the same pages. */
+ ptr[offset] = 'b';
+ dup[dup_size - 1] = 'c';
+ success = dup[0] == 'b' && ptr[size - 1] == 'c' && ptr[0] != 'c';
+
+out_unmap:
+ if (dup != MAP_FAILED)
+ munmap(dup, dup_size);
+ munmap(ptr, size);
+out:
+ ksft_test_result(success, "%s%s\n", test_name,
+ offset ? " [from the middle]" : "");
+}
+
static void mremap_move_multiple_vmas_split(unsigned int pattern_seed,
unsigned long page_size,
bool dont_unmap)
@@ -1249,7 +1296,7 @@ int main(int argc, char **argv)
char *rand_addr;
size_t rand_size;
int num_expand_tests = 2;
- int num_misc_tests = 9;
+ int num_misc_tests = 11;
struct test test_cases[MAX_TEST] = {};
struct test perf_test_cases[MAX_PERF_TEST];
int page_size;
@@ -1386,6 +1433,8 @@ int main(int argc, char **argv)
mremap_move_multiple_vmas_split(pattern_seed, page_size, /* dontunmap= */ false);
mremap_move_multiple_vmas_split(pattern_seed, page_size, /* dontunmap= */ true);
mremap_move_multi_invalid_vmas(maps_fp, page_size);
+ mremap_duplicate_shared(maps_fp, page_size, 0);
+ mremap_duplicate_shared(maps_fp, page_size, page_size);
fclose(maps_fp);
_
Patches currently in -mm which might be from josef@toxicpanda.com are
mm-zswap-drop-the-stale-zswap-entry-of-a-zero-folio.patch
mm-swap-account-synchronous-swap-reads-as-memory-stall.patch
mm-mremap-fix-hugetlb-reservation-leak-on-partial-move.patch
selftests-mm-test-a-partial-mremap-of-hugetlb-memory.patch
mm-mremap-reaccount-on-unmap-failure-only-if-accounted.patch
mm-mremap-restore-vma_account_bit-if-the-unmap-fails.patch
selftests-mm-test-mremap-with-an-old-size-of-0.patch
zram-lz4-lz4hc-accept-dictionaries-of-more-than-64-kib.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-06 1:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06 1:27 + selftests-mm-test-mremap-with-an-old-size-of-0.patch added to mm-new branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.