From: Jan Kara <jack@suse.cz>
To: Zhang Yi <yi.zhang@huaweicloud.com>
Cc: Zhihao Cheng <chengzhihao1@huawei.com>, Jan Kara <jack@suse.cz>,
linux-ext4@vger.kernel.org, tytso@mit.edu,
adilger.kernel@dilger.ca, yi.zhang@huawei.com,
yukuai3@huawei.com
Subject: Re: [PATCH 4/5] jbd2: Fix wrongly judgement for buffer head removing while doing checkpoint
Date: Thu, 1 Jun 2023 18:31:21 +0200 [thread overview]
Message-ID: <20230601163121.jjdo4f2xfpfx6dzi@quack3> (raw)
In-Reply-To: <ee706b3e-2a87-fa1a-570b-64870d5e49ad@huaweicloud.com>
On Thu 01-06-23 22:20:38, Zhang Yi wrote:
> On 2023/6/1 21:44, Zhihao Cheng wrote:
> > 在 2023/6/1 17:41, Jan Kara 写道:
> >
> > Hi, Jan
> >> On Wed 31-05-23 19:50:59, Zhang Yi wrote:
> >>> From: Zhihao Cheng <chengzhihao1@huawei.com>
> >>>
> >>> Following process,
> >>>
> >>> jbd2_journal_commit_transaction
> >>> // there are several dirty buffer heads in transaction->t_checkpoint_list
> >>> P1 wb_workfn
> >>> jbd2_log_do_checkpoint
> >>> if (buffer_locked(bh)) // false
> >>> __block_write_full_page
> >>> trylock_buffer(bh)
> >>> test_clear_buffer_dirty(bh)
> >>> if (!buffer_dirty(bh))
> >>> __jbd2_journal_remove_checkpoint(jh)
> >>> if (buffer_write_io_error(bh)) // false
> >>> >> bh IO error occurs <<
> >>> jbd2_cleanup_journal_tail
> >>> __jbd2_update_log_tail
> >>> jbd2_write_superblock
> >>> // The bh won't be replayed in next mount.
> >>> , which could corrupt the ext4 image, fetch a reproducer in [Link].
> >>>
> >>> Since writeback process clears buffer dirty after locking buffer head,
> >>> we can fix it by checking buffer dirty firstly and then checking buffer
> >>> locked, the buffer head can be removed if it is neither dirty nor locked.
> >>>
> >>> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217490
> >>> Fixes: 470decc613ab ("[PATCH] jbd2: initial copy of files from jbd")
> >>> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
> >>> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> >>
> >> OK, the analysis is correct but I'm afraid the fix won't be that easy. The
> >> reordering of tests you did below doesn't really help because CPU or the
> >> compiler are free to order the loads (and stores) in whatever way they
> >> wish. You'd have to use memory barriers when reading and modifying bh flags
> >> (although the modification side is implicitely handled by the bitlock
> >> code) to make this work reliably. But that is IMHO too subtle for this
> >> code.
> >>
> >
>
> I write two litmus-test files in tools/memory-model to check the memory module
> of these two cases as jbd2_log_do_checkpoint() and __cp_buffer_busy() does.
<snip litmus tests>
> So it looks like the out-of-order situation cannot happen, am I miss something?
After thinking about it a bit, indeed CPU cannot reorder the two loads
because they are from the same location in memory. Thanks for correcting me
on this. I'm not sure whether a C compiler still could not reorder the
tests - technically I suspect the C standard does not forbid this although
it would have to be really evil compiler to do this.
But still I think with the helper function I've suggested things are much
more obviously correct.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2023-06-01 16:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 11:50 [PATCH 0/5] jbd2: fix several checkpoint inconsistent issues Zhang Yi
2023-05-31 11:50 ` [PATCH 1/5] jbd2: recheck chechpointing non-dirty buffer Zhang Yi
2023-05-31 11:50 ` [PATCH 2/5] jbd2: remove t_checkpoint_io_list Zhang Yi
2023-05-31 11:50 ` [PATCH 3/5] jbd2: remove released parameter in journal_shrink_one_cp_list() Zhang Yi
2023-05-31 11:50 ` [PATCH 4/5] jbd2: Fix wrongly judgement for buffer head removing while doing checkpoint Zhang Yi
2023-06-01 9:41 ` Jan Kara
2023-06-01 13:44 ` Zhihao Cheng
2023-06-01 14:20 ` Zhang Yi
2023-06-01 16:31 ` Jan Kara [this message]
2023-06-02 1:52 ` Zhihao Cheng
2023-05-31 11:51 ` [PATCH 5/5] jbd2: fix a race when checking checkpoint buffer busy Zhang Yi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230601163121.jjdo4f2xfpfx6dzi@quack3 \
--to=jack@suse.cz \
--cc=adilger.kernel@dilger.ca \
--cc=chengzhihao1@huawei.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.com \
--cc=yi.zhang@huaweicloud.com \
--cc=yukuai3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox