[syzbot] [ext4?] [ocfs2?] possible deadlock in dqget

8 views
Skip to first unread message

syzbot

unread,
Oct 1, 2024, 4:09:30 AM10/1/24
to ja...@suse.com, jl...@evilplan.org, jose...@linux.alibaba.com, linux...@vger.kernel.org, linux-...@vger.kernel.org, ma...@fasheh.com, ocfs2...@lists.linux.dev, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 5f5673607153 Merge branch 'for-next/core' into for-kernelci
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci
console output: https://syzkaller.appspot.com/x/log.txt?x=104a559f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=dedbcb1ff4387972
dashboard link: https://syzkaller.appspot.com/bug?extid=6e493c165d26d6fcbf72
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
userspace arch: arm64
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16d3de27980000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16f786a9980000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/40172aed5414/disk-5f567360.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/58372f305e9d/vmlinux-5f567360.xz
kernel image: https://storage.googleapis.com/syzbot-assets/d2aae6fa798f/Image-5f567360.gz.xz
mounted in repro #1: https://storage.googleapis.com/syzbot-assets/23ae94668485/mount_0.gz
mounted in repro #2: https://storage.googleapis.com/syzbot-assets/942e4e36cd02/mount_2.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+6e493c...@syzkaller.appspotmail.com

======================================================
WARNING: possible circular locking dependency detected
6.11.0-rc7-syzkaller-g5f5673607153 #0 Not tainted
------------------------------------------------------
syz-executor334/6555 is trying to acquire lock:
ffff0000e436e0a8 (&dquot->dq_lock){+.+.}-{3:3}, at: wait_on_dquot fs/quota/dquot.c:356 [inline]
ffff0000e436e0a8 (&dquot->dq_lock){+.+.}-{3:3}, at: dqget+0x5f0/0xcec fs/quota/dquot.c:972

but task is already holding lock:
ffff0000dcbec690 (&ei->xattr_sem){++++}-{3:3}, at: ext4_write_lock_xattr fs/ext4/xattr.h:155 [inline]
ffff0000dcbec690 (&ei->xattr_sem){++++}-{3:3}, at: ext4_xattr_set_handle+0x1dc/0x12d0 fs/ext4/xattr.c:2373

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #5 (&ei->xattr_sem){++++}-{3:3}:
down_write+0x50/0xc0 kernel/locking/rwsem.c:1579
ext4_write_lock_xattr fs/ext4/xattr.h:155 [inline]
ext4_xattr_set_handle+0x1dc/0x12d0 fs/ext4/xattr.c:2373
ext4_initxattrs+0xa4/0x11c fs/ext4/xattr_security.c:44
security_inode_init_security+0x210/0x3fc security/security.c:1744
ext4_init_security+0x44/0x58 fs/ext4/xattr_security.c:58
__ext4_new_inode+0x2a80/0x376c fs/ext4/ialloc.c:1326
ext4_create+0x234/0x480 fs/ext4/namei.c:2832
lookup_open fs/namei.c:3578 [inline]
open_last_lookups fs/namei.c:3647 [inline]
path_openat+0xfb4/0x29f8 fs/namei.c:3883
do_filp_open+0x1bc/0x3cc fs/namei.c:3913
do_sys_openat2+0x124/0x1b8 fs/open.c:1416
do_sys_open fs/open.c:1431 [inline]
__do_sys_openat fs/open.c:1447 [inline]
__se_sys_openat fs/open.c:1442 [inline]
__arm64_sys_openat+0x1f0/0x240 fs/open.c:1442
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:712
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598

