Re: [RFC PATCH 2/7] io_uring: add helper __io_buffer_[un]register_bvec

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 28, 2025 at 2:44 AM Ming Lei <ming.lei@xxxxxxxxxx> 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@xxxxxxxxxx>
> ---
>  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
>





[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux