diff mbox series

[v6,1/2] mm/gup.c: Don't pass gup_flags to check_and_migrate_movable_pages()

Message ID d611c65a9008ff55887307df457c6c2220ad6163.1661317396.git-series.apopple@nvidia.com (mailing list archive)
State New
Headers show
Series [v6,1/2] mm/gup.c: Don't pass gup_flags to check_and_migrate_movable_pages() | expand

Commit Message

Alistair Popple Aug. 24, 2022, 5:09 a.m. UTC
gup_flags is passed to check_and_migrate_movable_pages() so that it can
call either put_page() or unpin_user_page() to drop the page reference.
However check_and_migrate_movable_pages() is only called for
FOLL_LONGTERM, which implies FOLL_PIN so there is no need to pass
gup_flags.

Signed-off-by: Alistair Popple <apopple@nvidia.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>

---

Changes for v6:

 - Rebased onto mm-unstable

Changes for v3:

 - Move WARN_ON() out of loop
---
 mm/gup.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)


base-commit: d711de4adbec4cb0b8769bcae971b13293e6d311
diff mbox series

Patch

diff --git a/mm/gup.c b/mm/gup.c
index 3b656b7..8d66ee2 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1934,8 +1934,7 @@  struct page *get_dump_page(unsigned long addr)
  * migration failure.
  */
 static long check_and_migrate_movable_pages(unsigned long nr_pages,
-					    struct page **pages,
-					    unsigned int gup_flags)
+					    struct page **pages)
 {
 	unsigned long i;
 	struct folio *prev_folio = NULL;
@@ -1968,10 +1967,8 @@  static long check_and_migrate_movable_pages(unsigned long nr_pages,
 			 * Migration will fail if the page is pinned, so convert
 			 * the pin on the source page to a normal reference.
 			 */
-			if (gup_flags & FOLL_PIN) {
-				get_page(&folio->page);
-				unpin_user_page(&folio->page);
-			}
+			get_page(&folio->page);
+			unpin_user_page(&folio->page);
 
 			if (migrate_device_coherent_page(&folio->page)) {
 				ret = -EBUSY;
@@ -2024,10 +2021,7 @@  static long check_and_migrate_movable_pages(unsigned long nr_pages,
 		if (!pages[i])
 			continue;
 
-		if (gup_flags & FOLL_PIN)
-			unpin_user_page(pages[i]);
-		else
-			put_page(pages[i]);
+		unpin_user_page(pages[i]);
 	}
 
 	if (!list_empty(&movable_page_list)) {
@@ -2050,8 +2044,7 @@  static long check_and_migrate_movable_pages(unsigned long nr_pages,
 }
 #else
 static long check_and_migrate_movable_pages(unsigned long nr_pages,
-					    struct page **pages,
-					    unsigned int gup_flags)
+					    struct page **pages)
 {
 	return 0;
 }
@@ -2074,6 +2067,9 @@  static long __gup_longterm_locked(struct mm_struct *mm,
 	if (!(gup_flags & FOLL_LONGTERM))
 		return __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
 					       NULL, gup_flags);
+	/* check_and_migrate_movable_pages() assumes pages have been pinned. */
+	if (WARN_ON(!(gup_flags & FOLL_PIN)))
+		return -EINVAL;
 	flags = memalloc_pin_save();
 	do {
 		nr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages,
@@ -2081,8 +2077,7 @@  static long __gup_longterm_locked(struct mm_struct *mm,
 							  gup_flags);
 		if (nr_pinned_pages <= 0)
 			break;
-		rc = check_and_migrate_movable_pages(nr_pinned_pages, pages,
-						     gup_flags);
+		rc = check_and_migrate_movable_pages(nr_pinned_pages, pages);
 	} while (rc == -EAGAIN);
 	memalloc_pin_restore(flags);