syzbot


possible deadlock in __ntfs_clear_inode

Status: upstream: reported on 2022/11/25 10:07
Reported-by: syzbot+5ebb8d0e9b8c47867596@syzkaller.appspotmail.com
First crash: 8d20h, last: 1d12h

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.1.0-rc7-syzkaller-00103-gef4d3ea40565 #0 Not tainted
------------------------------------------------------
kswapd0/110 is trying to acquire lock:
ffff888089821180 (&rl->lock){++++}-{3:3}, at: __ntfs_clear_inode+0x32/0x1f0 fs/ntfs/inode.c:2189

but task is already holding lock:
ffffffff8d1ff140 (fs_reclaim){+.+.}-{0:0}, at: arch_static_branch arch/x86/include/asm/jump_label.h:27 [inline]
ffffffff8d1ff140 (fs_reclaim){+.+.}-{0:0}, at: freezing include/linux/freezer.h:36 [inline]
ffffffff8d1ff140 (fs_reclaim){+.+.}-{0:0}, at: try_to_freeze include/linux/freezer.h:54 [inline]
ffffffff8d1ff140 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0x109c/0x1c50 mm/vmscan.c:7134

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (fs_reclaim){+.+.}-{0:0}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __fs_reclaim_acquire mm/page_alloc.c:4682 [inline]
       fs_reclaim_acquire+0x82/0x120 mm/page_alloc.c:4696
       might_alloc include/linux/sched/mm.h:271 [inline]
       prepare_alloc_pages+0x145/0x5a0 mm/page_alloc.c:5328
       __alloc_pages+0x161/0x560 mm/page_alloc.c:5547
       folio_alloc+0x1a/0x50 mm/mempolicy.c:2295
       filemap_alloc_folio+0x7e/0x1c0 mm/filemap.c:971
       do_read_cache_folio+0x28a/0x790 mm/filemap.c:3498
       do_read_cache_page mm/filemap.c:3576 [inline]
       read_cache_page+0x56/0x270 mm/filemap.c:3585
       read_mapping_page include/linux/pagemap.h:756 [inline]
       ntfs_map_page fs/ntfs/aops.h:75 [inline]
       map_mft_record_page fs/ntfs/mft.c:73 [inline]
       map_mft_record+0x1dc/0x610 fs/ntfs/mft.c:156
       ntfs_read_locked_inode+0x194/0x47c0 fs/ntfs/inode.c:550
       ntfs_iget+0x10f/0x190 fs/ntfs/inode.c:177
       ntfs_lookup+0x268/0xdb0 fs/ntfs/namei.c:117
       lookup_open fs/namei.c:3391 [inline]
       open_last_lookups fs/namei.c:3481 [inline]
       path_openat+0x10e6/0x2df0 fs/namei.c:3711
       do_filp_open+0x264/0x4f0 fs/namei.c:3741
       do_sys_openat2+0x124/0x4e0 fs/open.c:1310
       do_sys_open fs/open.c:1326 [inline]
       __do_sys_open fs/open.c:1334 [inline]
       __se_sys_open fs/open.c:1330 [inline]
       __x64_sys_open+0x221/0x270 fs/open.c:1330
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #1 (&ni->mrec_lock){+.+.}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __mutex_lock_common+0x1bd/0x26e0 kernel/locking/mutex.c:603
       __mutex_lock kernel/locking/mutex.c:747 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
       map_mft_record+0x46/0x610 fs/ntfs/mft.c:154
       ntfs_truncate+0x24e/0x2720 fs/ntfs/inode.c:2383
       ntfs_truncate_vfs fs/ntfs/inode.c:2862 [inline]
       ntfs_setattr+0x2b9/0x3a0 fs/ntfs/inode.c:2914
       notify_change+0xe38/0x10f0 fs/attr.c:420
       do_truncate+0x1fb/0x2e0 fs/open.c:65
       handle_truncate fs/namei.c:3216 [inline]
       do_open fs/namei.c:3561 [inline]
       path_openat+0x2770/0x2df0 fs/namei.c:3714
       do_filp_open+0x264/0x4f0 fs/namei.c:3741
       do_sys_openat2+0x124/0x4e0 fs/open.c:1310
       do_sys_open fs/open.c:1326 [inline]
       __do_sys_open fs/open.c:1334 [inline]
       __se_sys_open fs/open.c:1330 [inline]
       __x64_sys_open+0x221/0x270 fs/open.c:1330
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #0 (&rl->lock){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3097 [inline]
       check_prevs_add kernel/locking/lockdep.c:3216 [inline]
       validate_chain+0x1898/0x6ae0 kernel/locking/lockdep.c:3831
       __lock_acquire+0x1292/0x1f60 kernel/locking/lockdep.c:5055
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_write+0x9c/0x270 kernel/locking/rwsem.c:1562
       __ntfs_clear_inode+0x32/0x1f0 fs/ntfs/inode.c:2189
       ntfs_evict_big_inode+0x2b6/0x470 fs/ntfs/inode.c:2278
       evict+0x2a4/0x620 fs/inode.c:664
       dispose_list fs/inode.c:697 [inline]
       prune_icache_sb+0x268/0x320 fs/inode.c:896
       super_cache_scan+0x362/0x470 fs/super.c:106
       do_shrink_slab+0x4e1/0xa00 mm/vmscan.c:842
       shrink_slab_memcg+0x2ec/0x630 mm/vmscan.c:911
       shrink_slab+0xbe/0x340 mm/vmscan.c:990
       shrink_node_memcgs+0x3c3/0x770 mm/vmscan.c:6112
       shrink_node+0x299/0x1050 mm/vmscan.c:6141
       kswapd_shrink_node mm/vmscan.c:6930 [inline]
       balance_pgdat+0xec2/0x1c50 mm/vmscan.c:7120
       kswapd+0x2d5/0x590 mm/vmscan.c:7380
       kthread+0x266/0x300 kernel/kthread.c:376
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

other info that might help us debug this:

Chain exists of:
  &rl->lock --> &ni->mrec_lock --> fs_reclaim

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(fs_reclaim);
                               lock(&ni->mrec_lock);
                               lock(fs_reclaim);
  lock(&rl->lock);

 *** DEADLOCK ***

3 locks held by kswapd0/110:
 #0: ffffffff8d1ff140 (fs_reclaim){+.+.}-{0:0}, at: arch_static_branch arch/x86/include/asm/jump_label.h:27 [inline]
 #0: ffffffff8d1ff140 (fs_reclaim){+.+.}-{0:0}, at: freezing include/linux/freezer.h:36 [inline]
 #0: ffffffff8d1ff140 (fs_reclaim){+.+.}-{0:0}, at: try_to_freeze include/linux/freezer.h:54 [inline]
 #0: ffffffff8d1ff140 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0x109c/0x1c50 mm/vmscan.c:7134
 #1: ffffffff8d1d5ff0 (shrinker_rwsem){++++}-{3:3}, at: shrink_slab_memcg+0xd9/0x630 mm/vmscan.c:884
 #2: ffff8880791200e0 (&type->s_umount_key#58){++++}-{3:3}, at: trylock_super fs/super.c:415 [inline]
 #2: ffff8880791200e0 (&type->s_umount_key#58){++++}-{3:3}, at: super_cache_scan+0x6a/0x470 fs/super.c:79

stack backtrace:
CPU: 0 PID: 110 Comm: kswapd0 Not tainted 6.1.0-rc7-syzkaller-00103-gef4d3ea40565 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106
 check_noncircular+0x2cc/0x390 kernel/locking/lockdep.c:2177
 check_prev_add kernel/locking/lockdep.c:3097 [inline]
 check_prevs_add kernel/locking/lockdep.c:3216 [inline]
 validate_chain+0x1898/0x6ae0 kernel/locking/lockdep.c:3831
 __lock_acquire+0x1292/0x1f60 kernel/locking/lockdep.c:5055
 lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
 down_write+0x9c/0x270 kernel/locking/rwsem.c:1562
 __ntfs_clear_inode+0x32/0x1f0 fs/ntfs/inode.c:2189
 ntfs_evict_big_inode+0x2b6/0x470 fs/ntfs/inode.c:2278
 evict+0x2a4/0x620 fs/inode.c:664
 dispose_list fs/inode.c:697 [inline]
 prune_icache_sb+0x268/0x320 fs/inode.c:896
 super_cache_scan+0x362/0x470 fs/super.c:106
 do_shrink_slab+0x4e1/0xa00 mm/vmscan.c:842
 shrink_slab_memcg+0x2ec/0x630 mm/vmscan.c:911
 shrink_slab+0xbe/0x340 mm/vmscan.c:990
 shrink_node_memcgs+0x3c3/0x770 mm/vmscan.c:6112
 shrink_node+0x299/0x1050 mm/vmscan.c:6141
 kswapd_shrink_node mm/vmscan.c:6930 [inline]
 balance_pgdat+0xec2/0x1c50 mm/vmscan.c:7120
 kswapd+0x2d5/0x590 mm/vmscan.c:7380
 kthread+0x266/0x300 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
 </TASK>

Crashes (3):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci2-upstream-fs 2022/12/02 04:08 upstream ef4d3ea40565 e080de16 .config log report info possible deadlock in __ntfs_clear_inode
ci2-upstream-fs 2022/11/28 05:25 upstream cf562a45a0d5 f4470a7b .config log report info possible deadlock in __ntfs_clear_inode
ci2-upstream-fs 2022/11/24 19:57 upstream 4312098baf37 ff68ff8f .config log report info possible deadlock in __ntfs_clear_inode
* Struck through repros no longer work on HEAD.