mm-various-small-mmap_prepare-cleanups.patch removed from -mm tree
The quilt patch titled
Subject: mm: various small mmap_prepare cleanups
has been removed from the -mm tree. Its filename was
mm-various-small-mmap_prepare-cleanups.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: "Lorenzo Stoakes (Oracle)" <[email protected]>
Subject: mm: various small mmap_prepare cleanups
Date: Fri, 20 Mar 2026 22:39:27 +0000
Patch series "mm: expand mmap_prepare functionality and usage", v4.
This series expands the mmap_prepare functionality, which is intended to replace the deprecated f_op->mmap hook which has been the source of bugs and security issues for some time.
This series starts with some cleanup of existing mmap_prepare logic, then adds documentation for the mmap_prepare call to make it easier for filesystem and driver writers to understand how it works.
It then importantly adds a vm_ops->mapped hook, a key feature that was missing from mmap_prepare previously - this is invoked when a driver which specifies mmap_prepare has successfully been mapped but not merged with another VMA.
mmap_prepare is invoked prior to a merge being attempted, so you cannot manipulate state such as reference counts as if it were a new mapping.
The vm_ops->mapped hook allows a driver to perform tasks required at this stage, and provides symmetry against subsequent vm_ops->open,close calls.
The series uses this to correct the afs implementation which wrongly manipulated reference count at mmap_prepare time.
It then adds an mmap_prepare equivalent of vm_iomap_memory() - mmap_action_simple_ioremap(), then uses this to update a number of drivers.
It then splits out the mmap_prepare compatibility layer (which allows for invocation of mmap_prepare hooks in an mmap() hook) in such a way as to allow for more incremental implementation of mmap_prepare hooks.
It then uses this to extend mmap_prepare usage in drivers.
Finally it adds an mmap_prepare equivalent of vm_map_pages(), which lays the foundation for future work which will extend mmap_prepare to DMA coherent mappings.
This patch (of 21):
Rather than passing arbitrary fields, pass a vm_area_desc pointer to mmap prepare functions to mmap prepare, and an action and vma pointer to mmap complete in order to put all the action-specific logic in the function actually doing the work.
Additionally, allow mmap prepare functions to return an error so we can error out as soon as possible if there is something logically incorrect in the input.
Update remap_pfn_range_prepare() to properly check the input range for the CoW case.
Also remove io_remap_pfn_range_complete(), as we can simply set up the fields correctly in io_remap_pfn_range_prepare() and use remap_pfn_range_complete() for this.
While we're here, make remap_pfn_range_prepare_vma() a little neater, and pass mmap_action directly to call_action_complete().
Then, update compat_vma_mmap() to perform its logic directly, as __compat_vma_map() is not used by anything so we don't need to export it.
Also update compat_vma_mmap() to use vfs_mmap_prepare() rather than calling the mmap_prepare op directly.
Finally, update the VMA userland tests to reflect the changes.
---
include/linux/fs.h | 2 include/linux/mm.h | 7 - mm/internal.h | 34 ++++--- mm/memory.c | 45 ++++++---- mm/util.c | 121 ++++++++++++---------------- mm/vma.c | 24 +++-- tools/testing/vma/include/dup.h | 7 + tools/testing/vma/include/stubs.h | 8 - 8 files changed, 127 insertions(+), 121 deletions(-)
include/linux/fs.h renamed from include/linux/fs.h~mm-various-small-mmap_prepare-cleanups +0 -2
@@ -2058,8 +2058,6 @@ static inline bool can_mmap_file(structreturn true; } -int __compat_vma_mmap (const struct file_operations *f_op, -struct file *file,struct vm_area_struct *vma);int compat_vma_mmap (struct file *file,struct vm_area_struct *vma);static inline int vfs_mmap (struct file *file,struct vm_area_struct *vma)
include/linux/mm.h renamed from include/linux/mm.h~mm-various-small-mmap_prepare-cleanups +3 -4
@@ -4304,10 +4304,9 @@ static inline void mmap_action_ioremap_fmmap_action_ioremap (desc, desc->start, start_pfn,vma_desc_size (desc)); } -void mmap_action_prepare (struct mmap_action *action, -struct vm_area_desc *desc); -int mmap_action_complete (struct mmap_action *action, -struct vm_area_struct *vma); +int mmap_action_prepare (struct vm_area_desc *desc); +int mmap_action_complete (struct vm_area_struct *vma, +struct mmap_action *action);/* Look up the first VMA which exactly match the interval vm_start ... vm_end */ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
mm/internal.h renamed from mm/internal.h~mm-various-small-mmap_prepare-cleanups +18 -16
@@ -1839,26 +1839,28 @@ int walk_page_range_debug(struct mm_struvoid dup_mm_exe_file (struct mm_struct *mm,struct mm_struct *oldmm);int dup_mmap (struct mm_struct *mm,struct mm_struct *oldmm); -void remap_pfn_range_prepare (struct vm_area_desc *desc,unsigned long pfn); -int remap_pfn_range_complete (struct vm_area_struct *vma,unsigned long addr, -unsigned long pfn,unsigned long size,pgprot_t pgprot); +int remap_pfn_range_prepare (struct vm_area_desc *desc); +int remap_pfn_range_complete (struct vm_area_struct *vma, +struct mmap_action *action); -static inline void io_remap_pfn_range_prepare (struct vm_area_desc *desc, -unsigned long orig_pfn,unsigned long size) +static inline int io_remap_pfn_range_prepare (struct vm_area_desc *desc) { +struct mmap_action *action = &desc->action; +const unsigned long orig_pfn = action->remap.start_pfn; +const pgprot_t orig_pgprot = action->remap.pgprot; +const unsigned long size = action->remap.size;const unsigned long pfn =io_remap_pfn_range_pfn (orig_pfn, size); +int err; -return remap_pfn_range_prepare (desc, pfn); -} - -static inline int io_remap_pfn_range_complete (struct vm_area_struct *vma, -unsigned long addr,unsigned long orig_pfn,unsigned long size, -pgprot_t orig_prot) -{ -const unsigned long pfn =io_remap_pfn_range_pfn (orig_pfn, size); -const pgprot_t prot =pgprot_decrypted (orig_prot); - -return remap_pfn_range_complete (vma, addr, pfn, size, prot); + action->remap.start_pfn = pfn; + action->remap.pgprot =pgprot_decrypted (orig_pgprot); + err =remap_pfn_range_prepare (desc); +if (err) +return err; + +/* Remap does the actual work. */ + action->type =MMAP_REMAP_PFN ; +return 0 ; }#ifdef CONFIG_MMU_NOTIFIER
mm/memory.c renamed from mm/memory.c~mm-various-small-mmap_prepare-cleanups +29 -16
65 lines not on this page · raw message
mm/util.c renamed from mm/util.c~mm-various-small-mmap_prepare-cleanups +54 -67
192 lines not on this page · raw message
mm/vma.c renamed from mm/vma.c~mm-various-small-mmap_prepare-cleanups +14 -10
@@ -2640,15 +2640,18 @@ static void __mmap_complete(struct mmap_vma_set_page_prot (vma); } -static void call_action_prepare (struct mmap_state *map, -struct vm_area_desc *desc) +static int call_action_prepare (struct mmap_state *map, +struct vm_area_desc *desc) { -struct mmap_action *action = &desc->action; +int err; -mmap_action_prepare (action, desc); + err =mmap_action_prepare (desc); +if (err) +return err; -if (action->hide_from_rmap_until_complete) +if (desc->action.hide_from_rmap_until_complete) map->hold_file_rmap_lock = true; +return 0 ; }/*
@@ -2672,7 +2675,9 @@ static int call_mmap_prepare(struct mmapif (err)return err; -call_action_prepare (map, desc); + err =call_action_prepare (map, desc); +if (err) +return err;/* Update fields permitted to be changed. */ map->pgoff = desc->pgoff;
@@ -2727,13 +2732,12 @@ static bool can_set_ksm_flags_early(stru }static int call_action_complete (struct mmap_state *map, -struct vm_area_desc *desc, +struct mmap_action *action,struct vm_area_struct *vma) { -struct mmap_action *action = &desc->action;int ret; - ret =mmap_action_complete (action, vma); + ret =mmap_action_complete (vma, action);/* If we held the file rmap we need to release it. */ if (map->hold_file_rmap_lock) {
@@ -2795,7 +2799,7 @@ static unsigned long __mmap_region(struc__mmap_complete (&map, vma);if (have_mmap_prepare && allocated_new) { - error =call_action_complete (&map, &desc, vma); + error =call_action_complete (&map, &desc.action, vma);if (error)return error;
tools/testing/vma/include/dup.h renamed from tools/testing/vma/include/dup.h~mm-various-small-mmap_prepare-cleanups +5 -2
@@ -1277,9 +1277,12 @@ static inline int __compat_vma_mmap(consif (err)return err; -mmap_action_prepare (&desc.action, &desc); + err =mmap_action_prepare (&desc); +if (err) +return err; +set_vma_from_desc (vma, &desc); -return mmap_action_complete (&desc.action, vma); +return mmap_action_complete (vma, &desc.action); } static inline int compat_vma_mmap(struct file *file,
tools/testing/vma/include/stubs.h renamed from tools/testing/vma/include/stubs.h~mm-various-small-mmap_prepare-cleanups +4 -4
@@ -81,13 +81,13 @@ static inline void free_anon_vma_name(st { } -static inline void mmap_action_prepare (struct mmap_action *action, -struct vm_area_desc *desc) +static inline int mmap_action_prepare (struct vm_area_desc *desc) { +return 0 ; } -static inline int mmap_action_complete (struct mmap_action *action, -struct vm_area_struct *vma) +static inline int mmap_action_complete (struct vm_area_struct *vma, +struct mmap_action *action) {return 0 ; }
_
Patches currently in -mm which might be from [email protected] are
maintainers-update-mglru-entry-to-reflect-current-status.patch selftests-mm-add-merge-test-for-partial-msealed-range.patch