From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Josef Bacik <josef@toxicpanda.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <liam@infradead.org>,
David Hildenbrand <david@kernel.org>,
Vlastimil Babka <vbabka@kernel.org>,
Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
linux-mm@kvack.org
Subject: Re: [PATCH 5/6] selftests/mm: test mremap() with an old size of 0
Date: Mon, 2 Nov 2026 13:39:51 +0000 [thread overview]
Message-ID: <auiSj5MUeyY907tJ@gremlin> (raw)
In-Reply-To: <20261030-b4-mremap-pre-split-v1-5-c1829811aed0@toxicpanda.com>
On Fri, Oct 30, 2026 at 02:42:50PM +0000, Josef Bacik wrote:
> 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.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Looks sensible so:
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
> tools/testing/selftests/mm/mremap_test.c | 52 +++++++++++++++++++++++++++++++-
> 1 file changed, 51 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
> index 31b484517bda..92960fff9537 100644
> --- a/tools/testing/selftests/mm/mremap_test.c
> +++ b/tools/testing/selftests/mm/mremap_test.c
> @@ -603,6 +603,54 @@ static void mremap_shrink_multiple_vmas(unsigned long page_size,
> 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) {
> + perror("mmap");
> + goto out;
> + }
> + memset(ptr, 'a', size);
> +
> + dup = mremap(ptr + offset, 0, dup_size, MREMAP_MAYMOVE);
> + if (dup == MAP_FAILED) {
> + 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))
> + perror("munmap dup");
> + if (munmap(ptr, size))
> + perror("munmap src");
> +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)
> @@ -1248,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;
> @@ -1385,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);
>
>
> --
> 2.55.0
>
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-11-02 13:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 14:42 [PATCH 0/6] mm/mremap: report a failed split before moving anything Josef Bacik
2026-10-30 14:42 ` [PATCH 1/6] mm/mremap: fix hugetlb reservation leak on partial move Josef Bacik
2026-11-02 13:13 ` Lorenzo Stoakes (ARM)
2026-10-30 14:42 ` [PATCH 2/6] selftests/mm: test a partial mremap() of hugetlb memory Josef Bacik
2026-11-02 13:14 ` Lorenzo Stoakes (ARM)
2026-10-30 14:42 ` [PATCH 3/6] mm/mremap: reaccount on unmap failure only if accounted Josef Bacik
2026-11-02 13:17 ` Lorenzo Stoakes (ARM)
2026-10-30 14:42 ` [PATCH 4/6] mm/mremap: restore VM_ACCOUNT if the unmap fails Josef Bacik
2026-11-02 13:38 ` Lorenzo Stoakes (ARM)
2026-10-30 14:42 ` [PATCH 5/6] selftests/mm: test mremap() with an old size of 0 Josef Bacik
2026-11-02 13:39 ` Lorenzo Stoakes (ARM) [this message]
2026-10-30 14:42 ` [PATCH 6/6] mm/mremap: split first so a failed split is reported Josef Bacik
2026-10-31 19:27 ` Jose A. Perez de Azpillaga
2026-11-02 13:57 ` Lorenzo Stoakes (ARM)
2026-11-02 12:50 ` [PATCH 0/6] mm/mremap: report a failed split before moving anything Lorenzo Stoakes (ARM)
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=auiSj5MUeyY907tJ@gremlin \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=jannh@google.com \
--cc=josef@toxicpanda.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=pfalcato@suse.de \
--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 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.