-> #4 (jbd2_handle){++++}-{0:0}:
start_this_handle+0xf34/0x11c4 fs/jbd2/transaction.c:448
jbd2__journal_start+0x298/0x544 fs/jbd2/transaction.c:505
jbd2_journal_start+0x3c/0x4c fs/jbd2/transaction.c:544
ocfs2_start_trans+0x3d0/0x71c fs/ocfs2/journal.c:352
ocfs2_modify_bh+0xe4/0x484 fs/ocfs2/quota_local.c:101
ocfs2_local_read_info+0xec8/0x1550 fs/ocfs2/quota_local.c:769
dquot_load_quota_sb+0x700/0xb48 fs/quota/dquot.c:2460
dquot_load_quota_inode+0x280/0x4f4 fs/quota/dquot.c:2497
ocfs2_enable_quotas+0x17c/0x3cc fs/ocfs2/super.c:926
ocfs2_fill_super+0x3c80/0x4740 fs/ocfs2/super.c:1141
mount_bdev+0x1d4/0x2a0 fs/super.c:1679
ocfs2_mount+0x44/0x58 fs/ocfs2/super.c:1188
legacy_get_tree+0xd4/0x16c fs/fs_context.c:662
vfs_get_tree+0x90/0x28c fs/super.c:1800
do_new_mount+0x278/0x900 fs/namespace.c:3472
path_mount+0x590/0xe04 fs/namespace.c:3799
do_mount fs/namespace.c:3812 [inline]
__do_sys_mount fs/namespace.c:4020 [inline]
__se_sys_mount fs/namespace.c:3997 [inline]
__arm64_sys_mount+0x45c/0x5a8 fs/namespace.c:3997
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:712
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598

-> #3 (&journal->j_trans_barrier){.+.+}-{3:3}:
down_read+0x58/0x2fc kernel/locking/rwsem.c:1526
ocfs2_start_trans+0x3c4/0x71c fs/ocfs2/journal.c:350
ocfs2_modify_bh+0xe4/0x484 fs/ocfs2/quota_local.c:101
ocfs2_local_read_info+0xec8/0x1550 fs/ocfs2/quota_local.c:769
dquot_load_quota_sb+0x700/0xb48 fs/quota/dquot.c:2460
dquot_load_quota_inode+0x280/0x4f4 fs/quota/dquot.c:2497
ocfs2_enable_quotas+0x17c/0x3cc fs/ocfs2/super.c:926
ocfs2_fill_super+0x3c80/0x4740 fs/ocfs2/super.c:1141
mount_bdev+0x1d4/0x2a0 fs/super.c:1679
ocfs2_mount+0x44/0x58 fs/ocfs2/super.c:1188
legacy_get_tree+0xd4/0x16c fs/fs_context.c:662
vfs_get_tree+0x90/0x28c fs/super.c:1800
do_new_mount+0x278/0x900 fs/namespace.c:3472
path_mount+0x590/0xe04 fs/namespace.c:3799
do_mount fs/namespace.c:3812 [inline]
__do_sys_mount fs/namespace.c:4020 [inline]
__se_sys_mount fs/namespace.c:3997 [inline]
__arm64_sys_mount+0x45c/0x5a8 fs/namespace.c:3997
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:712
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598

-> #2 (sb_internal#2){.+.+}-{0:0}:
percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
__sb_start_write include/linux/fs.h:1676 [inline]
sb_start_intwrite include/linux/fs.h:1859 [inline]
ocfs2_start_trans+0x244/0x71c fs/ocfs2/journal.c:348
ocfs2_acquire_dquot+0x3c4/0xa8c fs/ocfs2/quota_global.c:852
dqget+0x660/0xcec fs/quota/dquot.c:977
__dquot_initialize+0x344/0xc04 fs/quota/dquot.c:1505
dquot_initialize+0x24/0x34 fs/quota/dquot.c:1567
ocfs2_get_init_inode+0x14c/0x1b8 fs/ocfs2/namei.c:202
ocfs2_mknod+0x878/0x243c fs/ocfs2/namei.c:308
ocfs2_create+0x194/0x4e0 fs/ocfs2/namei.c:672
lookup_open fs/namei.c:3578 [inline]
open_last_lookups fs/namei.c:3647 [inline]
path_openat+0xfb4/0x29f8 fs/namei.c:3883
do_filp_open+0x1bc/0x3cc fs/namei.c:3913
do_sys_openat2+0x124/0x1b8 fs/open.c:1416
do_sys_open fs/open.c:1431 [inline]
__do_sys_openat fs/open.c:1447 [inline]
__se_sys_openat fs/open.c:1442 [inline]
__arm64_sys_openat+0x1f0/0x240 fs/open.c:1442
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:712
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598

-> #1 (&ocfs2_quota_ip_alloc_sem_key){++++}-{3:3}:
down_write+0x50/0xc0 kernel/locking/rwsem.c:1579
ocfs2_create_local_dquot+0x1a0/0x1778 fs/ocfs2/quota_local.c:1227
ocfs2_acquire_dquot+0x6fc/0xa8c fs/ocfs2/quota_global.c:875
dqget+0x660/0xcec fs/quota/dquot.c:977
__dquot_initialize+0x344/0xc04 fs/quota/dquot.c:1505
dquot_initialize+0x24/0x34 fs/quota/dquot.c:1567
ocfs2_get_init_inode+0x14c/0x1b8 fs/ocfs2/namei.c:202
ocfs2_mknod+0x878/0x243c fs/ocfs2/namei.c:308
ocfs2_create+0x194/0x4e0 fs/ocfs2/namei.c:672
lookup_open fs/namei.c:3578 [inline]
open_last_lookups fs/namei.c:3647 [inline]
path_openat+0xfb4/0x29f8 fs/namei.c:3883
do_filp_open+0x1bc/0x3cc fs/namei.c:3913
do_sys_openat2+0x124/0x1b8 fs/open.c:1416
do_sys_open fs/open.c:1431 [inline]
__do_sys_openat fs/open.c:1447 [inline]
__se_sys_openat fs/open.c:1442 [inline]
__arm64_sys_openat+0x1f0/0x240 fs/open.c:1442
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:712
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598

-> #0 (&dquot->dq_lock){+.+.}-{3:3}:
check_prev_add kernel/locking/lockdep.c:3133 [inline]
check_prevs_add kernel/locking/lockdep.c:3252 [inline]
validate_chain kernel/locking/lockdep.c:3868 [inline]
__lock_acquire+0x33d8/0x779c kernel/locking/lockdep.c:5142
lock_acquire+0x240/0x728 kernel/locking/lockdep.c:5759
__mutex_lock_common+0x190/0x21a0 kernel/locking/mutex.c:608
__mutex_lock kernel/locking/mutex.c:752 [inline]
mutex_lock_nested+0x2c/0x38 kernel/locking/mutex.c:804
wait_on_dquot fs/quota/dquot.c:356 [inline]
dqget+0x5f0/0xcec fs/quota/dquot.c:972
__dquot_initialize+0x344/0xc04 fs/quota/dquot.c:1505
dquot_initialize+0x24/0x34 fs/quota/dquot.c:1567
__ext4_new_inode+0x664/0x376c fs/ext4/ialloc.c:991
ext4_xattr_inode_create fs/ext4/xattr.c:1486 [inline]
ext4_xattr_inode_lookup_create+0x9a4/0x19e4 fs/ext4/xattr.c:1596
ext4_xattr_block_set+0x224/0x2e08 fs/ext4/xattr.c:1916
ext4_xattr_set_handle+0xc68/0x12d0 fs/ext4/xattr.c:2458
ext4_xattr_set+0x1e0/0x354 fs/ext4/xattr.c:2560
ext4_xattr_trusted_set+0x4c/0x64 fs/ext4/xattr_trusted.c:38
__vfs_setxattr+0x3d8/0x400 fs/xattr.c:200
__vfs_setxattr_noperm+0x110/0x578 fs/xattr.c:234
__vfs_setxattr_locked+0x1ec/0x218 fs/xattr.c:295
vfs_setxattr+0x1a8/0x344 fs/xattr.c:321
do_setxattr fs/xattr.c:629 [inline]
path_setxattr+0x30c/0x428 fs/xattr.c:658
__do_sys_setxattr fs/xattr.c:676 [inline]
__se_sys_setxattr fs/xattr.c:672 [inline]
__arm64_sys_setxattr+0xbc/0xd8 fs/xattr.c:672
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:712
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598

