linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Brian Geffon <bgeffon@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 Brian Geffon <bgeffon@google.com>
Subject: [PATCH 0/2] mremap: Fix newaddr hint with MREMAP_DONTUNMAP
Date: Fri,  6 Dec 2024 10:20:30 -0500	[thread overview]
Message-ID: <20241206152032.1222067-1-bgeffon@google.com> (raw)

mmap(2) allows for a destination address to be specified without
MAP_FIXED and in this situation it's a hint to get_unmapped_area().
This address need not be page aligned because get_unmapped_area() will
align the hint.

In the case of 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 is specified we don't need to do alignment or size
checks on newaddr because they will be passed to get_unmapped_area() and
dealt with appropriately.

This patch corrects that behavior to match what non-MREMAP_DONTUNMAP
mremap(2) and mmap(2) do. This odd behavioral difference was reported by
Marco Vanotti. Additionally, I've included a self test to validate this
behavior.

Brian Geffon (2):
  mremap: Fix new_addr being used as a hint with MREMAP_DONTUNMAP
  selftests: mm: Add a new MREMAP_DONTUNMAP self test

 mm/mremap.c                                   | 26 ++++++++----
 tools/testing/selftests/mm/mremap_dontunmap.c | 41 ++++++++++++++++++-
 2 files changed, 59 insertions(+), 8 deletions(-)

-- 
2.47.0.338.g60cca15819-goog



             reply	other threads:[~2024-12-06 15:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-06 15:20 Brian Geffon [this message]
2024-12-06 15:20 ` [PATCH 1/2] mremap: Fix new_addr being used as a " Brian Geffon
2024-12-06 15:34   ` Marco Vanotti
2024-12-06 15:39     ` Brian Geffon
2024-12-06 15:20 ` [PATCH 2/2] selftests: mm: Add a new MREMAP_DONTUNMAP self test Brian Geffon
2024-12-06 18:42 ` [PATCH 0/2] mremap: Fix newaddr hint with MREMAP_DONTUNMAP Jann Horn
2024-12-06 18:52   ` Lorenzo Stoakes
2024-12-09  2:28     ` 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=20241206152032.1222067-1-bgeffon@google.com \
    --to=bgeffon@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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