summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorZhang Yi <yi.zhang@huawei.com>2023-06-06 21:59:27 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-08-30 16:10:58 +0200
commite5c768d809a85e9efd0274b2efe69d4970cc0014 (patch)
tree554485936f36da91229a4efe0885e0136f00e82e /include
parent5fda50e262e65bd553ff777c4b280afd1495a18b (diff)
downloadlinux-e5c768d809a85e9efd0274b2efe69d4970cc0014.tar.gz
jbd2: fix a race when checking checkpoint buffer busy
[ Upstream commit 46f881b5b1758dc4a35fba4a643c10717d0cf427 ]

Before removing checkpoint buffer from the t_checkpoint_list, we have to
check both BH_Dirty and BH_Lock bits together to distinguish buffers
have not been or were being written back. But __cp_buffer_busy() checks
them separately, it first check lock state and then check dirty, the
window between these two checks could be raced by writing back
procedure, which locks buffer and clears buffer dirty before I/O
completes. So it cannot guarantee checkpointing buffers been written
back to disk if some error happens later. Finally, it may clean
checkpoint transactions and lead to inconsistent filesystem.

jbd2_journal_forget() and __journal_try_to_free_buffer() also have the
same problem (journal_unmap_buffer() escape from this issue since it's
running under the buffer lock), so fix them through introducing a new
helper to try holding the buffer lock and remove really clean buffer.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=217490
Cc: stable@vger.kernel.org
Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230606135928.434610-6-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/jbd2.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 67912fe08fbb..ebb1608d9dcd 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1435,6 +1435,7 @@ extern void jbd2_journal_commit_transaction(journal_t *);
 void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy);
 unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal, unsigned long *nr_to_scan);
 int __jbd2_journal_remove_checkpoint(struct journal_head *);
+int jbd2_journal_try_remove_checkpoint(struct journal_head *jh);
 void jbd2_journal_destroy_checkpoint(journal_t *journal);
 void __jbd2_journal_insert_checkpoint(struct journal_head *, transaction_t *);