Skip to content

Commit 15e7987

Browse files
kerneltoastPlaidCat
authored andcommitted
mm/gup: introduce pin_user_pages_fast_only()
Like pin_user_pages_fast(), but with the internal-only FOLL_FAST_ONLY flag. This complements the get_user_pages*() API, which already has get_user_pages_fast_only(). Signed-off-by: Sultan Alsawaf <[email protected]> Signed-off-by: Jonathan Maple <[email protected]>
1 parent 78c300a commit 15e7987

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/linux/mm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages,
25442544
unsigned int gup_flags, struct page **pages);
25452545
int pin_user_pages_fast(unsigned long start, int nr_pages,
25462546
unsigned int gup_flags, struct page **pages);
2547+
int pin_user_pages_fast_only(unsigned long start, int nr_pages,
2548+
unsigned int gup_flags, struct page **pages);
25472549
void folio_add_pin(struct folio *folio);
25482550

25492551
int account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc);

mm/gup.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,34 @@ int pin_user_pages_fast(unsigned long start, int nr_pages,
33533353
}
33543354
EXPORT_SYMBOL_GPL(pin_user_pages_fast);
33553355

3356+
/**
3357+
* pin_user_pages_fast_only() - pin user pages in memory
3358+
* @start: starting user address
3359+
* @nr_pages: number of pages from start to pin
3360+
* @gup_flags: flags modifying pin behaviour
3361+
* @pages: array that receives pointers to the pages pinned.
3362+
* Should be at least nr_pages long.
3363+
*
3364+
* Like pin_user_pages_fast() except it's IRQ-safe in that it won't fall back to
3365+
* the regular GUP.
3366+
*
3367+
* If the architecture does not support this function, simply return with no
3368+
* pages pinned.
3369+
*
3370+
* Careful, careful! COW breaking can go either way, so a non-write
3371+
* access can get ambiguous page results. If you call this function without
3372+
* 'write' set, you'd better be sure that you're ok with that ambiguity.
3373+
*/
3374+
int pin_user_pages_fast_only(unsigned long start, int nr_pages,
3375+
unsigned int gup_flags, struct page **pages)
3376+
{
3377+
if (!is_valid_gup_args(pages, NULL, &gup_flags,
3378+
FOLL_PIN | FOLL_FAST_ONLY))
3379+
return -EINVAL;
3380+
return internal_get_user_pages_fast(start, nr_pages, gup_flags, pages);
3381+
}
3382+
EXPORT_SYMBOL_GPL(pin_user_pages_fast_only);
3383+
33563384
/**
33573385
* pin_user_pages_remote() - pin pages of a remote process
33583386
*

0 commit comments

Comments
 (0)