aboutsummaryrefslogtreecommitdiffstats
path: root/mm/gup.c
diff options
context:
space:
mode:
authorAlistair Popple <apopple@nvidia.com>2022-08-24 15:09:51 +1000
committerAndrew Morton <akpm@linux-foundation.org>2022-09-11 20:26:00 -0700
commitf6d299ec39d8ebb62fc047022d4904575c99a28c (patch)
treef2898e76057171a027bc6b3195d0b8f3d7d0de63 /mm/gup.c
parentmm: skip retry when new limit is not below old one in page_counter_set_max (diff)
downloadlinux-dev-f6d299ec39d8ebb62fc047022d4904575c99a28c.tar.xz
linux-dev-f6d299ec39d8ebb62fc047022d4904575c99a28c.zip
mm/gup.c: don't pass gup_flags to check_and_migrate_movable_pages()
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. Link: https://lkml.kernel.org/r/d611c65a9008ff55887307df457c6c2220ad6163.1661317396.git-series.apopple@nvidia.com Signed-off-by: Alistair Popple <apopple@nvidia.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Cc: Alex Sierra <alex.sierra@amd.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Felix Kuehling <felix.kuehling@amd.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Miaohe Lin <linmiaohe@huawei.com> Cc: Muchun Song <songmuchun@bytedance.com> Cc: Ralph Campbell <rcampbell@nvidia.com> Cc: Shigeru Yoshida <syoshida@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/gup.c')
-rw-r--r--mm/gup.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/mm/gup.c b/mm/gup.c
index b05810e7e9bb..1800af4806e3 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1933,8 +1933,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;
@@ -1967,10 +1966,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;
@@ -2023,10 +2020,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)) {
@@ -2049,8 +2043,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;
}
@@ -2073,6 +2066,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,
@@ -2082,8 +2078,7 @@ static long __gup_longterm_locked(struct mm_struct *mm,
rc = nr_pinned_pages;
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);