Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] mm: gup: handle fault retries in __mm_populate()
@ 2026-12-03 15:17 Yeoreum Yun
  2026-12-03 15:17 ` [PATCH 1/3] " Yeoreum Yun
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Yeoreum Yun @ 2026-12-03 15:17 UTC (permalink / raw)
  To: Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm, Jan Kara,
	Josef Bacik, Johannes Weiner, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jann Horn, Pedro Falcato
  Cc: David Hildenbrand, Andrew Morton, Harrison Crosse, Yeoreum Yun

When populating a file mapping whose reads repeatedly fail,
 __mm_populate() can retry the same page indefinitely [1].

On the first fault, filemap_fault() may drop mmap_lock before reading
the page and return VM_FAULT_RETRY without reporting the read error.
__get_user_pages() then returns the number of pages processed, which
may be zero. However, __mm_populate() retries the faulting page without
FOLL_TRIED, allowing this sequence to repeat indefinitely.

This patch series addresses this problem including small cleanup and
based on mm-core/for-next

To: Jason Gunthorpe <jgg@ziepe.ca>
To: John Hubbard <jhubbard@nvidia.com>
To: Peter Xu <peterx@redhat.com>
To: linux-mm@kvack.org
To: Jan Kara <jack@suse.cz>
To: Josef Bacik <josef@toxicpanda.com>
To: Johannes Weiner <hannes@cmpxchg.org>
To: Lorenzo Stoakes <ljs@kernel.org>
To: Liam R. Howlett <liam@infradead.org>
To: Vlastimil Babka <vbabka@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>
To: Michal Hocko <mhocko@suse.com>
To: Jann Horn <jannh@google.com>
To: Pedro Falcato <pfalcato@suse.de>
Cc: David Hildenbrand <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Harrison Crosse <harrison@crosse.dev>

Link: [1] https://lore.kernel.org/all/20261118-mmpop-populate-v1-1-9c561d178d11@crosse.dev/
---
Yeoreum Yun (3):
      mm: gup: handle fault retries in __mm_populate()
      mm: gup: remove unused argument in populate_vma_page_range()
      mm: gup: make mmap_lock acquisition in __mm_populate() killable

 mm/gup.c      | 30 ++++++++++++++++++++++++------
 mm/internal.h |  2 +-
 mm/mmap.c     |  4 ++--
 mm/mprotect.c |  2 +-
 4 files changed, 28 insertions(+), 10 deletions(-)
---
base-commit: c03465593e556e594b4efb1f6cb26565f11dc8b8
change-id: 20261201-infinite_mm_populate-6d659390695d

Best regards,
-- 
Sincerely,
Yeoreum Yun



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/3] mm: gup: handle fault retries in __mm_populate()
  2026-12-03 15:17 [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Yeoreum Yun
@ 2026-12-03 15:17 ` Yeoreum Yun
  2026-12-04  3:23   ` Liam R. Howlett
                     ` (2 more replies)
  2026-12-03 15:17 ` [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range() Yeoreum Yun
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 15+ messages in thread
From: Yeoreum Yun @ 2026-12-03 15:17 UTC (permalink / raw)
  To: Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm, Jan Kara,
	Josef Bacik, Johannes Weiner, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jann Horn, Pedro Falcato
  Cc: David Hildenbrand, Andrew Morton, Harrison Crosse, Yeoreum Yun

When populating a file mapping whose reads repeatedly fail,
__mm_populate() can retry the same page indefinitely.

On the first fault, filemap_fault() may drop mmap_lock before reading
the page and return VM_FAULT_RETRY without reporting the read error.
__get_user_pages() then returns the number of pages processed, which
may be zero. However, __mm_populate() retries the faulting page without
FOLL_TRIED, allowing this sequence to repeat indefinitely.

To address this, track whether __get_user_pages() dropped mmap_lock
After reacquiring the lock and looking up the VMA again, retry a single
page with FOLL_TRIED.

Fixes: 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations")
Co-developed-by: Harrison Crosse <harrison@crosse.dev>
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
 mm/gup.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index ec0bc9920216..d2ff0b667e37 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1886,7 +1886,7 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
 }
 
 /**
- * populate_vma_page_range() -  populate a range of pages in the vma.
+ * __populate_vma_page_range() -  populate a range of pages in the vma.
  * @vma:   target vma
  * @start: start address
  * @end:   end address
@@ -1905,8 +1905,8 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
  * If @locked is non-NULL, it must held for read only and may be
  * released.  If it's released, *@locked will be set to 0.
  */
-long populate_vma_page_range(struct vm_area_struct *vma,
-		unsigned long start, unsigned long end, int *locked)
+static long __populate_vma_page_range(struct vm_area_struct *vma,
+		unsigned long start, unsigned long end, int *locked, bool retry)
 {
 	struct mm_struct *mm = vma->vm_mm;
 	unsigned long nr_pages = (end - start) / PAGE_SIZE;
@@ -1949,8 +1949,10 @@ long populate_vma_page_range(struct vm_area_struct *vma,
 	else
 		gup_flags |= FOLL_FORCE;
 
-	if (locked)
+	if (locked) {
 		gup_flags |= FOLL_UNLOCKABLE;
+		gup_flags |= (retry) ? FOLL_TRIED : 0;
+	}
 
 	/*
 	 * We made sure addr is within a VMA, so the following will
@@ -1962,6 +1964,13 @@ long populate_vma_page_range(struct vm_area_struct *vma,
 	return ret;
 }
 
+
+long populate_vma_page_range(struct vm_area_struct *vma,
+		unsigned long start, unsigned long end, int *locked)
+{
+	return __populate_vma_page_range(vma, start, end, locked, false);
+}
+
 /*
  * faultin_page_range() - populate (prefault) page tables inside the
  *			  given range readable/writable
@@ -2028,10 +2037,12 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
 	struct vm_area_struct *vma = NULL;
 	int locked = 0;
 	long ret = 0;
+	bool tried = false;
 
 	end = start + len;
 
 	for (nstart = start; nstart < end; nstart = nend) {
+		unsigned long populate_end;
 		/*
 		 * We want to fault in pages for [nstart; end) address range.
 		 * Find first corresponding VMA.
@@ -2058,8 +2069,14 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
 		 * Now fault in a range of pages. populate_vma_page_range()
 		 * double checks the vma flags, so that it won't mlock pages
 		 * if the vma was already munlocked.
+		 *
+		 * If we dropped the mmap_lock due to VM_FAULT_RETRY, retry only
+		 * the faulting page with FOLL_TRIED, so the fault handler
+		 * reports errors instead of making us retry forever.
 		 */
-		ret = populate_vma_page_range(vma, nstart, nend, &locked);
+		populate_end = (tried) ? nstart + PAGE_SIZE : nend;
+		ret = __populate_vma_page_range(vma, nstart, populate_end, &locked, tried);
+		tried = !locked;
 		if (ret < 0) {
 			if (ignore_errors) {
 				ret = 0;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range()
  2026-12-03 15:17 [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Yeoreum Yun
  2026-12-03 15:17 ` [PATCH 1/3] " Yeoreum Yun
