Skip to content

Commit f6d299e

Browse files
apopple-nvidiaakpm00
authored andcommitted
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 <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Reviewed-by: John Hubbard <[email protected]> Cc: Alex Sierra <[email protected]> Cc: Dan Williams <[email protected]> Cc: Felix Kuehling <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Logan Gunthorpe <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Muchun Song <[email protected]> Cc: Ralph Campbell <[email protected]> Cc: Shigeru Yoshida <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 32d7727 commit f6d299e

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

mm/gup.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,8 +1933,7 @@ struct page *get_dump_page(unsigned long addr)
19331933
* migration failure.
19341934
*/
19351935
static long check_and_migrate_movable_pages(unsigned long nr_pages,
1936-
struct page **pages,
1937-
unsigned int gup_flags)
1936+
struct page **pages)
19381937
{
19391938
unsigned long i;
19401939
struct folio *prev_folio = NULL;
@@ -1967,10 +1966,8 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages,
19671966
* Migration will fail if the page is pinned, so convert
19681967
* the pin on the source page to a normal reference.
19691968
*/
1970-
if (gup_flags & FOLL_PIN) {
1971-
get_page(&folio->page);
1972-
unpin_user_page(&folio->page);
1973-
}
1969+
get_page(&folio->page);
1970+
unpin_user_page(&folio->page);
19741971

19751972
if (migrate_device_coherent_page(&folio->page)) {
19761973
ret = -EBUSY;
@@ -2023,10 +2020,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages,
20232020
if (!pages[i])
20242021
continue;
20252022

2026-
if (gup_flags & FOLL_PIN)
2027-
unpin_user_page(pages[i]);
2028-
else
2029-
put_page(pages[i]);
2023+
unpin_user_page(pages[i]);
20302024
}
20312025

20322026
if (!list_empty(&movable_page_list)) {
@@ -2049,8 +2043,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages,
20492043
}
20502044
#else
20512045
static long check_and_migrate_movable_pages(unsigned long nr_pages,
2052-
struct page **pages,
2053-
unsigned int gup_flags)
2046+
struct page **pages)
20542047
{
20552048
return 0;
20562049
}
@@ -2073,6 +2066,9 @@ static long __gup_longterm_locked(struct mm_struct *mm,
20732066
if (!(gup_flags & FOLL_LONGTERM))
20742067
return __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
20752068
NULL, gup_flags);
2069+
/* check_and_migrate_movable_pages() assumes pages have been pinned. */
2070+
if (WARN_ON(!(gup_flags & FOLL_PIN)))
2071+
return -EINVAL;
20762072
flags = memalloc_pin_save();
20772073
do {
20782074
nr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages,
@@ -2082,8 +2078,7 @@ static long __gup_longterm_locked(struct mm_struct *mm,
20822078
rc = nr_pinned_pages;
20832079
break;
20842080
}
2085-
rc = check_and_migrate_movable_pages(nr_pinned_pages, pages,
2086-
gup_flags);
2081+
rc = check_and_migrate_movable_pages(nr_pinned_pages, pages);
20872082
} while (rc == -EAGAIN);
20882083
memalloc_pin_restore(flags);
20892084

0 commit comments

Comments
 (0)