Skip to content

Commit e4dc348

Browse files
Qi Zhengtorvalds
authored andcommitted
mm: fix the deadlock in finish_fault()
Commit 63f3655 ("mm, memcg: fix reclaim deadlock with writeback") fix the following ABBA deadlock by pre-allocating the pte page table without holding the page lock. lock_page(A) SetPageWriteback(A) unlock_page(A) lock_page(B) lock_page(B) pte_alloc_one shrink_page_list wait_on_page_writeback(A) SetPageWriteback(B) unlock_page(B) # flush A, B to clear the writeback Commit f9ce0be ("mm: Cleanup faultaround and finish_fault() codepaths") reworked the relevant code but ignored this race. This will cause the deadlock above to appear again, so fix it. Link: https://lkml.kernel.org/r/20210721074849.57004-1-zhengqi.arch@bytedance.com Fixes: f9ce0be ("mm: Cleanup faultaround and finish_fault() codepaths") Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Muchun Song <songmuchun@bytedance.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e904c2c commit e4dc348

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

mm/memory.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4026,8 +4026,17 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
40264026
return ret;
40274027
}
40284028

4029-
if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd)))
4029+
if (vmf->prealloc_pte) {
4030+
vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd);
4031+
if (likely(pmd_none(*vmf->pmd))) {
4032+
mm_inc_nr_ptes(vma->vm_mm);
4033+
pmd_populate(vma->vm_mm, vmf->pmd, vmf->prealloc_pte);
4034+
vmf->prealloc_pte = NULL;
4035+
}
4036+
spin_unlock(vmf->ptl);
4037+
} else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) {
40304038
return VM_FAULT_OOM;
4039+
}
40314040
}
40324041

40334042
/* See comment in handle_pte_fault() */

0 commit comments

Comments
 (0)