From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Yang Xiuwei <yangxiuwei@kylinos.cn>, Chris Mason <clm@fb.com>,
David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org, Mark Harmstone <maharmstone@fb.com>
Subject: Re: [PATCH 1/3] btrfs: unlock inode and extent on pages alloc failure in uring read
Date: Wed, 5 Aug 2026 12:49:00 +0930 [thread overview]
Message-ID: <49b72d7e-be1b-4bd1-a6b5-3261502ed1a0@gmx.com> (raw)
In-Reply-To: <20260805021135.1896609-2-yangxiuwei@kylinos.cn>
在 2026/8/5 11:41, Yang Xiuwei 写道:
> btrfs_uring_read_extent() is only reached after btrfs_encoded_read()
> has taken the inode shared lock and the extent lock. If allocating
> the pages array fails it returned -ENOMEM directly and left both
> locks held.
>
> Fixes: 34310c442e17 ("btrfs: add io_uring command for encoded reads (ENCODED_READ ioctl)")
> Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
> ---
> fs/btrfs/ioctl.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 68b33f365fda..c953e4409d5b 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4626,8 +4626,10 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
>
> nr_pages = DIV_ROUND_UP(disk_io_size, PAGE_SIZE);
> pages = kzalloc_objs(struct page *, nr_pages, GFP_NOFS);
> - if (!pages)
> - return -ENOMEM;
> + if (!pages) {
> + ret = -ENOMEM;
> + goto out_fail;
The extra handling is only to unlock the inode and extent io tree.
And neither the inode nor extent io tree is locked by the function
itself, but btrfs_encoded_read().
I do not believe this is the correct location to unlock inode/extent io
tree.
Move the unlock into the caller, as the caller is already doing such
unlock after copy_to_user() failed.
> + }
> ret = btrfs_alloc_page_array(nr_pages, pages, GFP_NOFS);
> if (ret) {
> ret = -ENOMEM;
> @@ -4677,9 +4679,11 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
> btrfs_unlock_extent(io_tree, start, lockend, &cached_state);
> btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
> kfree(priv);
> - for (int i = 0; i < nr_pages; i++) {
> - if (pages[i])
> - __free_page(pages[i]);
> + if (pages) {
> + for (int i = 0; i < nr_pages; i++) {
> + if (pages[i])
> + __free_page(pages[i]);
> + }
> }
> kfree(pages);
> return ret;
next prev parent reply other threads:[~2026-08-05 3:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 2:11 [PATCH 0/3] btrfs: fix io_uring encoded read cleanup paths Yang Xiuwei
2026-08-05 2:11 ` [PATCH 1/3] btrfs: unlock inode and extent on pages alloc failure in uring read Yang Xiuwei
2026-08-05 3:19 ` Qu Wenruo [this message]
2026-08-05 4:18 ` Yang Xiuwei
2026-08-05 2:11 ` [PATCH 2/3] btrfs: always return -EIOCBQUEUED after btrfs_uring_read_extent_endio Yang Xiuwei
2026-08-05 3:21 ` Qu Wenruo
2026-08-05 4:18 ` Yang Xiuwei
2026-08-05 2:11 ` [PATCH 3/3] btrfs: free iov when btrfs_uring_read_extent fails Yang Xiuwei
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=49b72d7e-be1b-4bd1-a6b5-3261502ed1a0@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=maharmstone@fb.com \
--cc=yangxiuwei@kylinos.cn \
/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