Commit 1e2c0436 authored by Janosch Frank's avatar Janosch Frank Committed by Linus Torvalds

userfaultfd: hugetlbfs: fix userfaultfd_huge_must_wait() pte access

Use huge_ptep_get() to translate huge ptes to normal ptes so we can
check them with the huge_pte_* functions.  Otherwise some architectures
will check the wrong values and will not wait for userspace to bring in
the memory.

Link: http://lkml.kernel.org/r/20180626132421.78084-1-frankja@linux.ibm.com
Fixes: 369cd212 ("userfaultfd: hugetlbfs: userfaultfd_huge_must_wait for hugepmd ranges")
Signed-off-by: default avatarJanosch Frank <frankja@linux.ibm.com>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 410da1e1
...@@ -222,24 +222,26 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, ...@@ -222,24 +222,26 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,
unsigned long reason) unsigned long reason)
{ {
struct mm_struct *mm = ctx->mm; struct mm_struct *mm = ctx->mm;
pte_t *pte; pte_t *ptep, pte;
bool ret = true; bool ret = true;
VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem)); VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
pte = huge_pte_offset(mm, address, vma_mmu_pagesize(vma)); ptep = huge_pte_offset(mm, address, vma_mmu_pagesize(vma));
if (!pte)
if (!ptep)
goto out; goto out;
ret = false; ret = false;
pte = huge_ptep_get(ptep);
/* /*
* Lockless access: we're in a wait_event so it's ok if it * Lockless access: we're in a wait_event so it's ok if it
* changes under us. * changes under us.
*/ */
if (huge_pte_none(*pte)) if (huge_pte_none(pte))
ret = true; ret = true;
if (!huge_pte_write(*pte) && (reason & VM_UFFD_WP)) if (!huge_pte_write(pte) && (reason & VM_UFFD_WP))
ret = true; ret = true;
out: out:
return ret; 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