From: Qu Wenruo <wqu@suse.com>
To: Yang Xiuwei <yangxiuwei@kylinos.cn>, Chris Mason <clm@fb.com>,
David Sterba <dsterba@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Mark Harmstone <maharmstone@fb.com>,
Qu Wenruo <quwenruo.btrfs@gmx.com>,
linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH v2 5/7] btrfs: unlock inode and extent in caller when uring read extent fails
Date: Thu, 6 Aug 2026 18:40:10 +0930 [thread overview]
Message-ID: <2f43370d-0319-479d-998e-8cf09c84675f@suse.com> (raw)
In-Reply-To: <20260806085041.1410576-6-yangxiuwei@kylinos.cn>
在 2026/8/6 18:20, Yang Xiuwei 写道:
> btrfs_uring_read_extent() runs only after btrfs_encoded_read() has
> taken the inode shared lock and the extent lock. On failure it used to
> unlock in out_fail, and a pages-array allocation failure returned
> -ENOMEM without unlocking at all.
>
> Unlock in the caller instead, matching the copy_to_user() error path.
> out_fail only frees the local priv/pages allocations, and the pages
> array failure joins that path.
>
> Fixes: 34310c442e17 ("btrfs: add io_uring command for encoded reads (ENCODED_READ ioctl)")
> Suggested-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
> Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
> ---
> fs/btrfs/ioctl.c | 21 ++++++++++++---------
> 1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 939c4a9d47b6..b576887469bb 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4552,7 +4552,7 @@ static void btrfs_uring_read_finished(struct io_tw_req tw_req, io_tw_token_t tw)
> size_t page_offset;
> ssize_t ret;
>
> - /* The inode lock has already been acquired in btrfs_uring_read_extent. */
> + /* The inode lock has already been acquired in btrfs_encoded_read(). */
> btrfs_lockdep_inode_acquire(inode, i_rwsem);
>
> if (priv->err) {
> @@ -4618,7 +4618,6 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
> struct iovec *iov, struct io_uring_cmd *cmd)
> {
> struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp));
> - struct extent_io_tree *io_tree = &inode->io_tree;
> struct page **pages = NULL;
> struct btrfs_uring_priv *priv = NULL;
> unsigned long nr_pages;
> @@ -4626,8 +4625,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;
Why go to that label? We have nothing to release, the old return -ENOMEM
works completely fine now.
Otherwise looks good to me.
> + }
> ret = btrfs_alloc_page_array(nr_pages, pages, GFP_NOFS);
> if (ret) {
> ret = -ENOMEM;
> @@ -4674,12 +4675,12 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
> return -EIOCBQUEUED;
>
> out_fail:
> - 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;
> @@ -4819,6 +4820,8 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
> data->iov, cmd);
> if (ret == -EIOCBQUEUED)
> goto out_acct;
> + btrfs_unlock_extent(io_tree, start, lockend, &cached_state);
> + btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
> }
>
> out_free:
next prev parent reply other threads:[~2026-08-06 9:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 8:50 [PATCH v2 0/7] btrfs: fix io_uring encoded IO cleanup and compat Yang Xiuwei
2026-08-06 8:50 ` [PATCH v2 1/7] btrfs: always return -EIOCBQUEUED after btrfs_uring_read_extent_endio Yang Xiuwei
2026-08-06 8:50 ` [PATCH v2 2/7] btrfs: free iov when btrfs_uring_read_extent fails Yang Xiuwei
2026-08-06 8:50 ` [PATCH v2 3/7] iov_iter: export __import_iovec Yang Xiuwei
2026-08-06 8:50 ` [PATCH v2 4/7] btrfs: use IO_URING_F_COMPAT for uring encoded iovec import Yang Xiuwei
2026-08-06 8:50 ` [PATCH v2 5/7] btrfs: unlock inode and extent in caller when uring read extent fails Yang Xiuwei
2026-08-06 9:10 ` Qu Wenruo [this message]
2026-08-06 9:30 ` Yang Xiuwei
2026-08-06 9:31 ` Qu Wenruo
2026-08-06 8:50 ` [PATCH v2 6/7] btrfs: don't stash uring encoded data across -EAGAIN Yang Xiuwei
2026-08-06 8:50 ` [PATCH v2 7/7] btrfs: drop unused uring encoded IO REISSUE stash helpers 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=2f43370d-0319-479d-998e-8cf09c84675f@suse.com \
--to=wqu@suse.com \
--cc=akpm@linux-foundation.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=io-uring@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=maharmstone@fb.com \
--cc=quwenruo.btrfs@gmx.com \
--cc=viro@zeniv.linux.org.uk \
--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