mm/gup: fix comments to pin_user_pages_*()
pin_user_pages API forces FOLL_PIN in gup_flags, which means that the API requires struct page **pages to be provided (not NULL). However, the comment to pin_user_pages() clearly allows for passing in a NULL @pages argument. Remove the incorrect comments, and add WARN_ON_ONCE(!pages) calls to enforce the API. It has been independently spotted by Minchan Kim and confirmed with John Hubbard: https://lore.kernel.org/all/YgWA0ghrrzHONehH@google.com/ Link: https://lkml.kernel.org/r/20220422015839.1274328-1-yury.norov@gmail.com Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Cc: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
bff9beaa2e
commit
0768c8de1b
21
mm/gup.c
21
mm/gup.c
|
@ -2969,6 +2969,9 @@ int pin_user_pages_fast(unsigned long start, int nr_pages,
|
||||||
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (WARN_ON_ONCE(!pages))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
gup_flags |= FOLL_PIN;
|
gup_flags |= FOLL_PIN;
|
||||||
return internal_get_user_pages_fast(start, nr_pages, gup_flags, pages);
|
return internal_get_user_pages_fast(start, nr_pages, gup_flags, pages);
|
||||||
}
|
}
|
||||||
|
@ -2991,6 +2994,9 @@ int pin_user_pages_fast_only(unsigned long start, int nr_pages,
|
||||||
*/
|
*/
|
||||||
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (WARN_ON_ONCE(!pages))
|
||||||
|
return 0;
|
||||||
/*
|
/*
|
||||||
* FOLL_FAST_ONLY is required in order to match the API description of
|
* FOLL_FAST_ONLY is required in order to match the API description of
|
||||||
* this routine: no fall back to regular ("slow") GUP.
|
* this routine: no fall back to regular ("slow") GUP.
|
||||||
|
@ -3018,8 +3024,7 @@ EXPORT_SYMBOL_GPL(pin_user_pages_fast_only);
|
||||||
* @nr_pages: number of pages from start to pin
|
* @nr_pages: number of pages from start to pin
|
||||||
* @gup_flags: flags modifying lookup behaviour
|
* @gup_flags: flags modifying lookup behaviour
|
||||||
* @pages: array that receives pointers to the pages pinned.
|
* @pages: array that receives pointers to the pages pinned.
|
||||||
* Should be at least nr_pages long. Or NULL, if caller
|
* Should be at least nr_pages long.
|
||||||
* only intends to ensure the pages are faulted in.
|
|
||||||
* @vmas: array of pointers to vmas corresponding to each page.
|
* @vmas: array of pointers to vmas corresponding to each page.
|
||||||
* Or NULL if the caller does not require them.
|
* Or NULL if the caller does not require them.
|
||||||
* @locked: pointer to lock flag indicating whether lock is held and
|
* @locked: pointer to lock flag indicating whether lock is held and
|
||||||
|
@ -3042,6 +3047,9 @@ long pin_user_pages_remote(struct mm_struct *mm,
|
||||||
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (WARN_ON_ONCE(!pages))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
gup_flags |= FOLL_PIN;
|
gup_flags |= FOLL_PIN;
|
||||||
return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
|
return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
|
||||||
pages, vmas, locked);
|
pages, vmas, locked);
|
||||||
|
@ -3055,8 +3063,7 @@ EXPORT_SYMBOL(pin_user_pages_remote);
|
||||||
* @nr_pages: number of pages from start to pin
|
* @nr_pages: number of pages from start to pin
|
||||||
* @gup_flags: flags modifying lookup behaviour
|
* @gup_flags: flags modifying lookup behaviour
|
||||||
* @pages: array that receives pointers to the pages pinned.
|
* @pages: array that receives pointers to the pages pinned.
|
||||||
* Should be at least nr_pages long. Or NULL, if caller
|
* Should be at least nr_pages long.
|
||||||
* only intends to ensure the pages are faulted in.
|
|
||||||
* @vmas: array of pointers to vmas corresponding to each page.
|
* @vmas: array of pointers to vmas corresponding to each page.
|
||||||
* Or NULL if the caller does not require them.
|
* Or NULL if the caller does not require them.
|
||||||
*
|
*
|
||||||
|
@ -3074,6 +3081,9 @@ long pin_user_pages(unsigned long start, unsigned long nr_pages,
|
||||||
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (WARN_ON_ONCE(!pages))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
gup_flags |= FOLL_PIN;
|
gup_flags |= FOLL_PIN;
|
||||||
return __gup_longterm_locked(current->mm, start, nr_pages,
|
return __gup_longterm_locked(current->mm, start, nr_pages,
|
||||||
pages, vmas, gup_flags);
|
pages, vmas, gup_flags);
|
||||||
|
@ -3092,6 +3102,9 @@ long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
|
||||||
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
if (WARN_ON_ONCE(gup_flags & FOLL_GET))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (WARN_ON_ONCE(!pages))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
gup_flags |= FOLL_PIN;
|
gup_flags |= FOLL_PIN;
|
||||||
return get_user_pages_unlocked(start, nr_pages, pages, gup_flags);
|
return get_user_pages_unlocked(start, nr_pages, pages, gup_flags);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue