mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: guolingxing <guolingxing@tju.edu.cn>,
	David Sterba <dsterba@suse.com>, Chris Mason <mason@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] btrfs: sysfs: restore NOFS context on early return in btrfs_sysfs_add_block_group_type()
Date: Thu, 15 Oct 2026 19:22:52 +1030	[thread overview]
Message-ID: <f8b3634e-4219-4544-a008-9f3781e9dce6@gmx.com> (raw)
In-Reply-To: <20261015065319.3246988-1-guolingxing@tju.edu.cn>



在 2026/10/15 17:23, guolingxing 写道:
> btrfs_sysfs_add_block_group_type() sets up a NOFS context with
> memalloc_nofs_save() because kobject_add() performs GFP_KERNEL
> allocations deep in its call chain, and the function may be called
> while holding a transaction handle or a lock required for a
> transaction commit, where reclaim could deadlock.
> 
> Every other return path of this function calls memalloc_nofs_restore()
> except the early return taken when another thread has already created
> the kobject for the same raid index (this can happen when restriping).
> Taking that path leaves PF_MEMALLOC_NOFS set on the calling task, so
> all subsequent memory allocations performed by that task remain
> restricted to the NOFS scope, which may lead to unexpected allocation
> failures or deadlocks later on.
> 
> Restore the NOFS context before returning from that path.
> 
> Fixes: 49ea112da0e6 ("btrfs: do not create raid sysfs entries under any locks")
> Cc: stable@vger.kernel.org
> Signed-off-by: guolingxing <guolingxing@tju.edu.cn>

Reviewed-by: Qu Wenruo <wqu@suse.com>

> ---
>   fs/btrfs/sysfs.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 39cb01ee441a..71b1ec6c0643 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -1857,6 +1857,7 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group *cache)
>   	if (space_info->block_group_kobjs[index]) {
>   		spin_unlock(&space_info->lock);
>   		kobject_put(&rkobj->kobj);
> +		memalloc_nofs_restore(nofs_flag);
>   		return;
>   	} else {
>   		space_info->block_group_kobjs[index] = &rkobj->kobj;


      reply	other threads:[~2026-10-15  8:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  6:53 guolingxing
2026-10-15  8:52 ` 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=f8b3634e-4219-4544-a008-9f3781e9dce6@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.com \
    --cc=guolingxing@tju.edu.cn \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=stable@vger.kernel.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

all inboxes | Powered by JetHome®