syzbot


possible deadlock in ext4_writepages (2)

Status: upstream: reported on 2024/10/19 20:27
Subsystems: ext4
[Documentation on labels]
Reported-by: syzbot+eb5b4ef634a018917f3c@syzkaller.appspotmail.com
First crash: 268d, last: 8d06h
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [ext4?] possible deadlock in ext4_writepages (2) 0 (1) 2024/10/19 20:27
Similar bugs (2)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in ext4_writepages ext4 4 1 1063d 1059d 0/29 auto-obsoleted due to no activity on 2022/12/11 07:00
linux-5.15 possible deadlock in ext4_writepages 4 2 799d 800d 0/3 auto-obsoleted due to no activity on 2023/08/23 09:09

Sample crash report:
ext4 filesystem being mounted at /147/bus supports timestamps until 2038-01-19 (0x7fffffff)
======================================================
WARNING: possible circular locking dependency detected
6.16.0-rc3-syzkaller-00306-gaaf724ed6926 #0 Not tainted
------------------------------------------------------
syz.9.974/12611 is trying to acquire lock:
ffff888055352b98 (&sbi->s_writepages_rwsem){++++}-{0:0}, at: percpu_down_read include/linux/percpu-rwsem.h:77 [inline]
ffff888055352b98 (&sbi->s_writepages_rwsem){++++}-{0:0}, at: ext4_writepages_down_read fs/ext4/ext4.h:1804 [inline]
ffff888055352b98 (&sbi->s_writepages_rwsem){++++}-{0:0}, at: ext4_writepages+0x1cc/0x350 fs/ext4/inode.c:2952

but task is already holding lock:
ffff88805978c870 (mapping.invalidate_lock#2){++++}-{4:4}, at: filemap_invalidate_lock include/linux/fs.h:924 [inline]
ffff88805978c870 (mapping.invalidate_lock#2){++++}-{4:4}, at: ext4_fallocate+0x179/0xcd0 fs/ext4/extents.c:4777

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #5 (mapping.invalidate_lock#2){++++}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5871
       down_read+0x46/0x2e0 kernel/locking/rwsem.c:1524
       filemap_invalidate_lock_shared include/linux/fs.h:934 [inline]
       ext4_page_mkwrite+0x20b/0x1110 fs/ext4/inode.c:6579
       do_page_mkwrite+0x14a/0x310 mm/memory.c:3378
       wp_page_shared mm/memory.c:3779 [inline]
       do_wp_page+0x268d/0x5800 mm/memory.c:3998
       handle_pte_fault mm/memory.c:6085 [inline]
       __handle_mm_fault+0x1144/0x5620 mm/memory.c:6212
       handle_mm_fault+0x2d5/0x7f0 mm/memory.c:6381
       do_user_addr_fault+0xa81/0x1390 arch/x86/mm/fault.c:1336
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x76/0xf0 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:623

-> #4 (sb_pagefaults){.+.+}-{0:0}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5871
       percpu_down_read_internal+0x48/0x1c0 include/linux/percpu-rwsem.h:53
       percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
       __sb_start_write include/linux/fs.h:1795 [inline]
       sb_start_pagefault include/linux/fs.h:1960 [inline]
       ext4_page_mkwrite+0x1e3/0x1110 fs/ext4/inode.c:6576
       do_page_mkwrite+0x14a/0x310 mm/memory.c:3378
       do_shared_fault mm/memory.c:5666 [inline]
       do_fault mm/memory.c:5728 [inline]
       do_pte_missing mm/memory.c:4251 [inline]
       handle_pte_fault mm/memory.c:6069 [inline]
       __handle_mm_fault+0x1a60/0x5620 mm/memory.c:6212
       handle_mm_fault+0x2d5/0x7f0 mm/memory.c:6381
       do_user_addr_fault+0x764/0x1390 arch/x86/mm/fault.c:1387
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x76/0xf0 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:623

-> #3 (&mm->mmap_lock){++++}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5871
       __might_fault+0xcc/0x130 mm/memory.c:6971
       _inline_copy_to_user include/linux/uaccess.h:192 [inline]
       _copy_to_user+0x2c/0xb0 lib/usercopy.c:26
       copy_to_user include/linux/uaccess.h:225 [inline]
       fiemap_fill_next_extent+0x1c0/0x390 fs/ioctl.c:145
       ocfs2_fiemap+0x888/0xc90 fs/ocfs2/extent_map.c:806
       ioctl_fiemap fs/ioctl.c:220 [inline]
       do_vfs_ioctl+0x16d3/0x1990 fs/ioctl.c:841
       __do_sys_ioctl fs/ioctl.c:905 [inline]
       __se_sys_ioctl+0x82/0x170 fs/ioctl.c:893
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #2 (&ocfs2_quota_ip_alloc_sem_key){++++}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5871
       down_write+0x96/0x1f0 kernel/locking/rwsem.c:1577
       ocfs2_create_local_dquot+0x19d/0x1a40 fs/ocfs2/quota_local.c:1227
       ocfs2_acquire_dquot+0x80f/0xb30 fs/ocfs2/quota_global.c:883
       dqget+0x7b1/0xf10 fs/quota/dquot.c:977
       __dquot_initialize+0x3b3/0xcb0 fs/quota/dquot.c:1505
       ocfs2_get_init_inode+0x13b/0x1b0 fs/ocfs2/namei.c:202
       ocfs2_mknod+0x863/0x2050 fs/ocfs2/namei.c:310
       ocfs2_mkdir+0x191/0x440 fs/ocfs2/namei.c:656
       vfs_mkdir+0x306/0x510 fs/namei.c:4375
       do_mkdirat+0x247/0x590 fs/namei.c:4408
       __do_sys_mkdir fs/namei.c:4430 [inline]
       __se_sys_mkdir fs/namei.c:4428 [inline]
       __x64_sys_mkdir+0x6c/0x80 fs/namei.c:4428
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (&dquot->dq_lock){+.+.}-{4:4}:
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5871
       __mutex_lock_common kernel/locking/mutex.c:602 [inline]
       __mutex_lock+0x182/0xe80 kernel/locking/mutex.c:747
       wait_on_dquot fs/quota/dquot.c:354 [inline]
       dqget+0x72a/0xf10 fs/quota/dquot.c:972
       __dquot_initialize+0x3b3/0xcb0 fs/quota/dquot.c:1505
       __ext4_new_inode+0x7db/0x3c50 fs/ext4/ialloc.c:994
       ext4_ext_migrate+0x69f/0x1010 fs/ext4/migrate.c:456
       __ext4_ioctl fs/ext4/ioctl.c:1402 [inline]
       ext4_ioctl+0x1b1a/0x3510 fs/ext4/ioctl.c:1626
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:907 [inline]
       __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:893
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&sbi->s_writepages_rwsem){++++}-{0:0}:
       check_prev_add kernel/locking/lockdep.c:3168 [inline]
       check_prevs_add kernel/locking/lockdep.c:3287 [inline]
       validate_chain+0xb9b/0x2140 kernel/locking/lockdep.c:3911
       __lock_acquire+0xab9/0xd20 kernel/locking/lockdep.c:5240
       lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5871
       percpu_down_read_internal+0x48/0x1c0 include/linux/percpu-rwsem.h:53
       percpu_down_read include/linux/percpu-rwsem.h:77 [inline]
       ext4_writepages_down_read fs/ext4/ext4.h:1804 [inline]
       ext4_writepages+0x1cc/0x350 fs/ext4/inode.c:2952
       do_writepages+0x32e/0x550 mm/page-writeback.c:2636
       filemap_fdatawrite_wbc mm/filemap.c:386 [inline]
       __filemap_fdatawrite_range mm/filemap.c:419 [inline]
       filemap_write_and_wait_range+0x217/0x310 mm/filemap.c:691
       ext4_collapse_range+0x2da/0x950 fs/ext4/extents.c:5426
       ext4_fallocate+0x58d/0xcd0 fs/ext4/extents.c:4786
       vfs_fallocate+0x6a3/0x830 fs/open.c:341
       ksys_fallocate fs/open.c:365 [inline]
       __do_sys_fallocate fs/open.c:370 [inline]
       __se_sys_fallocate fs/open.c:368 [inline]
       __x64_sys_fallocate+0xc0/0x110 fs/open.c:368
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  &sbi->s_writepages_rwsem --> sb_pagefaults --> mapping.invalidate_lock#2

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(mapping.invalidate_lock#2);
                               lock(sb_pagefaults);
                               lock(mapping.invalidate_lock#2);
  rlock(&sbi->s_writepages_rwsem);

 *** DEADLOCK ***

3 locks held by syz.9.974/12611:
 #0: ffff8880336a4428 (sb_writers#4){.+.+}-{0:0}, at: file_start_write include/linux/fs.h:3096 [inline]
 #0: ffff8880336a4428 (sb_writers#4){.+.+}-{0:0}, at: vfs_fallocate+0x62a/0x830 fs/open.c:340
 #1: ffff88805978c6d0 (&sb->s_type->i_mutex_key#8){++++}-{4:4}, at: inode_lock include/linux/fs.h:869 [inline]
 #1: ffff88805978c6d0 (&sb->s_type->i_mutex_key#8){++++}-{4:4}, at: ext4_fallocate+0xf0/0xcd0 fs/ext4/extents.c:4755
 #2: ffff88805978c870 (mapping.invalidate_lock#2){++++}-{4:4}, at: filemap_invalidate_lock include/linux/fs.h:924 [inline]
 #2: ffff88805978c870 (mapping.invalidate_lock#2){++++}-{4:4}, at: ext4_fallocate+0x179/0xcd0 fs/ext4/extents.c:4777

stack backtrace:
CPU: 1 UID: 0 PID: 12611 Comm: syz.9.974 Not tainted 6.16.0-rc3-syzkaller-00306-gaaf724ed6926 #0 PREEMPT(full) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/07/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
 print_circular_bug+0x2ee/0x310 kernel/locking/lockdep.c:2046
 check_noncircular+0x134/0x160 kernel/locking/lockdep.c:2178
 check_prev_add kernel/locking/lockdep.c:3168 [inline]
 check_prevs_add kernel/locking/lockdep.c:3287 [inline]
 validate_chain+0xb9b/0x2140 kernel/locking/lockdep.c:3911
 __lock_acquire+0xab9/0xd20 kernel/locking/lockdep.c:5240
 lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5871
 percpu_down_read_internal+0x48/0x1c0 include/linux/percpu-rwsem.h:53
 percpu_down_read include/linux/percpu-rwsem.h:77 [inline]
 ext4_writepages_down_read fs/ext4/ext4.h:1804 [inline]
 ext4_writepages+0x1cc/0x350 fs/ext4/inode.c:2952
 do_writepages+0x32e/0x550 mm/page-writeback.c:2636
 filemap_fdatawrite_wbc mm/filemap.c:386 [inline]
 __filemap_fdatawrite_range mm/filemap.c:419 [inline]
 filemap_write_and_wait_range+0x217/0x310 mm/filemap.c:691
 ext4_collapse_range+0x2da/0x950 fs/ext4/extents.c:5426
 ext4_fallocate+0x58d/0xcd0 fs/ext4/extents.c:4786
 vfs_fallocate+0x6a3/0x830 fs/open.c:341
 ksys_fallocate fs/open.c:365 [inline]
 __do_sys_fallocate fs/open.c:370 [inline]
 __se_sys_fallocate fs/open.c:368 [inline]
 __x64_sys_fallocate+0xc0/0x110 fs/open.c:368
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fce70d8e929
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fce71b6d038 EFLAGS: 00000246 ORIG_RAX: 000000000000011d
RAX: ffffffffffffffda RBX: 00007fce70fb5fa0 RCX: 00007fce70d8e929
RDX: 0000000000000000 RSI: 0000000000000008 RDI: 0000000000000004
RBP: 00007fce70e10b39 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000002000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007fce70fb5fa0 R15: 00007ffead45eb98
 </TASK>

Crashes (9):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/06/28 12:35 upstream aaf724ed6926 fc9d8ee5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in ext4_writepages
2025/05/27 19:03 upstream b1456f6dc167 874a1386 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in ext4_writepages
2025/05/23 10:01 upstream 94305e83eccb fa44301a .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in ext4_writepages
2025/03/16 21:16 upstream d1275e99d1c4 e2826670 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in ext4_writepages
2024/12/08 23:27 upstream 62b5a46999c7 9ac0fdc6 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in ext4_writepages
2024/12/02 22:03 upstream e70140ba0d2b b499ea68 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in ext4_writepages
2024/10/15 20:23 upstream 2f87d0916ce0 7eb57b4a .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in ext4_writepages
2025/07/03 09:17 linux-next 50c8770a42fa 115ceea7 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in ext4_writepages
2025/07/03 09:17 linux-next 50c8770a42fa 115ceea7 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in ext4_writepages
* Struck through repros no longer work on HEAD.