Message ID | 20220131051752.447699-3-jhubbard@nvidia.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm/gup: some cleanups | expand |
On Sun, Jan 30, 2022 at 09:17:50PM -0800, John Hubbard wrote: > Regardless of any FOLL_* flags, get_user_pages() and its variants should > handle PFN-only entries by stopping early, if the caller expected > **pages to be filled in. > > This makes for a more reliable API, as compared to the previous approach > of skipping over such entries (and thus leaving them silently > unwritten). > > Cc: Peter Xu <peterx@redhat.com> > Suggested-by: Jason Gunthorpe <jgg@ziepe.ca> > Signed-off-by: John Hubbard <jhubbard@nvidia.com> > --- > mm/gup.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) I still think it should be squashed into the previous path, but otherwise Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Jason
diff --git a/mm/gup.c b/mm/gup.c index 65575ae3602f..8633bca12eab 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -439,10 +439,6 @@ static struct page *no_page_table(struct vm_area_struct *vma, static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, unsigned int flags) { - /* No page to get reference */ - if (flags & (FOLL_GET | FOLL_PIN)) - return -EFAULT; - if (flags & FOLL_TOUCH) { pte_t entry = *pte; @@ -1180,8 +1176,14 @@ static long __get_user_pages(struct mm_struct *mm, } else if (PTR_ERR(page) == -EEXIST) { /* * Proper page table entry exists, but no corresponding - * struct page. + * struct page. If the caller expects **pages to be + * filled in, bail out now, because that can't be done + * for this page. */ + if (pages) { + page = ERR_PTR(-EFAULT); + goto out; + } goto next_page; } else if (IS_ERR(page)) { ret = PTR_ERR(page);
Regardless of any FOLL_* flags, get_user_pages() and its variants should handle PFN-only entries by stopping early, if the caller expected **pages to be filled in. This makes for a more reliable API, as compared to the previous approach of skipping over such entries (and thus leaving them silently unwritten). Cc: Peter Xu <peterx@redhat.com> Suggested-by: Jason Gunthorpe <jgg@ziepe.ca> Signed-off-by: John Hubbard <jhubbard@nvidia.com> --- mm/gup.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)