Skip to content

Commit 981fcc5

Browse files
zhangyi089tytso
authored andcommitted
jbd2: fix deadlock in jbd2_journal_cancel_revoke()
Commit f76d4c2 ("fs/jbd2: use sleeping version of __find_get_block()") changed jbd2_journal_cancel_revoke() to use __find_get_block_nonatomic() which holds the folio lock instead of i_private_lock. This breaks the lock ordering (folio -> buffer) and causes an ABBA deadlock when the filesystem blocksize < pagesize: T1 T2 ext4_mkdir() ext4_init_new_dir() ext4_append() ext4_getblk() lock_buffer() <- A sync_blockdev() blkdev_writepages() writeback_iter() writeback_get_folio() folio_lock() <- B ext4_journal_get_create_access() jbd2_journal_cancel_revoke() __find_get_block_nonatomic() folio_lock() <- B block_write_full_folio() lock_buffer() <- A This can occasionally cause generic/013 to hang. Fix by only calling __find_get_block_nonatomic() when the passed buffer_head doesn't belong to the bdev, which is the only case that we need to look up its bdev alias. Otherwise, the lookup is redundant since the found buffer_head is equal to the one we passed in. Fixes: f76d4c2 ("fs/jbd2: use sleeping version of __find_get_block()") Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Link: https://patch.msgid.link/20260409114204.917154-1-yi.zhang@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org
1 parent 77d0595 commit 981fcc5

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

fs/jbd2/revoke.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ void jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
428428
journal_t *journal = handle->h_transaction->t_journal;
429429
int need_cancel;
430430
struct buffer_head *bh = jh2bh(jh);
431+
struct address_space *bh_mapping = bh->b_folio->mapping;
431432

432433
jbd2_debug(4, "journal_head %p, cancelling revoke\n", jh);
433434

@@ -464,13 +465,14 @@ void jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
464465
* buffer_head? If so, we'd better make sure we clear the
465466
* revoked status on any hashed alias too, otherwise the revoke
466467
* state machine will get very upset later on. */
467-
if (need_cancel) {
468+
if (need_cancel && !sb_is_blkdev_sb(bh_mapping->host->i_sb)) {
468469
struct buffer_head *bh2;
470+
469471
bh2 = __find_get_block_nonatomic(bh->b_bdev, bh->b_blocknr,
470472
bh->b_size);
471473
if (bh2) {
472-
if (bh2 != bh)
473-
clear_buffer_revoked(bh2);
474+
WARN_ON_ONCE(bh2 == bh);
475+
clear_buffer_revoked(bh2);
474476
__brelse(bh2);
475477
}
476478
}

0 commit comments

Comments
 (0)