]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
jbd2: fix a race when checking checkpoint buffer busy
authorZhang Yi <yi.zhang@huawei.com>
Tue, 6 Jun 2023 13:59:27 +0000 (21:59 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 30 Oct 2023 11:00:23 +0000 (12:00 +0100)
commita021a66c7b94f6e1ce6b7eb18ee739250c623a1c
tree58e11d45e9cc4a1aacda012441e5444f3dad870b
parentbdc347c15adf5f762196c901060ad19c88696357
jbd2: fix a race when checking checkpoint buffer busy

BugLink: https://bugs.launchpad.net/bugs/2039742
[ 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
fs/jbd2/checkpoint.c
fs/jbd2/transaction.c
include/linux/jbd2.h