* [PATCH v1] mm/gup: fix handling of errors from arch_make_folio_accessible() in follow_page_pte()
@ 2025-09-08 9:45 David Hildenbrand
2025-09-09 16:07 ` Claudio Imbrenda
0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2025-09-08 9:45 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, David Hildenbrand, Andrew Morton, Claudio Imbrenda,
Jason Gunthorpe, John Hubbard, Peter Xu, Christian Borntraeger
In case we call arch_make_folio_accessible() and it fails, we would
incorrectly return a value that is "!= 0" to the caller, indicating that
we pinned all requested pages and that the caller can keep going.
follow_page_pte() is not supposed to return error values, but instead
"0" on failure and "1" on success -- we'll clean that up separately.
In case we return "!= 0", the caller will just keep going pinning
more pages. If we happen to pin a page afterwards, we're in trouble,
because we essentially skipped some pages in the requested range.
Staring at the arch_make_folio_accessible() implementation on s390x, I
assume it should actually never really fail unless something unexpected
happens (BUG?). So let's not CC stable and just fix common code to do
the right thing.
Clean up the code a bit now that there is no reason to store the
return value of arch_make_folio_accessible().
Fixes: f28d43636d6f ("mm/gup/writeback: add callbacks for inaccessible pages")
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
mm/gup.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/mm/gup.c b/mm/gup.c
index d27b6b9818a18..c969259d095c9 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2920,12 +2920,9 @@ static int gup_fast_pte_range(pmd_t pmd, pmd_t *pmdp, unsigned long addr,
* see Documentation/core-api/pin_user_pages.rst for
* details.
*/
- if (flags & FOLL_PIN) {
- ret = arch_make_folio_accessible(folio);
- if (ret) {
- gup_put_folio(folio, 1, flags);
- goto pte_unmap;
- }
+ if ((flags & FOLL_PIN) && arch_make_folio_accessible(folio)) {
+ gup_put_folio(folio, 1, flags);
+ goto pte_unmap;
}
folio_set_referenced(folio);
pages[*nr] = page;
--
2.50.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] mm/gup: fix handling of errors from arch_make_folio_accessible() in follow_page_pte()
2025-09-08 9:45 [PATCH v1] mm/gup: fix handling of errors from arch_make_folio_accessible() in follow_page_pte() David Hildenbrand
@ 2025-09-09 16:07 ` Claudio Imbrenda
2025-09-09 16:15 ` David Hildenbrand
0 siblings, 1 reply; 4+ messages in thread
From: Claudio Imbrenda @ 2025-09-09 16:07 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, Andrew Morton, Jason Gunthorpe,
John Hubbard, Peter Xu, Christian Borntraeger
On Mon, 8 Sep 2025 11:45:17 +0200
David Hildenbrand <david@redhat.com> wrote:
> In case we call arch_make_folio_accessible() and it fails, we would
> incorrectly return a value that is "!= 0" to the caller, indicating that
> we pinned all requested pages and that the caller can keep going.
>
> follow_page_pte() is not supposed to return error values, but instead
> "0" on failure and "1" on success -- we'll clean that up separately.
>
> In case we return "!= 0", the caller will just keep going pinning
> more pages. If we happen to pin a page afterwards, we're in trouble,
> because we essentially skipped some pages in the requested range.
>
> Staring at the arch_make_folio_accessible() implementation on s390x, I
> assume it should actually never really fail unless something unexpected
> happens (BUG?). So let's not CC stable and just fix common code to do
> the right thing.
>
> Clean up the code a bit now that there is no reason to store the
> return value of arch_make_folio_accessible().
>
> Fixes: f28d43636d6f ("mm/gup/writeback: add callbacks for inaccessible pages")
Ooops!
thanks for finding and fixing this
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> mm/gup.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/mm/gup.c b/mm/gup.c
> index d27b6b9818a18..c969259d095c9 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -2920,12 +2920,9 @@ static int gup_fast_pte_range(pmd_t pmd, pmd_t *pmdp, unsigned long addr,
> * see Documentation/core-api/pin_user_pages.rst for
> * details.
> */
> - if (flags & FOLL_PIN) {
> - ret = arch_make_folio_accessible(folio);
> - if (ret) {
> - gup_put_folio(folio, 1, flags);
> - goto pte_unmap;
> - }
> + if ((flags & FOLL_PIN) && arch_make_folio_accessible(folio)) {
> + gup_put_folio(folio, 1, flags);
> + goto pte_unmap;
> }
> folio_set_referenced(folio);
> pages[*nr] = page;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] mm/gup: fix handling of errors from arch_make_folio_accessible() in follow_page_pte()
2025-09-09 16:07 ` Claudio Imbrenda
@ 2025-09-09 16:15 ` David Hildenbrand
2025-09-10 8:57 ` Claudio Imbrenda
0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2025-09-09 16:15 UTC (permalink / raw)
To: Claudio Imbrenda
Cc: linux-kernel, linux-mm, Andrew Morton, Jason Gunthorpe,
John Hubbard, Peter Xu, Christian Borntraeger
On 09.09.25 18:07, Claudio Imbrenda wrote:
> On Mon, 8 Sep 2025 11:45:17 +0200
> David Hildenbrand <david@redhat.com> wrote:
>
>> In case we call arch_make_folio_accessible() and it fails, we would
>> incorrectly return a value that is "!= 0" to the caller, indicating that
>> we pinned all requested pages and that the caller can keep going.
>>
>> follow_page_pte() is not supposed to return error values, but instead
>> "0" on failure and "1" on success -- we'll clean that up separately.
>>
>> In case we return "!= 0", the caller will just keep going pinning
>> more pages. If we happen to pin a page afterwards, we're in trouble,
>> because we essentially skipped some pages in the requested range.
>>
>> Staring at the arch_make_folio_accessible() implementation on s390x, I
>> assume it should actually never really fail unless something unexpected
>> happens (BUG?). So let's not CC stable and just fix common code to do
>> the right thing.
>>
>> Clean up the code a bit now that there is no reason to store the
>> return value of arch_make_folio_accessible().
>>
>> Fixes: f28d43636d6f ("mm/gup/writeback: add callbacks for inaccessible pages")
>
> Ooops!
>
> thanks for finding and fixing this
Thanks! Is my assumption correct that this is not stable material?
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] mm/gup: fix handling of errors from arch_make_folio_accessible() in follow_page_pte()
2025-09-09 16:15 ` David Hildenbrand
@ 2025-09-10 8:57 ` Claudio Imbrenda
0 siblings, 0 replies; 4+ messages in thread
From: Claudio Imbrenda @ 2025-09-10 8:57 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, Andrew Morton, Jason Gunthorpe,
John Hubbard, Peter Xu, Christian Borntraeger
On Tue, 9 Sep 2025 18:15:17 +0200
David Hildenbrand <david@redhat.com> wrote:
> On 09.09.25 18:07, Claudio Imbrenda wrote:
> > On Mon, 8 Sep 2025 11:45:17 +0200
> > David Hildenbrand <david@redhat.com> wrote:
> >
> >> In case we call arch_make_folio_accessible() and it fails, we would
> >> incorrectly return a value that is "!= 0" to the caller, indicating that
> >> we pinned all requested pages and that the caller can keep going.
> >>
> >> follow_page_pte() is not supposed to return error values, but instead
> >> "0" on failure and "1" on success -- we'll clean that up separately.
> >>
> >> In case we return "!= 0", the caller will just keep going pinning
> >> more pages. If we happen to pin a page afterwards, we're in trouble,
> >> because we essentially skipped some pages in the requested range.
> >>
> >> Staring at the arch_make_folio_accessible() implementation on s390x, I
> >> assume it should actually never really fail unless something unexpected
> >> happens (BUG?). So let's not CC stable and just fix common code to do
> >> the right thing.
> >>
> >> Clean up the code a bit now that there is no reason to store the
> >> return value of arch_make_folio_accessible().
> >>
> >> Fixes: f28d43636d6f ("mm/gup/writeback: add callbacks for inaccessible pages")
> >
> > Ooops!
> >
> > thanks for finding and fixing this
>
> Thanks! Is my assumption correct that this is not stable material?
>
your assessment looks correct, an error return value can only be caused
by a bug
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-10 8:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-08 9:45 [PATCH v1] mm/gup: fix handling of errors from arch_make_folio_accessible() in follow_page_pte() David Hildenbrand
2025-09-09 16:07 ` Claudio Imbrenda
2025-09-09 16:15 ` David Hildenbrand
2025-09-10 8:57 ` Claudio Imbrenda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox