* [PATCH] mm/gup.c: Fix return value for __gup_longterm_locked()
@ 2022-08-21 18:35 Shigeru Yoshida
2022-08-22 0:14 ` John Hubbard
0 siblings, 1 reply; 3+ messages in thread
From: Shigeru Yoshida @ 2022-08-21 18:35 UTC (permalink / raw)
To: akpm
Cc: linux-mm, linux-kernel, Shigeru Yoshida, Alistair Popple,
syzbot+616ff0452fec30f4dcfd
__get_user_pages_locked() may return the number of pages less than
nr_pages. So __gup_longterm_locked() have to return the number of
pages __get_user_pages_locked() returns if it succeeded, not nr_pages
passed.
Fixes: 61c63c2076d9 (mm/gup.c: simplify and fix check_and_migrate_movable_pages() return codes)
CC: Alistair Popple <apopple@nvidia.com>
Reported-by: syzbot+616ff0452fec30f4dcfd@syzkaller.appspotmail.com
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
---
mm/gup.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/mm/gup.c b/mm/gup.c
index 5aa7531a703b..542cf74c59b0 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2068,22 +2068,22 @@ static long __gup_longterm_locked(struct mm_struct *mm,
unsigned int gup_flags)
{
unsigned int flags;
- long rc;
+ long rc, nr_pinned_pages;
if (!(gup_flags & FOLL_LONGTERM))
return __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
NULL, gup_flags);
flags = memalloc_pin_save();
do {
- rc = __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
- NULL, gup_flags);
- if (rc <= 0)
+ nr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
+ NULL, gup_flags);
+ if (nr_pinned_pages <= 0)
break;
- rc = check_and_migrate_movable_pages(rc, pages, gup_flags);
+ rc = check_and_migrate_movable_pages(nr_pinned_pages, pages, gup_flags);
} while (rc == -EAGAIN);
memalloc_pin_restore(flags);
- return rc ? rc : nr_pages;
+ return rc ? rc : nr_pinned_pages;
}
static bool is_valid_gup_flags(unsigned int gup_flags)
--
2.37.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/gup.c: Fix return value for __gup_longterm_locked()
2022-08-21 18:35 [PATCH] mm/gup.c: Fix return value for __gup_longterm_locked() Shigeru Yoshida
@ 2022-08-22 0:14 ` John Hubbard
2022-08-22 15:23 ` Shigeru Yoshida
0 siblings, 1 reply; 3+ messages in thread
From: John Hubbard @ 2022-08-22 0:14 UTC (permalink / raw)
To: Shigeru Yoshida, akpm
Cc: linux-mm, linux-kernel, Alistair Popple, syzbot+616ff0452fec30f4dcfd
On 8/21/22 11:35, Shigeru Yoshida wrote:
> __get_user_pages_locked() may return the number of pages less than
> nr_pages. So __gup_longterm_locked() have to return the number of
> pages __get_user_pages_locked() returns if it succeeded, not nr_pages
> passed.
s/passed/requested/
>
> Fixes: 61c63c2076d9 (mm/gup.c: simplify and fix check_and_migrate_movable_pages() return codes)
> CC: Alistair Popple <apopple@nvidia.com>
> Reported-by: syzbot+616ff0452fec30f4dcfd@syzkaller.appspotmail.com
> Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
> ---
> mm/gup.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
(with a couple of nits about line length, below)
>
> diff --git a/mm/gup.c b/mm/gup.c
> index 5aa7531a703b..542cf74c59b0 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -2068,22 +2068,22 @@ static long __gup_longterm_locked(struct mm_struct *mm,
> unsigned int gup_flags)
> {
> unsigned int flags;
> - long rc;
> + long rc, nr_pinned_pages;
>
> if (!(gup_flags & FOLL_LONGTERM))
> return __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
> NULL, gup_flags);
> flags = memalloc_pin_save();
> do {
> - rc = __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
> - NULL, gup_flags);
> - if (rc <= 0)
> + nr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
> + NULL, gup_flags);
Can you please wrap at 80 cols, though?
> + if (nr_pinned_pages <= 0)
> break;
> - rc = check_and_migrate_movable_pages(rc, pages, gup_flags);
> + rc = check_and_migrate_movable_pages(nr_pinned_pages, pages, gup_flags);
Also here.
> } while (rc == -EAGAIN);
> memalloc_pin_restore(flags);
>
> - return rc ? rc : nr_pages;
> + return rc ? rc : nr_pinned_pages;
> }
>
> static bool is_valid_gup_flags(unsigned int gup_flags)
thanks,
--
John Hubbard
NVIDIA
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/gup.c: Fix return value for __gup_longterm_locked()
2022-08-22 0:14 ` John Hubbard
@ 2022-08-22 15:23 ` Shigeru Yoshida
0 siblings, 0 replies; 3+ messages in thread
From: Shigeru Yoshida @ 2022-08-22 15:23 UTC (permalink / raw)
To: John Hubbard
Cc: akpm, linux-mm, linux-kernel, Alistair Popple,
syzbot+616ff0452fec30f4dcfd
[-- Attachment #1: Type: text/plain, Size: 2489 bytes --]
On Mon, Aug 22, 2022 at 9:14 AM John Hubbard <jhubbard@nvidia.com> wrote:
> On 8/21/22 11:35, Shigeru Yoshida wrote:
> > __get_user_pages_locked() may return the number of pages less than
> > nr_pages. So __gup_longterm_locked() have to return the number of
> > pages __get_user_pages_locked() returns if it succeeded, not nr_pages
> > passed.
>
> s/passed/requested/
>
> >
> > Fixes: 61c63c2076d9 (mm/gup.c: simplify and fix
> check_and_migrate_movable_pages() return codes)
> > CC: Alistair Popple <apopple@nvidia.com>
> > Reported-by: syzbot+616ff0452fec30f4dcfd@syzkaller.appspotmail.com
> > Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
> > ---
> > mm/gup.c | 12 ++++++------
> > 1 file changed, 6 insertions(+), 6 deletions(-)
>
> Reviewed-by: John Hubbard <jhubbard@nvidia.com>
>
Hi John,
Thank you so much for your review.
I'll send v2 patch.
Shigeru
>
> (with a couple of nits about line length, below)
>
> >
> > diff --git a/mm/gup.c b/mm/gup.c
> > index 5aa7531a703b..542cf74c59b0 100644
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -2068,22 +2068,22 @@ static long __gup_longterm_locked(struct
> mm_struct *mm,
> > unsigned int gup_flags)
> > {
> > unsigned int flags;
> > - long rc;
> > + long rc, nr_pinned_pages;
> >
> > if (!(gup_flags & FOLL_LONGTERM))
> > return __get_user_pages_locked(mm, start, nr_pages, pages,
> vmas,
> > NULL, gup_flags);
> > flags = memalloc_pin_save();
> > do {
> > - rc = __get_user_pages_locked(mm, start, nr_pages, pages,
> vmas,
> > - NULL, gup_flags);
> > - if (rc <= 0)
> > + nr_pinned_pages = __get_user_pages_locked(mm, start,
> nr_pages, pages, vmas,
> > + NULL, gup_flags);
>
> Can you please wrap at 80 cols, though?
>
> > + if (nr_pinned_pages <= 0)
> > break;
> > - rc = check_and_migrate_movable_pages(rc, pages, gup_flags);
> > + rc = check_and_migrate_movable_pages(nr_pinned_pages,
> pages, gup_flags);
>
> Also here.
>
> > } while (rc == -EAGAIN);
> > memalloc_pin_restore(flags);
> >
> > - return rc ? rc : nr_pages;
> > + return rc ? rc : nr_pinned_pages;
> > }
> >
> > static bool is_valid_gup_flags(unsigned int gup_flags)
>
> thanks,
> --
> John Hubbard
> NVIDIA
>
>
[-- Attachment #2: Type: text/html, Size: 3842 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-22 15:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-21 18:35 [PATCH] mm/gup.c: Fix return value for __gup_longterm_locked() Shigeru Yoshida
2022-08-22 0:14 ` John Hubbard
2022-08-22 15:23 ` Shigeru Yoshida
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.