From: Hajime Tazaki <thehajime@gmail.com>
To: brad@sim.vu
Cc: akpm@linux-foundation.org, ljs@kernel.org, liam@infradead.org,
vbabka@kernel.org, jannh@google.com, pfalcato@suse.de,
david@kernel.org, surenb@google.com, shakeel.butt@linux.dev,
linux-mm@kvack.org, stable@vger.kernel.org
Subject: Re: [PATCH] mm/nommu: keep the maple tree in step when mremap() resizes in place
Date: Mon, 23 Nov 2026 20:41:54 +0900 [thread overview]
Message-ID: <87v75nsrjx.wl-thehajime@gmail.com> (raw)
In-Reply-To: <20261121083139.803682-1-brad@sim.vu>
[-- Attachment #1: Type: text/plain, Size: 1755 bytes --]
Hello Brad,
On Sat, 21 Nov 2026 17:31:39 +0900,
Brad Hawthorne wrote:
>
> On !MMU, do_mremap() resizes a VMA by writing vma->vm_end and nothing
> else, so mm->mm_mt keeps the old extent.
(snip)
> Sashiko's review of Hajime Tazaki's nommu series found the stale range
> in July, and his fixes and RFC since then cover it [1][2]; review asked
> for a minimal fix-only patch with a Fixes: tag [3]. This is a minimal
> version of that fix.
>
> The consequence was reproduced and this patch drafted with an AI coding
> assistant (Claude, Anthropic): it reviewed mm/nommu.c, wrote the
> reproducer and ran the board and QEMU tests; I checked the result.
> Stable backports need adjusting: 6.6.y and 6.12.y lack
> vma_iter_store_overwrite(), and 6.1.y nommu uses the ma_state API.
>
> Link: https://lore.kernel.org/linux-mm/20260710021028.892645-1-thehajime@gmail.com/ [1]
> Link: https://lore.kernel.org/linux-mm/20260813063401.1786548-2-thehajime@gmail.com/ [2]
> Link: https://lore.kernel.org/linux-mm/an77pELeQdW-sTEi@lucifer/ [3]
> Fixes: 524e00b36e8c ("mm: remove rb tree.")
> Cc: Hajime Tazaki <thehajime@gmail.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Brad Hawthorne <brad@sim.vu>
> ---
> Hajime, as you asked, here it is as a separate patch with you on Cc.
> Earlier note, and his reply: https://lore.kernel.org/linux-mm/20261120221021.789792-1-brad@sim.vu/
my earlier patchset contains a kselftest case, which tried to test the
issue which your patch addressed. Part of kselftest is now upstreamed
and I would add the additional one specifically for the case of this
issue (this patch addressed).
Attached is locally tested kselftest with your patch. Would be nice
to include this in your next spin as a part of patchset.
-- Hajime
[-- Attachment #2: 0001-selftests-nommu-test-mremap-grow-after-shrink.patch --]
[-- Type: text/plain, Size: 3148 bytes --]
From 608869187e388e16e4c2b2caf5a174c3a424dd7b Mon Sep 17 00:00:00 2001
From: Hajime Tazaki <thehajime@gmail.com>
Date: Mon, 23 Nov 2026 20:24:08 +0900
Subject: [PATCH] selftests/nommu: test mremap grow after shrink
The existing mremap shrink test covers dropping the old extent. Growing
a shortened VMA must also store its restored extent in the maple tree.
Shrink an anonymous mapping, grow it back, then partially unmap the
regrown tail and the remainder to exercise that tree update.
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
---
.../selftests/nommu/nommu_mremap_test.c | 58 ++++++++++++++++++-
1 file changed, 57 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/nommu/nommu_mremap_test.c b/tools/testing/selftests/nommu/nommu_mremap_test.c
index 6ee89cb25f61..550c21fadbf4 100644
--- a/tools/testing/selftests/nommu/nommu_mremap_test.c
+++ b/tools/testing/selftests/nommu/nommu_mremap_test.c
@@ -133,6 +133,61 @@ static void mremap_shrink_test(void)
ksft_test_result_pass("mremap shrink\n");
}
+/* mremap_shrink_test() covers stale entries after shrink; test regrowth here. */
+static void mremap_shrink_grow_test(void)
+{
+ void *addr, *addr2;
+ int cleanup, head, tail;
+
+ if (!nommu) {
+ ksft_test_result_skip("NOMMU only\n");
+ return;
+ }
+
+ addr = mmap(NULL, ps * 8, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (addr == MAP_FAILED) {
+ ksft_test_result_error("mmap failed: %s\n", strerror(errno));
+ return;
+ }
+
+ addr2 = mremap(addr, ps * 8, ps * 4, 0);
+ if (addr2 == MAP_FAILED) {
+ ksft_test_result_fail("mremap shrink failed: %s\n", strerror(errno));
+ if (munmap(addr, ps * 8))
+ ksft_print_msg("cleanup after shrink failure failed: %s\n",
+ strerror(errno));
+ return;
+ }
+
+ addr = mremap(addr2, ps * 4, ps * 8, 0);
+ if (addr == MAP_FAILED) {
+ ksft_test_result_fail("mremap grow failed: %s\n", strerror(errno));
+ if (munmap(addr2, ps * 4))
+ ksft_print_msg("cleanup after grow failure failed: %s\n",
+ strerror(errno));
+ return;
+ }
+ if (munmap(addr + ps * 4, ps * 4)) {
+ ksft_test_result_fail("munmap grown range failed: %s\n", strerror(errno));
+ cleanup = munmap(addr, ps * 8);
+ if (cleanup) {
+ head = munmap(addr, ps * 4);
+ tail = munmap(addr + ps * 4, ps * 4);
+ cleanup = head || tail;
+ }
+ if (cleanup)
+ ksft_print_msg("cleanup after munmap failure failed: %s\n",
+ strerror(errno));
+ return;
+ }
+ if (munmap(addr, ps * 4)) {
+ ksft_test_result_fail("munmap failed: %s\n", strerror(errno));
+ return;
+ }
+ ksft_test_result_pass("mremap shrink and grow\n");
+}
+
static int get_shared_writable_file_expected_error(const char *path)
{
if (nommu && get_fs_type(path) == RAMFS_MAGIC)
@@ -344,10 +399,11 @@ int main(int argc, char **argv)
ps = sysconf(_SC_PAGESIZE);
ksft_print_header();
- ksft_set_plan(ARRAY_SIZE(mremap_cases) + 2);
+ ksft_set_plan(ARRAY_SIZE(mremap_cases) + 3);
munmap_shrink_test();
mremap_shrink_test();
+ mremap_shrink_grow_test();
for (i = 0; i < (int)ARRAY_SIZE(mremap_cases); i++)
run_mremap_test(&mremap_cases[i]);
--
2.43.0
prev parent reply other threads:[~2026-11-23 11:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 8:31 [PATCH] mm/nommu: keep the maple tree in step when mremap() resizes in place Brad Hawthorne
2026-11-23 11:41 ` Hajime Tazaki [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v75nsrjx.wl-thehajime@gmail.com \
--to=thehajime@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=brad@sim.vu \
--cc=david@kernel.org \
--cc=jannh@google.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=pfalcato@suse.de \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox