From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Baptiste Lepers <baptiste.lepers@gmail.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>, Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: relocation: fix misplaced barrier in reloc_root_is_dead
Date: Wed, 26 May 2021 14:13:25 +0800 [thread overview]
Message-ID: <9fcd47ac-2642-88be-1bf0-7b920baefb10@gmx.com> (raw)
In-Reply-To: <20210526060947.26159-1-baptiste.lepers@gmail.com>
On 2021/5/26 下午2:09, Baptiste Lepers wrote:
> Fix a misplaced barrier in reloc_root_is_dead. The
> BTRFS_ROOT_DEAD_RELOC_TREE bit should be checked before accessing
> reloc_root.
>
> The fix forces the order documented in the original commit:
> "In the cross section C-D, either caller gets the DEAD bit set, avoiding
> access reloc_root no matter if it's safe or not. Or caller get the DEAD
> bit cleared, then access reloc_root, which is already NULL, nothing will
> be wrong."
>
> static bool reloc_root_is_dead()
> smp_rmb(); <--- misplaced
> if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state))
> return true;
> return false;
> }
Exactly what I originally purposed to David, we didn't reach an
agreement on where the barrier should be.
At least I'm completely fine with this patch.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
>
> static bool have_reloc_root(struct btrfs_root *root)
> {
> if (reloc_root_is_dead(root))
> return false;
> <--- the barrier should happen here
> if (!root->reloc_root)
> return false;
> return true;
> }
>
> Fixes: 6282675e6708e ("btrfs: relocation: fix reloc_root lifespan and access")
> Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
> ---
> fs/btrfs/relocation.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index b70be2ac2e9e..8cddcce56bf4 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -289,15 +289,14 @@ static int update_backref_cache(struct btrfs_trans_handle *trans,
>
> static bool reloc_root_is_dead(struct btrfs_root *root)
> {
> + bool is_dead = test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
> /*
> * Pair with set_bit/clear_bit in clean_dirty_subvols and
> * btrfs_update_reloc_root. We need to see the updated bit before
> * trying to access reloc_root
> */
> smp_rmb();
> - if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state))
> - return true;
> - return false;
> + return is_dead;
> }
>
> /*
>
prev parent reply other threads:[~2021-05-26 6:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 6:09 [PATCH] btrfs: relocation: fix misplaced barrier in reloc_root_is_dead Baptiste Lepers
2021-05-26 6:13 ` Qu Wenruo [this message]
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=9fcd47ac-2642-88be-1bf0-7b920baefb10@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=baptiste.lepers@gmail.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wqu@suse.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