bcachefs: fix deadlock in journal_entry_open()
PATCH 1/1 bcachefs: fix deadlock in journal_entry_open()
In the previous commit b3d82c2f2761, code was added to prevent journal sequence overflow. Among them, the code added to journal_entry_open() uses the bch2_fs_fatal_err_on() function to handle errors.
However, __journal_res_get() , which calls journal_entry_open() , calls journal_entry_open() while holding journal->lock , but bch2_fs_fatal_err_on() internally tries to acquire journal->lock , which results in a deadlock.
Therefore, we need to use bch_err() instead of bch2_fs_fatal_err_on() to prevent deadlock.
--- fs/bcachefs/journal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/bcachefs/journal.c +3 -2
@@ -382,9 +382,10 @@ static int journal_entry_open(struct journal *j)if (nr_unwritten_journal_entries (j) ==ARRAY_SIZE (j->buf))return JOURNAL_ERR_max_in_flight; -if (bch2_fs_fatal_err_on (journal_cur_seq (j) >=JOURNAL_SEQ_MAX , - c,"cannot start: journal seq overflow" )) +if (journal_cur_seq (j) >=JOURNAL_SEQ_MAX ) { +bch_err (c,"cannot start: journal seq overflow" );return JOURNAL_ERR_insufficient_devices;/* -EROFS */ + }BUG_ON (!j->cur_entry_sectors);
--
Quoted 10 lines · Jeongjun Park
In the previous commit
b3d82c2f2761, code was added to prevent journal sequence overflow. Among them, the code added tojournal_entry_open()uses thebch2_fs_fatal_err_on()function to handle errors.However,
__journal_res_get(), which callsjournal_entry_open(), callsjournal_entry_open()while holdingjournal->lock, butbch2_fs_fatal_err_on()internally tries to acquirejournal->lock, which results in a deadlock.Therefore, we need to use
bch_err()instead ofbch2_fs_fatal_err_on()to prevent deadlock.
We do the emergency shutdown though...
Perhaps add a bch2_journal_halt_locked() helper?
Quoted 24 lines
Fixes b3d82c2f2761 ("bcachefs: Guard against journal seq overflow")Signed-off-by Jeongjun Park <[email protected]>--- fs/bcachefs/journal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/bcachefs/journal.c +3
-3@@ -382,9 +382,10 @@ static int journal_entry_open(struct journal *j)if (nr_unwritten_journal_entries (j) ==ARRAY_SIZE (j->buf))return JOURNAL_ERR_max_in_flight; -if (bch2_fs_fatal_err_on (journal_cur_seq (j) >=JOURNAL_SEQ_MAX , - c,"cannot start: journal seq overflow" )) +if (journal_cur_seq (j) >=JOURNAL_SEQ_MAX ) { +bch_err (c,"cannot start: journal seq overflow" );return JOURNAL_ERR_insufficient_devices;/* -EROFS */ + }BUG_ON (!j->cur_entry_sectors); --