other info that might help us debug this:

Chain exists of:
&dquot->dq_lock --> jbd2_handle --> &ei->xattr_sem

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&ei->xattr_sem);
lock(jbd2_handle);
lock(&ei->xattr_sem);
lock(&dquot->dq_lock);

*** DEADLOCK ***

3 locks held by syz-executor334/6555:
#0: ffff0000d7c00420 (sb_writers#3){.+.+}-{0:0}, at: mnt_want_write+0x44/0x9c fs/namespace.c:515
#1: ffff0000dcbec9c0 (&type->i_mutex_dir_key#3){++++}-{3:3}, at: inode_lock include/linux/fs.h:800 [inline]
#1: ffff0000dcbec9c0 (&type->i_mutex_dir_key#3){++++}-{3:3}, at: vfs_setxattr+0x17c/0x344 fs/xattr.c:320
#2: ffff0000dcbec690 (&ei->xattr_sem){++++}-{3:3}, at: ext4_write_lock_xattr fs/ext4/xattr.h:155 [inline]
#2: ffff0000dcbec690 (&ei->xattr_sem){++++}-{3:3}, at: ext4_xattr_set_handle+0x1dc/0x12d0 fs/ext4/xattr.c:2373

stack backtrace:
CPU: 0 UID: 0 PID: 6555 Comm: syz-executor334 Not tainted 6.11.0-rc7-syzkaller-g5f5673607153 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
Call trace:
dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:319
show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:326
__dump_stack lib/dump_stack.c:93 [inline]
dump_stack_lvl+0xe4/0x150 lib/dump_stack.c:119
dump_stack+0x1c/0x28 lib/dump_stack.c:128
print_circular_bug+0x150/0x1b8 kernel/locking/lockdep.c:2059
check_noncircular+0x310/0x404 kernel/locking/lockdep.c:2186
check_prev_add kernel/locking/lockdep.c:3133 [inline]
check_prevs_add kernel/locking/lockdep.c:3252 [inline]
validate_chain kernel/locking/lockdep.c:3868 [inline]
__lock_acquire+0x33d8/0x779c kernel/locking/lockdep.c:5142
lock_acquire+0x240/0x728 kernel/locking/lockdep.c:5759
__mutex_lock_common+0x190/0x21a0 kernel/locking/mutex.c:608
__mutex_lock kernel/locking/mutex.c:752 [inline]
mutex_lock_nested+0x2c/0x38 kernel/locking/mutex.c:804
wait_on_dquot fs/quota/dquot.c:356 [inline]
dqget+0x5f0/0xcec fs/quota/dquot.c:972
__dquot_initialize+0x344/0xc04 fs/quota/dquot.c:1505
dquot_initialize+0x24/0x34 fs/quota/dquot.c:1567
__ext4_new_inode+0x664/0x376c fs/ext4/ialloc.c:991
ext4_xattr_inode_create fs/ext4/xattr.c:1486 [inline]
ext4_xattr_inode_lookup_create+0x9a4/0x19e4 fs/ext4/xattr.c:1596
ext4_xattr_block_set+0x224/0x2e08 fs/ext4/xattr.c:1916
ext4_xattr_set_handle+0xc68/0x12d0 fs/ext4/xattr.c:2458
ext4_xattr_set+0x1e0/0x354 fs/ext4/xattr.c:2560
ext4_xattr_trusted_set+0x4c/0x64 fs/ext4/xattr_trusted.c:38
__vfs_setxattr+0x3d8/0x400 fs/xattr.c:200
__vfs_setxattr_noperm+0x110/0x578 fs/xattr.c:234
__vfs_setxattr_locked+0x1ec/0x218 fs/xattr.c:295
vfs_setxattr+0x1a8/0x344 fs/xattr.c:321
do_setxattr fs/xattr.c:629 [inline]
path_setxattr+0x30c/0x428 fs/xattr.c:658
__do_sys_setxattr fs/xattr.c:676 [inline]
__se_sys_setxattr fs/xattr.c:672 [inline]
__arm64_sys_setxattr+0xbc/0xd8 fs/xattr.c:672
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:712
el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

