syzbot


possible deadlock in bd_prepare_to_claim

Status: auto-obsoleted due to no activity on 2024/01/27 23:26
Subsystems: block
[Documentation on labels]
Reported-by: syzbot+034076c3f2924132d327@syzkaller.appspotmail.com
First crash: 402d, last: 347d
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [block?] possible deadlock in bd_prepare_to_claim 0 (1) 2023/09/28 23:04

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.6.0-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.1/9625 is trying to acquire lock:
ffffffff8d0648e8 (bdev_lock){+.+.}-{3:3}, at: bd_prepare_to_claim+0x1b0/0x4c0 block/bdev.c:508

but task is already holding lock:
ffff88801ac94e40 (mapping.invalidate_lock#2){++++}-{3:3}, at: filemap_invalidate_lock include/linux/fs.h:847 [inline]
ffff88801ac94e40 (mapping.invalidate_lock#2){++++}-{3:3}, at: blkdev_fallocate+0x22a/0x660 block/fops.c:773

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #5 (mapping.invalidate_lock#2){++++}-{3:3}:
       down_read+0xb1/0xa40 kernel/locking/rwsem.c:1520
       filemap_invalidate_lock_shared include/linux/fs.h:857 [inline]
       filemap_fault+0x658/0x1710 mm/filemap.c:3283
       __do_fault+0x133/0x4e0 mm/memory.c:4207
       do_shared_fault mm/memory.c:4638 [inline]
       do_fault mm/memory.c:4712 [inline]
       do_pte_missing mm/memory.c:3672 [inline]
       handle_pte_fault mm/memory.c:4981 [inline]
       __handle_mm_fault mm/memory.c:5122 [inline]
       handle_mm_fault+0x21d9/0x62b0 mm/memory.c:5287
       do_user_addr_fault arch/x86/mm/fault.c:1413 [inline]
       handle_page_fault arch/x86/mm/fault.c:1505 [inline]
       exc_page_fault+0x2ac/0x860 arch/x86/mm/fault.c:1561
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570

-> #4 (&mm->mmap_lock){++++}-{3:3}:
       internal_get_user_pages_fast+0x254/0x2d60 mm/gup.c:3185
       iov_iter_extract_user_pages lib/iov_iter.c:1782 [inline]
       iov_iter_extract_pages+0x3bd/0x740 lib/iov_iter.c:1845
       __bio_iov_iter_get_pages block/bio.c:1255 [inline]
       bio_iov_iter_get_pages+0x5eb/0x17b0 block/bio.c:1333
       iomap_dio_bio_iter+0xc78/0x1650 fs/iomap/direct-io.c:387
       __iomap_dio_rw+0x12ca/0x2370 fs/iomap/direct-io.c:659
       iomap_dio_rw+0x46/0xa0 fs/iomap/direct-io.c:748
       ext4_dio_write_iter fs/ext4/file.c:605 [inline]
       ext4_file_write_iter+0x165f/0x1ad0 fs/ext4/file.c:715
       do_iter_write+0x84f/0xde0 fs/read_write.c:860
       vfs_writev fs/read_write.c:933 [inline]
       do_pwritev+0x21a/0x360 fs/read_write.c:1030
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #3 (&sb->s_type->i_mutex_key#7){++++}-{3:3}:
       down_read+0xb1/0xa40 kernel/locking/rwsem.c:1520
       inode_lock_shared include/linux/fs.h:812 [inline]
       ext4_bmap+0x4e/0x260 fs/ext4/inode.c:3089
       bmap+0xa5/0xe0 fs/inode.c:1826
       jbd2_journal_init_inode+0xa2/0x3d0 fs/jbd2/journal.c:1669
       ext4_open_inode_journal fs/ext4/super.c:5833 [inline]
       ext4_load_journal fs/ext4/super.c:5992 [inline]
       ext4_load_and_init_journal+0x374/0x2550 fs/ext4/super.c:4906
       __ext4_fill_super fs/ext4/super.c:5374 [inline]
       ext4_fill_super+0x4863/0x6d10 fs/ext4/super.c:5703
       get_tree_bdev+0x416/0x5b0 fs/super.c:1577
       vfs_get_tree+0x8c/0x280 fs/super.c:1750
       do_new_mount+0x28f/0xae0 fs/namespace.c:3335
       init_mount+0xd4/0x130 fs/init.c:25
       do_mount_root+0x98/0x230 init/do_mounts.c:166
       mount_root_generic+0x193/0x3b0 init/do_mounts.c:205
       prepare_namespace+0xc2/0x100 init/do_mounts.c:489
       kernel_init_freeable+0x46a/0x5c0 init/main.c:1560
       kernel_init+0x1d/0x2a0 init/main.c:1437
       ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304

-> #2 (&type->s_umount_key#31){++++}-{3:3}:
       down_read+0xb1/0xa40 kernel/locking/rwsem.c:1520
       __super_lock fs/super.c:58 [inline]
       super_lock+0x176/0x390 fs/super.c:117
       super_lock_shared fs/super.c:146 [inline]
       super_lock_shared_active fs/super.c:1431 [inline]
       fs_bdev_sync+0xa5/0x170 fs/super.c:1466
       blkdev_flushbuf block/ioctl.c:372 [inline]
       blkdev_common_ioctl+0x889/0x2860 block/ioctl.c:502
       blkdev_ioctl+0x520/0x730 block/ioctl.c:624
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:871 [inline]
       __se_sys_ioctl+0xf8/0x170 fs/ioctl.c:857
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #1 (&bdev->bd_holder_lock){+.+.}-{3:3}:
       __mutex_lock_common kernel/locking/mutex.c:603 [inline]
       __mutex_lock+0x136/0xd60 kernel/locking/mutex.c:747
       bd_finish_claiming+0x231/0x3f0 block/bdev.c:566
       blkdev_get_by_dev+0x481/0x620 block/bdev.c:799
       setup_bdev_super+0x5d/0x600 fs/super.c:1484
       mount_bdev+0x1e0/0x300 fs/super.c:1626
       legacy_get_tree+0xef/0x190 fs/fs_context.c:662
       vfs_get_tree+0x8c/0x280 fs/super.c:1750
       do_new_mount+0x28f/0xae0 fs/namespace.c:3335
       init_mount+0xd4/0x130 fs/init.c:25
       do_mount_root+0x98/0x230 init/do_mounts.c:166
       mount_root_generic+0x193/0x3b0 init/do_mounts.c:205
       prepare_namespace+0xc2/0x100 init/do_mounts.c:489
       kernel_init_freeable+0x46a/0x5c0 init/main.c:1560
       kernel_init+0x1d/0x2a0 init/main.c:1437
       ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304

-> #0 (bdev_lock){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3134 [inline]
       check_prevs_add kernel/locking/lockdep.c:3253 [inline]
       validate_chain kernel/locking/lockdep.c:3868 [inline]
       __lock_acquire+0x39ff/0x7f70 kernel/locking/lockdep.c:5136
       lock_acquire+0x1e3/0x520 kernel/locking/lockdep.c:5753
       __mutex_lock_common kernel/locking/mutex.c:603 [inline]
       __mutex_lock+0x136/0xd60 kernel/locking/mutex.c:747
       bd_prepare_to_claim+0x1b0/0x4c0 block/bdev.c:508
       truncate_bdev_range+0x4e/0x260 block/bdev.c:105
       blkdev_fallocate+0x4d2/0x660 block/fops.c:782
       vfs_fallocate+0x551/0x6b0 fs/open.c:324
       ksys_fallocate fs/open.c:347 [inline]
       __do_sys_fallocate fs/open.c:355 [inline]
       __se_sys_fallocate fs/open.c:353 [inline]
       __x64_sys_fallocate+0xbd/0x100 fs/open.c:353
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

other info that might help us debug this:

Chain exists of:
  bdev_lock --> &mm->mmap_lock --> mapping.invalidate_lock#2

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(mapping.invalidate_lock#2);
                               lock(&mm->mmap_lock);
                               lock(mapping.invalidate_lock#2);
  lock(bdev_lock);

 *** DEADLOCK ***

1 lock held by syz-executor.1/9625:
 #0: ffff88801ac94e40 (mapping.invalidate_lock#2){++++}-{3:3}, at: filemap_invalidate_lock include/linux/fs.h:847 [inline]
 #0: ffff88801ac94e40 (mapping.invalidate_lock#2){++++}-{3:3}, at: blkdev_fallocate+0x22a/0x660 block/fops.c:773

stack backtrace:
CPU: 0 PID: 9625 Comm: syz-executor.1 Not tainted 6.6.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106
 check_noncircular+0x375/0x4a0 kernel/locking/lockdep.c:2187
 check_prev_add kernel/locking/lockdep.c:3134 [inline]
 check_prevs_add kernel/locking/lockdep.c:3253 [inline]
 validate_chain kernel/locking/lockdep.c:3868 [inline]
 __lock_acquire+0x39ff/0x7f70 kernel/locking/lockdep.c:5136
 lock_acquire+0x1e3/0x520 kernel/locking/lockdep.c:5753
 __mutex_lock_common kernel/locking/mutex.c:603 [inline]
 __mutex_lock+0x136/0xd60 kernel/locking/mutex.c:747
 bd_prepare_to_claim+0x1b0/0x4c0 block/bdev.c:508
 truncate_bdev_range+0x4e/0x260 block/bdev.c:105
 blkdev_fallocate+0x4d2/0x660 block/fops.c:782
 vfs_fallocate+0x551/0x6b0 fs/open.c:324
 ksys_fallocate fs/open.c:347 [inline]
 __do_sys_fallocate fs/open.c:355 [inline]
 __se_sys_fallocate fs/open.c:353 [inline]
 __x64_sys_fallocate+0xbd/0x100 fs/open.c:353
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f96a207cae9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 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:00007f96a2d060c8 EFLAGS: 00000246 ORIG_RAX: 000000000000011d
RAX: ffffffffffffffda RBX: 00007f96a219bf80 RCX: 00007f96a207cae9
RDX: 0000000000000000 RSI: 0000000100000011 RDI: 0000000000000009
RBP: 00007f96a20c847a R08: 0000000000000000 R09: 0000000000000000
R10: 000000002811fdff R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f96a219bf80 R15: 00007ffda1769b08
 </TASK>

Crashes (15):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/10/30 12:32 upstream ffc253263a13 b5729d82 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/10/29 08:20 upstream 2af9b20dbb39 3c418d72 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/10/27 00:35 upstream 3a568e3a961b bf285f0c .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/10/26 12:07 upstream 611da07b89fd 23afc60f .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/10/25 17:27 upstream 4f82870119a4 72e794c4 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/10/25 11:01 upstream 4f82870119a4 17e6d526 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root possible deadlock in bd_prepare_to_claim
2023/10/25 07:52 upstream 4f82870119a4 17e6d526 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/10/15 08:12 upstream 9a3dad63edbe f757a323 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/10/14 05:18 upstream 8cb1f10d8c4b f757a323 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/10/11 01:42 upstream 1c8b86a3799f 83165b57 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-badwrites-root possible deadlock in bd_prepare_to_claim
2023/09/25 08:02 upstream 8a511e7efc5a 0b6a67ac .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root possible deadlock in bd_prepare_to_claim
2023/09/24 23:01 upstream 6465e260f487 0b6a67ac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in bd_prepare_to_claim
2023/09/26 17:07 upstream 50768a425b46 0b6a67ac .config console log report info [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream possible deadlock in bd_prepare_to_claim
2023/11/18 23:25 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 8de1e7afcc1c cb976f63 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 possible deadlock in bd_prepare_to_claim
2023/11/14 00:46 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 8de1e7afcc1c cb976f63 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 possible deadlock in bd_prepare_to_claim
* Struck through repros no longer work on HEAD.