netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: David Wei <dw@davidwei.uk>
Cc: io-uring@vger.kernel.org, netdev@vger.kernel.org,
	Jens Axboe <axboe@kernel.dk>,
	Pavel Begunkov <asml.silence@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	David Ahern <dsahern@kernel.org>,
	Mina Almasry <almasrymina@google.com>,
	Stanislav Fomichev <stfomichev@gmail.com>,
	Joe Damato <jdamato@fastly.com>,
	Pedro Tammela <pctammela@mojatatu.com>
Subject: Re: [PATCH net-next v8 09/17] io_uring/zcrx: add interface queue and refill queue
Date: Fri, 6 Dec 2024 16:05:11 +0000	[thread overview]
Message-ID: <20241206160511.GY2581@kernel.org> (raw)
In-Reply-To: <20241204172204.4180482-10-dw@davidwei.uk>

On Wed, Dec 04, 2024 at 09:21:48AM -0800, David Wei wrote:
> From: David Wei <davidhwei@meta.com>
> 
> Add a new object called an interface queue (ifq) that represents a net
> rx queue that has been configured for zero copy. Each ifq is registered
> using a new registration opcode IORING_REGISTER_ZCRX_IFQ.
> 
> The refill queue is allocated by the kernel and mapped by userspace
> using a new offset IORING_OFF_RQ_RING, in a similar fashion to the main
> SQ/CQ. It is used by userspace to return buffers that it is done with,
> which will then be re-used by the netdev again.
> 
> The main CQ ring is used to notify userspace of received data by using
> the upper 16 bytes of a big CQE as a new struct io_uring_zcrx_cqe. Each
> entry contains the offset + len to the data.
> 
> For now, each io_uring instance only has a single ifq.
> 
> Signed-off-by: David Wei <dw@davidwei.uk>

...

> diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c

...

> +int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
> +			  struct io_uring_zcrx_ifq_reg __user *arg)
> +{
> +	struct io_uring_zcrx_ifq_reg reg;
> +	struct io_uring_region_desc rd;
> +	struct io_zcrx_ifq *ifq;
> +	size_t ring_sz, rqes_sz;
> +	int ret;
> +
> +	/*
> +	 * 1. Interface queue allocation.
> +	 * 2. It can observe data destined for sockets of other tasks.
> +	 */
> +	if (!capable(CAP_NET_ADMIN))
> +		return -EPERM;
> +
> +	/* mandatory io_uring features for zc rx */
> +	if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN &&
> +	      ctx->flags & IORING_SETUP_CQE32))
> +		return -EINVAL;
> +	if (ctx->ifq)
> +		return -EBUSY;
> +	if (copy_from_user(&reg, arg, sizeof(reg)))
> +		return -EFAULT;
> +	if (copy_from_user(&rd, u64_to_user_ptr(reg.region_ptr), sizeof(rd)))
> +		return -EFAULT;
> +	if (memchr_inv(&reg.__resv, 0, sizeof(reg.__resv)))
> +		return -EINVAL;
> +	if (reg.if_rxq == -1 || !reg.rq_entries || reg.flags)
> +		return -EINVAL;
> +	if (reg.rq_entries > IO_RQ_MAX_ENTRIES) {
> +		if (!(ctx->flags & IORING_SETUP_CLAMP))
> +			return -EINVAL;
> +		reg.rq_entries = IO_RQ_MAX_ENTRIES;
> +	}
> +	reg.rq_entries = roundup_pow_of_two(reg.rq_entries);
> +
> +	if (!reg.area_ptr)
> +		return -EFAULT;
> +
> +	ifq = io_zcrx_ifq_alloc(ctx);
> +	if (!ifq)
> +		return -ENOMEM;
> +
> +	ret = io_allocate_rbuf_ring(ifq, &reg, &rd);
> +	if (ret)
> +		goto err;
> +
> +	ifq->rq_entries = reg.rq_entries;
> +	ifq->if_rxq = reg.if_rxq;
> +
> +	ring_sz = sizeof(struct io_uring);
> +	rqes_sz = sizeof(struct io_uring_zcrx_rqe) * ifq->rq_entries;

Hi David,

A minor nit from my side: rqes_sz is set but otherwise unused in this
function. Perhaps it can be removed?

Flagged by W=1 builds.

> +	reg.offsets.rqes = ring_sz;
> +	reg.offsets.head = offsetof(struct io_uring, head);
> +	reg.offsets.tail = offsetof(struct io_uring, tail);
> +
> +	if (copy_to_user(arg, &reg, sizeof(reg)) ||
> +	    copy_to_user(u64_to_user_ptr(reg.region_ptr), &rd, sizeof(rd))) {
> +		ret = -EFAULT;
> +		goto err;
> +	}
> +
> +	ctx->ifq = ifq;
> +	return 0;
> +err:
> +	io_zcrx_ifq_free(ifq);
> +	return ret;
> +}

...

  reply	other threads:[~2024-12-06 16:05 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 17:21 [PATCH net-next v8 00/17] io_uring zero copy rx David Wei
2024-12-04 17:21 ` [PATCH net-next v8 01/17] net: prefix devmem specific helpers David Wei
2024-12-04 21:00   ` Mina Almasry
2024-12-04 21:24     ` David Wei
2024-12-04 17:21 ` [PATCH net-next v8 02/17] net: generalise net_iov chunk owners David Wei
2024-12-09 17:01   ` Mina Almasry
2024-12-04 17:21 ` [PATCH net-next v8 03/17] net: page_pool: create hooks for custom page providers David Wei
2024-12-10  3:02   ` Jakub Kicinski
2024-12-10 16:31     ` David Wei
2024-12-04 17:21 ` [PATCH net-next v8 04/17] net: prepare for non devmem TCP memory providers David Wei
2024-12-09 17:04   ` Mina Almasry
2024-12-10  3:15   ` Jakub Kicinski
2024-12-10  3:53     ` Pavel Begunkov
2024-12-10  4:06       ` Jakub Kicinski
2024-12-10  4:15         ` Pavel Begunkov
2024-12-04 17:21 ` [PATCH net-next v8 05/17] net: page_pool: add ->scrub mem provider callback David Wei
2024-12-09 17:08   ` Mina Almasry
2024-12-09 17:24     ` Pavel Begunkov
2024-12-04 17:21 ` [PATCH net-next v8 06/17] net: page pool: add helper creating area from pages David Wei
2024-12-10  3:29   ` Jakub Kicinski
2024-12-10  3:58     ` Pavel Begunkov
2024-12-04 17:21 ` [PATCH net-next v8 07/17] net: page_pool: introduce page_pool_mp_return_in_cache David Wei
2024-12-09 17:15   ` Mina Almasry
2024-12-09 17:28     ` Pavel Begunkov
2024-12-10  3:40   ` Jakub Kicinski
2024-12-10  4:31     ` Pavel Begunkov
2024-12-11  0:06       ` Jakub Kicinski
2024-12-04 17:21 ` [PATCH net-next v8 08/17] net: add helper executing custom callback from napi David Wei
2024-12-10  3:44   ` Jakub Kicinski
2024-12-10  4:11     ` Pavel Begunkov
2024-12-04 17:21 ` [PATCH net-next v8 09/17] io_uring/zcrx: add interface queue and refill queue David Wei
2024-12-06 16:05   ` Simon Horman [this message]
2024-12-09 23:50     ` David Wei
2024-12-10  3:49   ` Jakub Kicinski
2024-12-10  4:03     ` Pavel Begunkov
2024-12-10  4:07       ` Jakub Kicinski
2024-12-04 17:21 ` [PATCH net-next v8 10/17] io_uring/zcrx: add io_zcrx_area David Wei
2024-12-04 17:21 ` [PATCH net-next v8 11/17] io_uring/zcrx: implement zerocopy receive pp memory provider David Wei
2024-12-10  4:01   ` Jakub Kicinski
2024-12-10  4:45     ` Pavel Begunkov
2024-12-10  4:50       ` Pavel Begunkov
2024-12-11  0:24       ` Jakub Kicinski
2024-12-11 14:42         ` Pavel Begunkov
2024-12-12  1:38           ` Jakub Kicinski
2024-12-12 13:42             ` Pavel Begunkov
2024-12-10 16:55     ` Mina Almasry
2024-12-04 17:21 ` [PATCH net-next v8 12/17] io_uring/zcrx: add io_recvzc request David Wei
2024-12-04 17:21 ` [PATCH net-next v8 13/17] io_uring/zcrx: set pp memory provider for an rx queue David Wei
2024-12-04 17:21 ` [PATCH net-next v8 14/17] io_uring/zcrx: add copy fallback David Wei
2024-12-04 17:21 ` [PATCH net-next v8 15/17] io_uring/zcrx: throttle receive requests David Wei
2024-12-04 17:21 ` [PATCH net-next v8 16/17] net: add documentation for io_uring zcrx David Wei
2024-12-09 17:51   ` Mina Almasry
2024-12-10 16:53     ` David Wei
2024-12-09 17:52   ` Mina Almasry
2024-12-10 16:54     ` David Wei
2024-12-04 17:21 ` [PATCH net-next v8 17/17] io_uring/zcrx: add selftest David Wei
2024-12-04 18:59 ` [PATCH net-next v8 00/17] io_uring zero copy rx Pavel Begunkov

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=20241206160511.GY2581@kernel.org \
    --to=horms@kernel.org \
    --cc=almasrymina@google.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=dw@davidwei.uk \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=io-uring@vger.kernel.org \
    --cc=jdamato@fastly.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pctammela@mojatatu.com \
    --cc=stfomichev@gmail.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;
as well as URLs for NNTP newsgroup(s).