linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] move all VMA allocation, freeing and duplication logic to mm
@ 2025-04-25 14:54 Lorenzo Stoakes
  2025-04-25 14:54 ` [PATCH v2 1/3] mm: abstract initial stack setup to mm subsystem Lorenzo Stoakes
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Lorenzo Stoakes @ 2025-04-25 14:54 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Liam R . Howlett, Vlastimil Babka, Jann Horn, Pedro Falcato,
	David Hildenbrand, Kees Cook, Alexander Viro, Christian Brauner,
	Jan Kara, Suren Baghdasaryan, linux-mm, linux-fsdevel,
	linux-kernel

Currently VMA allocation, freeing and duplication exist in kernel/fork.c,
which is a violation of separation of concerns, and leaves these functions
exposed to the rest of the kernel when they are in fact internal
implementation details.

Resolve this by moving this logic to mm, and making it internal to vma.c,
vma.h.

This also allows us, in future, to provide userland testing around this
functionality.

We additionally abstract dup_mmap() to mm, being careful to ensure
kernel/fork.c acceses this via the mm internal header so it is not exposed
elsewhere in the kernel.

As part of this change, also abstract initial stack allocation performed in
__bprm_mm_init() out of fs code into mm via the create_init_stack_vma(), as
this code uses vm_area_alloc() and vm_area_free().

In order to allow for this, we must add code shared between nommu and
mmu-enabled configurations in order to share VMA allocation, freeing and
duplication code correctly while also keeping these functions available in
userland VMA testing.

This is achieved by adding a vma_init.c file which is also compiled by the
userland tests.

v2:
* Moved vma init, alloc, free, dup functions to newly created vma_init.c
  function as per Suren, Liam.
* Added MAINTAINERS entry for vma_init.c, added to Makefile.
* Updated mmap_init() comment.
* Propagated tags (thanks everyone!)
* Added detach_free_vma() helper and correctly detached vmas in userland VMA
  test code.
* Updated userland test code to also compile the vma_init.c file.
* Corrected create_init_stack_vma() comment as per Suren.
* Updated commit message as per Suren.

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

Lorenzo Stoakes (3):
  mm: abstract initial stack setup to mm subsystem
  mm: move dup_mmap() to mm
  mm: perform VMA allocation, freeing, duplication in mm

 MAINTAINERS                      |   1 +
 fs/exec.c                        |  51 +-----
 include/linux/mm.h               |   2 +
 kernel/fork.c                    | 277 +------------------------------
 mm/Makefile                      |   2 +-
 mm/internal.h                    |   2 +
 mm/mmap.c                        | 253 +++++++++++++++++++++++++++-
 mm/nommu.c                       |  12 +-
 mm/vma.h                         |   6 +
 mm/vma_init.c                    | 101 +++++++++++
 tools/testing/vma/Makefile       |   2 +-
 tools/testing/vma/vma.c          |  26 ++-
 tools/testing/vma/vma_internal.h | 143 +++++++++++++---
 13 files changed, 511 insertions(+), 367 deletions(-)
 create mode 100644 mm/vma_init.c

--
2.49.0

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

end of thread, other threads:[~2025-04-28 20:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-25 14:54 [PATCH v2 0/3] move all VMA allocation, freeing and duplication logic to mm Lorenzo Stoakes
2025-04-25 14:54 ` [PATCH v2 1/3] mm: abstract initial stack setup to mm subsystem Lorenzo Stoakes
2025-04-25 17:09   ` Kees Cook
2025-04-28  8:53     ` Lorenzo Stoakes
2025-04-28 10:46       ` Lorenzo Stoakes
2025-04-28 20:29         ` Kees Cook
2025-04-25 14:54 ` [PATCH v2 2/3] mm: move dup_mmap() to mm Lorenzo Stoakes
2025-04-25 14:54 ` [PATCH v2 3/3] mm: perform VMA allocation, freeing, duplication in mm 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).