Commit 3567813e authored by John Hubbard's avatar John Hubbard Committed by Linus Torvalds
Browse files

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.


Signed-off-by: default avatarJohn Hubbard <>
Tested-by: default avatarAlex Williamson <>
Acked-by: default avatarAlex Williamson <>
Reviewed-by: default avatarJason Gunthorpe <>
Reviewed-by: default avatarIra Weiny <>
Suggested-by: default avatarJason Gunthorpe <>
Cc: Dan Williams <>
Cc: Jerome Glisse <>
Cc: Aneesh Kumar K.V <>
Cc: Björn Töpel <>
Cc: Christoph Hellwig <>
Cc: Daniel Vetter <>
Cc: Hans Verkuil <>
Cc: Jan Kara <>
Cc: Jens Axboe <>
Cc: Jonathan Corbet <>
Cc: Kirill A. Shutemov <>
Cc: Leon Romanovsky <>
Cc: Mauro Carvalho Chehab <>
Cc: Mike Rapoport <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent c4237f8b
......@@ -322,7 +322,6 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
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_struct *mm, unsigned long vaddr,
flags |= FOLL_WRITE;
if (mm == current->mm) {
ret = get_user_pages(vaddr, 1, flags | FOLL_LONGTERM, page,
} 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 = 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;
vaddr = untagged_addr(vaddr);
vma = find_vma_intersection(mm, vaddr, vaddr + 1);
......@@ -366,7 +346,7 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
if (is_invalid_reserved_pfn(*pfn))
ret = 0;
return ret;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment