Skip to content

mm/memory: cleanly support zeropage in vm_insert_page*(), vm_map_pages*() and vmf_insert_mixed()

David Hildenbrand linux-mm lkml 2 versions – Applied

Status from this message: [merged mm-stable] mm-rmap-sanity-check-that-zeropages-are-not-passed-to-rmap.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 0 repliesApplied 3/3
  2. v12 patches 5 repliesSuperseded

Changes in v2 from the cover letter

* "mm/memory: move page_count() check into validate_page_before_insert()" -> Added
* "mm/memory: cleanly support zeropage in vm_insert_page*(), ..." -> Fixed "return true;" for never-writable VMAs

Patches in v2 All 3 applied

#Subject and filesSizeRepliesApplied
1/3mm/memory: move page_count() check into validate_page_before_insert()mm/memory.c+2 -40 repliesApplied
2/3mm/memory: cleanly support zeropage in vm_insert_page*(), vm_map_pages*() and vmf_insert_mixed()mm/memory.c mm/mprotect.c+72 -210 repliesApplied
3/3mm/rmap: sanity check that zeropages are not passed to RMAPinclude/linux/rmap.h+3 -00 repliesApplied

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH v2 0/3] mm/memory: cleanly support zeropage in vm_insert_page*(), vm_map_pages*() and vmf_insert_mixed()

There is interest in mapping zeropages via vm_insert_pages() [1] into MAP_SHARED mappings.

For now, we only get zeropages in MAP_SHARED mappings via vmf_insert_mixed() from FSDAX code, and I think it's a bit shaky in some cases because we refcount the zeropage when mapping it but not necessarily always when unmapping it ... and we should actually never refcount it.

It's all a bit tricky, especially how zeropages in MAP_SHARED mappings interact with GUP (FOLL_LONGTERM), mprotect(), write-faults and s390x forbidding the shared zeropage (rewrite [2] s now upstream).

This series tries to take the careful approach of only allowing the zeropage where it is likely safe to use (which should cover the existing FSDAX use case and [1]), preventing that it could accidentally get mapped writable during a write fault, mprotect() etc, and preventing issues with FOLL_LONGTERM in the future with other users.

Tested with a patch from Vincent that uses the zeropage in context of [1]. Vincent will post that patch based on this series soon. (not tested with FSDAX, but I don't expect surprises).

[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]

v1 -> v2:
* "mm/memory: move page_count() check into validate_page_before_insert()" -> Added
* "mm/memory: cleanly support zeropage in vm_insert_page*(), ..." -> Fixed "return true;" for never-writable VMAs

Cc Andrew Morton <[email protected]>
Cc Vincent Donnefort <[email protected]>
Cc Dan Williams <[email protected]>

David Hildenbrand (3):
mm/memory: move page_count() check into validate_page_before_insert() mm/memory: cleanly support zeropage in vm_insert_page*(),
vm_map_pages*() and vmf_insert_mixed()
mm/rmap: sanity check that zeropages are not passed to RMAP

 include/linux/rmap.h |  3 ++
 mm/memory.c          | 97 ++++++++++++++++++++++++++++++++------------
 mm/mprotect.c        |  2 +
 3 files changed, 77 insertions(+), 25 deletions(-)

base-commit: 29c73fc794c83505066ee6db893b2a83ac5fac63

Signature · 1 line
2.45.0