Skip to contentSkip to conversation

mm-madvise-drop-range-checks-in-madvise_free_single_vma.patch removed from -mm tree

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

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/madvise: drop range checks in madvise_free_single_vma()
has been removed from the -mm tree. Its filename was
mm-madvise-drop-range-checks-in-madvise_free_single_vma.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: "David Hildenbrand (Arm)" <[email protected]>
Subject: mm/madvise: drop range checks in madvise_free_single_vma()
Date: Fri, 27 Feb 2026 21:08:32 +0100

Patch series "mm: cleanups around unmapping / zapping".

A bunch of cleanups around unmapping and zapping. Mostly simplifications, code movements, documentation and renaming of zapping functions.

With this series, we'll have the following high-level zap/unmap functions (excluding high-level folio zapping):
* unmap_vmas() for actual unmapping (vmas will go away)
* zap_vma(): zap all page table entries in a vma
* zap_vma_for_reaping(): zap_vma() that must not block
* zap_vma_range(): zap a range of page table entries
* zap_vma_range_batched(): zap_vma_range() with more options and batching
* zap_special_vma_range(): limited zap_vma_range() for modules
* __zap_vma_range(): internal helper

Patch #1 is not about unmapping/zapping, but I stumbled over it while verifying MADV_DONTNEED range handling.

Patch #16 is related to [1], but makes sense even independent of that.

This patch (of 16):

madvise_vma_behavior()-> madvise_dontneed_free()->madvise_free_single_vma() is only called from madvise_walk_vmas()

(a) After try_vma_read_lock() confirmed that the whole range falls into a single VMA (see is_vma_lock_sufficient()).

(b) After adjusting the range to the VMA in the loop afterwards.

madvise_dontneed_free() might drop the MM lock when handling userfaultfd, but it properly looks up the VMA again to adjust the range.

So in madvise_free_single_vma(), the given range should always fall into a single VMA and should also span at least one page.

Let's drop the error checks.

The code now matches what we do in madvise_dontneed_single_vma(), where we call zap_vma_range_batched() that documents: "The range must fit into one VMA.". Although that function still adjusts that range, we'll change that soon.

Cc Alexander Gordeev <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Alice Ryhl <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc "Borislav Petkov (AMD)" <[email protected]>
Cc Carlos Llamas <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Claudio Imbrenda <[email protected]>
Cc Daniel Borkman <[email protected]>
Cc Dave Airlie <[email protected]>
Cc David Ahern <[email protected]>
Cc David Rientjes <[email protected]>
Cc David S. Miller <[email protected]>
Cc Dimitri Sivanich <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Gerald Schaefer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hartley Sweeten <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Ian Abbott <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jakub Kacinski <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Jann Horn <[email protected]>
Cc Janosch Frank <[email protected]>
Cc Jarkko Sakkinen <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Jonas Lahtinen <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Liam Howlett <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Namhyung kim <[email protected]>
Cc Neal Cardwell <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Vasily Gorbik <[email protected]>
Cc Vincenzo Frascino <[email protected]>

---

 mm/madvise.c |   13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
mm/madvise.c renamed from mm/madvise.c~mm-madvise-drop-range-checks-in-madvise_free_single_vma +4 -9
@@ -799,9 +799,10 @@ static int madvise_free_single_vma(struc
 {
 	struct mm_struct *mm = madv_behavior->mm;
 	struct vm_area_struct *vma = madv_behavior->vma;
-	unsigned long start_addr = madv_behavior->range.start;
-	unsigned long end_addr = madv_behavior->range.end;
-	struct mmu_notifier_range range;
+	struct mmu_notifier_range range = {
+		.start = madv_behavior->range.start,
+		.end = madv_behavior->range.end,
+	};
 	struct mmu_gather *tlb = madv_behavior->tlb;
 	struct mm_walk_ops walk_ops = {
 		.pmd_entry		= madvise_free_pte_range,
@@ -811,12 +812,6 @@ static int madvise_free_single_vma(struc
 	if (!vma_is_anonymous(vma))
 		return -EINVAL;
 
-	range.start = max(vma->vm_start, start_addr);
-	if (range.start >= vma->vm_end)
-		return -EINVAL;
-	range.end = min(vma->vm_end, end_addr);
-	if (range.end <= vma->vm_start)
-		return -EINVAL;
 	mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm,
 				range.start, range.end);
 

_

Patches currently in -mm which might be from [email protected] are