Patch "mm: shmem: disable interrupt when acquiring info->lock in userfaultfd_copy path" has been added to the 5.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    mm: shmem: disable interrupt when acquiring info->lock in userfaultfd_copy path

to the 5.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     mm-shmem-disable-interrupt-when-acquiring-info-lock-.patch
and it can be found in the queue-5.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit b9c54120b13469865fb64ba3b57702854903d2e2
Author: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx>
Date:   Mon Apr 20 18:14:17 2020 -0700

    mm: shmem: disable interrupt when acquiring info->lock in userfaultfd_copy path
    
    commit 94b7cc01da5a3cc4f3da5e0ff492ef008bb555d6 upstream.
    
    Syzbot reported the below lockdep splat:
    
        WARNING: possible irq lock inversion dependency detected
        5.6.0-rc7-syzkaller #0 Not tainted
        --------------------------------------------------------
        syz-executor.0/10317 just changed the state of lock:
        ffff888021d16568 (&(&info->lock)->rlock){+.+.}, at: spin_lock include/linux/spinlock.h:338 [inline]
        ffff888021d16568 (&(&info->lock)->rlock){+.+.}, at: shmem_mfill_atomic_pte+0x1012/0x21c0 mm/shmem.c:2407
        but this lock was taken by another, SOFTIRQ-safe lock in the past:
         (&(&xa->xa_lock)->rlock#5){..-.}
    
        and interrupts could create inverse lock ordering between them.
    
        other info that might help us debug this:
         Possible interrupt unsafe locking scenario:
    
               CPU0                    CPU1
               ----                    ----
          lock(&(&info->lock)->rlock);
                                       local_irq_disable();
                                       lock(&(&xa->xa_lock)->rlock#5);
                                       lock(&(&info->lock)->rlock);
          <Interrupt>
            lock(&(&xa->xa_lock)->rlock#5);
    
         *** DEADLOCK ***
    
    The full report is quite lengthy, please see:
    
      https://lore.kernel.org/linux-mm/alpine.LSU.2.11.2004152007370.13597@eggly.anvils/T/#m813b412c5f78e25ca8c6c7734886ed4de43f241d
    
    It is because CPU 0 held info->lock with IRQ enabled in userfaultfd_copy
    path, then CPU 1 is splitting a THP which held xa_lock and info->lock in
    IRQ disabled context at the same time.  If softirq comes in to acquire
    xa_lock, the deadlock would be triggered.
    
    The fix is to acquire/release info->lock with *_irq version instead of
    plain spin_{lock,unlock} to make it softirq safe.
    
    Fixes: 4c27fe4c4c84 ("userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support")
    Reported-by: syzbot+e27980339d305f2dbfd9@xxxxxxxxxxxxxxxxxxxxxxxxx
    Signed-off-by: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Tested-by: syzbot+e27980339d305f2dbfd9@xxxxxxxxxxxxxxxxxxxxxxxxx
    Acked-by: Hugh Dickins <hughd@xxxxxxxxxx>
    Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx>
    Link: http://lkml.kernel.org/r/1587061357-122619-1-git-send-email-yang.shi@xxxxxxxxxxxxxxxxx
    Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

diff --git a/mm/shmem.c b/mm/shmem.c
index aad3ba74b0e9d..7406f91f8a528 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2404,11 +2404,11 @@ static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm,
 
 	lru_cache_add_anon(page);
 
-	spin_lock(&info->lock);
+	spin_lock_irq(&info->lock);
 	info->alloced++;
 	inode->i_blocks += BLOCKS_PER_PAGE;
 	shmem_recalc_inode(inode);
-	spin_unlock(&info->lock);
+	spin_unlock_irq(&info->lock);
 
 	inc_mm_counter(dst_mm, mm_counter_file(page));
 	page_add_file_rmap(page, false);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux