public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: David Wei <dw@davidwei.uk>,
	io-uring@vger.kernel.org, netdev@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH v4 12/12] io_uring/zcrx: share an ifq between rings
Date: Tue, 4 Nov 2025 13:53:17 +0000	[thread overview]
Message-ID: <98e5fe45-7d8a-4e40-884b-8f462b5f39a7@gmail.com> (raw)
In-Reply-To: <20251103234110.127790-13-dw@davidwei.uk>

On 11/3/25 23:41, David Wei wrote:
> Add a way to share an ifq from a src ring that is real (i.e. bound to a
> HW RX queue) with other rings. This is done by passing a new flag
> IORING_ZCRX_IFQ_REG_IMPORT in the registration struct
> io_uring_zcrx_ifq_reg, alongside the fd of an exported zcrx ifq.
> 
> Signed-off-by: David Wei <dw@davidwei.uk>
> ---
>   include/uapi/linux/io_uring.h |  4 +++
>   io_uring/zcrx.c               | 63 +++++++++++++++++++++++++++++++++--
>   2 files changed, 65 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
> index 34bd32402902..0ead7f6b2094 100644
> --- a/include/uapi/linux/io_uring.h
> +++ b/include/uapi/linux/io_uring.h
> @@ -1063,6 +1063,10 @@ struct io_uring_zcrx_area_reg {
>   	__u64	__resv2[2];
>   };
>   
> +enum io_uring_zcrx_ifq_reg_flags {

Maybe just zcrx_reg_flags? "io_uring" prefix we used before makes
things too long and quite unhandy. And "ifq" is dropped as it's
not great long term assuming one ifq backing it.

> +	IORING_ZCRX_IFQ_REG_IMPORT	= 1,

Same

> +};
> +
>   /*
>    * Argument for IORING_REGISTER_ZCRX_IFQ
>    */
> diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
> index 17ce49536f41..5a0af9dd6a8e 100644
> --- a/io_uring/zcrx.c
> +++ b/io_uring/zcrx.c
> @@ -625,6 +625,11 @@ static int export_zcrx(struct io_ring_ctx *ctx, struct io_zcrx_ifq *ifq,
>   	struct file *file;
>   	int fd = -1;
>   
> +	if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN))
> +		return -EINVAL;
> +	if (!(ctx->flags & (IORING_SETUP_CQE32|IORING_SETUP_CQE_MIXED)))
> +		return -EINVAL;

This chunk should be in the import path.

> +
>   	if (!mem_is_zero(&ctrl->resv, sizeof(ctrl->resv)))
>   		return -EINVAL;
>   	fd = get_unused_fd_flags(O_CLOEXEC);
> @@ -646,6 +651,58 @@ static int export_zcrx(struct io_ring_ctx *ctx, struct io_zcrx_ifq *ifq,
>   	return fd;
>   }
>   
> +static int import_zcrx(struct io_ring_ctx *ctx,
> +		       struct io_uring_zcrx_ifq_reg __user *arg,
> +		       struct io_uring_zcrx_ifq_reg *reg)
> +{
> +	struct io_zcrx_ifq *ifq;
> +	struct file *file;
> +	int fd, ret;
> +	u32 id;
> +
> +	if (reg->if_rxq || reg->rq_entries || reg->area_ptr || reg->region_ptr)
> +		return -EINVAL;
> +
> +	fd = reg->if_idx;
> +	CLASS(fd, f)(fd);
> +	if (fd_empty(f))
> +		return -EBADF;
> +
> +	file = fd_file(f);
> +	if (file->f_op != &zcrx_box_fops || !file->private_data)
> +		return -EBADF;
> +
> +	ifq = file->private_data;
> +	refcount_inc(&ifq->refs);
> +	refcount_inc(&ifq->user_refs);

It'd be a good idea to fill in basic info about zcrx
it usually returns from registration. E.g. offsets.

> +	scoped_guard(mutex, &ctx->mmap_lock) {
> +		ret = xa_alloc(&ctx->zcrx_ctxs, &id, NULL, xa_limit_31b, GFP_KERNEL);
> +		if (ret)
> +			goto err;
> +	}
> +
> +	reg->zcrx_id = id;
> +	if (copy_to_user(arg, reg, sizeof(*reg))) {
> +		ret = -EFAULT;
> +		goto err_xa_erase;
> +	}
> +
> +	scoped_guard(mutex, &ctx->mmap_lock) {
> +		ret = -ENOMEM;
> +		if (xa_store(&ctx->zcrx_ctxs, id, ifq, GFP_KERNEL))
> +			goto err_xa_erase;
> +	}
> +
> +	return 0;
> +err_xa_erase:
> +	scoped_guard(mutex, &ctx->mmap_lock)
> +		xa_erase(&ctx->zcrx_ctxs, id);
> +err:
> +	zcrx_unregister(ifq);
> +	return ret;
> +}
-- 
Pavel Begunkov


      reply	other threads:[~2025-11-04 13:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03 23:40 [PATCH v4 00/12] io_uring zcrx ifq sharing David Wei
2025-11-03 23:40 ` [PATCH v4 01/12] io_uring/zcrx: remove sync refill uapi David Wei
2025-11-04 13:19   ` Pavel Begunkov
2025-11-03 23:41 ` [PATCH v4 02/12] io_uring/zcrx: introduce IORING_REGISTER_ZCRX_CTRL David Wei
2025-11-03 23:41 ` [PATCH v4 03/12] io_uring/memmap: remove unneeded io_ring_ctx arg David Wei
2025-11-03 23:41 ` [PATCH v4 04/12] io_uring/memmap: refactor io_free_region() to take user_struct param David Wei
2025-11-03 23:41 ` [PATCH v4 05/12] io_uring/rsrc: refactor io_{un}account_mem() to take {user,mm}_struct param David Wei
2025-11-03 23:41 ` [PATCH v4 06/12] io_uring/zcrx: add io_zcrx_ifq arg to io_zcrx_free_area() David Wei
2025-11-03 23:41 ` [PATCH v4 07/12] io_uring/zcrx: add user_struct and mm_struct to io_zcrx_ifq David Wei
2025-11-03 23:41 ` [PATCH v4 08/12] io_uring/zcrx: move io_unregister_zcrx_ifqs() down David Wei
2025-11-03 23:41 ` [PATCH v4 09/12] io_uring/zcrx: reverse ifq refcount David Wei
2025-11-04 13:38   ` Pavel Begunkov
2025-11-03 23:41 ` [PATCH v4 10/12] io_uring/zcrx: move io_zcrx_scrub() and dependencies up David Wei
2025-11-03 23:41 ` [PATCH v4 11/12] io_uring/zcrx: export zcrx via a file David Wei
2025-11-03 23:41 ` [PATCH v4 12/12] io_uring/zcrx: share an ifq between rings David Wei
2025-11-04 13:53   ` Pavel Begunkov [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=98e5fe45-7d8a-4e40-884b-8f462b5f39a7@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=dw@davidwei.uk \
    --cc=io-uring@vger.kernel.org \
    --cc=netdev@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