syzbot

unread,
Oct 19, 2025, 4:33:23 AMĀ (yesterday)Ā Oct 19
to syzkall...@googlegroups.com
For archival purposes, forwarding an incoming command email to
syzkall...@googlegroups.com.

***

Subject: Re: [syzbot] [ext4?] [ocfs2?] possible deadlock in dqget
Author: penguin...@i-love.sakura.ne.jp

#syz test

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 699c15db28a8..71c1cb792e2d 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5956,7 +5956,7 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
return ERR_CAST(bdev_file);

journal = jbd2_journal_init_dev(file_bdev(bdev_file), sb->s_bdev, j_start,
- j_len, sb->s_blocksize);
+ j_len, sb->s_blocksize, EXT4_SUPER_MAGIC);
if (IS_ERR(journal)) {
ext4_msg(sb, KERN_ERR, "failed to create device journal");
errno = PTR_ERR(journal);
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index d480b94117cd..2f4fbd74cf76 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1517,11 +1517,13 @@ static int journal_load_superblock(journal_t *journal)
* superblock and initialize the journal_t object.
*/

-static journal_t *journal_init_common(struct block_device *bdev,
- struct block_device *fs_dev,
- unsigned long long start, int len, int blocksize)
+static journal_t *journal_init_common(struct block_device *bdev, struct block_device *fs_dev,
+ unsigned long long start, int len, int blocksize,
+ unsigned long fsmagic)
{
- static struct lock_class_key jbd2_trans_commit_key;
+ static struct lock_class_key jbd2_trans_commit_key_ext4;
+ static struct lock_class_key jbd2_trans_commit_key_ocfs2;
+ static struct lock_class_key jbd2_trans_commit_key_unknown;
journal_t *journal;
int err;
int n;
@@ -1547,20 +1549,49 @@ static journal_t *journal_init_common(struct block_device *bdev,
init_waitqueue_head(&journal->j_wait_updates);
init_waitqueue_head(&journal->j_wait_reserved);
init_waitqueue_head(&journal->j_fc_wait);
- mutex_init(&journal->j_abort_mutex);
- mutex_init(&journal->j_barrier);
- mutex_init(&journal->j_checkpoint_mutex);
- spin_lock_init(&journal->j_revoke_lock);
- spin_lock_init(&journal->j_list_lock);
- spin_lock_init(&journal->j_history_lock);
- rwlock_init(&journal->j_state_lock);
+ if (IS_ENABLED(CONFIG_LOCKDEP) && IS_ENABLED(CONFIG_EXT4_FS) &&
+ fsmagic == EXT4_SUPER_MAGIC) {
+ mutex_init(&journal->j_abort_mutex);
+ mutex_init(&journal->j_barrier);
+ mutex_init(&journal->j_checkpoint_mutex);
+ spin_lock_init(&journal->j_revoke_lock);
+ spin_lock_init(&journal->j_list_lock);
+ spin_lock_init(&journal->j_history_lock);
+ rwlock_init(&journal->j_state_lock);
+ } else if (IS_ENABLED(CONFIG_LOCKDEP) && IS_ENABLED(CONFIG_OCFS2_FS) &&
+ fsmagic == OCFS2_SUPER_MAGIC) {
+ mutex_init(&journal->j_abort_mutex);
+ mutex_init(&journal->j_barrier);
+ mutex_init(&journal->j_checkpoint_mutex);
+ spin_lock_init(&journal->j_revoke_lock);
+ spin_lock_init(&journal->j_list_lock);
+ spin_lock_init(&journal->j_history_lock);
+ rwlock_init(&journal->j_state_lock);
+ } else {
+ mutex_init(&journal->j_abort_mutex);
+ mutex_init(&journal->j_barrier);
+ mutex_init(&journal->j_checkpoint_mutex);
+ spin_lock_init(&journal->j_revoke_lock);
+ spin_lock_init(&journal->j_list_lock);
+ spin_lock_init(&journal->j_history_lock);
+ rwlock_init(&journal->j_state_lock);
+ }

journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
journal->j_min_batch_time = 0;
journal->j_max_batch_time = 15000; /* 15ms */
atomic_set(&journal->j_reserved_credits, 0);
- lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
- &jbd2_trans_commit_key, 0);
+ if (IS_ENABLED(CONFIG_LOCKDEP) && IS_ENABLED(CONFIG_EXT4_FS) &&
+ fsmagic == EXT4_SUPER_MAGIC)
+ lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle_ext4",
+ &jbd2_trans_commit_key_ext4, 0);
+ else if (IS_ENABLED(CONFIG_LOCKDEP) && IS_ENABLED(CONFIG_OCFS2_FS) &&
+ fsmagic == OCFS2_SUPER_MAGIC)
+ lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle_ocfs2",
+ &jbd2_trans_commit_key_ocfs2, 0);
+ else
+ lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle_unknown",
+ &jbd2_trans_commit_key_unknown, 0);

