Skip to contentSkip to conversation

mm-allow-handling-of-stacked-mmap_prepare-hooks-in-more-drivers.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Mar 31

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm: allow handling of stacked mmap_prepare hooks in more drivers
has been removed from the -mm tree. Its filename was
mm-allow-handling-of-stacked-mmap_prepare-hooks-in-more-drivers.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: allow handling of stacked mmap_prepare hooks in more drivers
Date: Fri, 20 Mar 2026 22:39:43 +0000

While the conversion of mmap hooks to mmap_prepare is underway, we will encounter situations where mmap hooks need to invoke nested mmap_prepare hooks.

The nesting of mmap hooks is termed 'stacking'. In order to flexibly facilitate the conversion of custom mmap hooks in drivers which stack, we must split up the existing __compat_vma_mmap() function into two separate functions:

* compat_set_desc_from_vma() - This allows the setting of a vm_area_desc object's fields to the relevant fields of a VMA.

* __compat_vma_mmap() - Once an mmap_prepare hook has been executed upon a vm_area_desc object, this function performs any mmap actions specified by the mmap_prepare hook and then invokes its vm_ops->mapped() hook if any were specified.

In ordinary cases, where a file's f_op->mmap_prepare() hook simply needs to be invoked in a stacked mmap() hook, compat_vma_mmap() can be used.

However some drivers define their own nested hooks, which are invoked in turn by another hook.

A concrete example is vmbus_channel->mmap_ring_buffer(), which is invoked in turn by bin_attribute->mmap():

vmbus_channel->mmap_ring_buffer() has a signature of:

int (*mmap_ring_buffer)(struct vmbus_channel *channel,

			struct vm_area_struct *vma);

And bin_attribute->mmap() has a signature of:

int (*mmap)(struct file *, struct kobject *,
const struct bin_attribute *attr, struct vm_area_struct *vma);

And so compat_vma_mmap() cannot be used here for incremental conversion of hooks from mmap() to mmap_prepare().

There are many such instances like this, where conversion to mmap_prepare would otherwise cascade to a huge change set due to nesting of this kind.

The changes in this patch mean we could now instead convert vmbus_channel->mmap_ring_buffer() to vmbus_channel->mmap_prepare_ring_buffer(), and implement something like:

	struct vm_area_desc desc;
	int err;

	compat_set_desc_from_vma(&desc, file, vma);
	err = channel->mmap_prepare_ring_buffer(channel, &desc);
	if (err)
		return err;

	return __compat_vma_mmap(&desc, vma);

Allowing us to incrementally update this logic, and other logic like it.

Unfortunately, as part of this change, we need to be able to flexibly assign to the VMA descriptor, so have to remove some of the const declarations within the structure.

Also update the VMA tests to reflect the changes.

Cc Alexander Shishkin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Cc Al Viro <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Bodo Stroesser <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Clemens Ladisch <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc David Howells <[email protected]>
Cc Dexuan Cui <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Haiyang Zhang <[email protected]>
Cc Jan Kara <[email protected]>
Cc Jann Horn <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc K. Y. Srinivasan <[email protected]>
Cc Liam Howlett <[email protected]>
Cc Long Li <[email protected]>
Cc Marc Dionne <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
Cc Wei Liu <[email protected]>

---

 include/linux/fs.h              |    3 
 include/linux/mm_types.h        |    4 -
 mm/util.c                       |  117 +++++++++++++++++++++---------
 mm/vma.h                        |    2 
 tools/testing/vma/include/dup.h |   68 +++++++++++------
 5 files changed, 135 insertions(+), 59 deletions(-)
include/linux/fs.h renamed from include/linux/fs.h~mm-allow-handling-of-stacked-mmap_prepare-hooks-in-more-drivers +3 -0
@@ -2058,6 +2058,9 @@ static inline bool can_mmap_file(struct
 	return true;
 }
 
+void compat_set_desc_from_vma(struct vm_area_desc *desc, const struct file *file,
+			      const struct vm_area_struct *vma);
+int __compat_vma_mmap(struct vm_area_desc *desc, struct vm_area_struct *vma);
 int compat_vma_mmap(struct file *file, struct vm_area_struct *vma);
 int __vma_check_mmap_hook(struct vm_area_struct *vma);
 
include/linux/mm_types.h renamed from include/linux/mm_types.h~mm-allow-handling-of-stacked-mmap_prepare-hooks-in-more-drivers +2 -2
@@ -891,8 +891,8 @@ static __always_inline bool vma_flags_em
  */
 struct vm_area_desc {
 	/* Immutable state. */
-	const struct mm_struct *const mm;
-	struct file *const file; /* May vary from vm_file in stacked callers. */
+	struct mm_struct *mm;
+	struct file *file; /* May vary from vm_file in stacked callers. */
 	unsigned long start;
 	unsigned long end;
 
mm/util.c renamed from mm/util.c~mm-allow-handling-of-stacked-mmap_prepare-hooks-in-more-drivers +85 -32

147 lines not on this page · raw message

mm/vma.h renamed from mm/vma.h~mm-allow-handling-of-stacked-mmap_prepare-hooks-in-more-drivers +1 -1
@@ -300,7 +300,7 @@ static inline int vma_iter_store_gfp(str
  * f_op->mmap() but which might have an underlying file system which implements
  * f_op->mmap_prepare().
  */
-static inline void set_vma_from_desc(struct vm_area_struct *vma,
+static inline void compat_set_vma_from_desc(struct vm_area_struct *vma,
 		struct vm_area_desc *desc)
 {
 	/*
tools/testing/vma/include/dup.h renamed from tools/testing/vma/include/dup.h~mm-allow-handling-of-stacked-mmap_prepare-hooks-in-more-drivers +44 -24

102 lines not on this page · raw message

_

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