From: Josef Bacik <josef@toxicpanda.com>
To: dsterba@suse.cz, 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 14:26:43 -0500 [thread overview]
Message-ID: <2d2d563f-6fa4-e307-1486-d249c2390570@toxicpanda.com> (raw)
In-Reply-To: <20200106180413.GQ3929@twin.jikos.cz>
On 1/6/20 1:04 PM, David Sterba wrote:
> 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.
>
Hmm didn't follow smp_read_barrier_depends() all the way down, I assumed it at
least protected from re-ordering. Looks like it only does something on alpha.
> 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.
>
There's still just too many of them, like I said before we're only worried about
either BTRFS_ROOT_DEAD_RELOC_TREE or !root->reloc_root. So I guess instead do
something like
static struct btrfs_root *get_reloc_root(struct btrfs_root *root)
{
if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state))
return NULL;
smp_mb__after_atomic();
return root->reloc_root;
}
And then in clean_dirty_subvols() do the smp_mb__before_atomic() before the
clear_bit. There's no reason for the random mb's around the other test_bit's.
Thanks,
Josef
next prev parent reply other threads:[~2020-01-06 19:26 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 ` r David Sterba
2020-01-06 19:26 ` Josef Bacik [this message]
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=2d2d563f-6fa4-e307-1486-d249c2390570@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=ce3g8jdj@umail.furryterror.org \
--cc=dsterba@suse.com \
--cc=dsterba@suse.cz \
--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