@ 2026-12-03 15:17 ` Yeoreum Yun
  2026-12-04  3:28   ` Liam R. Howlett
  2026-12-04 15:17   ` sashiko-bot
  2026-12-03 15:17 ` [PATCH 3/3] mm: gup: make mmap_lock acquisition in __mm_populate() killable Yeoreum Yun
  2026-12-04  3:23 ` [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Liam R. Howlett
  3 siblings, 2 replies; 15+ messages in thread
From: Yeoreum Yun @ 2026-12-03 15:17 UTC (permalink / raw)
  To: Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm, Jan Kara,
	Josef Bacik, Johannes Weiner, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jann Horn, Pedro Falcato
  Cc: David Hildenbrand, Andrew Morton, Harrison Crosse, Yeoreum Yun

Current users of populate_vma_page_range() set locked argument as NULL
always. Therefore, remove locked argument from it.

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
 mm/gup.c      | 4 ++--
 mm/internal.h | 2 +-
 mm/mmap.c     | 4 ++--
 mm/mprotect.c | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index d2ff0b667e37..4c0d00c37c21 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1966,9 +1966,9 @@ static long __populate_vma_page_range(struct vm_area_struct *vma,
 
 
 long populate_vma_page_range(struct vm_area_struct *vma,
-		unsigned long start, unsigned long end, int *locked)
+		unsigned long start, unsigned long end)
 {
-	return __populate_vma_page_range(vma, start, end, locked, false);
+	return __populate_vma_page_range(vma, start, end, NULL, false);
 }
 
 /*
diff --git a/mm/internal.h b/mm/internal.h
index 2132dd593b44..6d1dccd03284 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -945,7 +945,7 @@ struct anon_vma *folio_anon_vma(const struct folio *folio);
 #ifdef CONFIG_MMU
 void unmap_mapping_folio(struct folio *folio);
 extern long populate_vma_page_range(struct vm_area_struct *vma,
-		unsigned long start, unsigned long end, int *locked);
+		unsigned long start, unsigned long end);
 extern long faultin_page_range(struct mm_struct *mm, unsigned long start,
 		unsigned long end, bool write, int *locked);
 bool mlock_future_ok(const struct mm_struct *mm, bool is_vma_locked,
diff --git a/mm/mmap.c b/mm/mmap.c
index 7618e72766a5..4b104217a153 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -986,7 +986,7 @@ struct vm_area_struct *find_extend_vma_locked(struct mm_struct *mm, unsigned lon
 	if (expand_stack_locked(prev, addr))
 		return NULL;
 	if (vma_test(prev, VMA_LOCKED_BIT))
-		populate_vma_page_range(prev, addr, prev->vm_end, NULL);
+		populate_vma_page_range(prev, addr, prev->vm_end);
 	return prev;
 }
 #else
@@ -1010,7 +1010,7 @@ struct vm_area_struct *find_extend_vma_locked(struct mm_struct *mm, unsigned lon
 	if (expand_stack_locked(vma, addr))
 		return NULL;
 	if (vma_test(vma, VMA_LOCKED_BIT))
-		populate_vma_page_range(vma, addr, start, NULL);
+		populate_vma_page_range(vma, addr, start);
 	return vma;
 }
 #endif
diff --git a/mm/mprotect.c b/mm/mprotect.c
index e18d4e12fc34..209efa869174 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -851,7 +851,7 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb,
 	if (vma_flags_test(&new_vma_flags, VMA_WRITE_BIT) &&
 	    vma_flags_test(&old_vma_flags, VMA_LOCKED_BIT) &&
 	    !vma_flags_test_any(&old_vma_flags, VMA_WRITE_BIT, VMA_SHARED_BIT))
-		populate_vma_page_range(vma, start, end, NULL);
+		populate_vma_page_range(vma, start, end);
 
 	vm_stat_account(mm, vma_flags_to_legacy(old_vma_flags), -nrpages);
 	newflags = vma_flags_to_legacy(new_vma_flags);

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 3/3] mm: gup: make mmap_lock acquisition in __mm_populate() killable
  2026-12-03 15:17 [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Yeoreum Yun
  2026-12-03 15:17 ` [PATCH 1/3] " Yeoreum Yun
  2026-12-03 15:17 ` [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range() Yeoreum Yun
@ 2026-12-03 15:17 ` Yeoreum Yun
  2026-12-04  3:35   ` Liam R. Howlett
  2026-12-04  3:23 ` [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Liam R. Howlett
  3 siblings, 1 reply; 15+ messages in thread
From: Yeoreum Yun @ 2026-12-03 15:17 UTC (permalink / raw)
  To: Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm, Jan Kara,
	Josef Bacik, Johannes Weiner, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jann Horn, Pedro Falcato
  Cc: David Hildenbrand, Andrew Morton, Harrison Crosse, Yeoreum Yun

__mm_populate() uses mmap_read_lock() to acquire mmap_lock.
If the lock is contended, a task waiting here cannot abort
the wait on a fatal signal.

Use mmap_read_lock_killable() and exit the populate loop if lock
acquisition is interrupted.

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
 mm/gup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/gup.c b/mm/gup.c
index 4c0d00c37c21..65ce0c5a8e02 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2049,7 +2049,8 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
 		 */
 		if (!locked) {
 			locked = 1;
-			mmap_read_lock(mm);
+			if (mmap_read_lock_killable(mm))
+				return -EINTR;
 			vma = find_vma_intersection(mm, nstart, end);
 		} else if (nstart >= vma->vm_end)
 			vma = find_vma_intersection(mm, vma->vm_end, end);

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/3] mm: gup: handle fault retries in __mm_populate()
  2026-12-03 15:17 ` [PATCH 1/3] " Yeoreum Yun
@ 2026-12-04  3:23   ` Liam R. Howlett
  2026-12-04  8:30     ` Yeoreum Yun
  2026-12-04  5:29   ` kernel test robot
  2026-12-04 15:17   ` sashiko-bot
  2 siblings, 1 reply; 15+ messages in thread
From: Liam R. Howlett @ 2026-12-04  3:23 UTC (permalink / raw)
  To: Yeoreum Yun
  Cc: Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm, Jan Kara,
	Josef Bacik, Johannes Weiner, Lorenzo Stoakes, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jann Horn,
	Pedro Falcato, David Hildenbrand, Andrew Morton, Harrison Crosse

On 26/12/03 03:17PM, Yeoreum Yun wrote:
> When populating a file mapping whose reads repeatedly fail,
> __mm_populate() can retry the same page indefinitely.
> 
> On the first fault, filemap_fault() may drop mmap_lock before reading
> the page and return VM_FAULT_RETRY without reporting the read error.
> __get_user_pages() then returns the number of pages processed, which
> may be zero. However, __mm_populate() retries the faulting page without
> FOLL_TRIED, allowing this sequence to repeat indefinitely.
> 
> To address this, track whether __get_user_pages() dropped mmap_lock
> After reacquiring the lock and looking up the VMA again, retry a single
> page with FOLL_TRIED.
> 
> Fixes: 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations")

Cc: Stable ?

> Co-developed-by: Harrison Crosse <harrison@crosse.dev>

You are missing Harrison's signed-off-by here.

> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
> ---
>  mm/gup.c | 27 ++++++++++++++++++++++-----
>  1 file changed, 22 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index ec0bc9920216..d2ff0b667e37 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1886,7 +1886,7 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
>  }
>  
>  /**
> - * populate_vma_page_range() -  populate a range of pages in the vma.
> + * __populate_vma_page_range() -  populate a range of pages in the vma.
>   * @vma:   target vma
>   * @start: start address
>   * @end:   end address

Please add @retry: to the documentation, it'll create a warning for the
docs people otherwise.

> @@ -1905,8 +1905,8 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
>   * If @locked is non-NULL, it must held for read only and may be
>   * released.  If it's released, *@locked will be set to 0.
>   */
> -long populate_vma_page_range(struct vm_area_struct *vma,
> -		unsigned long start, unsigned long end, int *locked)
> +static long __populate_vma_page_range(struct vm_area_struct *vma,
> +		unsigned long start, unsigned long end, int *locked, bool retry)
>  {
>  	struct mm_struct *mm = vma->vm_mm;
>  	unsigned long nr_pages = (end - start) / PAGE_SIZE;
> @@ -1949,8 +1949,10 @@ long populate_vma_page_range(struct vm_area_struct *vma,
>  	else
>  		gup_flags |= FOLL_FORCE;
>  
> -	if (locked)
> +	if (locked) {
>  		gup_flags |= FOLL_UNLOCKABLE;
> +		gup_flags |= (retry) ? FOLL_TRIED : 0;
> +	}

An if statement is longer, but worth it here, imo.

>  
>  	/*
>  	 * We made sure addr is within a VMA, so the following will
> @@ -1962,6 +1964,13 @@ long populate_vma_page_range(struct vm_area_struct *vma,
>  	return ret;
>  }
>  
> +

double blank line.

> +long populate_vma_page_range(struct vm_area_struct *vma,
> +		unsigned long start, unsigned long end, int *locked)
> +{
> +	return __populate_vma_page_range(vma, start, end, locked, false);
> +}
> +
>  /*
>   * faultin_page_range() - populate (prefault) page tables inside the
>   *			  given range readable/writable
> @@ -2028,10 +2037,12 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
>  	struct vm_area_struct *vma = NULL;
>  	int locked = 0;
>  	long ret = 0;
> +	bool tried = false;
>  
>  	end = start + len;
>  
>  	for (nstart = start; nstart < end; nstart = nend) {
> +		unsigned long populate_end;
>  		/*
>  		 * We want to fault in pages for [nstart; end) address range.
>  		 * Find first corresponding VMA.
> @@ -2058,8 +2069,14 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
>  		 * Now fault in a range of pages. populate_vma_page_range()
>  		 * double checks the vma flags, so that it won't mlock pages
>  		 * if the vma was already munlocked.
> +		 *
> +		 * If we dropped the mmap_lock due to VM_FAULT_RETRY, retry only
> +		 * the faulting page with FOLL_TRIED, so the fault handler
> +		 * reports errors instead of making us retry forever.
>  		 */
> -		ret = populate_vma_page_range(vma, nstart, nend, &locked);
> +		populate_end = (tried) ? nstart + PAGE_SIZE : nend;
> +		ret = __populate_vma_page_range(vma, nstart, populate_end, &locked, tried);
> +		tried = !locked;

if the lock is dropped and another thread unmaps or moves the page, the
retry will look up the vma at or after the start address and will hit
the wrong one.

The initial patch saved the retry_addr to avoid this.

>  		if (ret < 0) {
>  			if (ignore_errors) {
>  				ret = 0;
> 
> -- 
> 2.43.0
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 0/3] mm: gup: handle fault retries in __mm_populate()
  2026-12-03 15:17 [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Yeoreum Yun
                   ` (2 preceding siblings ...)
  2026-12-03 15:17 ` [PATCH 3/3] mm: gup: make mmap_lock acquisition in __mm_populate() killable Yeoreum Yun
@ 2026-12-04  3:23 ` Liam R. Howlett
  2026-12-04 19:58   ` Yeoreum Yun
  3 siblings, 1 reply; 15+ messages in thread
From: Liam R. Howlett @ 2026-12-04  3:23 UTC (permalink / raw)
  To: Yeoreum Yun
  Cc: Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm, Jan Kara,
	Josef Bacik, Johannes Weiner, Lorenzo Stoakes, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jann Horn,
	Pedro Falcato, David Hildenbrand, Andrew Morton, Harrison Crosse

On 26/12/03 03:17PM, Yeoreum Yun wrote:
> When populating a file mapping whose reads repeatedly fail,
>  __mm_populate() can retry the same page indefinitely [1].
> 
> On the first fault, filemap_fault() may drop mmap_lock before reading
> the page and return VM_FAULT_RETRY without reporting the read error.
> __get_user_pages() then returns the number of pages processed, which
> may be zero. However, __mm_populate() retries the faulting page without
> FOLL_TRIED, allowing this sequence to repeat indefinitely.
> 
> This patch series addresses this problem including small cleanup and
> based on mm-core/for-next
> 
> To: Jason Gunthorpe <jgg@ziepe.ca>
> To: John Hubbard <jhubbard@nvidia.com>
> To: Peter Xu <peterx@redhat.com>
> To: linux-mm@kvack.org
> To: Jan Kara <jack@suse.cz>
> To: Josef Bacik <josef@toxicpanda.com>
> To: Johannes Weiner <hannes@cmpxchg.org>
> To: Lorenzo Stoakes <ljs@kernel.org>
> To: Liam R. Howlett <liam@infradead.org>
> To: Vlastimil Babka <vbabka@kernel.org>
> To: Mike Rapoport <rppt@kernel.org>
> To: Suren Baghdasaryan <surenb@google.com>
> To: Michal Hocko <mhocko@suse.com>
> To: Jann Horn <jannh@google.com>
> To: Pedro Falcato <pfalcato@suse.de>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Harrison Crosse <harrison@crosse.dev>
> 
> Link: [1] https://lore.kernel.org/all/20261118-mmpop-populate-v1-1-9c561d178d11@crosse.dev/
> ---
> Yeoreum Yun (3):
>       mm: gup: handle fault retries in __mm_populate()
>       mm: gup: remove unused argument in populate_vma_page_range()
>       mm: gup: make mmap_lock acquisition in __mm_populate() killable

What about the test from the previous patches?

> 
>  mm/gup.c      | 30 ++++++++++++++++++++++++------
>  mm/internal.h |  2 +-
>  mm/mmap.c     |  4 ++--
>  mm/mprotect.c |  2 +-
>  4 files changed, 28 insertions(+), 10 deletions(-)
> ---
> base-commit: c03465593e556e594b4efb1f6cb26565f11dc8b8
> change-id: 20261201-infinite_mm_populate-6d659390695d
> 
> Best regards,
> -- 
> Sincerely,
> Yeoreum Yun
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range()
  2026-12-03 15:17 ` [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range() Yeoreum Yun
@ 2026-12-04  3:28   ` Liam R. Howlett
  2026-12-04  8:41     ` Yeoreum Yun
  2026-12-04 15:17   ` sashiko-bot
  1 sibling, 1 reply; 15+ messages in thread
From: Liam R. Howlett @ 2026-12-04  3:28 UTC (permalink / raw)
  To: Yeoreum Yun
  Cc: Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm, Jan Kara,
	Josef Bacik, Johannes Weiner, Lorenzo Stoakes, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jann Horn,
	Pedro Falcato, David Hildenbrand, Andrew Morton, Harrison Crosse

On 26/12/03 03:17PM, Yeoreum Yun wrote:
> Current users of populate_vma_page_range() set locked argument as NULL
> always. Therefore, remove locked argument from it.
> 
> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>

Nit, the argument is used, it's just always passed through as null.

This also sounds like you found an existing issue, but you've removed
the last caller that used to pass a non-NULL argument here.

The code looks good, though.

> ---
>  mm/gup.c      | 4 ++--
>  mm/internal.h | 2 +-
>  mm/mmap.c     | 4 ++--
>  mm/mprotect.c | 2 +-
>  4 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index d2ff0b667e37..4c0d00c37c21 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1966,9 +1966,9 @@ static long __populate_vma_page_range(struct vm_area_struct *vma,
>  
>  
>  long populate_vma_page_range(struct vm_area_struct *vma,
> -		unsigned long start, unsigned long end, int *locked)
> +		unsigned long start, unsigned long end)
>  {
> -	return __populate_vma_page_range(vma, start, end, locked, false);
> +	return __populate_vma_page_range(vma, start, end, NULL, false);
>  }
>  
>  /*
> diff --git a/mm/internal.h b/mm/internal.h
> index 2132dd593b44..6d1dccd03284 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -945,7 +945,7 @@ struct anon_vma *folio_anon_vma(const struct folio *folio);
>  #ifdef CONFIG_MMU
>  void unmap_mapping_folio(struct folio *folio);
>  extern long populate_vma_page_range(struct vm_area_struct *vma,
> -		unsigned long start, unsigned long end, int *locked);
> +		unsigned long start, unsigned long end);
>  extern long faultin_page_range(struct mm_struct *mm, unsigned long start,
>  		unsigned long end, bool write, int *locked);
>  bool mlock_future_ok(const struct mm_struct *mm, bool is_vma_locked,
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 7618e72766a5..4b104217a153 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -986,7 +986,7 @@ struct vm_area_struct *find_extend_vma_locked(struct mm_struct *mm, unsigned lon
>  	if (expand_stack_locked(prev, addr))
>  		return NULL;
>  	if (vma_test(prev, VMA_LOCKED_BIT))
> -		populate_vma_page_range(prev, addr, prev->vm_end, NULL);
> +		populate_vma_page_range(prev, addr, prev->vm_end);
>  	return prev;
>  }
>  #else
> @@ -1010,7 +1010,7 @@ struct vm_area_struct *find_extend_vma_locked(struct mm_struct *mm, unsigned lon
>  	if (expand_stack_locked(vma, addr))
>  		return NULL;
>  	if (vma_test(vma, VMA_LOCKED_BIT))
> -		populate_vma_page_range(vma, addr, start, NULL);
> +		populate_vma_page_range(vma, addr, start);
>  	return vma;
>  }
>  #endif
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index e18d4e12fc34..209efa869174 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -851,7 +851,7 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb,
>  	if (vma_flags_test(&new_vma_flags, VMA_WRITE_BIT) &&
>  	    vma_flags_test(&old_vma_flags, VMA_LOCKED_BIT) &&
>  	    !vma_flags_test_any(&old_vma_flags, VMA_WRITE_BIT, VMA_SHARED_BIT))
> -		populate_vma_page_range(vma, start, end, NULL);
> +		populate_vma_page_range(vma, start, end);
>  
>  	vm_stat_account(mm, vma_flags_to_legacy(old_vma_flags), -nrpages);
>  	newflags = vma_flags_to_legacy(new_vma_flags);
> 
> -- 
> 2.43.0
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/3] mm: gup: make mmap_lock acquisition in __mm_populate() killable
  2026-12-03 15:17 ` [PATCH 3/3] mm: gup: make mmap_lock acquisition in __mm_populate() killable Yeoreum Yun
@ 2026-12-04  3:35   ` Liam R. Howlett
  2026-12-04  8:38     ` Yeoreum Yun
  0 siblings, 1 reply; 15+ messages in thread
From: Liam R. Howlett @ 2026-12-04  3:35 UTC (permalink / raw)
  To: Yeoreum Yun
  Cc: Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm, Jan Kara,
	Josef Bacik, Johannes Weiner, Lorenzo Stoakes, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jann Horn,
	Pedro Falcato, David Hildenbrand, Andrew Morton, Harrison Crosse

On 26/12/03 03:17PM, Yeoreum Yun wrote:
> __mm_populate() uses mmap_read_lock() to acquire mmap_lock.
> If the lock is contended, a task waiting here cannot abort
> the wait on a fatal signal.
> 
> Use mmap_read_lock_killable() and exit the populate loop if lock
> acquisition is interrupted.

You are restating the code here.

> 
> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>


> ---
>  mm/gup.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index 4c0d00c37c21..65ce0c5a8e02 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -2049,7 +2049,8 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
>  		 */
>  		if (!locked) {
>  			locked = 1;

Please move the locked = 1 below the return on the failure of trying to
lock.  It's fine today, but may not always be.

> -			mmap_read_lock(mm);
> +			if (mmap_read_lock_killable(mm))
> +				return -EINTR;
>  			vma = find_vma_intersection(mm, nstart, end);
>  		} else if (nstart >= vma->vm_end)
>  			vma = find_vma_intersection(mm, vma->vm_end, end);
> 
> -- 
> 2.43.0
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/3] mm: gup: handle fault retries in __mm_populate()
  2026-12-03 15:17 ` [PATCH 1/3] " Yeoreum Yun
  2026-12-04  3:23   ` Liam R. Howlett
