Skip to content

Commit 524c385

Browse files
Tetsuo Handatytso
authored andcommitted
jbd2: use a per-journal lock_class_key for jbd2_trans_commit_key
syzbot is reporting possibility of deadlock due to sharing lock_class_key for jbd2_handle across ext4 and ocfs2. But this is a false positive, for one disk partition can't have two filesystems at the same time. Reported-by: syzbot+6e493c165d26d6fcbf72@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=6e493c165d26d6fcbf72 Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Tested-by: syzbot+6e493c165d26d6fcbf72@syzkaller.appspotmail.com Reviewed-by: Jan Kara <jack@suse.cz> Message-ID: <987110fc-5470-457a-a218-d286a09dd82f@I-love.SAKURA.ne.jp> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org
1 parent b97cb7d commit 524c385

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

fs/jbd2/journal.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,6 @@ static journal_t *journal_init_common(struct block_device *bdev,
15211521
struct block_device *fs_dev,
15221522
unsigned long long start, int len, int blocksize)
15231523
{
1524-
static struct lock_class_key jbd2_trans_commit_key;
15251524
journal_t *journal;
15261525
int err;
15271526
int n;
@@ -1530,6 +1529,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
15301529
if (!journal)
15311530
return ERR_PTR(-ENOMEM);
15321531

1532+
lockdep_register_key(&journal->jbd2_trans_commit_key);
15331533
journal->j_blocksize = blocksize;
15341534
journal->j_dev = bdev;
15351535
journal->j_fs_dev = fs_dev;
@@ -1560,7 +1560,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
15601560
journal->j_max_batch_time = 15000; /* 15ms */
15611561
atomic_set(&journal->j_reserved_credits, 0);
15621562
lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
1563-
&jbd2_trans_commit_key, 0);
1563+
&journal->jbd2_trans_commit_key, 0);
15641564

15651565
/* The journal is marked for error until we succeed with recovery! */
15661566
journal->j_flags = JBD2_ABORT;
@@ -1611,6 +1611,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
16111611
kfree(journal->j_wbuf);
16121612
jbd2_journal_destroy_revoke(journal);
16131613
journal_fail_superblock(journal);
1614+
lockdep_unregister_key(&journal->jbd2_trans_commit_key);
16141615
kfree(journal);
16151616
return ERR_PTR(err);
16161617
}
@@ -2187,6 +2188,7 @@ int jbd2_journal_destroy(journal_t *journal)
21872188
jbd2_journal_destroy_revoke(journal);
21882189
kfree(journal->j_fc_wbuf);
21892190
kfree(journal->j_wbuf);
2191+
lockdep_unregister_key(&journal->jbd2_trans_commit_key);
21902192
kfree(journal);
21912193

21922194
return err;

include/linux/jbd2.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,12 @@ struct journal_s
12531253
*/
12541254
struct lockdep_map j_trans_commit_map;
12551255
#endif
1256+
/**
1257+
* @jbd2_trans_commit_key:
1258+
*
1259+
* "struct lock_class_key" for @j_trans_commit_map
1260+
*/
1261+
struct lock_class_key jbd2_trans_commit_key;
12561262

12571263
/**
12581264
* @j_fc_cleanup_callback:

0 commit comments

Comments
 (0)