The patch titled Subject: vfio: fix FOLL_LONGTERM use, simplify get_user_pages_remote() call has been added to the -mm tree. Its filename is vfio-fix-foll_longterm-use-simplify-get_user_pages_remote-call.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/vfio-fix-foll_longterm-use-simplify-get_user_pages_remote-call.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/vfio-fix-foll_longterm-use-simplify-get_user_pages_remote-call.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: John Hubbard <jhubbard@xxxxxxxxxx> Subject: vfio: fix FOLL_LONGTERM use, simplify get_user_pages_remote() call Update VFIO to take advantage of the recently loosened restriction on FOLL_LONGTERM with get_user_pages_remote(). Also, now it is possible to fix a bug: the VFIO caller is logically a FOLL_LONGTERM user, but it wasn't setting FOLL_LONGTERM. Also, remove an unnessary pair of calls that were releasing and reacquiring the mmap_sem. There is no need to avoid holding mmap_sem just in order to call page_to_pfn(). Also, now that the the DAX check ("if a VMA is DAX, don't allow long term pinning") is in the internals of get_user_pages_remote() and __gup_longterm_locked(), there's no need for it at the VFIO call site. So remove it. Link: http://lkml.kernel.org/r/20191209225344.99740-8-jhubbard@xxxxxxxxxx Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx> Tested-by: Alex Williamson <alex.williamson@xxxxxxxxxx> Acked-by: Alex Williamson <alex.williamson@xxxxxxxxxx> Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx> Reviewed-by: Ira Weiny <ira.weiny@xxxxxxxxx> Suggested-by: Jason Gunthorpe <jgg@xxxxxxxx> Cc: Dan Williams <dan.j.williams@xxxxxxxxx> Cc: Jerome Glisse <jglisse@xxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxx> Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx> Cc: Björn Töpel <bjorn.topel@xxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Daniel Vetter <daniel@xxxxxxxx> Cc: Daniel Vetter <daniel.vetter@xxxxxxxx> Cc: Dave Chinner <david@xxxxxxxxxxxxx> Cc: David Airlie <airlied@xxxxxxxx> Cc: "David S . Miller" <davem@xxxxxxxxxxxxx> Cc: Hans Verkuil <hverkuil-cisco@xxxxxxxxx> Cc: Jan Kara <jack@xxxxxxx> Cc: Jens Axboe <axboe@xxxxxxxxx> Cc: Jonathan Corbet <corbet@xxxxxxx> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Cc: Leon Romanovsky <leonro@xxxxxxxxxxxx> Cc: Magnus Karlsson <magnus.karlsson@xxxxxxxxx> Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx> Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Cc: Mike Rapoport <rppt@xxxxxxxxxxxxx> Cc: Paul Mackerras <paulus@xxxxxxxxx> Cc: Shuah Khan <shuah@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- drivers/vfio/vfio_iommu_type1.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) --- a/drivers/vfio/vfio_iommu_type1.c~vfio-fix-foll_longterm-use-simplify-get_user_pages_remote-call +++ a/drivers/vfio/vfio_iommu_type1.c @@ -322,7 +322,6 @@ static int vaddr_get_pfn(struct mm_struc { struct page *page[1]; struct vm_area_struct *vma; - struct vm_area_struct *vmas[1]; unsigned int flags = 0; int ret; @@ -330,33 +329,14 @@ static int vaddr_get_pfn(struct mm_struc flags |= FOLL_WRITE; down_read(&mm->mmap_sem); - if (mm == current->mm) { - ret = get_user_pages(vaddr, 1, flags | FOLL_LONGTERM, page, - vmas); - } else { - ret = get_user_pages_remote(NULL, mm, vaddr, 1, flags, page, - vmas, NULL); - /* - * The lifetime of a vaddr_get_pfn() page pin is - * userspace-controlled. In the fs-dax case this could - * lead to indefinite stalls in filesystem operations. - * Disallow attempts to pin fs-dax pages via this - * interface. - */ - if (ret > 0 && vma_is_fsdax(vmas[0])) { - ret = -EOPNOTSUPP; - put_page(page[0]); - } - } - up_read(&mm->mmap_sem); - + ret = get_user_pages_remote(NULL, mm, vaddr, 1, flags | FOLL_LONGTERM, + page, NULL, NULL); if (ret == 1) { *pfn = page_to_pfn(page[0]); - return 0; + ret = 0; + goto done; } - down_read(&mm->mmap_sem); - vaddr = untagged_addr(vaddr); vma = find_vma_intersection(mm, vaddr, vaddr + 1); @@ -366,7 +346,7 @@ static int vaddr_get_pfn(struct mm_struc if (is_invalid_reserved_pfn(*pfn)) ret = 0; } - +done: up_read(&mm->mmap_sem); return ret; } _ Patches currently in -mm which might be from jhubbard@xxxxxxxxxx are mm-gup-factor-out-duplicate-code-from-four-routines.patch mm-gup-move-try_get_compound_head-to-top-fix-minor-issues.patch mm-devmap-refactor-1-based-refcounting-for-zone_device-pages.patch goldish_pipe-rename-local-pin_user_pages-routine.patch mm-fix-get_user_pages_remotes-handling-of-foll_longterm.patch vfio-fix-foll_longterm-use-simplify-get_user_pages_remote-call.patch mm-gup-allow-foll_force-for-get_user_pages_fast.patch ib-umem-use-get_user_pages_fast-to-pin-dma-pages.patch mm-gup-introduce-pin_user_pages-and-foll_pin.patch goldish_pipe-convert-to-pin_user_pages-and-put_user_page.patch ib-corehwumem-set-foll_pin-via-pin_user_pages-fix-up-odp.patch mm-process_vm_access-set-foll_pin-via-pin_user_pages_remote.patch drm-via-set-foll_pin-via-pin_user_pages_fast.patch fs-io_uring-set-foll_pin-via-pin_user_pages.patch net-xdp-set-foll_pin-via-pin_user_pages.patch media-v4l2-core-set-pages-dirty-upon-releasing-dma-buffers.patch media-v4l2-core-pin_user_pages-foll_pin-and-put_user_page-conversion.patch vfio-mm-pin_user_pages-foll_pin-and-put_user_page-conversion.patch powerpc-book3s64-convert-to-pin_user_pages-and-put_user_page.patch powerpc-book3s64-convert-to-pin_user_pages-and-put_user_page-fix.patch mm-gup_benchmark-use-proper-foll_write-flags-instead-of-hard-coding-1.patch mm-tree-wide-rename-put_user_page-to-unpin_user_page.patch mm-gup-pass-flags-arg-to-__gup_device_-functions.patch mm-gup-track-foll_pin-pages.patch mm-gup_benchmark-support-pin_user_pages-and-related-calls.patch selftests-vm-run_vmtests-invoke-gup_benchmark-with-basic-foll_pin-coverage.patch