Skip to contentSkip to conversation

mm-have-mmap_action_complete-handle-the-rmap-lock-and-unmap.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: have mmap_action_complete() handle the rmap lock and unmap
has been removed from the -mm tree. Its filename was
mm-have-mmap_action_complete-handle-the-rmap-lock-and-unmap.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: have mmap_action_complete() handle the rmap lock and unmap
Date: Fri, 20 Mar 2026 22:39:33 +0000

Rather than have the callers handle this both the rmap lock release and unmapping the VMA on error, handle it within the mmap_action_complete() logic where it makes sense to, being careful not to unlock twice.

This simplifies the logic and makes it harder to make mistake with this, while retaining correct behaviour with regard to avoiding deadlocks.

Also replace the call_action_complete() function with a direct invocation of mmap_action_complete() as the abstraction is no longer required.

Also update the VMA tests to reflect this change.

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]>

---

 mm/internal.h                   |   19 +++++++++++++
 mm/util.c                       |   41 +++++++++++++-----------------
 mm/vma.c                        |   26 -------------------
 tools/testing/vma/include/dup.h |    8 -----
 4 files changed, 40 insertions(+), 54 deletions(-)
mm/internal.h renamed from mm/internal.h~mm-have-mmap_action_complete-handle-the-rmap-lock-and-unmap +19 -0
@@ -1863,6 +1863,25 @@ static inline int io_remap_pfn_range_pre
 	return 0;
 }
 
+/*
+ * When we succeed an mmap action or just before we unmap a VMA on error, we
+ * need to ensure any rmap lock held is released. On unmap it's required to
+ * avoid a deadlock.
+ */
+static inline void maybe_rmap_unlock_action(struct vm_area_struct *vma,
+		struct mmap_action *action)
+{
+	struct file *file;
+
+	if (!action->hide_from_rmap_until_complete)
+		return;
+
+	VM_WARN_ON_ONCE(vma_is_anonymous(vma));
+	file = vma->vm_file;
+	i_mmap_unlock_write(file->f_mapping);
+	action->hide_from_rmap_until_complete = false;
+}
+
 #ifdef CONFIG_MMU_NOTIFIER
 static inline bool clear_flush_young_ptes_notify(struct vm_area_struct *vma,
 		unsigned long addr, pte_t *ptep, unsigned int nr)
mm/util.c renamed from mm/util.c~mm-have-mmap_action_complete-handle-the-rmap-lock-and-unmap +19 -22

65 lines not on this page · raw message

mm/vma.c renamed from mm/vma.c~mm-have-mmap_action_complete-handle-the-rmap-lock-and-unmap +1 -25
@@ -2729,30 +2729,6 @@ static bool can_set_ksm_flags_early(stru
 	return false;
 }
 
-static int call_action_complete(struct mmap_state *map,
-				struct mmap_action *action,
-				struct vm_area_struct *vma)
-{
-	int err;
-
-	err = mmap_action_complete(vma, action);
-
-	/* If we held the file rmap we need to release it. */
-	if (action->hide_from_rmap_until_complete) {
-		struct file *file = vma->vm_file;
-
-		i_mmap_unlock_write(file->f_mapping);
-	}
-
-	if (err) {
-		const size_t len = vma_pages(vma) << PAGE_SHIFT;
-
-		do_munmap(current->mm, vma->vm_start, len, NULL);
-	}
-
-	return err;
-}
-
 static unsigned long __mmap_region(struct file *file, unsigned long addr,
 		unsigned long len, vma_flags_t vma_flags,
 		unsigned long pgoff, struct list_head *uf)
@@ -2804,7 +2780,7 @@ static unsigned long __mmap_region(struc
 	__mmap_complete(&map, vma);
 
 	if (have_mmap_prepare && allocated_new) {
-		error = call_action_complete(&map, &desc.action, vma);
+		error = mmap_action_complete(vma, &desc.action);
 
 		if (error)
 			return error;
tools/testing/vma/include/dup.h renamed from tools/testing/vma/include/dup.h~mm-have-mmap_action_complete-handle-the-rmap-lock-and-unmap +1 -7
@@ -1300,13 +1300,7 @@ static inline int compat_vma_mmap(struct
 	action->hide_from_rmap_until_complete = false;
 
 	set_vma_from_desc(vma, &desc);
-	err = mmap_action_complete(vma, action);
-	if (err) {
-		const size_t len = vma_pages(vma) << PAGE_SHIFT;
-
-		do_munmap(current->mm, vma->vm_start, len, NULL);
-	}
-	return err;
+	return mmap_action_complete(vma, action);
 }
 
 static inline void vma_iter_init(struct vma_iterator *vmi,

_

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