From: David Sterba <dsterba@suse.cz>
To: Josef Bacik <josef@toxicpanda.com>
Cc: Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org,
Zygo Blaxell <ce3g8jdj@umail.furryterror.org>,
David Sterba <dsterba@suse.com>
Subject: Re: r
Date: Mon, 6 Jan 2020 19:04:13 +0100 [thread overview]
Message-ID: <20200106180413.GQ3929@twin.jikos.cz> (raw)
In-Reply-To: <b58caea4-476b-bf83-292d-ea71052bbea7@toxicpanda.com>
On Mon, Jan 06, 2020 at 11:33:51AM -0500, Josef Bacik wrote:
> This took me a minute to figure out, but from what I can tell you are doing the
> mb's around the BTRFS_ROOT_DEAD_RELOC_TREE flag so that in clean_dirty_subvols()
> where we clear the bit and then set root->reloc_root = NULL we are sure to
> either see the bit or that reloc_root == NULL.
>
> That's fine, but man all these random memory barriers around the bit messing
> make 0 sense and confuse the issue, what we really want is the
> smp_mb__after_atomic() in clean_dirty_subvols() and the smp_mb__before_atomic()
> in have_reloc_root().
The barriers around test_bit are required, test_bit could be reordered
as it's not a RMW operation. I suggest reding docs/atomic_t.rst on that
topic.
> But instead since we really want to know the right answer for root->reloc_root,
> and we clear that _before_ we clear the BTRFS_ROOT_DEAD_RELOC_TREE let's just do
> READ_ONCE/WRITE_ONCE everywhere we access the reloc_root. In fact you could just do
But READ/WRITE_ONCE don't guarantee CPU-ordering, only that compiler
will not reload the variable in case it's used more than once.
> static struct btrfs_root get_reloc_root(struct btrfs_root *root)
> {
> if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state))
> return NULL;
> return READ_ONCE(root->reloc_root);
Use of READ_ONCE has no effect here and produces the same buggy code as
we have now.
I sent the code to Qu in the previous discussion as work in progress,
with uncommented barriers, expecting that they will be documented in the
final version. So don't blame him, I should have not let barriers
reasoning left only on him. I'll comment under the patch.
next prev parent reply other threads:[~2020-01-06 18:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-04 13:56 [PATCH] btrfs: relocation: Fix KASAN reports caused by extended reloc tree lifespan Qu Wenruo
2020-01-05 14:49 ` Nikolay Borisov
[not found] ` <b58caea4-476b-bf83-292d-ea71052bbea7@toxicpanda.com>
2020-01-06 18:04 ` David Sterba [this message]
2020-01-06 19:26 ` r Josef Bacik
2020-01-06 18:15 ` [PATCH] btrfs: relocation: Fix KASAN reports caused by extended reloc tree lifespan David Sterba
2020-01-07 2:30 ` Qu Wenruo
2020-01-07 2:35 ` Qu Wenruo
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=20200106180413.GQ3929@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=ce3g8jdj@umail.furryterror.org \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@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