diff options
| author | Andrea Arcangeli <aarcange@redhat.com> | 2015-02-11 18:27:20 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-11 20:06:05 -0500 |
| commit | 0fd71a56f41d4ffabeda1dae9ff5ed4f34d4e935 (patch) | |
| tree | bf1844624a69986ad308c298b894e1890977af91 | |
| parent | f0818f472d8d527a96ec9cc2c3a56223497f9dd3 (diff) | |
mm: gup: add __get_user_pages_unlocked to customize gup_flags
Some callers (like KVM) may want to set the gup_flags like FOLL_HWPOSION
to get a proper -EHWPOSION retval instead of -EFAULT to take a more
appropriate action if get_user_pages runs into a memory failure.
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andres Lagar-Cavilla <andreslc@google.com>
Cc: Peter Feiner <pfeiner@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | include/linux/mm.h | 4 | ||||
| -rw-r--r-- | mm/gup.c | 44 | ||||
| -rw-r--r-- | mm/nommu.c | 16 |
3 files changed, 49 insertions, 15 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h index fc499e675475..3696b3bd1d7e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
| @@ -1265,6 +1265,10 @@ long get_user_pages_locked(struct task_struct *tsk, struct mm_struct *mm, | |||
| 1265 | unsigned long start, unsigned long nr_pages, | 1265 | unsigned long start, unsigned long nr_pages, |
| 1266 | int write, int force, struct page **pages, | 1266 | int write, int force, struct page **pages, |
| 1267 | int *locked); | 1267 | int *locked); |
| 1268 | long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, | ||
| 1269 | unsigned long start, unsigned long nr_pages, | ||
| 1270 | int write, int force, struct page **pages, | ||
| 1271 | unsigned int gup_flags); | ||
| 1268 | long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, | 1272 | long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, |
| 1269 | unsigned long start, unsigned long nr_pages, | 1273 | unsigned long start, unsigned long nr_pages, |
| 1270 | int write, int force, struct page **pages); | 1274 | int write, int force, struct page **pages); |
| @@ -582,9 +582,9 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, | |||
| 582 | int write, int force, | 582 | int write, int force, |
| 583 | struct page **pages, | 583 | struct page **pages, |
| 584 | struct vm_area_struct **vmas, | 584 | struct vm_area_struct **vmas, |
| 585 | int *locked, bool notify_drop) | 585 | int *locked, bool notify_drop, |
| 586 | unsigned int flags) | ||
| 586 | { | 587 | { |
| 587 | int flags = FOLL_TOUCH; | ||
| 588 | long ret, pages_done; | 588 | long ret, pages_done; |
| 589 | bool lock_dropped; | 589 | bool lock_dropped; |
| 590 | 590 | ||
| @@ -698,11 +698,37 @@ long get_user_pages_locked(struct task_struct *tsk, struct mm_struct *mm, | |||
| 698 | int *locked) | 698 | int *locked) |
| 699 | { | 699 | { |
| 700 | return __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, | 700 | return __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, |
| 701 | pages, NULL, locked, true); | 701 | pages, NULL, locked, true, FOLL_TOUCH); |
| 702 | } | 702 | } |
| 703 | EXPORT_SYMBOL(get_user_pages_locked); | 703 | EXPORT_SYMBOL(get_user_pages_locked); |
| 704 | 704 | ||
| 705 | /* | 705 | /* |
| 706 | * Same as get_user_pages_unlocked(...., FOLL_TOUCH) but it allows to | ||
| 707 | * pass additional gup_flags as last parameter (like FOLL_HWPOISON). | ||
| 708 | * | ||
| 709 | * NOTE: here FOLL_TOUCH is not set implicitly and must be set by the | ||
| 710 | * caller if required (just like with __get_user_pages). "FOLL_GET", | ||
| 711 | * "FOLL_WRITE" and "FOLL_FORCE" are set implicitly as needed | ||
| 712 | * according to the parameters "pages", "write", "force" | ||
| 713 | * respectively. | ||
| 714 | */ | ||
| 715 | __always_inline long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, | ||
| 716 | unsigned long start, unsigned long nr_pages, | ||
| 717 | int write, int force, struct page **pages, | ||
| 718 | unsigned int gup_flags) | ||
| 719 | { | ||
| 720 | long ret; | ||
| 721 | int locked = 1; | ||
| 722 | down_read(&mm->mmap_sem); | ||
| 723 | ret = __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, | ||
| 724 | pages, NULL, &locked, false, gup_flags); | ||
| 725 | if (locked) | ||
| 726 | up_read(&mm->mmap_sem); | ||
| 727 | return ret; | ||
| 728 | } | ||
| 729 | EXPORT_SYMBOL(__get_user_pages_unlocked); | ||
| 730 | |||
| 731 | /* | ||
| 706 | * get_user_pages_unlocked() is suitable to replace the form: | 732 | * get_user_pages_unlocked() is suitable to replace the form: |
| 707 | * | 733 | * |
| 708 | * down_read(&mm->mmap_sem); | 734 | * down_read(&mm->mmap_sem); |
| @@ -723,14 +749,8 @@ long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, | |||
| 723 | unsigned long start, unsigned long nr_pages, | 749 | unsigned long start, unsigned long nr_pages, |
| 724 | int write, int force, struct page **pages) | 750 | int write, int force, struct page **pages) |
| 725 | { | 751 | { |
| 726 | long ret; | 752 | return __get_user_pages_unlocked(tsk, mm, start, nr_pages, write, |
| 727 | int locked = 1; | 753 | force, pages, FOLL_TOUCH); |
| 728 | down_read(&mm->mmap_sem); | ||
| 729 | ret = __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, | ||
| 730 | pages, NULL, &locked, false); | ||
| 731 | if (locked) | ||
| 732 | up_read(&mm->mmap_sem); | ||
| 733 | return ret; | ||
| 734 | } | 754 | } |
| 735 | EXPORT_SYMBOL(get_user_pages_unlocked); | 755 | EXPORT_SYMBOL(get_user_pages_unlocked); |
| 736 | 756 | ||
| @@ -794,7 +814,7 @@ long get_user_pages(struct task_struct *tsk, struct mm_struct *mm, | |||
| 794 | int force, struct page **pages, struct vm_area_struct **vmas) | 814 | int force, struct page **pages, struct vm_area_struct **vmas) |
| 795 | { | 815 | { |
| 796 | return __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, | 816 | return __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, |
| 797 | pages, vmas, NULL, false); | 817 | pages, vmas, NULL, false, FOLL_TOUCH); |
| 798 | } | 818 | } |
| 799 | EXPORT_SYMBOL(get_user_pages); | 819 | EXPORT_SYMBOL(get_user_pages); |
| 800 | 820 | ||
diff --git a/mm/nommu.c b/mm/nommu.c index bfb690b0f986..4d1b8a199867 100644 --- a/mm/nommu.c +++ b/mm/nommu.c | |||
| @@ -224,9 +224,10 @@ long get_user_pages_locked(struct task_struct *tsk, struct mm_struct *mm, | |||
| 224 | } | 224 | } |
| 225 | EXPORT_SYMBOL(get_user_pages_locked); | 225 | EXPORT_SYMBOL(get_user_pages_locked); |
| 226 | 226 | ||
| 227 | long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, | 227 | long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, |
| 228 | unsigned long start, unsigned long nr_pages, | 228 | unsigned long start, unsigned long nr_pages, |
| 229 | int write, int force, struct page **pages) | 229 | int write, int force, struct page **pages, |
| 230 | unsigned int gup_flags) | ||
| 230 | { | 231 | { |
| 231 | long ret; | 232 | long ret; |
| 232 | down_read(&mm->mmap_sem); | 233 | down_read(&mm->mmap_sem); |
| @@ -235,6 +236,15 @@ long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, | |||
| 235 | up_read(&mm->mmap_sem); | 236 | up_read(&mm->mmap_sem); |
| 236 | return ret; | 237 | return ret; |
| 237 | } | 238 | } |
| 239 | EXPORT_SYMBOL(__get_user_pages_unlocked); | ||
| 240 | |||
| 241 | long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, | ||
| 242 | unsigned long start, unsigned long nr_pages, | ||
| 243 | int write, int force, struct page **pages) | ||
| 244 | { | ||
| 245 | return __get_user_pages_unlocked(tsk, mm, start, nr_pages, write, | ||
| 246 | force, pages, 0); | ||
| 247 | } | ||
| 238 | EXPORT_SYMBOL(get_user_pages_unlocked); | 248 | EXPORT_SYMBOL(get_user_pages_unlocked); |
| 239 | 249 | ||
| 240 | /** | 250 | /** |