@ 2026-12-04  5:29   ` kernel test robot
  2026-12-04 15:17   ` sashiko-bot
  2 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2026-12-04  5:29 UTC (permalink / raw)
  To: Yeoreum Yun, Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm,
	Jan Kara, Josef Bacik, Johannes Weiner, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Pedro Falcato
  Cc: oe-kbuild-all, David Hildenbrand, Andrew Morton,
	Linux Memory Management List, Harrison Crosse, Yeoreum Yun

Hi Yeoreum,

kernel test robot noticed the following build warnings:

[auto build test WARNING on c03465593e556e594b4efb1f6cb26565f11dc8b8]

url:    https://github.com/intel-lab-lkp/linux/commits/Yeoreum-Yun/mm-gup-handle-fault-retries-in-__mm_populate/20261203-151717
base:   c03465593e556e594b4efb1f6cb26565f11dc8b8
patch link:    https://lore.kernel.org/r/20261203-infinite_mm_populate-v1-1-da5f1bccb3a2%40arm.com
patch subject: [PATCH 1/3] mm: gup: handle fault retries in __mm_populate()
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261204/20261204131830.EGGhjNXO-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261204/20261204131830.EGGhjNXO-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261204131830.EGGhjNXO-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> Warning: mm/gup.c:1909 function parameter 'retry' not described in '__populate_vma_page_range'
>> Warning: mm/gup.c:1909 function parameter 'retry' not described in '__populate_vma_page_range'

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/3] mm: gup: handle fault retries in __mm_populate()
  2026-12-04  3:23   ` Liam R. Howlett
@ 2026-12-04  8:30     ` Yeoreum Yun
  0 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2026-12-04  8:30 UTC (permalink / raw)
  To: Liam R. Howlett
  Cc: Yeoreum Yun, Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm,
	Jan Kara, Josef Bacik, Johannes Weiner, Lorenzo Stoakes,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jann Horn, Pedro Falcato, David Hildenbrand, Andrew Morton,
	Harrison Crosse