/* The journal is marked for error until we succeed with recovery! */
journal->j_flags = JBD2_ABORT;
@@ -1631,6 +1662,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
* @start: Block nr Start of journal.
* @len: Length of the journal in blocks.
* @blocksize: blocksize of journalling device
+ * @fsmagic: filesystem magic number for lockdep annotation
*
* Returns: a newly created journal_t *
*
@@ -1638,13 +1670,13 @@ static journal_t *journal_init_common(struct block_device *bdev,
* range of blocks on an arbitrary block device.
*
*/
-journal_t *jbd2_journal_init_dev(struct block_device *bdev,
- struct block_device *fs_dev,
- unsigned long long start, int len, int blocksize)
+journal_t *jbd2_journal_init_dev(struct block_device *bdev, struct block_device *fs_dev,
+ unsigned long long start, int len, int blocksize,
+ unsigned long fsmagic)
{
journal_t *journal;

- journal = journal_init_common(bdev, fs_dev, start, len, blocksize);
+ journal = journal_init_common(bdev, fs_dev, start, len, blocksize, fsmagic);
if (IS_ERR(journal))
return ERR_CAST(journal);

@@ -1682,8 +1714,8 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);

journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev,
- blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits,
- inode->i_sb->s_blocksize);
+ blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits,
+ inode->i_sb->s_blocksize, inode->i_sb->s_magic);
if (IS_ERR(journal))
return ERR_CAST(journal);

diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 43b9297fe8a7..a5d6f6ae5a35 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1523,9 +1523,9 @@ extern void jbd2_journal_unlock_updates (journal_t *);

void jbd2_journal_wait_updates(journal_t *);

-extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
- struct block_device *fs_dev,
- unsigned long long start, int len, int bsize);
+extern journal_t * jbd2_journal_init_dev(struct block_device *bdev, struct block_device *fs_dev,
+ unsigned long long start, int len, int bsize,
+ unsigned long fsmagic);
extern journal_t * jbd2_journal_init_inode (struct inode *);
extern int jbd2_journal_update_format (journal_t *);
extern int jbd2_journal_check_used_features

syzbot

unread,
9:27 AMĀ (6 hours ago)Ā 9:27 AM
to syzkall...@googlegroups.com
For archival purposes, forwarding an incoming command email to
syzkall...@googlegroups.com.

***

Subject: Re: [syzbot] [ext4?] [ocfs2?] possible deadlock in dqget
Author: penguin...@i-love.sakura.ne.jp

#syz test

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 33e7c08c9529..bd50ac035342 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -60,6 +60,8 @@
#define CREATE_TRACE_POINTS
#include <trace/events/ext4.h>

