Skip to contentSkip to conversation

mm/gup.c: Fix return value for __gup_longterm_locked()

PATCH Superseded Shigeru Yoshida 2 participants 3 messages Aug 21, 2022 – Aug 22, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/gup.c: Fix return value for __gup_longterm_locked()

__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 <[email protected]>
Reported-by [email protected]
---
 mm/gup.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/gup.c +6 -6
index 5aa7531a703b..542cf74c59b0 100644
@@ -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)
Signature · 1 line
2.37.2
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Shigeru Yoshida

__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/

Quoted 8 lines
Fixes 61c63c2076d9 (mm/gup.c: simplify and fix check_and_migrate_movable_pages() return codes)
CC Alistair Popple <[email protected]>
Reported-by [email protected]
---
  mm/gup.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)

(with a couple of nits about line length, below)

Quoted 12 lines
mm/gup.c +1 -1
index 5aa7531a703b..542cf74c59b0 100644
@@ -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;
 

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm, · line 2079

Quoted 10 lines
mm/gup.c +2 -3
  	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?

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm, · line 2082

Quoted 4 lines
mm/gup.c +2 -1
+		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.

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm, · line 2089

Quoted 8 lines
mm/gup.c +1 -1
  	} 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,

Signature · 2 lines
John Hubbard
NVIDIA
#2 lore raw
Quoted 11 lines · John Hubbard
Quoted 4 lines · Shigeru Yoshida

__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/

Quoted 2 lines
Fixes 61c63c2076d9 (mm/gup.c: simplify and fix

check_and_migrate_movable_pages() return codes)

Quoted 9 lines
Quoted 6 lines
---
  mm/gup.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)

Hi John,

Thank you so much for your review.
I'll send v2 patch.

Shigeru

Quoted 55 lines

(with a couple of nits about line length, below)

mm/gup.c static long __gup_longterm_locked(struct

Quoted 6 lines
mm/gup.c +0 -0
index 5aa7531a703b..542cf74c59b0 100644
@@ -2068,22 +2068,22 @@ static long __gup_longterm_locked(struct

mm_struct *mm,

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm,

Quoted 8 lines
mm/gup.c +1 -1
                                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,

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm,

Quoted 4 lines
mm/gup.c +0 -1
                                             NULL, gup_flags);
      flags = memalloc_pin_save();
      do {
-             rc = __get_user_pages_locked(mm, start, nr_pages, pages,

vmas,

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm,

Quoted 3 lines
mm/gup.c +1 -2
-                                          NULL, gup_flags);
-             if (rc <= 0)
+             nr_pinned_pages = __get_user_pages_locked(mm, start,

nr_pages, pages, vmas,

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm, · line 2079

Quoted 1 line
mm/gup.c +1 -0
+                                                       NULL, gup_flags);

Can you please wrap at 80 cols, though?

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm,

Quoted 4 lines
mm/gup.c +2 -1
+             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.

mm/gup.c static long __gup_longterm_locked(struct mm_struct *mm, · line 2089

Quoted 8 lines
mm/gup.c +1 -1
      } 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