From: Nikolay Borisov <nborisov@suse.com>
To: Matthew Wilcox <willy@infradead.org>,
Filipe Manana <fdmanana@kernel.org>
Cc: dai.ngo@oracle.com, linux-btrfs <linux-btrfs@vger.kernel.org>,
gniebler@suse.com,
"linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>
Subject: Re: bug in btrfs during low memory testing.
Date: Wed, 6 Jul 2022 09:36:42 +0300 [thread overview]
Message-ID: <148c0ac2-add4-69e8-ced7-49772841720b@suse.com> (raw)
In-Reply-To: <YsSfPl6IvqrM5OPU@casper.infradead.org>
On 5.07.22 г. 23:29 ч., Matthew Wilcox wrote:
> On Tue, Jul 05, 2022 at 09:26:47PM +0100, Filipe Manana wrote:
>> In this case we can actually call xa_insert() without holding that
>> spinlock, it's safe against other concurrent calls to
>> btrfs_get_or_create_delayed_node(), btrfs_get_delayed_node(),
>> btrfs_kill_delayed_inode_items(), etc.
>>
>> However, looking at xa_insert() we have:
>>
>> xa_lock(xa);
>> err = __xa_insert(xa, index, entry, gfp);
>> xa_unlock(xa);
>>
>> And xa_lock() is defined as:
>>
>> #define xa_lock(xa) spin_lock(&(xa)->xa_lock)
>>
>> So we'll always be under a spinlock even if we change btrfs to not
>> take the root->inode_lock spinlock.
>>
>> This seems more like a general problem outside btrfs' control.
>> So CC'ing Willy to double check.
>
> No, the XArray knows about its own spinlock. It'll drop it if it needs
> to allocate memory and the GFP flags indicate that the caller can sleep.
> It doesn't know about your spinlock, so it can't do the same thing for
> you ;-)
In order to catch (and prevent) further offensive can we perhaps have
something like that in xa_insert:
diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index c29e11b2c073..63c00b2945a2 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -770,6 +770,9 @@ static inline int __must_check xa_insert(struct
xarray *xa,
{
int err;
+ if (gfpflags_allow_blocking(gfp))
+ might_sleep()
+
xa_lock(xa);
err = __xa_insert(xa, index, entry, gfp);
xa_unlock(xa);
Because an alternative route to fix is it to have GFP_ATOMIC in the gfp.
Basically we'd want to bark on xa_insert execution when we are
in_atomic(), cause by something else apart from xa_lock ?
next prev parent reply other threads:[~2022-07-06 6:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-05 19:37 bug in btrfs during low memory testing dai.ngo
2022-07-05 20:26 ` Filipe Manana
2022-07-05 20:29 ` Matthew Wilcox
2022-07-05 20:33 ` Filipe Manana
2022-07-06 6:36 ` Nikolay Borisov [this message]
2022-07-06 12:09 ` Matthew Wilcox
2022-07-06 12:13 ` Nikolay Borisov
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=148c0ac2-add4-69e8-ced7-49772841720b@suse.com \
--to=nborisov@suse.com \
--cc=dai.ngo@oracle.com \
--cc=fdmanana@kernel.org \
--cc=gniebler@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=willy@infradead.org \
/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