+static struct jbd2_lock_class_keys jbd2_ext4_lock_class_keys = { .name = "jbd2_ext4_handle" };
+
static struct ext4_lazy_init *ext4_li_info;
static DEFINE_MUTEX(ext4_li_mtx);
static struct ratelimit_state ext4_mount_msg_ratelimit;
@@ -5859,7 +5861,7 @@ static journal_t *ext4_open_inode_journal(struct super_block *sb,
if (IS_ERR(journal_inode))
return ERR_CAST(journal_inode);

- journal = jbd2_journal_init_inode(journal_inode);
+ journal = jbd2_journal_init_inode(journal_inode, &jbd2_ext4_lock_class_keys);
if (IS_ERR(journal)) {
ext4_msg(sb, KERN_ERR, "Could not load journal inode");
iput(journal_inode);
@@ -5964,7 +5966,7 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
return ERR_CAST(bdev_file);

journal = jbd2_journal_init_dev(file_bdev(bdev_file), sb->s_bdev, j_start,
- j_len, sb->s_blocksize);
+ j_len, sb->s_blocksize, &jbd2_ext4_lock_class_keys);
if (IS_ERR(journal)) {
ext4_msg(sb, KERN_ERR, "failed to create device journal");
errno = PTR_ERR(journal);
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index d480b94117cd..821d440ce17a 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1517,11 +1517,10 @@ static int journal_load_superblock(journal_t *journal)
* superblock and initialize the journal_t object.
*/

-static journal_t *journal_init_common(struct block_device *bdev,
- struct block_device *fs_dev,
- unsigned long long start, int len, int blocksize)
+static journal_t *journal_init_common(struct block_device *bdev, struct block_device *fs_dev,
+ unsigned long long start, int len, int blocksize,
+ struct jbd2_lock_class_keys *keys)
{
- static struct lock_class_key jbd2_trans_commit_key;
journal_t *journal;
int err;
int n;
@@ -1547,9 +1546,9 @@ static journal_t *journal_init_common(struct block_device *bdev,
init_waitqueue_head(&journal->j_wait_updates);
init_waitqueue_head(&journal->j_wait_reserved);
init_waitqueue_head(&journal->j_fc_wait);
- mutex_init(&journal->j_abort_mutex);
- mutex_init(&journal->j_barrier);
- mutex_init(&journal->j_checkpoint_mutex);
+ mutex_init_with_key(&journal->j_abort_mutex, &keys->j_abort_mutex);
+ mutex_init_with_key(&journal->j_barrier, &keys->j_barrier);
+ mutex_init_with_key(&journal->j_checkpoint_mutex, &keys->j_checkpoint_mutex);
spin_lock_init(&journal->j_revoke_lock);
spin_lock_init(&journal->j_list_lock);
spin_lock_init(&journal->j_history_lock);
@@ -1559,8 +1558,8 @@ static journal_t *journal_init_common(struct block_device *bdev,
journal->j_min_batch_time = 0;
journal->j_max_batch_time = 15000; /* 15ms */
atomic_set(&journal->j_reserved_credits, 0);
- lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
- &jbd2_trans_commit_key, 0);
+ lockdep_init_map(&journal->j_trans_commit_map, keys->name,
+ &keys->jbd2_trans_commit_key, 0);

/* The journal is marked for error until we succeed with recovery! */
journal->j_flags = JBD2_ABORT;
@@ -1631,6 +1630,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
* @start: Block nr Start of journal.
* @len: Length of the journal in blocks.
* @blocksize: blocksize of journalling device
+ * @keys: Pointer to struct jbd2_lock_class_keys for lockdep annotation
*
* Returns: a newly created journal_t *
*
@@ -1638,13 +1638,13 @@ static journal_t *journal_init_common(struct block_device *bdev,
* range of blocks on an arbitrary block device.
*
*/
-journal_t *jbd2_journal_init_dev(struct block_device *bdev,
- struct block_device *fs_dev,
- unsigned long long start, int len, int blocksize)
+journal_t *jbd2_journal_init_dev(struct block_device *bdev, struct block_device *fs_dev,
+ unsigned long long start, int len, int blocksize,
+ struct jbd2_lock_class_keys *keys)
{
journal_t *journal;

- journal = journal_init_common(bdev, fs_dev, start, len, blocksize);
+ journal = journal_init_common(bdev, fs_dev, start, len, blocksize, keys);
if (IS_ERR(journal))
return ERR_CAST(journal);

@@ -1664,7 +1664,7 @@ journal_t *jbd2_journal_init_dev(struct block_device *bdev,
* the journal. The inode must exist already, must support bmap() and
* must have all data blocks preallocated.
*/
-journal_t *jbd2_journal_init_inode(struct inode *inode)
+journal_t *jbd2_journal_init_inode(struct inode *inode, struct jbd2_lock_class_keys *keys)
{
journal_t *journal;
sector_t blocknr;
@@ -1682,8 +1682,8 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);

journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev,
- blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits,
- inode->i_sb->s_blocksize);
+ blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits,
+ inode->i_sb->s_blocksize, keys);
if (IS_ERR(journal))
return ERR_CAST(journal);

diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index e5f58ff2175f..e92746e3cb0b 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -43,6 +43,8 @@

DEFINE_SPINLOCK(trans_inc_lock);

+static struct jbd2_lock_class_keys jbd2_ocfs2_lock_class_keys = { .name = "jbd2_ocfs2_handle" };
+
#define ORPHAN_SCAN_SCHEDULE_TIMEOUT 300000

static int ocfs2_force_read_journal(struct inode *inode);
@@ -968,7 +970,7 @@ int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty)
OCFS2_I(inode)->ip_clusters);

/* call the kernels journal init function now */
- j_journal = jbd2_journal_init_inode(inode);
+ j_journal = jbd2_journal_init_inode(inode, &jbd2_ocfs2_lock_class_keys);
if (IS_ERR(j_journal)) {
mlog(ML_ERROR, "Linux journal layer error\n");
status = PTR_ERR(j_journal);
@@ -1759,7 +1761,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
goto done;
}

- journal = jbd2_journal_init_inode(inode);
+ journal = jbd2_journal_init_inode(inode, &jbd2_ocfs2_lock_class_keys);
if (IS_ERR(journal)) {
mlog(ML_ERROR, "Linux journal layer error\n");
status = PTR_ERR(journal);
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 43b9297fe8a7..7ecfc7f7be62 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1287,6 +1287,14 @@ struct journal_s
int (*j_bmap)(struct journal_s *journal, sector_t *block);
};

+struct jbd2_lock_class_keys {
+ const char *name;
+ struct lock_class_key jbd2_trans_commit_key;
+ struct lock_class_key j_abort_mutex;
+ struct lock_class_key j_barrier;
+ struct lock_class_key j_checkpoint_mutex;
+};
+
#define jbd2_might_wait_for_commit(j) \
do { \
rwsem_acquire(&j->j_trans_commit_map, 0, 0, _THIS_IP_); \
@@ -1523,10 +1531,10 @@ extern void jbd2_journal_unlock_updates (journal_t *);

void jbd2_journal_wait_updates(journal_t *);

-extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
- struct block_device *fs_dev,
- unsigned long long start, int len, int bsize);
-extern journal_t * jbd2_journal_init_inode (struct inode *);
+extern journal_t *jbd2_journal_init_dev(struct block_device *bdev, struct block_device *fs_dev,
+ unsigned long long start, int len, int bsize,
+ struct jbd2_lock_class_keys *keys);
+extern journal_t *jbd2_journal_init_inode(struct inode *inode, struct jbd2_lock_class_keys *keys);
extern int jbd2_journal_update_format (journal_t *);
extern int jbd2_journal_check_used_features
(journal_t *, unsigned long, unsigned long, unsigned long);

Reply all
Reply to author
Forward
0 new messages