On Thu, Dec 03, 2026 at 10:23:05PM -0500, Liam R. Howlett wrote:
> On 26/12/03 03:17PM, Yeoreum Yun wrote:
> > When populating a file mapping whose reads repeatedly fail,
> > __mm_populate() can retry the same page indefinitely.
> > 
> > On the first fault, filemap_fault() may drop mmap_lock before reading
> > the page and return VM_FAULT_RETRY without reporting the read error.
> > __get_user_pages() then returns the number of pages processed, which
> > may be zero. However, __mm_populate() retries the faulting page without
> > FOLL_TRIED, allowing this sequence to repeat indefinitely.
> > 
> > To address this, track whether __get_user_pages() dropped mmap_lock
> > After reacquiring the lock and looking up the VMA again, retry a single
> > page with FOLL_TRIED.
> > 
> > Fixes: 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations")
> 
> Cc: Stable ?

Ah I missed. Thanks.


> 
> > Co-developed-by: Harrison Crosse <harrison@crosse.dev>
> 
> You are missing Harrison's signed-off-by here.

Yeap. Will do.

> 
> > Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
> > ---
> >  mm/gup.c | 27 ++++++++++++++++++++++-----
> >  1 file changed, 22 insertions(+), 5 deletions(-)
> > 
> > diff --git a/mm/gup.c b/mm/gup.c
> > index ec0bc9920216..d2ff0b667e37 100644
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -1886,7 +1886,7 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
> >  }
> >  
> >  /**
> > - * populate_vma_page_range() -  populate a range of pages in the vma.
> > + * __populate_vma_page_range() -  populate a range of pages in the vma.
> >   * @vma:   target vma
> >   * @start: start address
> >   * @end:   end address
> 
> Please add @retry: to the documentation, it'll create a warning for the
> docs people otherwise.

Okay. Thanks!

> 
> > @@ -1905,8 +1905,8 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
> >   * If @locked is non-NULL, it must held for read only and may be
> >   * released.  If it's released, *@locked will be set to 0.
> >   */
> > -long populate_vma_page_range(struct vm_area_struct *vma,
> > -		unsigned long start, unsigned long end, int *locked)
> > +static long __populate_vma_page_range(struct vm_area_struct *vma,
> > +		unsigned long start, unsigned long end, int *locked, bool retry)
> >  {
> >  	struct mm_struct *mm = vma->vm_mm;
> >  	unsigned long nr_pages = (end - start) / PAGE_SIZE;
> > @@ -1949,8 +1949,10 @@ long populate_vma_page_range(struct vm_area_struct *vma,
> >  	else
> >  		gup_flags |= FOLL_FORCE;
> >  
> > -	if (locked)
> > +	if (locked) {
> >  		gup_flags |= FOLL_UNLOCKABLE;
> > +		gup_flags |= (retry) ? FOLL_TRIED : 0;
> > +	}
> 
> An if statement is longer, but worth it here, imo.
> 
> >  
> >  	/*
> >  	 * We made sure addr is within a VMA, so the following will
> > @@ -1962,6 +1964,13 @@ long populate_vma_page_range(struct vm_area_struct *vma,
> >  	return ret;
> >  }
> >  
> > +
> 
> double blank line.

Grr. Sorry. I'll get rid of it.

> 
> > +long populate_vma_page_range(struct vm_area_struct *vma,
> > +		unsigned long start, unsigned long end, int *locked)
> > +{
> > +	return __populate_vma_page_range(vma, start, end, locked, false);
> > +}
> > +
> >  /*
> >   * faultin_page_range() - populate (prefault) page tables inside the
> >   *			  given range readable/writable
> > @@ -2028,10 +2037,12 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
> >  	struct vm_area_struct *vma = NULL;
> >  	int locked = 0;
> >  	long ret = 0;
> > +	bool tried = false;
> >  
> >  	end = start + len;
> >  
> >  	for (nstart = start; nstart < end; nstart = nend) {
> > +		unsigned long populate_end;
> >  		/*
> >  		 * We want to fault in pages for [nstart; end) address range.
> >  		 * Find first corresponding VMA.
> > @@ -2058,8 +2069,14 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
> >  		 * Now fault in a range of pages. populate_vma_page_range()
> >  		 * double checks the vma flags, so that it won't mlock pages
> >  		 * if the vma was already munlocked.
> > +		 *
> > +		 * If we dropped the mmap_lock due to VM_FAULT_RETRY, retry only
> > +		 * the faulting page with FOLL_TRIED, so the fault handler
> > +		 * reports errors instead of making us retry forever.
> >  		 */
> > -		ret = populate_vma_page_range(vma, nstart, nend, &locked);
> > +		populate_end = (tried) ? nstart + PAGE_SIZE : nend;
> > +		ret = __populate_vma_page_range(vma, nstart, populate_end, &locked, tried);
> > +		tried = !locked;
> 
> if the lock is dropped and another thread unmaps or moves the page, the
> retry will look up the vma at or after the start address and will hit
> the wrong one.
> 
> The initial patch saved the retry_addr to avoid this.

You're right. I handled this in a separate wrapper in an earlier version
(See another attached code), but dropped that handling while simplifying
the code because the wrapper seemed overly complicated.
I'm not sure why I overlooked it...

Anyway, I think we don't need to save the retry_addr. it's enough to clear
tried when it's required like:

@@ -2028,17 +2037,20 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
        struct vm_area_struct *vma = NULL;
        int locked = 0;
        long ret = 0;
+       bool tried = false;

        end = start + len;

        for (nstart = start; nstart < end; nstart = nend) {
+               unsigned long populate_end;
                /*
                 * We want to fault in pages for [nstart; end) address range.
                 * Find first corresponding VMA.
                 */
                if (!locked) {
                        locked = 1;
-                       mmap_read_lock(mm);
+                       if (mmap_read_lock_killable(mm))
+                               return -EINTR;
                        vma = find_vma_intersection(mm, nstart, end);
                } else if (nstart >= vma->vm_end)
                        vma = find_vma_intersection(mm, vma->vm_end, end);
                        vma = find_vma_intersection(mm, nstart, end);
                } else if (nstart >= vma->vm_end)
                        vma = find_vma_intersection(mm, vma->vm_end, end);
@@ -2050,16 +2062,28 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
                 * range with the first VMA. Also, skip undesirable VMA types.
                 */
                nend = min(end, vma->vm_end);
-               if (vma_test_any(vma, VMA_IO_BIT, VMA_PFNMAP_BIT))
+               if (vma_test_any(vma, VMA_IO_BIT, VMA_PFNMAP_BIT)) {
+                       tried = false;
                        continue;
-               if (nstart < vma->vm_start)
+               }
+
+               if (nstart < vma->vm_start) {
+                       tried = false;
                        nstart = vma->vm_start;
+               }
+
                /*
                 * Now fault in a range of pages. populate_vma_page_range()
                 * double checks the vma flags, so that it won't mlock pages
                 * if the vma was already munlocked.
+                *
+                * If we dropped the mmap_lock due to VM_FAULT_RETRY, retry only
+                * the faulting page with FOLL_TRIED, so the fault handler
+                * reports errors instead of making us retry forever.
                 */
-               ret = populate_vma_page_range(vma, nstart, nend, &locked);
+               populate_end = (tried) ? nstart + PAGE_SIZE : nend;
+               ret = __populate_vma_page_range(vma, nstart, populate_end, &locked, tried);
+               tried = !locked;
                if (ret < 0) {
                        if (ignore_errors) {
                                ret = 0;

> 
> >  		if (ret < 0) {
> >  			if (ignore_errors) {
> >  				ret = 0;
> > 
> > -- 
> > 2.43.0
> > 


---------&<--------

mm/gup.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 66 insertions(+), 18 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index d19944c3e7915..8f77b6bf3d34d 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1886,11 +1886,12 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
 }

 /**
- * populate_vma_page_range() -  populate a range of pages in the vma.
+ * __populate_vma_page_range() -  populate a range of pages in the vma.
  * @vma:   target vma
  * @start: start address
  * @end:   end address
  * @locked: whether the mmap_lock is still held
+ * @retry: whether retry or not
  *
  * This takes care of mlocking the pages too if VM_LOCKED is set.
  *
@@ -1905,8 +1906,8 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
  * If @locked is non-NULL, it must held for read only and may be
  * released.  If it's released, *@locked will be set to 0.
  */
-long populate_vma_page_range(struct vm_area_struct *vma,
-               unsigned long start, unsigned long end, int *locked)
+static long __populate_vma_page_range(struct vm_area_struct *vma,
+               unsigned long start, unsigned long end, int *locked, bool retry)
 {
         struct mm_struct *mm = vma->vm_mm;
         unsigned long nr_pages = (end - start) / PAGE_SIZE;
@@ -1949,8 +1950,10 @@ long populate_vma_page_range(struct vm_area_struct *vma,
         else
                 gup_flags |= FOLL_FORCE;

-       if (locked)
+       if (locked) {
                 gup_flags |= FOLL_UNLOCKABLE;
+               gup_flags |= (retry) ? FOLL_TRIED : 0;
+       }

         /*
          * We made sure addr is within a VMA, so the following will
@@ -1962,6 +1965,47 @@ long populate_vma_page_range(struct vm_area_struct *vma,
         return ret;
 }

+static long __populate_vma_page_range_locked(struct vm_area_struct *vma,
+               unsigned long start, unsigned long end, int *locked)
+{
+       struct mm_struct *mm = current->mm;
+       struct vm_area_struct *orig_vma = vma;
+       long ret = 0;
+
+       ret = __populate_vma_page_range(vma, start, end, locked, false);
+       if (ret < 0)
+               return ret;
+
+retry:
+       if (!*locked) {
+               if (mmap_read_lock_killable(mm))
+                       return -EINTR;
+               *locked = 1;
+
+               vma = find_vma_intersection(mm, start, end);
+               if (orig_vma != vma || start < vma->vm_start)
+                       return 0;
+       }
+
+       if (ret)
+               return ret;
+
+       ret = __populate_vma_page_range(vma, start, start + PAGE_SIZE,
+                                       locked, true);
+       if (!*locked) {
+               VM_WARN_ON_ONCE(ret != 0);
+               goto retry;
+       }
+
+       return ret;
+}
+
+long populate_vma_page_range(struct vm_area_struct *vma,
+               unsigned long start, unsigned long end, int *locked)
+{
+       return __populate_vma_page_range(vma, start, end, NULL, false);
+}
+
 /*
  * faultin_page_range() - populate (prefault) page tables inside the
  *                       given range readable/writable
@@ -2027,25 +2071,27 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
         unsigned long end, nstart, nend;
         struct vm_area_struct *vma = NULL;
         int locked = 0;
+       bool renew_vma = 1;
         long ret = 0;

         end = start + len;

+       if (mmap_read_lock_killable(mm))
+               return -EINTR;
+       locked = 1;
+
         for (nstart = start; nstart < end; nstart = nend) {
                 /*
                  * We want to fault in pages for [nstart; end) address range.
                  * Find first corresponding VMA.
                  */
-               if (!locked) {
-                       locked = 1;
-                       if (mmap_read_lock_killable(mm))
-                               return -EINTR;
+               if (renew_vma || nstart >= vma->vm_end) {
                         vma = find_vma_intersection(mm, nstart, end);
-               } else if (nstart >= vma->vm_end)
-                       vma = find_vma_intersection(mm, vma->vm_end, end);
-
+                       renew_vma = 0;
+               }
                 if (!vma)
                         break;
+
                 /*
                  * Set [nstart; nend) to intersection of desired address
                  * range with the first VMA. Also, skip undesirable VMA types.
@@ -2060,14 +2106,16 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
                  * double checks the vma flags, so that it won't mlock pages
                  * if the vma was already munlocked.
                  */
-               ret = populate_vma_page_range(vma, nstart, nend, &locked);
-               if (ret < 0) {
-                       if (ignore_errors) {
-                               ret = 0;
-                               continue;       /* continue at next VMA */
-                       }
-                       break;
+               ret = __populate_vma_page_range_locked(vma, nstart, nend, &locked);
+               if (!ret) {
+                       renew_vma = 1;
+               } else if (ret < 0) {
+                       if (ret == -EINTR || !ignore_errors)
+                               break;
+                       ret = 0;
+                       continue;       /* continue at next VMA */
                 }
+
                 nend = nstart + ret * PAGE_SIZE;
                 ret = 0;
         }

-- 
Sincerely,
Yeoreum Yun


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/3] mm: gup: make mmap_lock acquisition in __mm_populate() killable
  2026-12-04  3:35   ` Liam R. Howlett
@ 2026-12-04  8:38     ` Yeoreum Yun
  0 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2026-12-04  8:38 UTC (permalink / raw)
  To: Liam R. Howlett
  Cc: Yeoreum Yun, Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm,
	Jan Kara, Josef Bacik, Johannes Weiner, Lorenzo Stoakes,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jann Horn, Pedro Falcato, David Hildenbrand, Andrew Morton,
	Harrison Crosse

On Thu, Dec 03, 2026 at 10:35:44PM -0500, Liam R. Howlett wrote:
> On 26/12/03 03:17PM, Yeoreum Yun wrote:
> > __mm_populate() uses mmap_read_lock() to acquire mmap_lock.
> > If the lock is contended, a task waiting here cannot abort
> > the wait on a fatal signal.
> > 
> > Use mmap_read_lock_killable() and exit the populate loop if lock
> > acquisition is interrupted.
> 
> You are restating the code here.

Okay, I'll rephrase it but just allowing a fatal signal to abort
and making the locking behavior consistent with the retry path.

> 
> > 
> > Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
> 
> 
> > ---
> >  mm/gup.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/mm/gup.c b/mm/gup.c
> > index 4c0d00c37c21..65ce0c5a8e02 100644
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -2049,7 +2049,8 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
> >  		 */
> >  		if (!locked) {
> >  			locked = 1;
> 
> Please move the locked = 1 below the return on the failure of trying to
> lock.  It's fine today, but may not always be.

Acked.

> 
> > -			mmap_read_lock(mm);
> > +			if (mmap_read_lock_killable(mm))
> > +				return -EINTR;
> >  			vma = find_vma_intersection(mm, nstart, end);
> >  		} else if (nstart >= vma->vm_end)
> >  			vma = find_vma_intersection(mm, vma->vm_end, end);
> > 
> > -- 
> > 2.43.0
> > 

-- 
Sincerely,
Yeoreum Yun


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range()
  2026-12-04  3:28   ` Liam R. Howlett
@ 2026-12-04  8:41     ` Yeoreum Yun
  0 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2026-12-04  8:41 UTC (permalink / raw)
  To: Liam R. Howlett
  Cc: Yeoreum Yun, Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm,
	Jan Kara, Josef Bacik, Johannes Weiner, Lorenzo Stoakes,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jann Horn, Pedro Falcato, David Hildenbrand, Andrew Morton,
	Harrison Crosse

On Thu, Dec 03, 2026 at 10:28:55PM -0500, Liam R. Howlett wrote:
> On 26/12/03 03:17PM, Yeoreum Yun wrote:
> > Current users of populate_vma_page_range() set locked argument as NULL
> > always. Therefore, remove locked argument from it.
> > 
> > Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
> 
> Nit, the argument is used, it's just always passed through as null.
> 
> This also sounds like you found an existing issue, but you've removed
> the last caller that used to pass a non-NULL argument here.

Okay. I'll reparse the commit message.

> 
> The code looks good, though.

Thanks.

> 
> > ---
> >  mm/gup.c      | 4 ++--
> >  mm/internal.h | 2 +-
> >  mm/mmap.c     | 4 ++--
> >  mm/mprotect.c | 2 +-
> >  4 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/mm/gup.c b/mm/gup.c
> > index d2ff0b667e37..4c0d00c37c21 100644
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -1966,9 +1966,9 @@ static long __populate_vma_page_range(struct vm_area_struct *vma,
> >  
> >  
> >  long populate_vma_page_range(struct vm_area_struct *vma,
> > -		unsigned long start, unsigned long end, int *locked)
> > +		unsigned long start, unsigned long end)
> >  {
> > -	return __populate_vma_page_range(vma, start, end, locked, false);
> > +	return __populate_vma_page_range(vma, start, end, NULL, false);
> >  }
> >  
> >  /*
> > diff --git a/mm/internal.h b/mm/internal.h
> > index 2132dd593b44..6d1dccd03284 100644
> > --- a/mm/internal.h
> > +++ b/mm/internal.h
> > @@ -945,7 +945,7 @@ struct anon_vma *folio_anon_vma(const struct folio *folio);
> >  #ifdef CONFIG_MMU
> >  void unmap_mapping_folio(struct folio *folio);
> >  extern long populate_vma_page_range(struct vm_area_struct *vma,
> > -		unsigned long start, unsigned long end, int *locked);
> > +		unsigned long start, unsigned long end);
> >  extern long faultin_page_range(struct mm_struct *mm, unsigned long start,
> >  		unsigned long end, bool write, int *locked);
> >  bool mlock_future_ok(const struct mm_struct *mm, bool is_vma_locked,
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index 7618e72766a5..4b104217a153 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -986,7 +986,7 @@ struct vm_area_struct *find_extend_vma_locked(struct mm_struct *mm, unsigned lon
> >  	if (expand_stack_locked(prev, addr))
> >  		return NULL;
> >  	if (vma_test(prev, VMA_LOCKED_BIT))
> > -		populate_vma_page_range(prev, addr, prev->vm_end, NULL);
> > +		populate_vma_page_range(prev, addr, prev->vm_end);
> >  	return prev;
> >  }
> >  #else
> > @@ -1010,7 +1010,7 @@ struct vm_area_struct *find_extend_vma_locked(struct mm_struct *mm, unsigned lon
> >  	if (expand_stack_locked(vma, addr))
> >  		return NULL;
> >  	if (vma_test(vma, VMA_LOCKED_BIT))
> > -		populate_vma_page_range(vma, addr, start, NULL);
> > +		populate_vma_page_range(vma, addr, start);
> >  	return vma;
> >  }
> >  #endif
> > diff --git a/mm/mprotect.c b/mm/mprotect.c
> > index e18d4e12fc34..209efa869174 100644
> > --- a/mm/mprotect.c
> > +++ b/mm/mprotect.c
> > @@ -851,7 +851,7 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb,
> >  	if (vma_flags_test(&new_vma_flags, VMA_WRITE_BIT) &&
> >  	    vma_flags_test(&old_vma_flags, VMA_LOCKED_BIT) &&
> >  	    !vma_flags_test_any(&old_vma_flags, VMA_WRITE_BIT, VMA_SHARED_BIT))
> > -		populate_vma_page_range(vma, start, end, NULL);
> > +		populate_vma_page_range(vma, start, end);
> >  
> >  	vm_stat_account(mm, vma_flags_to_legacy(old_vma_flags), -nrpages);
> >  	newflags = vma_flags_to_legacy(new_vma_flags);
> > 
> > -- 
> > 2.43.0
> > 

-- 
Sincerely,
Yeoreum Yun


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/3] mm: gup: handle fault retries in __mm_populate()
  2026-12-03 15:17 ` [PATCH 1/3] " Yeoreum Yun
  2026-12-04  3:23   ` Liam R. Howlett
  2026-12-04  5:29   ` kernel test robot
@ 2026-12-04 15:17   ` sashiko-bot
  2 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-12-04 15:17 UTC (permalink / raw)
  To: Yeoreum Yun, Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm,
	Jan Kara, Josef Bacik, Johannes Weiner, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Pedro Falcato
  Cc: David Hildenbrand, Andrew Morton, Harrison Crosse

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] mm: missing Signed-off-by trailer for Co-developed-by co-author
- [Medium] mm: stale tried flag in __mm_populate() leaks FOLL_TRIED to
  next VMA
- [Medium] mm: __mm_populate() flushes LRU batches after every 1-page
  retry
- [Low] mm: missing kernel-doc for retry param in
  __populate_vma_page_range()
--

commit d410414cbb98de6eb94b0fba36ff0f79882dcf4e
Author: Yeoreum Yun <yeoreum.yun@arm.com>

> mm: gup: handle fault retries in __mm_populate()
>
> When populating a file mapping whose reads repeatedly fail,
> __mm_populate() can retry the same page indefinitely.
>
> On the first fault, filemap_fault() may drop mmap_lock before reading
> the page and return VM_FAULT_RETRY without reporting the read error.
> __get_user_pages() then returns the number of pages processed, which
> may be zero. However, __mm_populate() retries the faulting page without
> FOLL_TRIED, allowing this sequence to repeat indefinitely.
>
> To address this, track whether __get_user_pages() dropped mmap_lock
> After reacquiring the lock and looking up the VMA again, retry a single
> page with FOLL_TRIED.
>
> Fixes: 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations")
> Co-developed-by: Harrison Crosse <harrison@crosse.dev>
> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>

[Severity: High]
Co-developed-by: Harrison Crosse <harrison@crosse.dev> is missing a
matching Signed-off-by trailer.  Per
Documentation/process/submitting-patches.rst, every Co-developed-by tag
must be immediately followed by a Signed-off-by from that co-author.

> diff --git a/mm/gup.c b/mm/gup.c
> index ec0bc99202169..d2ff0b667e377 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1886,7 +1886,7 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
>  }
>  
>  /**
> - * populate_vma_page_range() -  populate a range of pages in the vma.
> + * __populate_vma_page_range() -  populate a range of pages in the vma.
>   * @vma:   target vma
>   * @start: start address
>   * @end:   end address
> @@ -1905,8 +1905,8 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
>   * If @locked is non-NULL, it must held for read only and may be
>   * released.  If it's released, *@locked will be set to 0.
>   */
> -long populate_vma_page_range(struct vm_area_struct *vma,
> -		unsigned long start, unsigned long end, int *locked)
> +static long __populate_vma_page_range(struct vm_area_struct *vma,
> +		unsigned long start, unsigned long end, int *locked, bool retry)
>  {

[Severity: Low]
The kernel-doc comment for __populate_vma_page_range() does not document
the new @retry parameter, which triggers a warning under make W=1 /
scripts/kernel-doc.

[ ... ]

> @@ -2058,8 +2069,14 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
>  		 * Now fault in a range of pages. populate_vma_page_range()
>  		 * double checks the vma flags, so that it won't mlock pages
>  		 * if the vma was already munlocked.
> +		 *
> +		 * If we dropped the mmap_lock due to VM_FAULT_RETRY, retry only
> +		 * the faulting page with FOLL_TRIED, so the fault handler
> +		 * reports errors instead of making us retry forever.
>  		 */
> -		ret = populate_vma_page_range(vma, nstart, nend, &locked);
> +		populate_end = (tried) ? nstart + PAGE_SIZE : nend;
> +		ret = __populate_vma_page_range(vma, nstart, populate_end, &locked, tried);
> +		tried = !locked;
>  		if (ret < 0) {
>  			if (ignore_errors) {
>  				ret = 0;

[Severity: Medium]
Can tried stay true when __mm_populate() moves on to a different address
or VMA?

After __populate_vma_page_range() drops mmap_read_lock, another thread
can unmap the faulting VMA or replace it with a VM_IO/VM_PFNMAP VMA.  On
the next iteration, __mm_populate() advances past the faulting address
without clearing tried:

mm/gup.c:__mm_populate() {
    ...
	if (vma_test_any(vma, VMA_IO_BIT, VMA_PFNMAP_BIT))
		continue;
	if (nstart < vma->vm_start)
		nstart = vma->vm_start;
    ...
}

The first fault on the next VMA then runs with FOLL_TRIED
(FAULT_FLAG_TRIED), so maybe_unlock_mmap_for_io() keeps mmap_read_lock
held across blocking file I/O and mm_account_fault() accounts it as a
major fault.  Resetting tried = false in both branches would avoid
leaking retry state across addresses.

[Severity: Medium]
Does clamping the retry to a single page cause a performance regression
by flushing LRU batches after every 1-page retry?

__populate_vma_page_range() unconditionally calls lru_add_drain() before
returning.  The next iteration then re-enters __populate_vma_page_range()
for [nstart + PAGE_SIZE, nend) under the same mmap_read_lock, repeating
gup_vma_lookup().

During mlock() on swapped-out memory or MAP_POPULATE on a writable
MAP_PRIVATE mapping, the 1-page retry queues one folio into mlock_fbatch
or cpu_fbatches.lru_add, and lru_add_drain() immediately takes
lruvec->lru_lock with IRQs disabled to flush it instead of batching.

Hoisting lru_add_drain() out of __populate_vma_page_range() to
populate_vma_page_range() and once at the end of __mm_populate(),
matching faultin_page_range(), would avoid draining 1-folio batches on
retries.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-infinite_mm_populate-v1-0-da5f1bccb3a2@arm.com?part=1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range()
  2026-12-03 15:17 ` [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range() Yeoreum Yun
  2026-12-04  3:28   ` Liam R. Howlett
@ 2026-12-04 15:17   ` sashiko-bot
  1 sibling, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-12-04 15:17 UTC (permalink / raw)
  To: Yeoreum Yun, Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm,
	Jan Kara, Josef Bacik, Johannes Weiner, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Pedro Falcato
  Cc: David Hildenbrand, Andrew Morton, Harrison Crosse

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mm: missing retry parameter in __populate_vma_page_range()
  kernel-doc
--

commit 2709f07a148327588fa4049cd5dfd07e980cd0f9
Author: Yeoreum Yun <yeoreum.yun@arm.com>

mm: gup: remove unused argument in populate_vma_page_range()

This commit removes the unused locked parameter from
populate_vma_page_range() and updates its callers in mm/mmap.c and
mm/mprotect.c to match, passing NULL directly to
__populate_vma_page_range().

> diff --git a/mm/gup.c b/mm/gup.c
> index d2ff0b667e377..4c0d00c37c21d 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1966,9 +1966,9 @@ static long __populate_vma_page_range(struct vm_area_struct *vma,
>  
>  
>  long populate_vma_page_range(struct vm_area_struct *vma,
> -		unsigned long start, unsigned long end, int *locked)
> +		unsigned long start, unsigned long end)
>  {
> -	return __populate_vma_page_range(vma, start, end, locked, false);
> +	return __populate_vma_page_range(vma, start, end, NULL, false);
>  }

[Severity: Low]
Should the kernel-doc comment on __populate_vma_page_range() also document
the @retry parameter, or drop the /** marker since it is static?

Commit "mm: gup: handle fault retries in __mm_populate()" renamed the
kernel-doc block to __populate_vma_page_range() and added bool retry to
its signature, but left @retry out of the parameter list.  This triggers a
scripts/kernel-doc parameter mismatch warning on W=1 builds.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-infinite_mm_populate-v1-0-da5f1bccb3a2@arm.com?part=2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 0/3] mm: gup: handle fault retries in __mm_populate()
  2026-12-04  3:23 ` [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Liam R. Howlett
@ 2026-12-04 19:58   ` Yeoreum Yun
  0 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2026-12-04 19:58 UTC (permalink / raw)
  To: Liam R. Howlett
  Cc: Yeoreum Yun, Jason Gunthorpe, John Hubbard, Peter Xu, linux-mm,
	Jan Kara, Josef Bacik, Johannes Weiner, Lorenzo Stoakes,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Jann Horn, Pedro Falcato, David Hildenbrand, Andrew Morton,
	Harrison Crosse

On Thu, Dec 03, 2026 at 10:23:50PM -0500, Liam R. Howlett wrote:
> On 26/12/03 03:17PM, Yeoreum Yun wrote:
> > When populating a file mapping whose reads repeatedly fail,
> >  __mm_populate() can retry the same page indefinitely [1].
> > 
> > On the first fault, filemap_fault() may drop mmap_lock before reading
> > the page and return VM_FAULT_RETRY without reporting the read error.
> > __get_user_pages() then returns the number of pages processed, which
> > may be zero. However, __mm_populate() retries the faulting page without
> > FOLL_TRIED, allowing this sequence to repeat indefinitely.
> > 
> > This patch series addresses this problem including small cleanup and
> > based on mm-core/for-next
> > 
> > To: Jason Gunthorpe <jgg@ziepe.ca>
> > To: John Hubbard <jhubbard@nvidia.com>
> > To: Peter Xu <peterx@redhat.com>
> > To: linux-mm@kvack.org
> > To: Jan Kara <jack@suse.cz>
> > To: Josef Bacik <josef@toxicpanda.com>
> > To: Johannes Weiner <hannes@cmpxchg.org>
> > To: Lorenzo Stoakes <ljs@kernel.org>
> > To: Liam R. Howlett <liam@infradead.org>
> > To: Vlastimil Babka <vbabka@kernel.org>
> > To: Mike Rapoport <rppt@kernel.org>
> > To: Suren Baghdasaryan <surenb@google.com>
> > To: Michal Hocko <mhocko@suse.com>
> > To: Jann Horn <jannh@google.com>
> > To: Pedro Falcato <pfalcato@suse.de>
> > Cc: David Hildenbrand <david@kernel.org>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: Harrison Crosse <harrison@crosse.dev>
> > 
> > Link: [1] https://lore.kernel.org/all/20261118-mmpop-populate-v1-1-9c561d178d11@crosse.dev/
> > ---
> > Yeoreum Yun (3):
> >       mm: gup: handle fault retries in __mm_populate()
> >       mm: gup: remove unused argument in populate_vma_page_range()
> >       mm: gup: make mmap_lock acquisition in __mm_populate() killable
> 
> What about the test from the previous patches?

Ah. I forgot it, I'll include it as-is in next spin.

> 
> > 
> >  mm/gup.c      | 30 ++++++++++++++++++++++++------
> >  mm/internal.h |  2 +-
> >  mm/mmap.c     |  4 ++--
> >  mm/mprotect.c |  2 +-
> >  4 files changed, 28 insertions(+), 10 deletions(-)
> > ---
> > base-commit: c03465593e556e594b4efb1f6cb26565f11dc8b8
> > change-id: 20261201-infinite_mm_populate-6d659390695d
> > 
> > Best regards,
> > -- 
> > Sincerely,
> > Yeoreum Yun
> > 
> 

-- 
Sincerely,
Yeoreum Yun


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-12-04 19:58 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 15:17 [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Yeoreum Yun
2026-12-03 15:17 ` [PATCH 1/3] " Yeoreum Yun
2026-12-04  3:23   ` Liam R. Howlett
2026-12-04  8:30     ` Yeoreum Yun
2026-12-04  5:29   ` kernel test robot
2026-12-04 15:17   ` sashiko-bot
2026-12-03 15:17 ` [PATCH 2/3] mm: gup: remove unused argument in populate_vma_page_range() Yeoreum Yun
2026-12-04  3:28   ` Liam R. Howlett
2026-12-04  8:41     ` Yeoreum Yun
2026-12-04 15:17   ` sashiko-bot
2026-12-03 15:17 ` [PATCH 3/3] mm: gup: make mmap_lock acquisition in __mm_populate() killable Yeoreum Yun
2026-12-04  3:35   ` Liam R. Howlett
2026-12-04  8:38     ` Yeoreum Yun
2026-12-04  3:23 ` [PATCH 0/3] mm: gup: handle fault retries in __mm_populate() Liam R. Howlett
2026-12-04 19:58   ` Yeoreum Yun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox