• Qi Zheng's avatar
    mm: fix the deadlock in finish_fault() · e4dc3489
    Qi Zheng authored
    Commit 63f3655f ("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 f9ce0be7 ("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: f9ce0be7 ("mm: Cleanup faultaroun...
    e4dc3489
memory.c 148 KB