提交 643aa36e 编写于 作者: W Wei Yang 提交者: Linus Torvalds

userfaultfd: wrap the common dst_vma check into an inlined function

When doing UFFDIO_COPY, it is necessary to find the correct destination
vma and make sure fault range is in it.

Since there are two places need to do the same task, just wrap those
common check into an inlined function.

Link: http://lkml.kernel.org/r/20190927070032.2129-3-richardw.yang@linux.intel.comSigned-off-by: NWei Yang <richardw.yang@linux.intel.com>
Reviewed-by: NMike Kravetz <mike.kravetz@oracle.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 53eaa14b
...@@ -18,6 +18,36 @@ ...@@ -18,6 +18,36 @@
#include <asm/tlbflush.h> #include <asm/tlbflush.h>
#include "internal.h" #include "internal.h"
static __always_inline
struct vm_area_struct *find_dst_vma(struct mm_struct *dst_mm,
unsigned long dst_start,
unsigned long len)
{
/*
* Make sure that the dst range is both valid and fully within a
* single existing vma.
*/
struct vm_area_struct *dst_vma;
dst_vma = find_vma(dst_mm, dst_start);
if (!dst_vma)
return NULL;
if (dst_start < dst_vma->vm_start ||
dst_start + len > dst_vma->vm_end)
return NULL;
/*
* Check the vma is registered in uffd, this is required to
* enforce the VM_MAYWRITE check done at uffd registration
* time.
*/
if (!dst_vma->vm_userfaultfd_ctx.ctx)
return NULL;
return dst_vma;
}
static int mcopy_atomic_pte(struct mm_struct *dst_mm, static int mcopy_atomic_pte(struct mm_struct *dst_mm,
pmd_t *dst_pmd, pmd_t *dst_pmd,
struct vm_area_struct *dst_vma, struct vm_area_struct *dst_vma,
...@@ -220,20 +250,9 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, ...@@ -220,20 +250,9 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm,
*/ */
if (!dst_vma) { if (!dst_vma) {
err = -ENOENT; err = -ENOENT;
dst_vma = find_vma(dst_mm, dst_start); dst_vma = find_dst_vma(dst_mm, dst_start, len);
if (!dst_vma || !is_vm_hugetlb_page(dst_vma)) if (!dst_vma || !is_vm_hugetlb_page(dst_vma))
goto out_unlock; goto out_unlock;
/*
* Check the vma is registered in uffd, this is
* required to enforce the VM_MAYWRITE check done at
* uffd registration time.
*/
if (!dst_vma->vm_userfaultfd_ctx.ctx)
goto out_unlock;
if (dst_start < dst_vma->vm_start ||
dst_start + len > dst_vma->vm_end)
goto out_unlock;
err = -EINVAL; err = -EINVAL;
if (vma_hpagesize != vma_kernel_pagesize(dst_vma)) if (vma_hpagesize != vma_kernel_pagesize(dst_vma))
...@@ -468,20 +487,9 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, ...@@ -468,20 +487,9 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm,
* both valid and fully within a single existing vma. * both valid and fully within a single existing vma.
*/ */
err = -ENOENT; err = -ENOENT;
dst_vma = find_vma(dst_mm, dst_start); dst_vma = find_dst_vma(dst_mm, dst_start, len);
if (!dst_vma) if (!dst_vma)
goto out_unlock; goto out_unlock;
/*
* Check the vma is registered in uffd, this is required to
* enforce the VM_MAYWRITE check done at uffd registration
* time.
*/
if (!dst_vma->vm_userfaultfd_ctx.ctx)
goto out_unlock;
if (dst_start < dst_vma->vm_start ||
dst_start + len > dst_vma->vm_end)
goto out_unlock;
err = -EINVAL; err = -EINVAL;
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册