From: Andrea Arcangeli Date: Wed, 22 Feb 2017 23:43:49 +0000 (-0800) Subject: userfaultfd: shmem: lock the page before adding it to pagecache X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9cc90c664a65f9b6b9f3ce1c719f1308539427bd;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git 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.com Signed-off-by: Andrea Arcangeli Cc: "Dr. David Alan Gilbert" Cc: Hillf Danton Cc: Michael Rapoport Cc: Mike Kravetz Cc: Mike Rapoport Cc: Pavel Emelyanov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/shmem.c b/mm/shmem.c index ab6644194fee..4e5e7a57e5b4 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2245,6 +2245,10 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm, *pagep = NULL; } + VM_BUG_ON(PageLocked(page) || PageSwapBacked(page)); + __SetPageLocked(page); + __SetPageSwapBacked(page); + ret = mem_cgroup_try_charge(page, dst_mm, gfp, &memcg, false); if (ret) goto out_release; @@ -2294,6 +2298,7 @@ out_release_uncharge_unlock: out_release_uncharge: mem_cgroup_cancel_charge(page, memcg, false); out_release: + unlock_page(page); put_page(page); out_dec_used_blocks: if (sbinfo->max_blocks)