Skip to content

mremap: Fix newaddr hint with MREMAP_DONTUNMAP

Brian Geffon linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2mremap: Fix new_addr being used as a hint with MREMAP_DONTUNMAPmm/mremap.c+19 -72 replies
2/2selftests: mm: Add a new MREMAP_DONTUNMAP self testtools/testing/selftests/mm/mremap_dontunmap.c+40 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] mremap: Fix newaddr hint with MREMAP_DONTUNMAP

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(-)
Signature · 1 line
2.47.0.338.g60cca15819-goog