Commit 9cc90c66 authored by Andrea Arcangeli's avatar Andrea Arcangeli Committed by Linus Torvalds

userfaultfd: shmem: lock the page before adding it to pagecache

A VM_BUG_ON triggered on the shmem selftest.

Link: http://lkml.kernel.org/r/20161216144821.5183-36-aarcange@redhat.comSigned-off-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Hillf Danton <hillf.zj@alibaba-inc.com>
Cc: Michael Rapoport <RAPOPORT@il.ibm.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 419624da
...@@ -2245,6 +2245,10 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, ...@@ -2245,6 +2245,10 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
*pagep = NULL; *pagep = NULL;
} }
VM_BUG_ON(PageLocked(page) || PageSwapBacked(page));
__SetPageLocked(page);
__SetPageSwapBacked(page);
ret = mem_cgroup_try_charge(page, dst_mm, gfp, &memcg, false); ret = mem_cgroup_try_charge(page, dst_mm, gfp, &memcg, false);
if (ret) if (ret)
goto out_release; goto out_release;
...@@ -2294,6 +2298,7 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, ...@@ -2294,6 +2298,7 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
out_release_uncharge: out_release_uncharge:
mem_cgroup_cancel_charge(page, memcg, false); mem_cgroup_cancel_charge(page, memcg, false);
out_release: out_release:
unlock_page(page);
put_page(page); put_page(page);
out_dec_used_blocks: out_dec_used_blocks:
if (sbinfo->max_blocks) if (sbinfo->max_blocks)
......
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