From: Brian Geffon <bgeffon@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Jann Horn <jannh@google.com>, Vlastimil Babka <vbabka@suse.cz>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
linux-mm@kvack.org, Marco Vanotti <mvanotti@google.com>,
linux-kernel@vger.kernel.org, Brian Geffon <bgeffon@google.com>
Subject: [RFC PATCH 0/5] mm: Fix mremap behavior when using addr hints
Date: Tue, 10 Dec 2024 16:30:45 -0500 [thread overview]
Message-ID: <20241210213050.2839638-1-bgeffon@google.com> (raw)
When MREMAP_DONTUNMAP was added in e346b38 ("mm/mremap: add
MREMAP_DONTUNMAP to mremap()") we inadvertently allows for an
address hint to be specified when not using MREMAP_FIXED. This is because
mremap(2) with MREMAP_DONTUNMAP it shares a code path with MREMAP_FIXED
in mremap_to(), which means this function can be called in 3 different
scenarios: MREMAP_FIXED only, MREMAP_DONTUNMAP
only, or MREMAP_FIXED | MREMAP_DONTUNMAP. In the second case when only
MREMAP_DONTUNMAP the new_addr is passed to get_unmapped_area() which
behaves like a hint as it does with mmap(2).
Glibc now expects this behavior so it would seem it probably cannot be
removed [1]. Additionally, as Jann Horn pointed out Debian apparently
has tests for this odd undocumented behavior [2].
This series attempts to reconcile this situation.
Patch 1: Will fix the checks that should only apply to the MREMAP_FIXED
case, so that they don't apply to just MREMAP_MAYMOVE.
Patch 2: Addresses an actual bug where we can allow a hint which is
lower than the mmap_min_addr.
Patch 3: Since we're stuck with this behavior we might as well support
it for mremap(2) when MREMAP_MAYMOVE is specified.
Patch 4: Self tests for patch 1
Patch 5: Self tests for patch 3
I will mail man page updates once we finalize on the behavior for
mremap(2).
1. https://sourceware.org/git/?p=glibc.git;a=commit;h=6c40cb0e9f893d49dc7caee580a055de53562206
2. https://sources.debian.org/src/glibc/2.40-4/debian/patches/git-updates.diff/?hl=22820#L22818
Brian Geffon (5):
mm: mremap: Fix new_addr being used as a hint with MREMAP_DONTUNMAP
mm: mremap: Use round_hint_to_min() for new_addr hints
mm: mremap: Allow new_addr to be specified as a hint
selftests: mm: Add a new MREMAP_DONTUNMAP self test
selftests: mm: Add selftest for new_addr hint with MREMAP_MAYMOVE.
include/linux/mm_inline.h | 14 +++
mm/mmap.c | 13 --
mm/mremap.c | 34 ++++--
tools/testing/selftests/mm/mremap_dontunmap.c | 41 ++++++-
tools/testing/selftests/mm/mremap_test.c | 113 +++++++++++++++++-
5 files changed, 189 insertions(+), 26 deletions(-)
--
2.47.0.338.g60cca15819-goog
next reply other threads:[~2024-12-10 21:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 21:30 Brian Geffon [this message]
2024-12-10 21:30 ` [RFC PATCH 1/5] mm: mremap: Fix new_addr being used as a hint with MREMAP_DONTUNMAP Brian Geffon
2024-12-11 16:46 ` Marco Vanotti
2024-12-10 21:30 ` [RFC PATCH 2/5] mm: mremap: Use round_hint_to_min() for new_addr hints Brian Geffon
2024-12-10 21:30 ` [RFC PATCH 3/5] mm: mremap: Allow new_addr to be specified as a hint Brian Geffon
2024-12-11 20:34 ` Brian Geffon
2024-12-10 21:30 ` [RFC PATCH 4/5] selftests: mm: Add a new MREMAP_DONTUNMAP self test Brian Geffon
2024-12-10 21:30 ` [RFC PATCH 5/5] selftests: mm: Add selftest for new_addr hint with MREMAP_MAYMOVE Brian Geffon
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=20241210213050.2839638-1-bgeffon@google.com \
--to=bgeffon@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mvanotti@google.com \
--cc=vbabka@suse.cz \
/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