From: Caleb Sander Mateos <csander@purestorage.com>
To: Ming Lei <ming.lei@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>,
io-uring@vger.kernel.org,
Pavel Begunkov <asml.silence@gmail.com>,
linux-block@vger.kernel.org,
Uday Shankar <ushankar@purestorage.com>,
Keith Busch <kbusch@kernel.org>
Subject: Re: [RFC PATCH 2/7] io_uring: add helper __io_buffer_[un]register_bvec
Date: Mon, 28 Apr 2025 17:36:28 -0700 [thread overview]
Message-ID: <CADUfDZpTnntS0r40rBV4aeBx6Sf=X8jQiZDiB+C8Vch7CdaPtQ@mail.gmail.com> (raw)
In-Reply-To: <20250428094420.1584420-3-ming.lei@redhat.com>
On Mon, Apr 28, 2025 at 2:44 AM Ming Lei <ming.lei@redhat.com> wrote:
>
> Add helper __io_buffer_[un]register_bvec and prepare for supporting to
> register bvec buffer into specified io_uring and buffer index.
>
> No functional change.
>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> io_uring/rsrc.c | 88 ++++++++++++++++++++++++++-----------------------
> 1 file changed, 46 insertions(+), 42 deletions(-)
>
> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 66d2c11e2f46..5f8ab130a573 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c
> @@ -918,11 +918,9 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
> return ret;
> }
>
> -int io_buffer_register_bvec(struct io_uring_cmd *cmd,
> - struct io_buf_data *buf,
> - unsigned int issue_flags)
> +static int __io_buffer_register_bvec(struct io_ring_ctx *ctx,
> + struct io_buf_data *buf)
__must_hold(&ctx->uring_lock) ? Same comment about
__io_buffer_unregister_bvec().
Best,
Caleb
> {
> - struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx;
> struct io_rsrc_data *data = &ctx->buf_table;
> unsigned int index = buf->index;
> struct request *rq = buf->rq;
> @@ -931,32 +929,23 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd,
> struct io_rsrc_node *node;
> struct bio_vec bv, *bvec;
> u16 nr_bvecs;
> - int ret = 0;
>
> - io_ring_submit_lock(ctx, issue_flags);
> - if (index >= data->nr) {
> - ret = -EINVAL;
> - goto unlock;
> - }
> - index = array_index_nospec(index, data->nr);
> + if (index >= data->nr)
> + return -EINVAL;
>
> - if (data->nodes[index]) {
> - ret = -EBUSY;
> - goto unlock;
> - }
> + index = array_index_nospec(index, data->nr);
> + if (data->nodes[index])
> + return -EBUSY;
>
> node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER);
> - if (!node) {
> - ret = -ENOMEM;
> - goto unlock;
> - }
> + if (!node)
> + return -ENOMEM;
>
> nr_bvecs = blk_rq_nr_phys_segments(rq);
> imu = io_alloc_imu(ctx, nr_bvecs);
> if (!imu) {
> kfree(node);
> - ret = -ENOMEM;
> - goto unlock;
> + return -ENOMEM;
> }
>
> imu->ubuf = 0;
> @@ -976,43 +965,58 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd,
>
> node->buf = imu;
> data->nodes[index] = node;
> -unlock:
> +
> + return 0;
> +}
> +
> +int io_buffer_register_bvec(struct io_uring_cmd *cmd,
> + struct io_buf_data *buf,
> + unsigned int issue_flags)
> +{
> + struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx;
> + int ret;
> +
> + io_ring_submit_lock(ctx, issue_flags);
> + ret = __io_buffer_register_bvec(ctx, buf);
> io_ring_submit_unlock(ctx, issue_flags);
> +
> return ret;
> }
> EXPORT_SYMBOL_GPL(io_buffer_register_bvec);
>
> -int io_buffer_unregister_bvec(struct io_uring_cmd *cmd,
> - struct io_buf_data *buf,
> - unsigned int issue_flags)
> +static int __io_buffer_unregister_bvec(struct io_ring_ctx *ctx,
> + struct io_buf_data *buf)
> {
> - struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx;
> struct io_rsrc_data *data = &ctx->buf_table;
> unsigned index = buf->index;
> struct io_rsrc_node *node;
> - int ret = 0;
>
> - io_ring_submit_lock(ctx, issue_flags);
> - if (index >= data->nr) {
> - ret = -EINVAL;
> - goto unlock;
> - }
> - index = array_index_nospec(index, data->nr);
> + if (index >= data->nr)
> + return -EINVAL;
>
> + index = array_index_nospec(index, data->nr);
> node = data->nodes[index];
> - if (!node) {
> - ret = -EINVAL;
> - goto unlock;
> - }
> - if (!node->buf->is_kbuf) {
> - ret = -EBUSY;
> - goto unlock;
> - }
> + if (!node)
> + return -EINVAL;
> + if (!node->buf->is_kbuf)
> + return -EBUSY;
>
> io_put_rsrc_node(ctx, node);
> data->nodes[index] = NULL;
> -unlock:
> + return 0;
> +}
> +
> +int io_buffer_unregister_bvec(struct io_uring_cmd *cmd,
> + struct io_buf_data *buf,
> + unsigned int issue_flags)
> +{
> + struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx;
> + int ret;
> +
> + io_ring_submit_lock(ctx, issue_flags);
> + ret = __io_buffer_unregister_bvec(ctx, buf);
> io_ring_submit_unlock(ctx, issue_flags);
> +
> return ret;
> }
> EXPORT_SYMBOL_GPL(io_buffer_unregister_bvec);
> --
> 2.47.0
>
next prev parent reply other threads:[~2025-04-29 0:36 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 9:44 [RFC PATCH 0/7] ublk: support to register bvec buffer automatically Ming Lei
2025-04-28 9:44 ` [RFC PATCH 1/7] io_uring: add 'struct io_buf_data' for register/unregister bvec buffer Ming Lei
2025-04-29 0:35 ` Caleb Sander Mateos
2025-04-28 9:44 ` [RFC PATCH 2/7] io_uring: add helper __io_buffer_[un]register_bvec Ming Lei
2025-04-29 0:36 ` Caleb Sander Mateos [this message]
2025-04-28 9:44 ` [RFC PATCH 3/7] io_uring: support to register bvec buffer to specified io_uring Ming Lei
2025-04-28 10:28 ` Pavel Begunkov
2025-04-29 0:46 ` Caleb Sander Mateos
2025-04-29 0:47 ` Ming Lei
2025-04-30 8:25 ` Pavel Begunkov
2025-04-30 14:44 ` Ming Lei
2025-04-29 0:43 ` Caleb Sander Mateos
2025-04-30 15:34 ` Ming Lei
2025-05-02 1:31 ` Caleb Sander Mateos
2025-05-02 15:59 ` Ming Lei
2025-05-02 21:21 ` Caleb Sander Mateos
2025-05-03 1:00 ` Ming Lei
2025-05-03 18:55 ` Caleb Sander Mateos
2025-05-06 2:45 ` Ming Lei
2025-04-28 9:44 ` [RFC PATCH 4/7] ublk: convert to refcount_t Ming Lei
2025-04-28 17:13 ` Caleb Sander Mateos
2025-04-28 9:44 ` [RFC PATCH 5/7] ublk: prepare for supporting to register request buffer automatically Ming Lei
2025-04-29 0:50 ` Caleb Sander Mateos
2025-04-28 9:44 ` [RFC PATCH 6/7] ublk: register buffer to specified io_uring & buf index via UBLK_F_AUTO_BUF_REG Ming Lei
2025-04-29 0:52 ` Caleb Sander Mateos
2025-04-30 15:45 ` Ming Lei
2025-04-30 16:30 ` Caleb Sander Mateos
2025-05-02 14:09 ` Ming Lei
2025-04-28 9:44 ` [RFC PATCH 7/7] selftests: ublk: support UBLK_F_AUTO_BUF_REG Ming Lei
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='CADUfDZpTnntS0r40rBV4aeBx6Sf=X8jQiZDiB+C8Vch7CdaPtQ@mail.gmail.com' \
--to=csander@purestorage.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=ushankar@purestorage.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