linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/5] mseal cleanups
@ 2025-07-25  8:29 Lorenzo Stoakes
  2025-07-25  8:29 ` [PATCH v4 1/5] mm/mseal: always define VM_SEALED Lorenzo Stoakes
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Lorenzo Stoakes @ 2025-07-25  8:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Liam R . Howlett, David Hildenbrand, Vlastimil Babka, Jann Horn,
	Pedro Falcato, linux-mm, linux-kernel, Jeff Xu, Kees Cook

Perform a number of cleanups to the mseal logic. Firstly, VM_SEALED is
treated differently from every other VMA flag, it really doesn't make sense
to do this, so we start by making this consistent with everything else.

Next we place the madvise logic where it belongs - in mm/madvise.c. It
really makes no sense to abstract this elsewhere. In doing so, we go to
great lengths to explain very clearly the previously very confusing logic
as to what sealed mappings are impacted here.

In doing so, we retain existing logic regarding treatment of madvise()
discard operations for a sealed, read-only MAP_PRIVATE file-backed
mapping. This is something we likely need to revisit.

We then abstract out and explain the 'are there are any gaps in this range
in the mm?' check being performed as a prerequisite to mseal being
performed.

Finally, we simplify the actual mseal logic which is really quite
straightforward.

No functional change is intended.


NOTE - this replaces the previous "mseal cleanups, fixup MAP_PRIVATE
file-backed case" series (linked below under v3), I renamed to 'mseal
cleaups' only as now we do not adjust MAP_PRIVATE behaviour.

v4:
* Propagated tags, thanks Jeff!
* Remove the change in semantics for MAP_PRIVATE, file-backed, mseal()'d
  mappings, as it turns out there is more complexity than expected
  here. Let's stick to a straight refactoring for now. Based on discussions
  with Jeff, Kees and David.
* Reinstated comment previously present in check_mm_seal() regarding
  expectations of input range in range_contains_unmapped() where this makes
  sense to locate, removing the redundant 'map is sealable' step, as per
  Jeff.

v3:
* Propagated more tags, thanks everyone!
* Updated 5/5 to assign curr_start in a smarter way as per Liam. Adjust
  code to more sensibly handle already-sealed case at the same time.
* Updated 4/5 to not move range_contains_unmapped() for better diff.
* Renamed can_modify_vma() to vma_is_sealed() and inverted the logic - this
  is far clearer than the nebulous 'can modify VMA'.
https://lore.kernel.org/all/cover.1752687069.git.lorenzo.stoakes@oracle.com/

v2:
* Propagated tags, thanks everyone!
* Updated can_madvise_modify() to a more logical order re: the checks
  performed, as per David.
* Replaced vma_is_anonymous() check (which was, in the original code, a
  vma->vm_file or vma->vm_ops check) with a vma->vm_flags & VM_SHARED
  check - to explicitly check for shared mappings vs private to preclude
  MAP_PRIVATE-mapping file-baked mappings, as per David.
* Made range_contains_unmapped() static and placed in mm/mseal.c to avoid
  encouraging any other internal users towards this rather silly pattern,
  as per Pedro and Liam.
https://lore.kernel.org/all/cover.1752586090.git.lorenzo.stoakes@oracle.com/

v1:
https://lore.kernel.org/all/cover.1752497324.git.lorenzo.stoakes@oracle.com/


Lorenzo Stoakes (5):
  mm/mseal: always define VM_SEALED
  mm/mseal: update madvise() logic
  mm/mseal: small cleanups
  mm/mseal: simplify and rename VMA gap check
  mm/mseal: rework mseal apply logic

 include/linux/mm.h               |   6 +-
 mm/madvise.c                     |  71 +++++++++++++-
 mm/mprotect.c                    |   2 +-
 mm/mremap.c                      |   2 +-
 mm/mseal.c                       | 160 +++++++------------------------
 mm/vma.c                         |   4 +-
 mm/vma.h                         |  27 +-----
 tools/testing/vma/vma_internal.h |   6 +-
 8 files changed, 119 insertions(+), 159 deletions(-)

--
2.50.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2025-07-25 19:34 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-25  8:29 [PATCH v4 0/5] mseal cleanups Lorenzo Stoakes
2025-07-25  8:29 ` [PATCH v4 1/5] mm/mseal: always define VM_SEALED Lorenzo Stoakes
2025-07-25  8:29 ` [PATCH v4 2/5] mm/mseal: update madvise() logic Lorenzo Stoakes
2025-07-25 17:28   ` Jeff Xu
2025-07-25 17:53     ` Lorenzo Stoakes
2025-07-25 18:41       ` Jeff Xu
2025-07-25 18:44         ` Lorenzo Stoakes
2025-07-25  8:29 ` [PATCH v4 3/5] mm/mseal: small cleanups Lorenzo Stoakes
2025-07-25  8:29 ` [PATCH v4 4/5] mm/mseal: simplify and rename VMA gap check Lorenzo Stoakes
2025-07-25 17:30   ` Jeff Xu
2025-07-25 17:43     ` Lorenzo Stoakes
2025-07-25 18:09       ` Jeff Xu
2025-07-25 18:15         ` Lorenzo Stoakes
2025-07-25 19:32         ` Pedro Falcato
2025-07-25 18:10       ` David Hildenbrand
2025-07-25 18:22         ` Lorenzo Stoakes
2025-07-25 18:26         ` Jeff Xu
2025-07-25 18:41   ` Lorenzo Stoakes
2025-07-25 19:34   ` Pedro Falcato
2025-07-25  8:29 ` [PATCH v4 5/5] mm/mseal: rework mseal apply logic Lorenzo Stoakes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).