syzbot


possible deadlock in inode_add_bytes

Status: fixed on 2023/10/12 12:48
Subsystems: fs
[Documentation on labels]
Reported-by: syzbot+440ff8cca06ee7a1d4db@syzkaller.appspotmail.com
Fix commit: 509f006932de shmem: fix quota lock nesting in huge hole handling
First crash: 371d, last: 368d
Cause bisection: introduced by (bisect log) :
commit 1a93dd24f1bee98ca121e68ce5c0de4a60a0a0b6
Author: Carlos Maiolino <cem@kernel.org>
Date: Thu Jul 13 13:48:47 2023 +0000

  shmem: quota support

Crash: possible deadlock in inode_add_bytes (log)
Repro: C syz .config
  
Discussions (3)
Title Replies (including bot) Last reply
[PATCH 7/7] shmem: fix quota lock nesting in huge hole handling 1 (1) 2023/07/25 14:45
[syzbot] [mm?] possible deadlock in shmem_uncharge (2) 4 (5) 2023/07/24 12:00
[syzbot] [fs?] possible deadlock in inode_add_bytes 0 (1) 2023/07/18 09:41

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.5.0-rc1-next-20230714-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor340/5089 is trying to acquire lock:
ffff888075decae0 (&sb->s_type->i_lock_key){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
ffff888075decae0 (&sb->s_type->i_lock_key){+.+.}-{2:2}, at: inode_add_bytes+0x24/0xf0 fs/stat.c:794

but task is already holding lock:
ffff888075decca0 (&xa->xa_lock#7){..-.}-{2:2}, at: spin_lock_irq include/linux/spinlock.h:376 [inline]
ffff888075decca0 (&xa->xa_lock#7){..-.}-{2:2}, at: collapse_file+0x1ccc/0x5530 mm/khugepaged.c:1962

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&xa->xa_lock#7){..-.}-{2:2}:
       __raw_spin_lock_irq include/linux/spinlock_api_smp.h:119 [inline]
       _raw_spin_lock_irq+0x36/0x50 kernel/locking/spinlock.c:170
       spin_lock_irq include/linux/spinlock.h:376 [inline]
       filemap_remove_folio+0xbf/0x250 mm/filemap.c:259
       truncate_inode_folio+0x49/0x70 mm/truncate.c:195
       shmem_undo_range+0x363/0x1190 mm/shmem.c:1004
       shmem_truncate_range mm/shmem.c:1120 [inline]
       shmem_evict_inode+0x334/0xb10 mm/shmem.c:1250
       evict+0x2ed/0x6b0 fs/inode.c:665
       iput_final fs/inode.c:1791 [inline]
       iput.part.0+0x55e/0x7a0 fs/inode.c:1817
       iput+0x5c/0x80 fs/inode.c:1807
       dentry_unlink_inode+0x292/0x430 fs/dcache.c:401
       __dentry_kill+0x3b8/0x640 fs/dcache.c:607
       dentry_kill fs/dcache.c:745 [inline]
       dput+0x703/0xfd0 fs/dcache.c:913
       do_renameat2+0xc4c/0xdc0 fs/namei.c:5011
       __do_sys_rename fs/namei.c:5055 [inline]
       __se_sys_rename fs/namei.c:5053 [inline]
       __x64_sys_rename+0x81/0xa0 fs/namei.c:5053
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #0 (&sb->s_type->i_lock_key){+.+.}-{2:2}:
       check_prev_add kernel/locking/lockdep.c:3142 [inline]
       check_prevs_add kernel/locking/lockdep.c:3261 [inline]
       validate_chain kernel/locking/lockdep.c:3876 [inline]
       __lock_acquire+0x2e3d/0x5de0 kernel/locking/lockdep.c:5144
       lock_acquire kernel/locking/lockdep.c:5761 [inline]
       lock_acquire+0x1ae/0x510 kernel/locking/lockdep.c:5726
       __raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
       _raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154
       spin_lock include/linux/spinlock.h:351 [inline]
       inode_add_bytes+0x24/0xf0 fs/stat.c:794
       __dquot_alloc_space+0x730/0xb60 fs/quota/dquot.c:1682
       dquot_alloc_space_nodirty include/linux/quotaops.h:300 [inline]
       dquot_alloc_block_nodirty include/linux/quotaops.h:327 [inline]
       shmem_inode_acct_block mm/shmem.c:226 [inline]
       shmem_charge+0x152/0x500 mm/shmem.c:429
       collapse_file+0x20ad/0x5530 mm/khugepaged.c:1831
       hpage_collapse_scan_file+0xc8e/0x1650 mm/khugepaged.c:2285
       madvise_collapse+0x52c/0xb50 mm/khugepaged.c:2729
       madvise_vma_behavior+0x200/0x1e60 mm/madvise.c:1094
       madvise_walk_vmas+0x1cf/0x2c0 mm/madvise.c:1268
       do_madvise+0x333/0x660 mm/madvise.c:1448
       __do_sys_madvise mm/madvise.c:1461 [inline]
       __se_sys_madvise mm/madvise.c:1459 [inline]
       __x64_sys_madvise+0xaa/0x110 mm/madvise.c:1459
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&xa->xa_lock#7);
                               lock(&sb->s_type->i_lock_key);
                               lock(&xa->xa_lock#7);
  lock(&sb->s_type->i_lock_key);

 *** DEADLOCK ***

1 lock held by syz-executor340/5089:
 #0: ffff888075decca0 (&xa->xa_lock#7){..-.}-{2:2}, at: spin_lock_irq include/linux/spinlock.h:376 [inline]
 #0: ffff888075decca0 (&xa->xa_lock#7){..-.}-{2:2}, at: collapse_file+0x1ccc/0x5530 mm/khugepaged.c:1962

stack backtrace:
CPU: 1 PID: 5089 Comm: syz-executor340 Not tainted 6.5.0-rc1-next-20230714-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/03/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd9/0x1b0 lib/dump_stack.c:106
 check_noncircular+0x311/0x3f0 kernel/locking/lockdep.c:2195
 check_prev_add kernel/locking/lockdep.c:3142 [inline]
 check_prevs_add kernel/locking/lockdep.c:3261 [inline]
 validate_chain kernel/locking/lockdep.c:3876 [inline]
 __lock_acquire+0x2e3d/0x5de0 kernel/locking/lockdep.c:5144
 lock_acquire kernel/locking/lockdep.c:5761 [inline]
 lock_acquire+0x1ae/0x510 kernel/locking/lockdep.c:5726
 __raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
 _raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154
 spin_lock include/linux/spinlock.h:351 [inline]
 inode_add_bytes+0x24/0xf0 fs/stat.c:794
 __dquot_alloc_space+0x730/0xb60 fs/quota/dquot.c:1682
 dquot_alloc_space_nodirty include/linux/quotaops.h:300 [inline]
 dquot_alloc_block_nodirty include/linux/quotaops.h:327 [inline]
 shmem_inode_acct_block mm/shmem.c:226 [inline]
 shmem_charge+0x152/0x500 mm/shmem.c:429
 collapse_file+0x20ad/0x5530 mm/khugepaged.c:1831
 hpage_collapse_scan_file+0xc8e/0x1650 mm/khugepaged.c:2285
 madvise_collapse+0x52c/0xb50 mm/khugepaged.c:2729
 madvise_vma_behavior+0x200/0x1e60 mm/madvise.c:1094
 madvise_walk_vmas+0x1cf/0x2c0 mm/madvise.c:1268
 do_madvise+0x333/0x660 mm/madvise.c:1448
 __do_sys_madvise mm/madvise.c:1461 [inline]
 __se_sys_madvise mm/madvise.c:1459 [inline]
 __x64_sys_madvise+0xaa/0x110 mm/madvise.c:1459
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fa09783a5f9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 b1 1f 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fa0977ad178 EFLAGS: 00000246 ORIG_RAX: 000000000000001c
RAX: ffffffffffffffda RBX: 00007fa0978c31c8 RCX: 00007fa09783a5f9
RDX: 0000000000000019 RSI: 0000000000400000 RDI: 0000000020000000
RBP: 00007fa0978c31c0 R08: 00007ffc2e84b837 R09: 00007fa0977ad6c0
R10: 0000000000000000 R11: 0000000000000246 R12: 00007fa0978c31cc
R13: 000000000000006e R14: 00007ffc2e84b750 R15: 00007ffc2e84b838
 </TASK>

Crashes (124):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/07/14 14:48 linux-next 7c2878be5732 d624500f .config console log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 14:21 linux-next 7c2878be5732 d624500f .config console log report syz [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/17 02:46 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/17 01:07 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/17 00:08 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 21:07 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 18:45 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 16:46 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 15:23 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 14:10 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 10:20 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 09:51 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 05:57 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 04:26 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/16 02:01 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 23:22 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 21:49 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 18:49 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 18:40 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 13:07 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 10:27 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 09:02 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 06:43 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 04:46 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/15 00:56 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 23:56 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 22:45 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 22:19 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 22:17 linux-next 7c2878be5732 35d9ecc5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 15:34 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 15:02 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 14:59 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 13:17 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 13:12 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 13:03 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 13:03 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 13:03 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 13:03 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 12:40 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 12:32 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 12:20 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 12:14 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 12:00 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 11:54 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
2023/07/14 11:49 linux-next 7c2878be5732 d624500f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in inode_add_bytes
* Struck through repros no longer work on HEAD.