[PATCH v2 1/2] mm: gup: move pmd_protnone() into gup_fast_pmd_leaf()

Aristeu Rozanski <[email protected]> Tue, 04 Aug 2026 23:58:48 -0400
Newsgroups org.kvack.linux-mm
Message-ID <[email protected]>
Make pmd handling match pud handling by calling pmd_protnone()
inside gup_fast_pmd_leaf().

Suggested-by: David Hildenbrand <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/T/#u
Cc: Andrew Morton <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Jason Gunthorpe <[email protected]>
Cc: John Hubbard <[email protected]>
Cc: Peter Xu <[email protected]>
Signed-off-by: Aristeu Rozanski <[email protected]>

---
 mm/gup.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/mm/gup.c	2026-02-17 23:14:22.288234753 -0500
+++ b/mm/gup.c	2026-02-17 23:31:36.522625385 -0500
@@ -2929,6 +2929,10 @@ static int gup_fast_pmd_leaf(pmd_t orig,
 	struct folio *folio;
 	int refs;
 
+	/* See gup_fast_pte_range() */
+	if (pmd_protnone(orig))
+		return 0;
+
 	if (!pmd_access_permitted(orig, flags & FOLL_WRITE))
 		return 0;
 
@@ -3024,10 +3028,6 @@ static int gup_fast_pmd_range(pud_t *pud
 			return 0;
 
 		if (unlikely(pmd_leaf(pmd))) {
-			/* See gup_fast_pte_range() */
-			if (pmd_protnone(pmd))
-				return 0;
-
 			if (!gup_fast_pmd_leaf(pmd, pmdp, addr, next, flags,
 				pages, nr))
 				return 0;