Skip to contentSkip to conversation

io_uring zero copy rx

PATCH RESEND Superseded David Wei 5 participants 51 messages Dec 18, 2024 – Jan 9, 2025

Subsystems (8)

v9 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

David Wei

author
#0 lore raw

v9 cover io_uring zero copy rx

Sorry, resending because I didn't edit the version number correctly.

This patchset adds support for zero copy rx into userspace pages using io_uring, eliminating a kernel to user copy.

We configure a page pool that a driver uses to fill a hw rx queue to hand out user pages instead of kernel pages. Any data that ends up hitting this hw rx queue will thus be dma'd into userspace memory directly, without needing to be bounced through kernel memory. 'Reading' data out of a socket instead becomes a _notification_ mechanism, where the kernel tells userspace where the data is. The overall approach is similar to the devmem TCP proposal.

This relies on hw header/data split, flow steering and RSS to ensure packet headers remain in kernel memory and only desired flows hit a hw rx queue configured for zero copy. Configuring this is outside of the scope of this patchset.

We share netdev core infra with devmem TCP. The main difference is that io_uring is used for the uAPI and the lifetime of all objects are bound to an io_uring instance. Data is 'read' using a new io_uring request type. When done, data is returned via a new shared refill queue. A zero copy page pool refills a hw rx queue from this refill queue directly. Of course, the lifetime of these data buffers are managed by io_uring rather than the networking stack, with different refcounting rules.

This patchset is the first step adding basic zero copy support. We will extend this iteratively with new features e.g. dynamically allocated zero copy areas, THP support, dmabuf support, improved copy fallback, general optimisations and more.

In terms of netdev support, we're first targeting Broadcom bnxt. Patches aren't included since Taehee Yoo has already sent a more comprehensive patchset adding support in [1]. Google gve should already support this, and Mellanox mlx5 support is WIP pending driver changes.

============
Pull Request
============

The following changes since commit d22f955cc2cb9684dd45396f974101f288869485:

rust: net::phy scope ThisModule usage in the module_phy_driver macro (2024-12-17 13:30:45 +0100)

are available in the Git repository at:

https://github.com/spikeh/linux zcrx/v9

for you to fetch changes up to ea606d17b90b853c8c72d490daaccfb81adce3b8:

io_uring/zcrx: add selftest (2024-12-17 16:26:02 -0800)

===========
Performance
===========

Note: Comparison with epoll + TCP_ZEROCOPY_RECEIVE isn't done yet.

Test setup:
* AMD EPYC 9454
* Broadcom BCM957508 200G
* Kernel v6.11 base [2]
* liburing fork [3]
* kperf fork [4]
* 4K MTU
* Single TCP flow

With application thread + net rx softirq pinned to _different_ cores:

+-------------------------------+
| epoll     | io_uring          |
|-----------|-------------------|
| 82.2 Gbps | 116.2 Gbps (+41%) |
+-------------------------------+

Pinned to _same_ core:

+-------------------------------+
| epoll     | io_uring          |
|-----------|-------------------|
| 62.6 Gbps | 80.9 Gbps (+29%)  |
+-------------------------------+

=====
Links
=====

Broadcom bnxt support:
[1]: https://lore.kernel.org/netdev/[email protected]/

Linux kernel branch:
[2]: https://github.com/spikeh/linux.git zcrx/v9

liburing for testing:
[3]: https://github.com/isilence/liburing.git zcrx/next

kperf for testing:
[4]: https://git.kernel.dk/kperf.git

Changes in v9:
--------------
* Fail proof against multiple page pools running the same memory provider
* Lock the consumer side of the refill queue.
* Move scrub into io_uring exit.
* Kill napi_execute.
* Kill area init api and export finer grained net helpers as partial

    init now need to happen in ->alloc_netmems()

* Separate user refcounting.
* Fix copy fallback path math.
* Add rodata check to page_pool_init()
* Fix incorrect path in documentation

Changes in v8:
--------------
* add documentation and selftest
* use io_uring regions for the refill ring

Changes in v7:
--------------
net:
* Use NAPI_F_PREFER_BUSY_POLL for napi_execute + stylistics changes.

Changes in v6:
--------------
Please note: Comparison with TCP_ZEROCOPY_RECEIVE isn't done yet.

net:
* Drop a devmem.h clean up patch.
* Migrate to netdev_get_by_index from deprecated API.
* Fix !CONFIG_NET_DEVMEM build.
* Don’t return into the page pool cache directly, use a new helper
* Refactor napi_execute

io_uring:
* Require IORING_RECV_MULTISHOT flag set.
* Add unselectable CONFIG_IO_URING_ZCRX.
* Pulled latest io_uring changes.
* Unexport io_uring_pp_zc_ops.

Changes in v5:
--------------
* Rebase on top of merged net_iov + netmem infra.
* Decouple net_iov from devmem TCP.
* Use netdev queue API to allocate an rx queue.
* Minor uAPI enhancements for future extensibility.
* QoS improvements with request throttling.

Changes in RFC v4:
------------------
* Rebased on top of Mina Almasry's TCP devmem patchset and latest net-next, now sharing common infra e.g.:
* netmem_t and net_iovs
* Page pool memory provider
* The registered buffer (rbuf) completion queue where completions from io_recvzc requests are posted is removed. Now these post into the main completion queue, using big (32-byte) CQEs. The first 16 bytes is an ordinary CQE, while the latter 16 bytes contain the io_uring_rbuf_cqe as before. This vastly simplifies the uAPI and removes a level of indirection in userspace when looking for payloads.
* The rbuf refill queue is still needed for userspace to return buffers to kernel.
* Simplified code and uAPI on the io_uring side, particularly io_recvzc() and io_zc_rx_recv(). Many unnecessary lines were removed e.g. extra msg flags, readlen, etc.

Changes in RFC v3:
------------------
* Rebased on top of Jakub Kicinski's memory provider API RFC. The ZC pool added is now a backend for memory provider.
* We're also reusing ppiov infrastructure. The refcounting rules stay the same but it's shifted into ppiov->refcount. That lets us to flexibly manage buffer lifetimes without adding any extra code to the common networking paths. It'd also make it easier to support dmabufs and device memory in the future.
* io_uring also knows about pages, and so ppiovs might unnecessarily break tools inspecting data, that can easily be solved later.

Many patches are not for upstream as they depend on work in progress, namely from Mina:

* struct netmem_t
* Driver ndo commands for Rx queue configs
* struct page_pool_iov and shared pp infra

Changes in RFC v2:
------------------
* Added copy fallback support if userspace memory allocated for ZC Rx runs out, or if header splitting or flow steering fails.
* Added veth support for ZC Rx, for testing and demonstration. We will need to figure out what driver would be best for such testing functionality in the future. Perhaps netdevsim?
* Added socket registration API to io_uring to associate specific sockets with ifqs/Rx queues for ZC.
* Added multi-socket support, such that multiple connections can be steered into the same hardware Rx queue.
* Added Netbench server/client support.

David Wei (7):
io_uring/zcrx: add interface queue and refill queue io_uring/zcrx: add io_zcrx_area
net: page pool: export page_pool_set_dma_addr_netmem() io_uring/zcrx: add io_recvzc request io_uring/zcrx: set pp memory provider for an rx queue
net: add documentation for io_uring zcrx io_uring/zcrx: add selftest

Jakub Kicinski (1):
net: page_pool: create hooks for custom page providers

Pavel Begunkov (13):
net: page_pool: don't cast mp param to devmem
net: prefix devmem specific helpers
net: generalise net_iov chunk owners
net: page_pool: add mp op for netlink reporting
net: page_pool: add a mp hook to unregister_netdevice*
net: prepare for non devmem TCP memory providers
net: expose page_pool_{set,clear}_pp_info
net: page_pool: introduce page_pool_mp_return_in_cache io_uring/zcrx: grab a net device
io_uring/zcrx: dma-map area for the device io_uring/zcrx: implement zerocopy receive pp memory provider io_uring/zcrx: throttle receive requests io_uring/zcrx: add copy fallback

 Documentation/networking/index.rst            |   1 +
 Documentation/networking/iou-zcrx.rst         | 201 ++++
 Kconfig                                       |   2 +
 include/linux/io_uring_types.h                |   6 +
 include/net/netmem.h                          |  21 +-
 include/net/page_pool/helpers.h               |  20 +
 include/net/page_pool/types.h                 |  13 +
 include/uapi/linux/io_uring.h                 |  54 +-
 include/uapi/linux/netdev.h                   |   1 +
 io_uring/KConfig                              |  10 +
 io_uring/Makefile                             |   1 +
 io_uring/io_uring.c                           |   7 +
 io_uring/io_uring.h                           |  10 +
 io_uring/memmap.h                             |   1 +
 io_uring/net.c                                |  74 ++
 io_uring/opdef.c                              |  16 +
 io_uring/register.c                           |   7 +
 io_uring/rsrc.c                               |   2 +-
 io_uring/rsrc.h                               |   1 +
 io_uring/zcrx.c                               | 936 ++++++++++++++++++
 io_uring/zcrx.h                               |  71 ++
 net/core/dev.c                                |  16 +-
 net/core/devmem.c                             |  91 +-
 net/core/devmem.h                             |  50 +-
 net/core/page_pool.c                          |  53 +-
 net/core/page_pool_priv.h                     |  26 -
 net/core/page_pool_user.c                     |   5 +-
 net/ipv4/tcp.c                                |   7 +-
 .../selftests/drivers/net/hw/.gitignore       |   2 +
 .../testing/selftests/drivers/net/hw/Makefile |   6 +
 .../selftests/drivers/net/hw/iou-zcrx.c       | 432 ++++++++
 .../selftests/drivers/net/hw/iou-zcrx.py      |  64 ++
 32 files changed, 2104 insertions(+), 103 deletions(-)
 create mode 100644 Documentation/networking/iou-zcrx.rst
 create mode 100644 io_uring/KConfig
 create mode 100644 io_uring/zcrx.c
 create mode 100644 io_uring/zcrx.h
 create mode 100644 tools/testing/selftests/drivers/net/hw/iou-zcrx.c
 create mode 100755 tools/testing/selftests/drivers/net/hw/iou-zcrx.py
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH v9 1/20 net: page_pool: don't cast mp param to devmem

From: Pavel Begunkov <[email protected]>

page_pool_check_memory_provider() is a generic path and shouldn't assume anything about the actual type of the memory provider argument. It's fine while devmem is the only provider, but cast away the devmem specific binding types to avoid confusion.

---
 net/core/page_pool_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/page_pool_user.c +1 -1
index 48335766c1bf..8d31c71bea1a 100644
@@ -353,7 +353,7 @@ void page_pool_unlist(struct page_pool *pool)
 int page_pool_check_memory_provider(struct net_device *dev,
 				    struct netdev_rx_queue *rxq)
 {
-	struct net_devmem_dmabuf_binding *binding = rxq->mp_params.mp_priv;
+	void *binding = rxq->mp_params.mp_priv;
 	struct page_pool *pool;
 	struct hlist_node *n;
 
Signature · 1 line
2.43.5
maintainer Reviewed-by on v9 1/20
#2 lore raw

Re: [PATCH net-next v9 01/20] net: page_pool: don't cast mp param to devmem

Quoted 6 lines · On Tue, 17 Dec 2024 16:37:27 -0800 David Wei wrote:

From: Pavel Begunkov <[email protected]>

page_pool_check_memory_provider() is a generic path and shouldn't assume anything about the actual type of the memory provider argument. It's fine while devmem is the only provider, but cast away the devmem specific binding types to avoid confusion.

Reviewed-by on v9 1/20
#3 lore raw

Re: [PATCH net-next v9 01/20] net: page_pool: don't cast mp param to devmem

In reply to David Wei
Quoted 10 lines · David Wei

From: Pavel Begunkov <[email protected]>

page_pool_check_memory_provider() is a generic path and shouldn't assume anything about the actual type of the memory provider argument. It's fine while devmem is the only provider, but cast away the devmem specific binding types to avoid confusion.

Signature · 2 lines
Thanks,
Mina
author
#4 lore raw

PATCH v9 2/20 net: prefix devmem specific helpers

In reply to David Wei

From: Pavel Begunkov <[email protected]>

Add prefixes to all helpers that are specific to devmem TCP, i.e. net_iov_binding[_id].

---
 net/core/devmem.c |  2 +-
 net/core/devmem.h | 14 +++++++-------
 net/ipv4/tcp.c    |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)
net/core/devmem.c +1 -1
index 0b6ed7525b22..5e1a05082ab8 100644
@@ -93,7 +93,7 @@ net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding)
 
 void net_devmem_free_dmabuf(struct net_iov *niov)
 {
-	struct net_devmem_dmabuf_binding *binding = net_iov_binding(niov);
+	struct net_devmem_dmabuf_binding *binding = net_devmem_iov_binding(niov);
 	unsigned long dma_addr = net_devmem_get_dma_addr(niov);
 
 	if (WARN_ON(!gen_pool_has_addr(binding->chunk_pool, dma_addr,
net/core/devmem.h +7 -7
index 76099ef9c482..99782ddeca40 100644
@@ -86,11 +86,16 @@ static inline unsigned int net_iov_idx(const struct net_iov *niov)
 }
 
 static inline struct net_devmem_dmabuf_binding *
-net_iov_binding(const struct net_iov *niov)
+net_devmem_iov_binding(const struct net_iov *niov)
 {
 	return net_iov_owner(niov)->binding;
 }
 
+static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)
+{
+	return net_devmem_iov_binding(niov)->id;
+}
+
 static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov)
 {
 	struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov);
@@ -99,11 +104,6 @@ static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov)
 	       ((unsigned long)net_iov_idx(niov) << PAGE_SHIFT);
 }
 
-static inline u32 net_iov_binding_id(const struct net_iov *niov)
-{
-	return net_iov_owner(niov)->binding->id;
-}
-
 static inline void
 net_devmem_dmabuf_binding_get(struct net_devmem_dmabuf_binding *binding)
 {
@@ -171,7 +171,7 @@ static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov)
 	return 0;
 }
 
-static inline u32 net_iov_binding_id(const struct net_iov *niov)
+static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)
 {
 	return 0;
 }
net/ipv4/tcp.c +1 -1
index 0d704bda6c41..b872de9a8271 100644
@@ -2494,7 +2494,7 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb,
 
 				/* Will perform the exchange later */
 				dmabuf_cmsg.frag_token = tcp_xa_pool.tokens[tcp_xa_pool.idx];
-				dmabuf_cmsg.dmabuf_id = net_iov_binding_id(niov);
+				dmabuf_cmsg.dmabuf_id = net_devmem_iov_binding_id(niov);
 
 				offset += copy;
 				remaining_len -= copy;
Signature · 1 line
2.43.5
maintainer Reviewed-by on v9 2/20
#5 lore raw

Re: [PATCH net-next v9 02/20] net: prefix devmem specific helpers

Quoted 4 lines · On Tue, 17 Dec 2024 16:37:28 -0800 David Wei wrote:

From: Pavel Begunkov <[email protected]>

Add prefixes to all helpers that are specific to devmem TCP, i.e. net_iov_binding[_id].

author
#6 lore raw

PATCH v9 3/20 net: generalise net_iov chunk owners

In reply to David Wei

From: Pavel Begunkov <[email protected]>

Currently net_iov stores a pointer to struct dmabuf_genpool_chunk_owner, which serves as a useful abstraction to share data and provide a context. However, it's too devmem specific, and we want to reuse it for other memory providers, and for that we need to decouple net_iov from devmem. Make net_iov to point to a new base structure called net_iov_area, which dmabuf_genpool_chunk_owner extends.

---
 include/net/netmem.h | 21 ++++++++++++++++++++-
 net/core/devmem.c    | 25 +++++++++++++------------
 net/core/devmem.h    | 25 +++++++++----------------
 3 files changed, 42 insertions(+), 29 deletions(-)
include/net/netmem.h +20 -1
index 1b58faa4f20f..c61d5b21e7b4 100644
@@ -24,11 +24,20 @@ struct net_iov {
 	unsigned long __unused_padding;
 	unsigned long pp_magic;
 	struct page_pool *pp;
-	struct dmabuf_genpool_chunk_owner *owner;
+	struct net_iov_area *owner;
 	unsigned long dma_addr;
 	atomic_long_t pp_ref_count;
 };
 
+struct net_iov_area {
+	/* Array of net_iovs for this area. */
+	struct net_iov *niovs;
+	size_t num_niovs;
+
+	/* Offset into the dma-buf where this chunk starts.  */
+	unsigned long base_virtual;
+};
+
 /* These fields in struct page are used by the page_pool and net stack:
  *
  *        struct {
@@ -54,6 +63,16 @@ NET_IOV_ASSERT_OFFSET(dma_addr, dma_addr);
 NET_IOV_ASSERT_OFFSET(pp_ref_count, pp_ref_count);
 #undef NET_IOV_ASSERT_OFFSET
 
+static inline struct net_iov_area *net_iov_owner(const struct net_iov *niov)
+{
+	return niov->owner;
+}
+
+static inline unsigned int net_iov_idx(const struct net_iov *niov)
+{
+	return niov - net_iov_owner(niov)->niovs;
+}
+
 /* netmem */
 
 /**
net/core/devmem.c +13 -12
index 5e1a05082ab8..c250db6993d3 100644
@@ -32,14 +32,15 @@ static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool,
 {
 	struct dmabuf_genpool_chunk_owner *owner = chunk->owner;
 
-	kvfree(owner->niovs);
+	kvfree(owner->area.niovs);
 	kfree(owner);
 }
 
 static dma_addr_t net_devmem_get_dma_addr(const struct net_iov *niov)
 {
-	struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov);
+	struct dmabuf_genpool_chunk_owner *owner;
 
+	owner = net_devmem_iov_to_chunk_owner(niov);
 	return owner->base_dma_addr +
 	       ((dma_addr_t)net_iov_idx(niov) << PAGE_SHIFT);
 }
@@ -82,7 +83,7 @@ net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding)
 
 	offset = dma_addr - owner->base_dma_addr;
 	index = offset / PAGE_SIZE;
-	niov = &owner->niovs[index];
+	niov = &owner->area.niovs[index];
 
 	niov->pp_magic = 0;
 	niov->pp = NULL;
@@ -250,9 +251,9 @@ net_devmem_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd,
 			goto err_free_chunks;
 		}
 
-		owner->base_virtual = virtual;
+		owner->area.base_virtual = virtual;
 		owner->base_dma_addr = dma_addr;
-		owner->num_niovs = len / PAGE_SIZE;
+		owner->area.num_niovs = len / PAGE_SIZE;
 		owner->binding = binding;
 
 		err = gen_pool_add_owner(binding->chunk_pool, dma_addr,
@@ -264,17 +265,17 @@ net_devmem_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd,
 			goto err_free_chunks;
 		}
 
-		owner->niovs = kvmalloc_array(owner->num_niovs,
-					      sizeof(*owner->niovs),
-					      GFP_KERNEL);
-		if (!owner->niovs) {
+		owner->area.niovs = kvmalloc_array(owner->area.num_niovs,
+						   sizeof(*owner->area.niovs),
+						   GFP_KERNEL);
+		if (!owner->area.niovs) {
 			err = -ENOMEM;
 			goto err_free_chunks;
 		}
 
-		for (i = 0; i < owner->num_niovs; i++) {
-			niov = &owner->niovs[i];
-			niov->owner = owner;
+		for (i = 0; i < owner->area.num_niovs; i++) {
+			niov = &owner->area.niovs[i];
+			niov->owner = &owner->area;
 			page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov),
 						      net_devmem_get_dma_addr(niov));
 		}
net/core/devmem.h +9 -16
index 99782ddeca40..a2b9913e9a17 100644
@@ -10,6 +10,8 @@
 #ifndef _NET_DEVMEM_H
 #define _NET_DEVMEM_H
 
+#include <net/netmem.h>
+
 struct netlink_ext_ack;
 
 struct net_devmem_dmabuf_binding {
@@ -51,17 +53,11 @@ struct net_devmem_dmabuf_binding {
  * allocations from this chunk.
  */
 struct dmabuf_genpool_chunk_owner {
-	/* Offset into the dma-buf where this chunk starts.  */
-	unsigned long base_virtual;
+	struct net_iov_area area;
+	struct net_devmem_dmabuf_binding *binding;
 
 	/* dma_addr of the start of the chunk.  */
 	dma_addr_t base_dma_addr;
-
-	/* Array of net_iovs for this chunk. */
-	struct net_iov *niovs;
-	size_t num_niovs;
-
-	struct net_devmem_dmabuf_binding *binding;
 };
 
 void __net_devmem_dmabuf_binding_free(struct net_devmem_dmabuf_binding *binding);
@@ -75,20 +71,17 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 void dev_dmabuf_uninstall(struct net_device *dev);
 
 static inline struct dmabuf_genpool_chunk_owner *
-net_iov_owner(const struct net_iov *niov)
+net_devmem_iov_to_chunk_owner(const struct net_iov *niov)
 {
-	return niov->owner;
-}
+	struct net_iov_area *owner = net_iov_owner(niov);
 
-static inline unsigned int net_iov_idx(const struct net_iov *niov)
-{
-	return niov - net_iov_owner(niov)->niovs;
+	return container_of(owner, struct dmabuf_genpool_chunk_owner, area);
 }
 
 static inline struct net_devmem_dmabuf_binding *
 net_devmem_iov_binding(const struct net_iov *niov)
 {
-	return net_iov_owner(niov)->binding;
+	return net_devmem_iov_to_chunk_owner(niov)->binding;
 }
 
 static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)
@@ -98,7 +91,7 @@ static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)
 
 static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov)
 {
-	struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov);
+	struct net_iov_area *owner = net_iov_owner(niov);
 
 	return owner->base_virtual +
 	       ((unsigned long)net_iov_idx(niov) << PAGE_SHIFT);
Signature · 1 line
2.43.5
maintainer
#7 lore raw

Re: [PATCH net-next v9 03/20] net: generalise net_iov chunk owners

net/core/devmem.h struct net_devmem_dmabuf_binding { · line 60

Quoted 8 lines · On Tue, 17 Dec 2024 16:37:29 -0800 David Wei wrote:

struct dmabuf_genpool_chunk_owner {

net/core/devmem.h +2 -2
-	/* Offset into the dma-buf where this chunk starts.  */
-	unsigned long base_virtual;
+	struct net_iov_area area;
+	struct net_devmem_dmabuf_binding *binding;
 
 	/* dma_addr of the start of the chunk.  */
 	dma_addr_t base_dma_addr;

Is there a good reason why dma addr is not part of net_iov_area? net_iov_area is one chunk of continuous address space. Instead of looping over pages in io_zcrx_map_area we could map the whole thing in one go.

maintainer
#8 lore raw

Re: [PATCH net-next v9 03/20] net: generalise net_iov chunk owners

Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Tue, 17 Dec 2024 16:37:29 -0800 David Wei wrote:
  struct dmabuf_genpool_chunk_owner {
net/core/devmem.h +2 -2
-	/* Offset into the dma-buf where this chunk starts.  */
-	unsigned long base_virtual;
+	struct net_iov_area area;
+	struct net_devmem_dmabuf_binding *binding;
Quoted 7 lines
Quoted 2 lines

/* dma_addr of the start of the chunk. */ dma_addr_t base_dma_addr;

Is there a good reason why dma addr is not part of net_iov_area? net_iov_area is one chunk of continuous address space. Instead of looping over pages in io_zcrx_map_area we could map the whole thing in one go.

It's not physically contiguous. The registration API takes contig user addresses, but that's not a hard requirement either.

Signature · 1 line
Pavel Begunkov
maintainer
#9 lore raw

Re: [PATCH net-next v9 03/20] net: generalise net_iov chunk owners

Quoted 8 lines · On Sat, 21 Dec 2024 00:50:37 +0000 Pavel Begunkov wrote:
Quoted 4 lines

Is there a good reason why dma addr is not part of net_iov_area? net_iov_area is one chunk of continuous address space. Instead of looping over pages in io_zcrx_map_area we could map the whole thing in one go.

It's not physically contiguous. The registration API takes contig user addresses, but that's not a hard requirement either.

Okay, I was thrown off by the base_virtual being in the common struct. But it appears you don't use that?

AFAIR for devmem each area is physically contiguous if the region is not it gets split into areas.

maintainer
#10 lore raw

Re: [PATCH net-next v9 03/20] net: generalise net_iov chunk owners

Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Sat, 21 Dec 2024 00:50:37 +0000 Pavel Begunkov wrote:
Quoted 4 lines

Is there a good reason why dma addr is not part of net_iov_area? net_iov_area is one chunk of continuous address space. Instead of looping over pages in io_zcrx_map_area we could map the whole thing in one go.

Quoted 6 lines
Quoted 3 lines

It's not physically contiguous. The registration API takes contig user addresses, but that's not a hard requirement either.

Okay, I was thrown off by the base_virtual being in the common struct. But it appears you don't use that?

Right, but io_uring can make use of it, it just needs better types, which is why I left it there to follow up later.

Quoted 2 lines

AFAIR for devmem each area is physically contiguous if the region is not it gets split into areas.

Seems so, it's split into areas / chunk owners by following the sg list layout.

Signature · 1 line
Pavel Begunkov
#11 lore raw

Re: [PATCH net-next v9 03/20] net: generalise net_iov chunk owners

In reply to David Wei
Quoted 29 lines · David Wei

From: Pavel Begunkov <[email protected]>

Currently net_iov stores a pointer to struct dmabuf_genpool_chunk_owner, which serves as a useful abstraction to share data and provide a context. However, it's too devmem specific, and we want to reuse it for other memory providers, and for that we need to decouple net_iov from devmem. Make net_iov to point to a new base structure called net_iov_area, which dmabuf_genpool_chunk_owner extends.

---
 include/net/netmem.h | 21 ++++++++++++++++++++-
 net/core/devmem.c    | 25 +++++++++++++------------
 net/core/devmem.h    | 25 +++++++++----------------
 3 files changed, 42 insertions(+), 29 deletions(-)
include/net/netmem.h +1 -1
index 1b58faa4f20f..c61d5b21e7b4 100644
@@ -24,11 +24,20 @@ struct net_iov {
        unsigned long __unused_padding;
        unsigned long pp_magic;
        struct page_pool *pp;
-       struct dmabuf_genpool_chunk_owner *owner;
+       struct net_iov_area *owner;

include/net/netmem.h struct net_iov { · line 37

Quoted 10 lines
include/net/netmem.h +6 -0
        unsigned long dma_addr;
        atomic_long_t pp_ref_count;
 };
 
+struct net_iov_area {
+       /* Array of net_iovs for this area. */
+       struct net_iov *niovs;
+       size_t num_niovs;
+
+       /* Offset into the dma-buf where this chunk starts.  */

Probably could use a rewriting of the comment. I think net_iov_area is meant to be a memory-type agnostic struct, so it shouldn't refer to dma-bufs here.

But on second thought I'm not sure base_virtual belongs in the common struct because i'm not sure yet how it applies to other memory providers. for dmabuf, each 'chunk' is physically and virtually contiguous, and the virtual address is well-defined to be the offset in bytes into the dmabuf, but that is very dmabuf specific.

Consider keeping this in dmabuf_genpool_chunk_owner if we don't plan to use this same field with the same semantics for other memory providers, or re-write the comment.

Signature · 2 lines
Thanks,
Mina
author
#12 lore raw

PATCH v9 4/20 net: page_pool: create hooks for custom page providers

In reply to David Wei

From: Jakub Kicinski <[email protected]>

The page providers which try to reuse the same pages will need to hold onto the ref, even if page gets released from the pool - as in releasing the page from the pp just transfers the "ownership" reference from pp to the provider, and provider will wait for other references to be gone before feeding this page back into the pool.

---
 include/net/page_pool/types.h |  9 +++++++++
 net/core/devmem.c             | 14 +++++++++++++-
 net/core/page_pool.c          | 22 ++++++++++++++--------
 3 files changed, 36 insertions(+), 9 deletions(-)
include/net/page_pool/types.h +9 -0
index ed4cd114180a..d6241e8a5106 100644
@@ -152,8 +152,16 @@ struct page_pool_stats {
  */
 #define PAGE_POOL_FRAG_GROUP_ALIGN	(4 * sizeof(long))
 
+struct memory_provider_ops {
+	netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
+	bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
+	int (*init)(struct page_pool *pool);
+	void (*destroy)(struct page_pool *pool);
+};
+
 struct pp_memory_provider_params {
 	void *mp_priv;
+	const struct memory_provider_ops *mp_ops;
 };
 
 struct page_pool {
@@ -216,6 +224,7 @@ struct page_pool {
 	struct ptr_ring ring;
 
 	void *mp_priv;
+	const struct memory_provider_ops *mp_ops;
 
 #ifdef CONFIG_PAGE_POOL_STATS
 	/* recycle stats are per-cpu to avoid locking */
net/core/devmem.c +13 -1
index c250db6993d3..48903b7ab215 100644
@@ -26,6 +26,8 @@
 /* Protected by rtnl_lock() */
 static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);
 
+static const struct memory_provider_ops dmabuf_devmem_ops;
+
 static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool,
 					       struct gen_pool_chunk *chunk,
 					       void *not_used)
@@ -117,6 +119,7 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)
 		WARN_ON(rxq->mp_params.mp_priv != binding);
 
 		rxq->mp_params.mp_priv = NULL;
+		rxq->mp_params.mp_ops = NULL;
 
 		rxq_idx = get_netdev_rx_queue_index(rxq);
 
@@ -142,7 +145,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 	}
 
 	rxq = __netif_get_rx_queue(dev, rxq_idx);
-	if (rxq->mp_params.mp_priv) {
+	if (rxq->mp_params.mp_ops) {
 		NL_SET_ERR_MSG(extack, "designated queue already memory provider bound");
 		return -EEXIST;
 	}
@@ -160,6 +163,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 		return err;
 
 	rxq->mp_params.mp_priv = binding;
+	rxq->mp_params.mp_ops = &dmabuf_devmem_ops;
 
 	err = netdev_rx_queue_restart(dev, rxq_idx);
 	if (err)
@@ -169,6 +173,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 
 err_xa_erase:
 	rxq->mp_params.mp_priv = NULL;
+	rxq->mp_params.mp_ops = NULL;
 	xa_erase(&binding->bound_rxqs, xa_idx);
 
 	return err;
@@ -388,3 +393,10 @@ bool mp_dmabuf_devmem_release_page(struct page_pool *pool, netmem_ref netmem)
 	/* We don't want the page pool put_page()ing our net_iovs. */
 	return false;
 }
+
+static const struct memory_provider_ops dmabuf_devmem_ops = {
+	.init			= mp_dmabuf_devmem_init,
+	.destroy		= mp_dmabuf_devmem_destroy,
+	.alloc_netmems		= mp_dmabuf_devmem_alloc_netmems,
+	.release_netmem		= mp_dmabuf_devmem_release_page,
+};
net/core/page_pool.c +14 -8
index e07ad7315955..784a547b2ca4 100644
@@ -285,13 +285,19 @@ static int page_pool_init(struct page_pool *pool,
 		rxq = __netif_get_rx_queue(pool->slow.netdev,
 					   pool->slow.queue_idx);
 		pool->mp_priv = rxq->mp_params.mp_priv;
+		pool->mp_ops = rxq->mp_params.mp_ops;
 	}
 
-	if (pool->mp_priv) {
+	if (pool->mp_ops) {
 		if (!pool->dma_map || !pool->dma_sync)
 			return -EOPNOTSUPP;
 
-		err = mp_dmabuf_devmem_init(pool);
+		if (WARN_ON(!is_kernel_rodata((unsigned long)pool->mp_ops))) {
+			err = -EFAULT;
+			goto free_ptr_ring;
+		}
+
+		err = pool->mp_ops->init(pool);
 		if (err) {
 			pr_warn("%s() mem-provider init failed %d\n", __func__,
 				err);
@@ -588,8 +594,8 @@ netmem_ref page_pool_alloc_netmems(struct page_pool *pool, gfp_t gfp)
 		return netmem;
 
 	/* Slow-path: cache empty, do real allocation */
-	if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_priv)
-		netmem = mp_dmabuf_devmem_alloc_netmems(pool, gfp);
+	if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops)
+		netmem = pool->mp_ops->alloc_netmems(pool, gfp);
 	else
 		netmem = __page_pool_alloc_pages_slow(pool, gfp);
 	return netmem;
@@ -680,8 +686,8 @@ void page_pool_return_page(struct page_pool *pool, netmem_ref netmem)
 	bool put;
 
 	put = true;
-	if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_priv)
-		put = mp_dmabuf_devmem_release_page(pool, netmem);
+	if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops)
+		put = pool->mp_ops->release_netmem(pool, netmem);
 	else
 		__page_pool_release_page_dma(pool, netmem);
 
@@ -1049,8 +1055,8 @@ static void __page_pool_destroy(struct page_pool *pool)
 	page_pool_unlist(pool);
 	page_pool_uninit(pool);
 
-	if (pool->mp_priv) {
-		mp_dmabuf_devmem_destroy(pool);
+	if (pool->mp_ops) {
+		pool->mp_ops->destroy(pool);
 		static_branch_dec(&page_pool_mem_providers);
 	}
 
Signature · 1 line
2.43.5
maintainer
#13 lore raw

Re: [PATCH net-next v9 04/20] net: page_pool: create hooks for custom page providers

Quoted 10 lines · David Wei

From: Jakub Kicinski <[email protected]>

The page providers which try to reuse the same pages will need to hold onto the ref, even if page gets released from the pool - as in releasing the page from the pp just transfers the "ownership" reference from pp to the provider, and provider will wait for other references to be gone before feeding this page back into the pool.

My apologies, seems it lost a note that it's a derivative patch with changes not explicitly confirmed by the author.

Quoted 2 lines
Signature · 1 line
Pavel Begunkov
author
#14 lore raw

PATCH v9 5/20 net: page_pool: add mp op for netlink reporting

In reply to David Wei

From: Pavel Begunkov <[email protected]>

Add a mandatory memory provider callback that prints information about the provider.

---
 include/net/page_pool/types.h | 1 +
 net/core/devmem.c             | 9 +++++++++
 net/core/page_pool_user.c     | 3 +--
 3 files changed, 11 insertions(+), 2 deletions(-)
include/net/page_pool/types.h +1 -0
index d6241e8a5106..a473ea0c48c4 100644
@@ -157,6 +157,7 @@ struct memory_provider_ops {
 	bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
 	int (*init)(struct page_pool *pool);
 	void (*destroy)(struct page_pool *pool);
+	int (*nl_report)(const struct page_pool *pool, struct sk_buff *rsp);
 };
 
 struct pp_memory_provider_params {
net/core/devmem.c +9 -0
index 48903b7ab215..df51a6c312db 100644
@@ -394,9 +394,18 @@ bool mp_dmabuf_devmem_release_page(struct page_pool *pool, netmem_ref netmem)
 	return false;
 }
 
+static int mp_dmabuf_devmem_nl_report(const struct page_pool *pool,
+				      struct sk_buff *rsp)
+{
+	const struct net_devmem_dmabuf_binding *binding = pool->mp_priv;
+
+	return nla_put_u32(rsp, NETDEV_A_PAGE_POOL_DMABUF, binding->id);
+}
+
 static const struct memory_provider_ops dmabuf_devmem_ops = {
 	.init			= mp_dmabuf_devmem_init,
 	.destroy		= mp_dmabuf_devmem_destroy,
 	.alloc_netmems		= mp_dmabuf_devmem_alloc_netmems,
 	.release_netmem		= mp_dmabuf_devmem_release_page,
+	.nl_report		= mp_dmabuf_devmem_nl_report,
 };
net/core/page_pool_user.c +1 -2
index 8d31c71bea1a..61212f388bc8 100644
@@ -214,7 +214,6 @@ static int
 page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
 		  const struct genl_info *info)
 {
-	struct net_devmem_dmabuf_binding *binding = pool->mp_priv;
 	size_t inflight, refsz;
 	void *hdr;
 
@@ -244,7 +243,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
 			 pool->user.detach_time))
 		goto err_cancel;
 
-	if (binding && nla_put_u32(rsp, NETDEV_A_PAGE_POOL_DMABUF, binding->id))
+	if (pool->mp_ops && pool->mp_ops->nl_report(pool, rsp))
 		goto err_cancel;
 
 	genlmsg_end(rsp, hdr);
Signature · 1 line
2.43.5
maintainer Reviewed-by on v9 5/20
#15 lore raw

Re: [PATCH net-next v9 05/20] net: page_pool: add mp op for netlink reporting

Quoted 7 lines · On Tue, 17 Dec 2024 16:37:31 -0800 David Wei wrote:

From: Pavel Begunkov <[email protected]>

Add a mandatory memory provider callback that prints information about the provider.

net/core/page_pool_user.c

Quoted 4 lines
net/core/page_pool_user.c +0 -0
index 8d31c71bea1a..61212f388bc8 100644

net/core/page_pool_user.c doesn't have to include devmem.h any more

author
#16 lore raw

Re: [PATCH net-next v9 05/20] net: page_pool: add mp op for netlink reporting

Quoted 9 lines · Jakub Kicinski
Quoted 7 lines · On Tue, 17 Dec 2024 16:37:31 -0800 David Wei wrote:

From: Pavel Begunkov <[email protected]>

Add a mandatory memory provider callback that prints information about the provider.

Quoted 8 lines

net/core/page_pool_user.c

Quoted 4 lines
net/core/page_pool_user.c +0 -0
index 8d31c71bea1a..61212f388bc8 100644

net/core/page_pool_user.c doesn't have to include devmem.h any more

Will remove the include in the next version.

Reviewed-by on v9 5/20
#17 lore raw

Re: [PATCH net-next v9 05/20] net: page_pool: add mp op for netlink reporting

In reply to David Wei
Quoted 8 lines · David Wei

From: Pavel Begunkov <[email protected]>

Add a mandatory memory provider callback that prints information about the provider.

Seems like a straightforward refactor to add the op that Jakub requested:

Quoted 54 lines
---
 include/net/page_pool/types.h | 1 +
 net/core/devmem.c             | 9 +++++++++
 net/core/page_pool_user.c     | 3 +--
 3 files changed, 11 insertions(+), 2 deletions(-)
include/net/page_pool/types.h +1 -0
index d6241e8a5106..a473ea0c48c4 100644
@@ -157,6 +157,7 @@ struct memory_provider_ops {
        bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
        int (*init)(struct page_pool *pool);
        void (*destroy)(struct page_pool *pool);
+       int (*nl_report)(const struct page_pool *pool, struct sk_buff *rsp);
 };
 
 struct pp_memory_provider_params {
net/core/devmem.c +9 -0
index 48903b7ab215..df51a6c312db 100644
@@ -394,9 +394,18 @@ bool mp_dmabuf_devmem_release_page(struct page_pool *pool, netmem_ref netmem)
        return false;
 }
 
+static int mp_dmabuf_devmem_nl_report(const struct page_pool *pool,
+                                     struct sk_buff *rsp)
+{
+       const struct net_devmem_dmabuf_binding *binding = pool->mp_priv;
+
+       return nla_put_u32(rsp, NETDEV_A_PAGE_POOL_DMABUF, binding->id);
+}
+
 static const struct memory_provider_ops dmabuf_devmem_ops = {
        .init                   = mp_dmabuf_devmem_init,
        .destroy                = mp_dmabuf_devmem_destroy,
        .alloc_netmems          = mp_dmabuf_devmem_alloc_netmems,
        .release_netmem         = mp_dmabuf_devmem_release_page,
+       .nl_report              = mp_dmabuf_devmem_nl_report,
 };
net/core/page_pool_user.c +0 -1
index 8d31c71bea1a..61212f388bc8 100644
@@ -214,7 +214,6 @@ static int
 page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
                  const struct genl_info *info)
 {
-       struct net_devmem_dmabuf_binding *binding = pool->mp_priv;
        size_t inflight, refsz;
        void *hdr;
 

net/core/page_pool_user.c page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, · line 248

Quoted 7 lines
net/core/page_pool_user.c +1 -1
@@ -244,7 +243,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
                         pool->user.detach_time))
                goto err_cancel;
 
-       if (binding && nla_put_u32(rsp, NETDEV_A_PAGE_POOL_DMABUF, binding->id))
+       if (pool->mp_ops && pool->mp_ops->nl_report(pool, rsp))
                goto err_cancel;
 

I thought maybe you should check nl_report exists here so that we don't crash if we accidentally merge a memory provider that doesn't define this, but the commit message says it's mandatory and we don't check the existence of the other ops anyway, so this is probably fine.

Signature · 2 lines
Thanks,
Mina
author
#18 lore raw

PATCH v9 6/20 net: page_pool: add a mp hook to unregister_netdevice*

In reply to David Wei

From: Pavel Begunkov <[email protected]>

Devmem TCP needs a hook in unregister_netdevice_many_notify() to upkeep the set tracking queues it's bound to, i.e. ->bound_rxqs. Instead of devmem sticking directly out of the genetic path, add a mp function.

---
 include/net/page_pool/types.h |  3 +++
 net/core/dev.c                | 15 ++++++++++++++-
 net/core/devmem.c             | 36 ++++++++++++++++-------------------
 net/core/devmem.h             |  5 -----
 4 files changed, 33 insertions(+), 26 deletions(-)
include/net/page_pool/types.h +3 -0
index a473ea0c48c4..140fec6857c6 100644
@@ -152,12 +152,15 @@ struct page_pool_stats {
  */
 #define PAGE_POOL_FRAG_GROUP_ALIGN	(4 * sizeof(long))
 
+struct netdev_rx_queue;
+
 struct memory_provider_ops {
 	netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
 	bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
 	int (*init)(struct page_pool *pool);
 	void (*destroy)(struct page_pool *pool);
 	int (*nl_report)(const struct page_pool *pool, struct sk_buff *rsp);
+	void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq);
 };
 
 struct pp_memory_provider_params {
net/core/dev.c +14 -1
index c7f3dea3e0eb..aa082770ab1c 100644
@@ -11464,6 +11464,19 @@ void unregister_netdevice_queue(struct net_device *dev, struct list_head *head)
 }
 EXPORT_SYMBOL(unregister_netdevice_queue);
 
+static void dev_memory_provider_uninstall(struct net_device *dev)
+{
+	unsigned int i;
+
+	for (i = 0; i < dev->real_num_rx_queues; i++) {
+		struct netdev_rx_queue *rxq = &dev->_rx[i];
+		struct pp_memory_provider_params *p = &rxq->mp_params;
+
+		if (p->mp_ops && p->mp_ops->uninstall)
+			p->mp_ops->uninstall(rxq->mp_params.mp_priv, rxq);
+	}
+}
+
 void unregister_netdevice_many_notify(struct list_head *head,
 				      u32 portid, const struct nlmsghdr *nlh)
 {
@@ -11516,7 +11529,7 @@ void unregister_netdevice_many_notify(struct list_head *head,
 		dev_tcx_uninstall(dev);
 		dev_xdp_uninstall(dev);
 		bpf_dev_bound_netdev_unregister(dev);
-		dev_dmabuf_uninstall(dev);
+		dev_memory_provider_uninstall(dev);
 
 		netdev_offload_xstats_disable_all(dev);
 
net/core/devmem.c +16 -20
index df51a6c312db..4ef67b63ea74 100644
@@ -308,26 +308,6 @@ net_devmem_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd,
 	return ERR_PTR(err);
 }
 
-void dev_dmabuf_uninstall(struct net_device *dev)
-{
-	struct net_devmem_dmabuf_binding *binding;
-	struct netdev_rx_queue *rxq;
-	unsigned long xa_idx;
-	unsigned int i;
-
-	for (i = 0; i < dev->real_num_rx_queues; i++) {
-		binding = dev->_rx[i].mp_params.mp_priv;
-		if (!binding)
-			continue;
-
-		xa_for_each(&binding->bound_rxqs, xa_idx, rxq)
-			if (rxq == &dev->_rx[i]) {
-				xa_erase(&binding->bound_rxqs, xa_idx);
-				break;
-			}
-	}
-}
-
 /*** "Dmabuf devmem memory provider" ***/
 
 int mp_dmabuf_devmem_init(struct page_pool *pool)
@@ -402,10 +382,26 @@ static int mp_dmabuf_devmem_nl_report(const struct page_pool *pool,
 	return nla_put_u32(rsp, NETDEV_A_PAGE_POOL_DMABUF, binding->id);
 }
 
+static void mp_dmabuf_devmem_uninstall(void *mp_priv,
+				       struct netdev_rx_queue *rxq)
+{
+	struct net_devmem_dmabuf_binding *binding = mp_priv;
+	struct netdev_rx_queue *bound_rxq;
+	unsigned long xa_idx;
+
+	xa_for_each(&binding->bound_rxqs, xa_idx, bound_rxq) {
+		if (bound_rxq == rxq) {
+			xa_erase(&binding->bound_rxqs, xa_idx);
+			break;
+		}
+	}
+}
+
 static const struct memory_provider_ops dmabuf_devmem_ops = {
 	.init			= mp_dmabuf_devmem_init,
 	.destroy		= mp_dmabuf_devmem_destroy,
 	.alloc_netmems		= mp_dmabuf_devmem_alloc_netmems,
 	.release_netmem		= mp_dmabuf_devmem_release_page,
 	.nl_report		= mp_dmabuf_devmem_nl_report,
+	.uninstall		= mp_dmabuf_devmem_uninstall,
 };
net/core/devmem.h +0 -5
index a2b9913e9a17..8e999fe2ae67 100644
@@ -68,7 +68,6 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding);
 int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 				    struct net_devmem_dmabuf_binding *binding,
 				    struct netlink_ext_ack *extack);
-void dev_dmabuf_uninstall(struct net_device *dev);
 
 static inline struct dmabuf_genpool_chunk_owner *
 net_devmem_iov_to_chunk_owner(const struct net_iov *niov)
@@ -145,10 +144,6 @@ net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 	return -EOPNOTSUPP;
 }
 
-static inline void dev_dmabuf_uninstall(struct net_device *dev)
-{
-}
-
 static inline struct net_iov *
 net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding)
 {
Signature · 1 line
2.43.5
maintainer Reviewed-by on v9 6/20
#19 lore raw

Re: [PATCH net-next v9 06/20] net: page_pool: add a mp hook to unregister_netdevice*

Quoted 8 lines · On Tue, 17 Dec 2024 16:37:32 -0800 David Wei wrote:

From: Pavel Begunkov <[email protected]>

Devmem TCP needs a hook in unregister_netdevice_many_notify() to upkeep the set tracking queues it's bound to, i.e. ->bound_rxqs. Instead of devmem sticking directly out of the genetic path, add a mp function.

but we may need to start adding kdoc to the struct memory_provider_ops if it continues to grow

Reviewed-by on v9 6/20
#20 lore raw

Re: [PATCH net-next v9 06/20] net: page_pool: add a mp hook to unregister_netdevice*

In reply to David Wei
Quoted 23 lines · David Wei

From: Pavel Begunkov <[email protected]>

Devmem TCP needs a hook in unregister_netdevice_many_notify() to upkeep the set tracking queues it's bound to, i.e. ->bound_rxqs. Instead of devmem sticking directly out of the genetic path, add a mp function.

---
 include/net/page_pool/types.h |  3 +++
 net/core/dev.c                | 15 ++++++++++++++-
 net/core/devmem.c             | 36 ++++++++++++++++-------------------
 net/core/devmem.h             |  5 -----
 4 files changed, 33 insertions(+), 26 deletions(-)
include/net/page_pool/types.h +0 -0
index a473ea0c48c4..140fec6857c6 100644
@@ -152,12 +152,15 @@ struct page_pool_stats {
  */
 #define PAGE_POOL_FRAG_GROUP_ALIGN     (4 * sizeof(long))

include/net/page_pool/types.h struct page_pool_stats { · line 163

Quoted 10 lines
include/net/page_pool/types.h +3 -0
 
+struct netdev_rx_queue;
+
 struct memory_provider_ops {
        netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
        bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
        int (*init)(struct page_pool *pool);
        void (*destroy)(struct page_pool *pool);
        int (*nl_report)(const struct page_pool *pool, struct sk_buff *rsp);
+       void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq);

nit: the other params take struct page_pool *pool as input, and find the mp_priv in there if they need, it may be nice for consistency to continue to pass the entire pool to these ops.

AFAIU this is the first added non-mandatory op, right? Please specify it as so, maybe something like:

/* optional: called when the memory provider is uninstalled from the netdev_rx_queue due to the interface going down or otherwise. The memory provider may perform whatever cleanup necessary here if it needs to. */

Quoted 10 lines
include/net/page_pool/types.h +0 -0
 };
 
 struct pp_memory_provider_params {
net/core/dev.c +0 -0
index c7f3dea3e0eb..aa082770ab1c 100644
@@ -11464,6 +11464,19 @@ void unregister_netdevice_queue(struct net_device *dev, struct list_head *head)
 }
 EXPORT_SYMBOL(unregister_netdevice_queue);

net/core/dev.c void unregister_netdevice_queue(struct net_device *dev, struct list_head *head) · line 11475

Quoted 10 lines
net/core/dev.c +9 -0
 
+static void dev_memory_provider_uninstall(struct net_device *dev)
+{
+       unsigned int i;
+
+       for (i = 0; i < dev->real_num_rx_queues; i++) {
+               struct netdev_rx_queue *rxq = &dev->_rx[i];
+               struct pp_memory_provider_params *p = &rxq->mp_params;
+
+               if (p->mp_ops && p->mp_ops->uninstall)

Previous versions of the code checked p->mp_priv to check if the queue is mp enabled or not, I guess you check mp_ops and that is set/cleared along with p->mp_priv. I guess that is fine. It would have been nicer, maybe, to have all the mp stuff behind one pointer/struct. I would dread some code path setting one of mp_[ops|priv] but forgetting to set the other... :shrug:

Anyhow:

Signature · 2 lines
Thanks,
Mina
author
#21 lore raw

Re: [PATCH net-next v9 06/20] net: page_pool: add a mp hook to unregister_netdevice*

Quoted 39 lines · Mina Almasry
Quoted 23 lines · David Wei

From: Pavel Begunkov <[email protected]>

Devmem TCP needs a hook in unregister_netdevice_many_notify() to upkeep the set tracking queues it's bound to, i.e. ->bound_rxqs. Instead of devmem sticking directly out of the genetic path, add a mp function.

---
 include/net/page_pool/types.h |  3 +++
 net/core/dev.c                | 15 ++++++++++++++-
 net/core/devmem.c             | 36 ++++++++++++++++-------------------
 net/core/devmem.h             |  5 -----
 4 files changed, 33 insertions(+), 26 deletions(-)
include/net/page_pool/types.h +0 -0
index a473ea0c48c4..140fec6857c6 100644
@@ -152,12 +152,15 @@ struct page_pool_stats {
  */
 #define PAGE_POOL_FRAG_GROUP_ALIGN     (4 * sizeof(long))

include/net/page_pool/types.h struct page_pool_stats { · line 163

Quoted 10 lines
include/net/page_pool/types.h +3 -0
 
+struct netdev_rx_queue;
+
 struct memory_provider_ops {
        netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
        bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
        int (*init)(struct page_pool *pool);
        void (*destroy)(struct page_pool *pool);
        int (*nl_report)(const struct page_pool *pool, struct sk_buff *rsp);
+       void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq);

nit: the other params take struct page_pool *pool as input, and find the mp_priv in there if they need, it may be nice for consistency to continue to pass the entire pool to these ops.

Quoted 7 lines

AFAIU this is the first added non-mandatory op, right? Please specify it as so, maybe something like:

/* optional: called when the memory provider is uninstalled from the netdev_rx_queue due to the interface going down or otherwise. The memory provider may perform whatever cleanup necessary here if it needs to. */

Sounds good, I'll make the change in the next version.

Quoted 12 lines
Quoted 12 lines
include/net/page_pool/types.h +0 -0
 };
 
 struct pp_memory_provider_params {
net/core/dev.c +0 -0
index c7f3dea3e0eb..aa082770ab1c 100644
@@ -11464,6 +11464,19 @@ void unregister_netdevice_queue(struct net_device *dev, struct list_head *head)
 }
 EXPORT_SYMBOL(unregister_netdevice_queue);
 
Quoted 16 lines

net/core/dev.c void unregister_netdevice_queue(struct net_device *dev, struct list_head *head) · line 11475

Quoted 9 lines
net/core/dev.c +9 -0
+static void dev_memory_provider_uninstall(struct net_device *dev)
+{
+       unsigned int i;
+
+       for (i = 0; i < dev->real_num_rx_queues; i++) {
+               struct netdev_rx_queue *rxq = &dev->_rx[i];
+               struct pp_memory_provider_params *p = &rxq->mp_params;
+
+               if (p->mp_ops && p->mp_ops->uninstall)

Previous versions of the code checked p->mp_priv to check if the queue is mp enabled or not, I guess you check mp_ops and that is set/cleared along with p->mp_priv. I guess that is fine. It would have been nicer, maybe, to have all the mp stuff behind one pointer/struct. I would dread some code path setting one of mp_[ops|priv] but forgetting to set the other... :shrug:

We can follow up with helpers that do the set/unset/check to make sure it is consistent.

Quoted 5 lines

Anyhow:

maintainer
#22 lore raw

Re: [PATCH net-next v9 06/20] net: page_pool: add a mp hook to unregister_netdevice*

In reply to Mina Almasry

On 1/6/25 21:44, Mina Almasry wrote:
...

Quoted 8 lines
Quoted 8 lines
include/net/page_pool/types.h +0 -0
index a473ea0c48c4..140fec6857c6 100644
@@ -152,12 +152,15 @@ struct page_pool_stats {
   */
  #define PAGE_POOL_FRAG_GROUP_ALIGN     (4 * sizeof(long))
 
Quoted 13 lines

include/net/page_pool/types.h struct page_pool_stats { · line 163

Quoted 9 lines
include/net/page_pool/types.h +3 -0
+struct netdev_rx_queue;
+
  struct memory_provider_ops {
         netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
         bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
         int (*init)(struct page_pool *pool);
         void (*destroy)(struct page_pool *pool);
         int (*nl_report)(const struct page_pool *pool, struct sk_buff *rsp);
+       void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq);

nit: the other params take struct page_pool *pool as input, and find the mp_priv in there if they need, it may be nice for consistency to continue to pass the entire pool to these ops.

I think so as well, but there is simply no page pool to pass from where it's called.

Quoted 19 lines

AFAIU this is the first added non-mandatory op, right? Please specify it as so, maybe something like:

/* optional: called when the memory provider is uninstalled from the netdev_rx_queue due to the interface going down or otherwise. The memory provider may perform whatever cleanup necessary here if it needs to. */

Quoted 11 lines
include/net/page_pool/types.h +0 -0
  };
 
  struct pp_memory_provider_params {
net/core/dev.c +0 -0
index c7f3dea3e0eb..aa082770ab1c 100644
@@ -11464,6 +11464,19 @@ void unregister_netdevice_queue(struct net_device *dev, struct list_head *head)
  }
  EXPORT_SYMBOL(unregister_netdevice_queue);
 
Quoted 12 lines

net/core/dev.c void unregister_netdevice_queue(struct net_device *dev, struct list_head *head) · line 11475

Quoted 9 lines
net/core/dev.c +9 -0
+static void dev_memory_provider_uninstall(struct net_device *dev)
+{
+       unsigned int i;
+
+       for (i = 0; i < dev->real_num_rx_queues; i++) {
+               struct netdev_rx_queue *rxq = &dev->_rx[i];
+               struct pp_memory_provider_params *p = &rxq->mp_params;
+
+               if (p->mp_ops && p->mp_ops->uninstall)

Previous versions of the code checked p->mp_priv to check if the queue is mp enabled or not, I guess you check mp_ops and that is set/cleared

The patchset converts it all to mp_ops (v9 missed one place), which is the right thing to do as only ops are typed and strictly defined.

Signature · 1 line
Pavel Begunkov
author
#23 lore raw

PATCH v9 7/20 net: prepare for non devmem TCP memory providers

In reply to David Wei

From: Pavel Begunkov <[email protected]>

There is a good bunch of places in generic paths assuming that the only page pool memory provider is devmem TCP. As we want to reuse the net_iov and provider infrastructure, we need to patch it up and explicitly check the provider type when we branch into devmem TCP code.

---
 net/core/devmem.c | 5 +++++
 net/core/devmem.h | 8 ++++++++
 net/ipv4/tcp.c    | 5 +++++
 3 files changed, 18 insertions(+)
net/core/devmem.c +5 -0
index 4ef67b63ea74..fd2be02564dc 100644
@@ -28,6 +28,11 @@ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);
 
 static const struct memory_provider_ops dmabuf_devmem_ops;
 
+bool net_is_devmem_iov(struct net_iov *niov)
+{
+	return niov->pp->mp_ops == &dmabuf_devmem_ops;
+}
+
 static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool,
 					       struct gen_pool_chunk *chunk,
 					       void *not_used)
net/core/devmem.h +8 -0
index 8e999fe2ae67..5ecc1b2877e4 100644
@@ -115,6 +115,8 @@ struct net_iov *
 net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding);
 void net_devmem_free_dmabuf(struct net_iov *ppiov);
 
+bool net_is_devmem_iov(struct net_iov *niov);
+
 #else
 struct net_devmem_dmabuf_binding;
 
@@ -163,6 +165,12 @@ static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)
 {
 	return 0;
 }
+
+static inline bool
+bool net_is_devmem_iov(struct net_iov *niov)
+{
+	return false;
+}
 #endif
 
 #endif /* _NET_DEVMEM_H */
net/ipv4/tcp.c +5 -0
index b872de9a8271..7f43d31c9400 100644
@@ -2476,6 +2476,11 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb,
 			}
 
 			niov = skb_frag_net_iov(frag);
+			if (!net_is_devmem_iov(niov)) {
+				err = -ENODEV;
+				goto out;
+			}
+
 			end = start + skb_frag_size(frag);
 			copy = end - offset;
 
Signature · 1 line
2.43.5
maintainer Reviewed-by on v9 7/20
#24 lore raw

Re: [PATCH net-next v9 07/20] net: prepare for non devmem TCP memory providers

Quoted 10 lines · On Tue, 17 Dec 2024 16:37:33 -0800 David Wei wrote:

From: Pavel Begunkov <[email protected]>

There is a good bunch of places in generic paths assuming that the only page pool memory provider is devmem TCP. As we want to reuse the net_iov and provider infrastructure, we need to patch it up and explicitly check the provider type when we branch into devmem TCP code.

author
#25 lore raw

PATCH v9 8/20 net: expose page_pool_{set,clear}_pp_info

In reply to David Wei

From: Pavel Begunkov <[email protected]>

Memory providers need to set page pool to its net_iovs on allocation, so expose page_pool_{set,clear}_pp_info to providers outside net/.

---
 include/net/page_pool/helpers.h | 13 +++++++++++++
 net/core/page_pool_priv.h       |  9 ---------
 2 files changed, 13 insertions(+), 9 deletions(-)
include/net/page_pool/helpers.h +13 -0
index e555921e5233..872947179bae 100644
@@ -483,4 +483,17 @@ static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid)
 		page_pool_update_nid(pool, new_nid);
 }
 
+#if defined(CONFIG_PAGE_POOL)
+void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem);
+void page_pool_clear_pp_info(netmem_ref netmem);
+#else
+static inline void page_pool_set_pp_info(struct page_pool *pool,
+					 netmem_ref netmem)
+{
+}
+static inline void page_pool_clear_pp_info(netmem_ref netmem)
+{
+}
+#endif
+
 #endif /* _NET_PAGE_POOL_HELPERS_H */
net/core/page_pool_priv.h +0 -9
index 57439787b9c2..11a45a5f3c9c 100644
@@ -36,18 +36,9 @@ static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr)
 }
 
 #if defined(CONFIG_PAGE_POOL)
-void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem);
-void page_pool_clear_pp_info(netmem_ref netmem);
 int page_pool_check_memory_provider(struct net_device *dev,
 				    struct netdev_rx_queue *rxq);
 #else
-static inline void page_pool_set_pp_info(struct page_pool *pool,
-					 netmem_ref netmem)
-{
-}
-static inline void page_pool_clear_pp_info(netmem_ref netmem)
-{
-}
 static inline int page_pool_check_memory_provider(struct net_device *dev,
 						  struct netdev_rx_queue *rxq)
 {
Signature · 1 line
2.43.5
maintainer
#26 lore raw

Re: [PATCH net-next v9 08/20] net: expose page_pool_{set,clear}_pp_info

Quoted 4 lines · On Tue, 17 Dec 2024 16:37:34 -0800 David Wei wrote:

From: Pavel Begunkov <[email protected]>

Memory providers need to set page pool to its net_iovs on allocation, so expose page_pool_{set,clear}_pp_info to providers outside net/.

I'd really rather not expose such low level functions in a header included by every single user of the page pool API.

maintainer
#27 lore raw

Re: [PATCH net-next v9 08/20] net: expose page_pool_{set,clear}_pp_info

Quoted 8 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 17 Dec 2024 16:37:34 -0800 David Wei wrote:

From: Pavel Begunkov <[email protected]>

Memory providers need to set page pool to its net_iovs on allocation, so expose page_pool_{set,clear}_pp_info to providers outside net/.

I'd really rather not expose such low level functions in a header included by every single user of the page pool API.

Are you fine if it's exposed in a new header file?

Signature · 1 line
Pavel Begunkov
maintainer
#28 lore raw

Re: [PATCH net-next v9 08/20] net: expose page_pool_{set,clear}_pp_info

Quoted 7 lines · On Sat, 21 Dec 2024 01:07:44 +0000 Pavel Begunkov wrote:
Quoted 5 lines
Quoted 2 lines

Memory providers need to set page pool to its net_iovs on allocation, so expose page_pool_{set,clear}_pp_info to providers outside net/.

I'd really rather not expose such low level functions in a header included by every single user of the page pool API.

Are you fine if it's exposed in a new header file?

I guess.

I'm uncomfortable with the "outside net/" phrasing of the commit message. Nothing outside net should used this stuff. Next we'll have a four letter subsystem abusing it and claiming that it's in a header so it's a public.

Maybe we should have a conversation about whether io_uring/zcrx.c is considered part of networking, whether all patches will get cross posted and need to get acks from both sides etc. Save ourselves unpleasant misunderstandings.

maintainer
#29 lore raw

Re: [PATCH net-next v9 08/20] net: expose page_pool_{set,clear}_pp_info

Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Sat, 21 Dec 2024 01:07:44 +0000 Pavel Begunkov wrote:
Quoted 5 lines
Quoted 2 lines

Memory providers need to set page pool to its net_iovs on allocation, so expose page_pool_{set,clear}_pp_info to providers outside net/.

I'd really rather not expose such low level functions in a header included by every single user of the page pool API.

Quoted 8 lines
Quoted 1 line

Are you fine if it's exposed in a new header file?

I guess.

I'm uncomfortable with the "outside net/" phrasing of the commit message. Nothing outside net should used this stuff. Next we'll have a four letter subsystem abusing it and claiming that it's in a header so it's a public.

By net/ I purely meant the folder, even though it also dictates the available API. io_uring is outside, having some glue API between them is the only way I can think of, even if it looks different from the current series.

Since there are strong opinions would make sense to shove it into a new file and name helpers more appropriately, like net_mp_*.

Quoted 4 lines

Maybe we should have a conversation about whether io_uring/zcrx.c is considered part of networking, whether all patches will get cross posted and need to get acks from both sides etc. Save ourselves unpleasant misunderstandings.

That would be terribly inefficient. Net is already quite busy, would be a shame spamming it even more with io_uring patches that are not being particularly interesting to networking. Even the patchwork tooling won't work too well unless patches are sync'ed with both trees.

IMHO it sounds saner finalising the API and cross posting when it needs to be changed.

Signature · 1 line
Pavel Begunkov
#30 lore raw

Re: [PATCH net-next v9 08/20] net: expose page_pool_{set,clear}_pp_info

Quoted 18 lines · Pavel Begunkov
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Sat, 21 Dec 2024 01:07:44 +0000 Pavel Begunkov wrote:
Quoted 5 lines
Quoted 2 lines

Memory providers need to set page pool to its net_iovs on allocation, so expose page_pool_{set,clear}_pp_info to providers outside net/.

I'd really rather not expose such low level functions in a header included by every single user of the page pool API.

Quoted 8 lines
Quoted 1 line

Are you fine if it's exposed in a new header file?

I guess.

I'm uncomfortable with the "outside net/" phrasing of the commit message. Nothing outside net should used this stuff. Next we'll have a four letter subsystem abusing it and claiming that it's in a header so it's a public.

Quoted 8 lines

By net/ I purely meant the folder, even though it also dictates the available API. io_uring is outside, having some glue API between them is the only way I can think of, even if it looks different from the current series.

Since there are strong opinions would make sense to shove it into a new file and name helpers more appropriately, like net_mp_*.

I guess I'm a bit sorry here because I think I suggested this approach. I think the root of the issue is that the io_uring memory provider (and future mps) need to set_pp_info/clear_pp_info the netmems. dmabuf mp has no issue because it's defined under net/core so it can easily include net/core/page_pool_priv.h.

I guess more options I see here are:

1. move the io_uring mp to somewhere under net/core. Moving only the mp should be sufficient here I think.

2. Do some mp refactor such that the mp gives the page_pool the netmems but the page_pool is responsible for set_pp_info/clear_pp_info.

3. Revert back to earlier versions of the code where page_pool.c exposed a helper that did all the memory processing. I had pushed back against that version of the code because the helper seemed like io_uring mp specific code masquerading as a generic helper that wasn't very reusable :shrug:

For what little it's worth I'm having trouble imagining how set_pp_info/clear_pp_info can be abused if exposed, so this approach is fine by me, but I'm probably missing something if there is huge concern about this.

Signature · 2 lines
Thanks,
Mina
maintainer
#31 lore raw

Re: [PATCH net-next v9 08/20] net: expose page_pool_{set,clear}_pp_info

Quoted 24 lines · Mina Almasry
Quoted 23 lines · Pavel Begunkov
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Sat, 21 Dec 2024 01:07:44 +0000 Pavel Begunkov wrote:
Quoted 5 lines
Quoted 2 lines

Memory providers need to set page pool to its net_iovs on allocation, so expose page_pool_{set,clear}_pp_info to providers outside net/.

I'd really rather not expose such low level functions in a header included by every single user of the page pool API.

Quoted 8 lines
Quoted 1 line

Are you fine if it's exposed in a new header file?

I guess.

I'm uncomfortable with the "outside net/" phrasing of the commit message. Nothing outside net should used this stuff. Next we'll have a four letter subsystem abusing it and claiming that it's in a header so it's a public.

By net/ I purely meant the folder, even though it also dictates the available API. io_uring is outside, having some glue API between them is the only way I can think of, even if it looks different from the current series.

Quoted 6 lines
Quoted 3 lines

Since there are strong opinions would make sense to shove it into a new file and name helpers more appropriately, like net_mp_*.

I guess I'm a bit sorry here because I think I suggested this approach. I think the root of the issue is that the io_uring memory

No worries, that wasn't the reason at all. It got split to support multiple pools per provider because of intricacies of the queue api.

In v10 {set,clear}_pp* it's wrapped into helpers, which hide even more networking bits.

Signature · 1 line
Pavel Begunkov
author
#32 lore raw

PATCH v9 9/20 net: page_pool: introduce page_pool_mp_return_in_cache

In reply to David Wei

From: Pavel Begunkov <[email protected]>

Add a helper that allows a page pool memory provider to efficiently return a netmem off the allocation callback.

---
 include/net/page_pool/helpers.h |  2 ++
 net/core/page_pool.c            | 15 +++++++++++++++
 2 files changed, 17 insertions(+)
include/net/page_pool/helpers.h +2 -0
index 872947179bae..d968eebc4322 100644
@@ -486,6 +486,8 @@ static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid)
 #if defined(CONFIG_PAGE_POOL)
 void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem);
 void page_pool_clear_pp_info(netmem_ref netmem);
+
+void page_pool_mp_return_in_cache(struct page_pool *pool, netmem_ref netmem);
 #else
 static inline void page_pool_set_pp_info(struct page_pool *pool,
 					 netmem_ref netmem)
net/core/page_pool.c +15 -0
index 784a547b2ca4..bd7f33d02652 100644
@@ -1195,3 +1195,18 @@ void page_pool_update_nid(struct page_pool *pool, int new_nid)
 	}
 }
 EXPORT_SYMBOL(page_pool_update_nid);
+
+/*
+ * page_pool_mp_return_in_cache() - return a netmem to the allocation cache.
+ * @pool:	pool from which pages were allocated
+ * @netmem:	netmem to return
+ *
+ * Return already allocated and accounted netmem to the page pool's allocation
+ * cache. The function doesn't provide synchronisation and can only be called
+ * off the mp_ops->alloc_netmems() path.
+ */
+void page_pool_mp_return_in_cache(struct page_pool *pool, netmem_ref netmem)
+{
+	page_pool_dma_sync_for_device(pool, netmem, -1);
+	pool->alloc.cache[pool->alloc.count++] = netmem;
+}
Signature · 1 line
2.43.5
author
#33 lore raw

PATCH v9 10/20 io_uring/zcrx: add interface queue and refill queue

In reply to David Wei

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.

---
 Kconfig                        |   2 +
 include/linux/io_uring_types.h |   6 ++
 include/uapi/linux/io_uring.h  |  43 +++++++++-
 io_uring/KConfig               |  10 +++
 io_uring/Makefile              |   1 +
 io_uring/io_uring.c            |   7 ++
 io_uring/memmap.h              |   1 +
 io_uring/register.c            |   7 ++
 io_uring/zcrx.c                | 149 +++++++++++++++++++++++++++++++++
 io_uring/zcrx.h                |  35 ++++++++
 10 files changed, 260 insertions(+), 1 deletion(-)
 create mode 100644 io_uring/KConfig
 create mode 100644 io_uring/zcrx.c
 create mode 100644 io_uring/zcrx.h
Kconfig +2 -0
index 745bc773f567..529ea7694ba9 100644
@@ -30,3 +30,5 @@ source "lib/Kconfig"
 source "lib/Kconfig.debug"
 
 source "Documentation/Kconfig"
+
+source "io_uring/KConfig"
include/linux/io_uring_types.h +6 -0
index 493a8f7fa8e4..f0c6e18d176a 100644
@@ -40,6 +40,8 @@ enum io_uring_cmd_flags {
 	IO_URING_F_TASK_DEAD		= (1 << 13),
 };
 
+struct io_zcrx_ifq;
+
 struct io_wq_work_node {
 	struct io_wq_work_node *next;
 };
@@ -384,6 +386,8 @@ struct io_ring_ctx {
 	struct wait_queue_head		poll_wq;
 	struct io_restriction		restrictions;
 
+	struct io_zcrx_ifq		*ifq;
+
 	u32			pers_next;
 	struct xarray		personalities;
 
@@ -436,6 +440,8 @@ struct io_ring_ctx {
 	struct io_mapped_region		ring_region;
 	/* used for optimised request parameter and wait argument passing  */
 	struct io_mapped_region		param_region;
+	/* just one zcrx per ring for now, will move to io_zcrx_ifq eventually */
+	struct io_mapped_region		zcrx_region;
 };
 
 struct io_tw_state {
include/uapi/linux/io_uring.h +42 -1

55 lines not on this page · raw message

io_uring/KConfig new file +10 -0
new file mode 100644
index 000000000000..9e2a4beba1ef
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# io_uring configuration
+#
+
+config IO_URING_ZCRX
+	def_bool y
+	depends on PAGE_POOL
+	depends on INET
+	depends on NET_RX_BUSY_POLL
io_uring/Makefile +1 -0
index 53167bef37d7..a95b0b8229c9 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_IO_URING)		+= io_uring.o opdef.o kbuf.o rsrc.o notif.o \
 					epoll.o statx.o timeout.o fdinfo.o \
 					cancel.o waitid.o register.o \
 					truncate.o memmap.o
+obj-$(CONFIG_IO_URING_ZCRX)	+= zcrx.o
 obj-$(CONFIG_IO_WQ)		+= io-wq.o
 obj-$(CONFIG_FUTEX)		+= futex.o
 obj-$(CONFIG_NET_RX_BUSY_POLL) += napi.o
io_uring/io_uring.c +7 -0
index 5535a72b0ce1..0c02a2e97f01 100644
@@ -97,6 +97,7 @@
 #include "uring_cmd.h"
 #include "msg_ring.h"
 #include "memmap.h"
+#include "zcrx.h"
 
 #include "timeout.h"
 #include "poll.h"
@@ -2686,6 +2687,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
 	mutex_lock(&ctx->uring_lock);
 	io_sqe_buffers_unregister(ctx);
 	io_sqe_files_unregister(ctx);
+	io_unregister_zcrx_ifqs(ctx);
 	io_cqring_overflow_kill(ctx);
 	io_eventfd_unregister(ctx);
 	io_alloc_cache_free(&ctx->apoll_cache, kfree);
@@ -2851,6 +2853,11 @@ static __cold void io_ring_exit_work(struct work_struct *work)
 			io_cqring_overflow_kill(ctx);
 			mutex_unlock(&ctx->uring_lock);
 		}
+		if (ctx->ifq) {
+			mutex_lock(&ctx->uring_lock);
+			io_shutdown_zcrx_ifqs(ctx);
+			mutex_unlock(&ctx->uring_lock);
+		}
 
 		if (ctx->flags & IORING_SETUP_DEFER_TASKRUN)
 			io_move_task_work_from_local(ctx);
io_uring/memmap.h +1 -0
index c898dcba2b4e..dad0aa5b1b45 100644
@@ -2,6 +2,7 @@
 #define IO_URING_MEMMAP_H
 
 #define IORING_MAP_OFF_PARAM_REGION		0x20000000ULL
+#define IORING_MAP_OFF_ZCRX_REGION		0x30000000ULL
 
 struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages);
 
io_uring/register.c +7 -0
index f1698c18c7cb..f9dfdca79a80 100644
@@ -30,6 +30,7 @@
 #include "eventfd.h"
 #include "msg_ring.h"
 #include "memmap.h"
+#include "zcrx.h"
 
 #define IORING_MAX_RESTRICTIONS	(IORING_RESTRICTION_LAST + \
 				 IORING_REGISTER_LAST + IORING_OP_LAST)
@@ -798,6 +799,12 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
 			break;
 		ret = io_register_clone_buffers(ctx, arg);
 		break;
+	case IORING_REGISTER_ZCRX_IFQ:
+		ret = -EINVAL;
+		if (!arg || nr_args != 1)
+			break;
+		ret = io_register_zcrx_ifq(ctx, arg);
+		break;
 	case IORING_REGISTER_RESIZE_RINGS:
 		ret = -EINVAL;
 		if (!arg || nr_args != 1)
io_uring/zcrx.c new file +149 -0

149 lines not on this page · raw message

io_uring/zcrx.h new file +35 -0
new file mode 100644
index 000000000000..58e4ab6c6083
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef IOU_ZC_RX_H
+#define IOU_ZC_RX_H
+
+#include <linux/io_uring_types.h>
+
+struct io_zcrx_ifq {
+	struct io_ring_ctx		*ctx;
+	struct io_uring			*rq_ring;
+	struct io_uring_zcrx_rqe	*rqes;
+	u32				rq_entries;
+
+	u32				if_rxq;
+};
+
+#if defined(CONFIG_IO_URING_ZCRX)
+int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
+			 struct io_uring_zcrx_ifq_reg __user *arg);
+void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx);
+void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx);
+#else
+static inline int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
+					struct io_uring_zcrx_ifq_reg __user *arg)
+{
+	return -EOPNOTSUPP;
+}
+static inline void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx)
+{
+}
+static inline void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx)
+{
+}
+#endif
+
+#endif
Signature · 1 line
2.43.5
author
#34 lore raw

PATCH v9 11/20 io_uring/zcrx: add io_zcrx_area

In reply to David Wei

Add io_zcrx_area that represents a region of userspace memory that is used for zero copy. During ifq registration, userspace passes in the uaddr and len of userspace memory, which is then pinned by the kernel. Each net_iov is mapped to one of these pages.

The freelist is a spinlock protected list that keeps track of all the net_iovs/pages that aren't used.

For now, there is only one area per ifq and area registration happens implicitly as part of ifq registration. There is no API for adding/removing areas yet. The struct for area registration is there for future extensibility once we support multiple areas and TCP devmem.

---
 include/uapi/linux/io_uring.h |  9 ++++
 io_uring/rsrc.c               |  2 +-
 io_uring/rsrc.h               |  1 +
 io_uring/zcrx.c               | 89 ++++++++++++++++++++++++++++++++++-
 io_uring/zcrx.h               | 16 +++++++
 5 files changed, 114 insertions(+), 3 deletions(-)
include/uapi/linux/io_uring.h +9 -0
index 3af8b7a19824..e251f28507ce 100644
@@ -980,6 +980,15 @@ struct io_uring_zcrx_offsets {
 	__u64	__resv[2];
 };
 
+struct io_uring_zcrx_area_reg {
+	__u64	addr;
+	__u64	len;
+	__u64	rq_area_token;
+	__u32	flags;
+	__u32	__resv1;
+	__u64	__resv2[2];
+};
+
 /*
  * Argument for IORING_REGISTER_ZCRX_IFQ
  */
io_uring/rsrc.c +1 -1
index f2ff108485c8..d0f11b5aec0d 100644
@@ -77,7 +77,7 @@ static int io_account_mem(struct io_ring_ctx *ctx, unsigned long nr_pages)
 	return 0;
 }
 
-static int io_buffer_validate(struct iovec *iov)
+int io_buffer_validate(struct iovec *iov)
 {
 	unsigned long tmp, acct_len = iov->iov_len + (PAGE_SIZE - 1);
 
io_uring/rsrc.h +1 -0
index c8b093584461..0ae54ddeb1fd 100644
@@ -66,6 +66,7 @@ int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
 			    unsigned size, unsigned type);
 int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
 			unsigned int size, unsigned int type);
+int io_buffer_validate(struct iovec *iov);
 
 bool io_check_coalesce_buffer(struct page **page_array, int nr_pages,
 			      struct io_imu_folio_data *data);
io_uring/zcrx.c +87 -2

131 lines not on this page · raw message

io_uring/zcrx.h +16 -0
index 58e4ab6c6083..53fd94b65b38 100644
@@ -3,9 +3,25 @@
 #define IOU_ZC_RX_H
 
 #include <linux/io_uring_types.h>
+#include <net/page_pool/types.h>
+
+struct io_zcrx_area {
+	struct net_iov_area	nia;
+	struct io_zcrx_ifq	*ifq;
+
+	u16			area_id;
+	struct page		**pages;
+
+	/* freelist */
+	spinlock_t		freelist_lock ____cacheline_aligned_in_smp;
+	u32			free_count;
+	u32			*freelist;
+};
 
 struct io_zcrx_ifq {
 	struct io_ring_ctx		*ctx;
+	struct io_zcrx_area		*area;
+
 	struct io_uring			*rq_ring;
 	struct io_uring_zcrx_rqe	*rqes;
 	u32				rq_entries;
Signature · 1 line
2.43.5
#35 lore raw

Re: [PATCH net-next v9 11/20] io_uring/zcrx: add io_zcrx_area

Quoted 9 lines · David Wei

Add io_zcrx_area that represents a region of userspace memory that is used for zero copy. During ifq registration, userspace passes in the uaddr and len of userspace memory, which is then pinned by the kernel. Each net_iov is mapped to one of these pages.

The freelist is a spinlock protected list that keeps track of all the net_iovs/pages that aren't used.

FWIW we devmem uses genpool to manage the freelist and that lets us do allocations/free without locks. Not saying you should migrate to that but it's an option you have available.

Signature · 2 lines
Thanks,
Mina
maintainer
#36 lore raw

Re: [PATCH net-next v9 11/20] io_uring/zcrx: add io_zcrx_area

Quoted 7 lines · Mina Almasry
Quoted 6 lines · David Wei

Add io_zcrx_area that represents a region of userspace memory that is used for zero copy. During ifq registration, userspace passes in the uaddr and len of userspace memory, which is then pinned by the kernel. Each net_iov is mapped to one of these pages.

Quoted 7 lines
Quoted 3 lines

The freelist is a spinlock protected list that keeps track of all the net_iovs/pages that aren't used.

FWIW we devmem uses genpool to manage the freelist and that lets us do allocations/free without locks. Not saying you should migrate to that but it's an option you have available.

It's not the hot path to care that much, but even then lockfree is not always faster. It's naturally batched for allocations while genpool does enough of work including at least a couple of atomics.

Signature · 1 line
Pavel Begunkov
author
#37 lore raw

PATCH v9 12/20 io_uring/zcrx: grab a net device

In reply to David Wei

From: Pavel Begunkov <[email protected]>

Zerocopy receive needs a net device to bind to its rx queue and dma map buffers. As a preparation to following patches, resolve a net device from the if_idx parameter with no functional changes otherwise.

---
 io_uring/zcrx.c | 10 ++++++++++
 io_uring/zcrx.h |  3 +++
 2 files changed, 13 insertions(+)
io_uring/zcrx.c +10 -0
index 04883a3ae80c..e6cca6747148 100644
@@ -3,6 +3,8 @@
 #include <linux/errno.h>
 #include <linux/mm.h>
 #include <linux/io_uring.h>
+#include <linux/netdevice.h>
+#include <linux/rtnetlink.h>
 
 #include <uapi/linux/io_uring.h>
 
@@ -136,6 +138,8 @@ static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq)
 	if (ifq->area)
 		io_zcrx_free_area(ifq->area);
 
+	if (ifq->dev)
+		netdev_put(ifq->dev, &ifq->netdev_tracker);
 	io_free_rbuf_ring(ifq);
 	kfree(ifq);
 }
@@ -195,6 +199,12 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
 	ifq->rq_entries = reg.rq_entries;
 	ifq->if_rxq = reg.if_rxq;
 
+	ret = -ENODEV;
+	ifq->dev = netdev_get_by_index(current->nsproxy->net_ns, reg.if_idx,
+					&ifq->netdev_tracker, GFP_KERNEL);
+	if (!ifq->dev)
+		goto err;
+
 	reg.offsets.rqes = sizeof(struct io_uring);
 	reg.offsets.head = offsetof(struct io_uring, head);
 	reg.offsets.tail = offsetof(struct io_uring, tail);
io_uring/zcrx.h +3 -0
index 53fd94b65b38..46988a1dbd54 100644
@@ -4,6 +4,7 @@
 
 #include <linux/io_uring_types.h>
 #include <net/page_pool/types.h>
+#include <net/net_trackers.h>
 
 struct io_zcrx_area {
 	struct net_iov_area	nia;
@@ -27,6 +28,8 @@ struct io_zcrx_ifq {
 	u32				rq_entries;
 
 	u32				if_rxq;
+	struct net_device		*dev;
+	netdevice_tracker		netdev_tracker;
 };
 
 #if defined(CONFIG_IO_URING_ZCRX)
Signature · 1 line
2.43.5
author
#38 lore raw

PATCH v9 13/20 net: page pool: export page_pool_set_dma_addr_netmem()

In reply to David Wei

Export page_pool_set_dma_addr_netmem() in page_pool/helpers.h. This is needed by memory provider implementations that are outside of net/ to be able to set the dma addrs on net_iovs during alloc/free.

---
 include/net/page_pool/helpers.h |  5 +++++
 net/core/page_pool.c            | 16 ++++++++++++++++
 net/core/page_pool_priv.h       | 17 -----------------
 3 files changed, 21 insertions(+), 17 deletions(-)
include/net/page_pool/helpers.h +5 -0
index d968eebc4322..00eea5dd6f88 100644
@@ -486,6 +486,7 @@ static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid)
 #if defined(CONFIG_PAGE_POOL)
 void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem);
 void page_pool_clear_pp_info(netmem_ref netmem);
+bool page_pool_set_dma_addr_netmem(netmem_ref netmem, dma_addr_t addr);
 
 void page_pool_mp_return_in_cache(struct page_pool *pool, netmem_ref netmem);
 #else
@@ -493,6 +494,10 @@ static inline void page_pool_set_pp_info(struct page_pool *pool,
 					 netmem_ref netmem)
 {
 }
+static inline bool page_pool_set_dma_addr_netmem(netmem_ref netmem,
+						 dma_addr_t addr)
+{
+}
 static inline void page_pool_clear_pp_info(netmem_ref netmem)
 {
 }
net/core/page_pool.c +16 -0
index bd7f33d02652..3d1ed8b8f79e 100644
@@ -655,6 +655,22 @@ void page_pool_clear_pp_info(netmem_ref netmem)
 	netmem_set_pp(netmem, NULL);
 }
 
+bool page_pool_set_dma_addr_netmem(netmem_ref netmem, dma_addr_t addr)
+{
+	if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) {
+		netmem_set_dma_addr(netmem, addr >> PAGE_SHIFT);
+
+		/* We assume page alignment to shave off bottom bits,
+		 * if this "compression" doesn't work we need to drop.
+		 */
+		return addr != (dma_addr_t)netmem_get_dma_addr(netmem)
+				       << PAGE_SHIFT;
+	}
+
+	netmem_set_dma_addr(netmem, addr);
+	return false;
+}
+
 static __always_inline void __page_pool_release_page_dma(struct page_pool *pool,
 							 netmem_ref netmem)
 {
net/core/page_pool_priv.h +0 -17
index 11a45a5f3c9c..cac300c83e29 100644
@@ -13,23 +13,6 @@ int page_pool_list(struct page_pool *pool);
 void page_pool_detached(struct page_pool *pool);
 void page_pool_unlist(struct page_pool *pool);
 
-static inline bool
-page_pool_set_dma_addr_netmem(netmem_ref netmem, dma_addr_t addr)
-{
-	if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) {
-		netmem_set_dma_addr(netmem, addr >> PAGE_SHIFT);
-
-		/* We assume page alignment to shave off bottom bits,
-		 * if this "compression" doesn't work we need to drop.
-		 */
-		return addr != (dma_addr_t)netmem_get_dma_addr(netmem)
-				       << PAGE_SHIFT;
-	}
-
-	netmem_set_dma_addr(netmem, addr);
-	return false;
-}
-
 static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr)
 {
 	return page_pool_set_dma_addr_netmem(page_to_netmem(page), addr);
Signature · 1 line
2.43.5
author
#39 lore raw

PATCH v9 14/20 io_uring/zcrx: dma-map area for the device

In reply to David Wei

From: Pavel Begunkov <[email protected]>

Setup DMA mappings for the area into which we intend to receive data later on. We know the device we want to attach to even before we get a page pool and can pre-map in advance. All net_iov are synchronised for device when allocated, see page_pool_mp_return_in_cache().

---
 include/uapi/linux/netdev.h |   1 +
 io_uring/zcrx.c             | 320 ++++++++++++++++++++++++++++++++++++
 io_uring/zcrx.h             |   4 +
 3 files changed, 325 insertions(+)
include/uapi/linux/netdev.h +1 -0
index e4be227d3ad6..13d810a28ed6 100644
@@ -94,6 +94,7 @@ enum {
 	NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
 	NETDEV_A_PAGE_POOL_DETACH_TIME,
 	NETDEV_A_PAGE_POOL_DMABUF,
+	NETDEV_A_PAGE_POOL_IO_URING,
 
 	__NETDEV_A_PAGE_POOL_MAX,
 	NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1)
io_uring/zcrx.c +320 -0

372 lines not on this page · raw message

io_uring/zcrx.h +4 -0
index 46988a1dbd54..beacf1ea6380 100644
@@ -9,7 +9,9 @@
 struct io_zcrx_area {
 	struct net_iov_area	nia;
 	struct io_zcrx_ifq	*ifq;
+	atomic_t		*user_refs;
 
+	bool			is_mapped;
 	u16			area_id;
 	struct page		**pages;
 
@@ -26,6 +28,8 @@ struct io_zcrx_ifq {
 	struct io_uring			*rq_ring;
 	struct io_uring_zcrx_rqe	*rqes;
 	u32				rq_entries;
+	u32				cached_rq_head;
+	spinlock_t			rq_lock;
 
 	u32				if_rxq;
 	struct net_device		*dev;
Signature · 1 line
2.43.5
maintainer
#40 lore raw

Re: [PATCH net-next v9 14/20] io_uring/zcrx: dma-map area for the device

include/uapi/linux/netdev.h

Quoted 4 lines · On Tue, 17 Dec 2024 16:37:40 -0800 David Wei wrote:
include/uapi/linux/netdev.h +0 -0
index e4be227d3ad6..13d810a28ed6 100644

The top of this file says:

/* Do not edit directly, auto-generated from: */
/* Documentation/netlink/specs/netdev.yaml */

include/uapi/linux/netdev.h

Quoted 13 lines
include/uapi/linux/netdev.h +12 -0
+static void io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *ifq)
+{
+	struct io_zcrx_area *area = ifq->area;
+
+	spin_lock_bh(&area->freelist_lock);
+	while (area->free_count && pp->alloc.count < PP_ALLOC_CACHE_REFILL) {
+		struct net_iov *niov = __io_zcrx_get_free_niov(area);
+		netmem_ref netmem = net_iov_to_netmem(niov);
+
+		page_pool_set_pp_info(pp, netmem);
+		page_pool_mp_return_in_cache(pp, netmem);
 
+		pp->pages_state_hold_cnt++;

But the kdoc on page_pool_mp_return_in_cache() says:

+ * Return already allocated and accounted netmem to the page pool's allocation

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

include/uapi/linux/netdev.h

Quoted 6 lines
include/uapi/linux/netdev.h +5 -0
+		trace_page_pool_state_hold(pp, netmem, pp->pages_state_hold_cnt);
+	}
+	spin_unlock_bh(&area->freelist_lock);
+}
 
+	if (page_pool_unref_netmem(netmem, 1) == 0)

page_pool_unref_and_test()

Quoted 3 lines
include/uapi/linux/netdev.h +2 -0
+		io_zcrx_return_niov_freelist(netmem_to_net_iov(netmem));
+	return false;
 }
maintainer
#41 lore raw

Re: [PATCH net-next v9 14/20] io_uring/zcrx: dma-map area for the device

Quoted 10 lines · Jakub Kicinski

include/uapi/linux/netdev.h

Quoted 4 lines · On Tue, 17 Dec 2024 16:37:40 -0800 David Wei wrote:
include/uapi/linux/netdev.h +0 -0
index e4be227d3ad6..13d810a28ed6 100644

The top of this file says:

/* Do not edit directly, auto-generated from: */
/* Documentation/netlink/specs/netdev.yaml */

Ok

Quoted 12 lines
Quoted 12 lines
include/uapi/linux/netdev.h +11 -0
+static void io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *ifq)
+{
+	struct io_zcrx_area *area = ifq->area;
+
+	spin_lock_bh(&area->freelist_lock);
+	while (area->free_count && pp->alloc.count < PP_ALLOC_CACHE_REFILL) {
+		struct net_iov *niov = __io_zcrx_get_free_niov(area);
+		netmem_ref netmem = net_iov_to_netmem(niov);
+
+		page_pool_set_pp_info(pp, netmem);
+		page_pool_mp_return_in_cache(pp, netmem);
Quoted 6 lines

include/uapi/linux/netdev.h

Quoted 1 line
include/uapi/linux/netdev.h +1 -0
+		pp->pages_state_hold_cnt++;

But the kdoc on page_pool_mp_return_in_cache() says:

+ * Return already allocated and accounted netmem to the page pool's allocation

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Ok, I'll reword it

Quoted 9 lines

include/uapi/linux/netdev.h

Quoted 7 lines
include/uapi/linux/netdev.h +5 -0
+		trace_page_pool_state_hold(pp, netmem, pp->pages_state_hold_cnt);
+	}
+	spin_unlock_bh(&area->freelist_lock);
+}
 
+	if (page_pool_unref_netmem(netmem, 1) == 0)

page_pool_unref_and_test()

That would make the series to depend on net-next, which would make merging with io_uring trickier. I actually used page_pool_is_last_ref() for a brief moment until it got renamed.

Signature · 1 line
Pavel Begunkov
#42 lore raw

Re: [PATCH net-next v9 14/20] io_uring/zcrx: dma-map area for the device

In reply to David Wei
Quoted 296 lines · David Wei

From: Pavel Begunkov <[email protected]>

Setup DMA mappings for the area into which we intend to receive data later on. We know the device we want to attach to even before we get a page pool and can pre-map in advance. All net_iov are synchronised for device when allocated, see page_pool_mp_return_in_cache().

---
 include/uapi/linux/netdev.h |   1 +
 io_uring/zcrx.c             | 320 ++++++++++++++++++++++++++++++++++++
 io_uring/zcrx.h             |   4 +
 3 files changed, 325 insertions(+)
include/uapi/linux/netdev.h +1 -0
index e4be227d3ad6..13d810a28ed6 100644
@@ -94,6 +94,7 @@ enum {
        NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
        NETDEV_A_PAGE_POOL_DETACH_TIME,
        NETDEV_A_PAGE_POOL_DMABUF,
+       NETDEV_A_PAGE_POOL_IO_URING,
 
        __NETDEV_A_PAGE_POOL_MAX,
        NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1)
io_uring/zcrx.c +206 -0
index e6cca6747148..42098bc1a60f 100644
@@ -1,11 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/kernel.h>
 #include <linux/errno.h>
+#include <linux/dma-map-ops.h>
 #include <linux/mm.h>
+#include <linux/nospec.h>
 #include <linux/io_uring.h>
 #include <linux/netdevice.h>
 #include <linux/rtnetlink.h>
 
+#include <net/page_pool/helpers.h>
+#include <net/netlink.h>
+
+#include <trace/events/page_pool.h>
+
 #include <uapi/linux/io_uring.h>
 
 #include "io_uring.h"
@@ -14,8 +21,92 @@
 #include "zcrx.h"
 #include "rsrc.h"
 
+#define IO_DMA_ATTR (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
+
+static void __io_zcrx_unmap_area(struct io_zcrx_ifq *ifq,
+                                struct io_zcrx_area *area, int nr_mapped)
+{
+       struct device *dev = ifq->dev->dev.parent;
+       int i;
+
+       for (i = 0; i < nr_mapped; i++) {
+               struct net_iov *niov = &area->nia.niovs[i];
+               dma_addr_t dma;
+
+               dma = page_pool_get_dma_addr_netmem(net_iov_to_netmem(niov));
+               dma_unmap_page_attrs(dev, dma, PAGE_SIZE, DMA_FROM_DEVICE,
+                                    IO_DMA_ATTR);
+               page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), 0);
+       }
+}
+
+static void io_zcrx_unmap_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
+{
+       if (area->is_mapped)
+               __io_zcrx_unmap_area(ifq, area, area->nia.num_niovs);
+}
+
+static int io_zcrx_map_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
+{
+       struct device *dev = ifq->dev->dev.parent;
+       int i;
+
+       if (!dev)
+               return -EINVAL;
+
+       for (i = 0; i < area->nia.num_niovs; i++) {
+               struct net_iov *niov = &area->nia.niovs[i];
+               dma_addr_t dma;
+
+               dma = dma_map_page_attrs(dev, area->pages[i], 0, PAGE_SIZE,
+                                        DMA_FROM_DEVICE, IO_DMA_ATTR);
+               if (dma_mapping_error(dev, dma))
+                       break;
+               if (page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), dma)) {
+                       dma_unmap_page_attrs(dev, dma, PAGE_SIZE,
+                                            DMA_FROM_DEVICE, IO_DMA_ATTR);
+                       break;
+               }
+       }
+
+       if (i != area->nia.num_niovs) {
+               __io_zcrx_unmap_area(ifq, area, i);
+               return -EINVAL;
+       }
+
+       area->is_mapped = true;
+       return 0;
+}
+
 #define IO_RQ_MAX_ENTRIES              32768
 
+__maybe_unused
+static const struct memory_provider_ops io_uring_pp_zc_ops;
+
+static inline struct io_zcrx_area *io_zcrx_iov_to_area(const struct net_iov *niov)
+{
+       struct net_iov_area *owner = net_iov_owner(niov);
+
+       return container_of(owner, struct io_zcrx_area, nia);
+}
+
+static inline atomic_t *io_get_user_counter(struct net_iov *niov)
+{
+       struct io_zcrx_area *area = io_zcrx_iov_to_area(niov);
+
+       return &area->user_refs[net_iov_idx(niov)];
+}
+
+static bool io_zcrx_put_niov_uref(struct net_iov *niov)
+{
+       atomic_t *uref = io_get_user_counter(niov);
+
+       if (unlikely(!atomic_read(uref)))
+               return false;
+       atomic_dec(uref);
+       return true;
+}
+
 static int io_allocate_rbuf_ring(struct io_zcrx_ifq *ifq,
                                 struct io_uring_zcrx_ifq_reg *reg,
                                 struct io_uring_region_desc *rd)
@@ -49,8 +140,11 @@ static void io_free_rbuf_ring(struct io_zcrx_ifq *ifq)
 
 static void io_zcrx_free_area(struct io_zcrx_area *area)
 {
+       io_zcrx_unmap_area(area->ifq, area);
+
        kvfree(area->freelist);
        kvfree(area->nia.niovs);
+       kvfree(area->user_refs);
        if (area->pages) {
                unpin_user_pages(area->pages, area->nia.num_niovs);
                kvfree(area->pages);
@@ -106,6 +200,19 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
        for (i = 0; i < nr_pages; i++)
                area->freelist[i] = i;
 
+       area->user_refs = kvmalloc_array(nr_pages, sizeof(area->user_refs[0]),
+                                       GFP_KERNEL | __GFP_ZERO);
+       if (!area->user_refs)
+               goto err;
+
+       for (i = 0; i < nr_pages; i++) {
+               struct net_iov *niov = &area->nia.niovs[i];
+
+               niov->owner = &area->nia;
+               area->freelist[i] = i;
+               atomic_set(&area->user_refs[i], 0);
+       }
+
        area->free_count = nr_pages;
        area->ifq = ifq;
        /* we're only supporting one area per ifq for now */
@@ -130,6 +237,7 @@ static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx)
 
        ifq->if_rxq = -1;
        ifq->ctx = ctx;
+       spin_lock_init(&ifq->rq_lock);
        return ifq;
 }
 
@@ -205,6 +313,10 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
        if (!ifq->dev)
                goto err;
 
+       ret = io_zcrx_map_area(ifq, ifq->area);
+       if (ret)
+               goto err;
+
        reg.offsets.rqes = sizeof(struct io_uring);
        reg.offsets.head = offsetof(struct io_uring, head);
        reg.offsets.tail = offsetof(struct io_uring, tail);
@@ -238,7 +350,215 @@ void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx)
        io_zcrx_ifq_free(ifq);
 }
 
+static struct net_iov *__io_zcrx_get_free_niov(struct io_zcrx_area *area)
+{
+       unsigned niov_idx;
+
+       lockdep_assert_held(&area->freelist_lock);
+
+       niov_idx = area->freelist[--area->free_count];
+       return &area->nia.niovs[niov_idx];
+}
+
+static void io_zcrx_return_niov_freelist(struct net_iov *niov)
+{
+       struct io_zcrx_area *area = io_zcrx_iov_to_area(niov);
+
+       spin_lock_bh(&area->freelist_lock);
+       area->freelist[area->free_count++] = net_iov_idx(niov);
+       spin_unlock_bh(&area->freelist_lock);
+}
+
+static void io_zcrx_return_niov(struct net_iov *niov)
+{
+       netmem_ref netmem = net_iov_to_netmem(niov);
+
+       page_pool_put_unrefed_netmem(niov->pp, netmem, -1, false);
+}
+
+static void io_zcrx_scrub(struct io_zcrx_ifq *ifq)
+{
+       struct io_zcrx_area *area = ifq->area;
+       int i;
+
+       if (!area)
+               return;
+
+       /* Reclaim back all buffers given to the user space. */
+       for (i = 0; i < area->nia.num_niovs; i++) {
+               struct net_iov *niov = &area->nia.niovs[i];
+               int nr;
+
+               if (!atomic_read(io_get_user_counter(niov)))
+                       continue;
+               nr = atomic_xchg(io_get_user_counter(niov), 0);
+               if (nr && !page_pool_unref_netmem(net_iov_to_netmem(niov), nr))
+                       io_zcrx_return_niov(niov);
+       }
+}
+
 void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx)
 {
        lockdep_assert_held(&ctx->uring_lock);
+
+       if (ctx->ifq)
+               io_zcrx_scrub(ctx->ifq);
+}
+
+static inline u32 io_zcrx_rqring_entries(struct io_zcrx_ifq *ifq)
+{
+       u32 entries;
+
+       entries = smp_load_acquire(&ifq->rq_ring->tail) - ifq->cached_rq_head;
+       return min(entries, ifq->rq_entries);
+}
+
+static struct io_uring_zcrx_rqe *io_zcrx_get_rqe(struct io_zcrx_ifq *ifq,
+                                                unsigned mask)
+{
+       unsigned int idx = ifq->cached_rq_head++ & mask;
+
+       return &ifq->rqes[idx];
+}
+
+static void io_zcrx_ring_refill(struct page_pool *pp,
+                               struct io_zcrx_ifq *ifq)
+{
+       unsigned int mask = ifq->rq_entries - 1;
+       unsigned int entries;
+       netmem_ref netmem;
+
+       spin_lock_bh(&ifq->rq_lock);
+
+       entries = io_zcrx_rqring_entries(ifq);
+       entries = min_t(unsigned, entries, PP_ALLOC_CACHE_REFILL - pp->alloc.count);
+       if (unlikely(!entries)) {
+               spin_unlock_bh(&ifq->rq_lock);
+               return;
+       }
+
+       do {
+               struct io_uring_zcrx_rqe *rqe = io_zcrx_get_rqe(ifq, mask);
+               struct io_zcrx_area *area;
+               struct net_iov *niov;
+               unsigned niov_idx, area_idx;
+
+               area_idx = rqe->off >> IORING_ZCRX_AREA_SHIFT;
+               niov_idx = (rqe->off & ~IORING_ZCRX_AREA_MASK) >> PAGE_SHIFT;
+
+               if (unlikely(rqe->__pad || area_idx))

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 459

Quoted 10 lines
io_uring/zcrx.c +10 -0
+                       continue;
+               area = ifq->area;
+
+               if (unlikely(niov_idx >= area->nia.num_niovs))
+                       continue;
+               niov_idx = array_index_nospec(niov_idx, area->nia.num_niovs);
+
+               niov = &area->nia.niovs[niov_idx];
+               if (!io_zcrx_put_niov_uref(niov))
+                       continue;

I have a suspicion that uref is now redundant in this series, although I'm not 100% sure. You seem to acquire a uref and pp_ref in tandem in io_zcrx_recv_frag and drop both in tandem in this function, which makes me think the uref maybe is redundant now.

io_zcrx_copy_chunk acquires a uref but not a pp_ref. I wonder if copy_chunk can do a page_pool_ref_netmem() instead of a uref, maybe you would be able to make do without urefs at all. I have not looked at the copy fallback code closely.

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 465

Quoted 6 lines
io_uring/zcrx.c +6 -0
+
+               netmem = net_iov_to_netmem(niov);
+               if (page_pool_unref_netmem(netmem, 1) != 0)
+                       continue;
+
+               if (unlikely(niov->pp != pp)) {

From niov->pp != pp I surmise in this iteration one io_zcrx_area can serve niovs to multiple RX queues?

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 466

Quoted 1 line
io_uring/zcrx.c +1 -0
+                       io_zcrx_return_niov(niov);

The last 5 lines or so is basically doing what page_pool_put_netmem() does, except there is a pp != niov->pp check in the middle. Can we call page_pool_put_netmem() directly if pp != niov->pp? It would just reduce the code duplication a bit and reduce the amount of custom reffing code we need to add for this mp.

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 470

Quoted 4 lines
io_uring/zcrx.c +4 -0
+                       continue;
+               }
+
+               page_pool_mp_return_in_cache(pp, netmem);

So if niov->pp != pp, we end up basically doing a page_pool_put_netmem(), which is the 'correct' way to return a netmem to the page_pool, or at least is the way to return a netmem that all the other devmem/pages memory types uses. However if niov->pp == pp, we end up page_pool_mp_return_in_cache(), which is basically the same as page_pool_put_unrefed_netmem but skips the ptr_ring, so it's slightly faster and less overhead.

I would honestly elect to page_pool_put_netmem() regardless of niov->pp/pp check. Sure it would be a bit more overhead than the code here, but it would reduce the custom pp refing code we need to add for this mp and it will replenish the ptr_ring in both cases, which may be even faster by reducing the number of times we need to replenish. We can always add micro optimizations like skipping the ptr_ring for slightly faster code if there is evidence there is significant perf improvement.

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 481

Quoted 11 lines
io_uring/zcrx.c +11 -0
+       } while (--entries);
+
+       smp_store_release(&ifq->rq_ring->head, ifq->cached_rq_head);
+       spin_unlock_bh(&ifq->rq_lock);
+}
+
+static void io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *ifq)
+{
+       struct io_zcrx_area *area = ifq->area;
+
+       spin_lock_bh(&area->freelist_lock);

I assume if you have 1 area serving many rx queues then you start contending on this lock, no? If you find it so in the future, genpool may help.

Quoted 28 lines
io_uring/zcrx.c +28 -0
+       while (area->free_count && pp->alloc.count < PP_ALLOC_CACHE_REFILL) {
+               struct net_iov *niov = __io_zcrx_get_free_niov(area);
+               netmem_ref netmem = net_iov_to_netmem(niov);
+
+               page_pool_set_pp_info(pp, netmem);
+               page_pool_mp_return_in_cache(pp, netmem);
+
+               pp->pages_state_hold_cnt++;
+               trace_page_pool_state_hold(pp, netmem, pp->pages_state_hold_cnt);
+       }
+       spin_unlock_bh(&area->freelist_lock);
+}
+
+static netmem_ref io_pp_zc_alloc_netmems(struct page_pool *pp, gfp_t gfp)
+{
+       struct io_zcrx_ifq *ifq = pp->mp_priv;
+
+       /* pp should already be ensuring that */
+       if (unlikely(pp->alloc.count))
+               goto out_return;
+
+       io_zcrx_ring_refill(pp, ifq);
+       if (likely(pp->alloc.count))
+               goto out_return;
+
+       io_zcrx_refill_slow(pp, ifq);
+       if (!pp->alloc.count)
+               return 0;

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 519

Quoted 10 lines
io_uring/zcrx.c +10 -0
+out_return:
+       return pp->alloc.cache[--pp->alloc.count];
+}
+
+static bool io_pp_zc_release_netmem(struct page_pool *pp, netmem_ref netmem)
+{
+       if (WARN_ON_ONCE(!netmem_is_net_iov(netmem)))
+               return false;
+
+       if (page_pool_unref_netmem(netmem, 1) == 0)

Check is redundant, AFAICT. pp would never release a netmem unless the pp refcount is 1.

Quoted 69 lines
io_uring/zcrx.c +44 -0
+               io_zcrx_return_niov_freelist(netmem_to_net_iov(netmem));
+       return false;
 }
+
+static int io_pp_zc_init(struct page_pool *pp)
+{
+       struct io_zcrx_ifq *ifq = pp->mp_priv;
+
+       if (WARN_ON_ONCE(!ifq))
+               return -EINVAL;
+       if (WARN_ON_ONCE(ifq->dev != pp->slow.netdev))
+               return -EINVAL;
+       if (pp->dma_map)
+               return -EOPNOTSUPP;
+       if (pp->p.order != 0)
+               return -EOPNOTSUPP;
+       if (pp->p.dma_dir != DMA_FROM_DEVICE)
+               return -EOPNOTSUPP;
+
+       percpu_ref_get(&ifq->ctx->refs);
+       return 0;
+}
+
+static void io_pp_zc_destroy(struct page_pool *pp)
+{
+       struct io_zcrx_ifq *ifq = pp->mp_priv;
+       struct io_zcrx_area *area = ifq->area;
+
+       if (WARN_ON_ONCE(area->free_count != area->nia.num_niovs))
+               return;
+       percpu_ref_put(&ifq->ctx->refs);
+}
+
+static int io_pp_nl_report(const struct page_pool *pool, struct sk_buff *rsp)
+{
+       return nla_put_u32(rsp, NETDEV_A_PAGE_POOL_IO_URING, 0);
+}
+
+static const struct memory_provider_ops io_uring_pp_zc_ops = {
+       .alloc_netmems          = io_pp_zc_alloc_netmems,
+       .release_netmem         = io_pp_zc_release_netmem,
+       .init                   = io_pp_zc_init,
+       .destroy                = io_pp_zc_destroy,
+       .nl_report              = io_pp_nl_report,
+};
io_uring/zcrx.h +4 -1
index 46988a1dbd54..beacf1ea6380 100644
@@ -9,7 +9,9 @@
 struct io_zcrx_area {
        struct net_iov_area     nia;
        struct io_zcrx_ifq      *ifq;
+       atomic_t                *user_refs;
 
+       bool                    is_mapped;
        u16                     area_id;
        struct page             **pages;
 
@@ -26,6 +28,8 @@ struct io_zcrx_ifq {
        struct io_uring                 *rq_ring;
        struct io_uring_zcrx_rqe        *rqes;
        u32                             rq_entries;
+       u32                             cached_rq_head;
+       spinlock_t                      rq_lock;
 
        u32                             if_rxq;
        struct net_device               *dev;
--
Quoted 2 lines

2.43.5

--
Thanks,
Mina

maintainer
#43 lore raw

Re: [PATCH net-next v9 14/20] io_uring/zcrx: dma-map area for the device

Quoted 1 line · Mina Almasry

On Tue, Dec 17, 2024 at 4:38 PM David Wei <[email protected]> wrote:

...

Quoted 10 lines

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 459

Quoted 8 lines
io_uring/zcrx.c +8 -0
+
+               if (unlikely(niov_idx >= area->nia.num_niovs))
+                       continue;
+               niov_idx = array_index_nospec(niov_idx, area->nia.num_niovs);
+
+               niov = &area->nia.niovs[niov_idx];
+               if (!io_zcrx_put_niov_uref(niov))
+                       continue;

I have a suspicion that uref is now redundant in this series, although

It's not. You can't lose track of buffers given to the user. It plays a similar role to devmem's ->sk_user_frags, think what happens if you don't have it and don't track buffers in any other way.

Quoted 6 lines

I'm not 100% sure. You seem to acquire a uref and pp_ref in tandem in io_zcrx_recv_frag and drop both in tandem in this function, which makes me think the uref maybe is redundant now.

io_zcrx_copy_chunk acquires a uref but not a pp_ref. I wonder if copy_chunk can do a page_pool_ref_netmem() instead of a uref, maybe

It takes both references.

Quoted 2 lines

you would be able to make do without urefs at all. I have not looked at the copy fallback code closely.

If we're talking about optimisations, there is a way I described and going to pursue, but that's not for the initial set.

Quoted 9 lines

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 465

Quoted 6 lines
io_uring/zcrx.c +6 -0
+
+               netmem = net_iov_to_netmem(niov);
+               if (page_pool_unref_netmem(netmem, 1) != 0)
+                       continue;
+
+               if (unlikely(niov->pp != pp)) {

From niov->pp != pp I surmise in this iteration one io_zcrx_area can
serve niovs to multiple RX queues?

It should, but the main goal was rather to support multiple pools per queue because of queue api shortcomings, even if it almost never happens.

Quoted 5 lines

The last 5 lines or so is basically doing what page_pool_put_netmem() does, except there is a pp != niov->pp check in the middle. Can we call page_pool_put_netmem() directly if pp != niov->pp? It would just reduce the code duplication a bit and reduce the amount of custom reffing code we need to add for this mp.

Right, that sub path is basically page_pool_put_netmem(). Can be replaced, but it's not going to de-duplicate code as the path is shared with page_pool_mp_return_in_cache(). And it'd likely bloat the binary a bit, though it's not that important.

Quoted 5 lines

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 470

Quoted 4 lines
io_uring/zcrx.c +4 -0
+                       continue;
+               }
+
+               page_pool_mp_return_in_cache(pp, netmem);
Quoted 7 lines

So if niov->pp != pp, we end up basically doing a page_pool_put_netmem(), which is the 'correct' way to return a netmem to the page_pool, or at least is the way to return a netmem that all the other devmem/pages memory types uses. However if niov->pp == pp, we end up page_pool_mp_return_in_cache(), which is basically the same as page_pool_put_unrefed_netmem but skips the ptr_ring, so it's slightly faster and less overhead.

Jumping through the loops is surely not great, but there are bigger semantical reasons. page_pool_put_netmem() has always been called by users from the outside, this one is off the page pool allocation path. For example, it'd nest io_uring with ptr_ring, which is not a bug and not so bad, but that's something you'd need to always consider while patching generic page pool. On top with the ptr_ring path in there, either providers would need to make implicit assumptions that it'd never happen, which is shabby, or the code should be prepared to that. I'd say it should be more convenient to have a separate and simple for all that.

We can play with the API more, hopefully after it's merged, but just replacing it with page_pool_put_netmem() would do a disservice.

Quoted 15 lines

I would honestly elect to page_pool_put_netmem() regardless of niov->pp/pp check. Sure it would be a bit more overhead than the code here, but it would reduce the custom pp refing code we need to add for this mp and it will replenish the ptr_ring in both cases, which may be even faster by reducing the number of times we need to replenish. We can always add micro optimizations like skipping the ptr_ring for slightly faster code if there is evidence there is significant perf improvement.

Quoted 6 lines
io_uring/zcrx.c +6 -0
+       } while (--entries);
+
+       smp_store_release(&ifq->rq_ring->head, ifq->cached_rq_head);
+       spin_unlock_bh(&ifq->rq_lock);
+}
+

...

Quoted 9 lines

io_uring/zcrx.c void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) · line 519

Quoted 6 lines
io_uring/zcrx.c +6 -0
+static bool io_pp_zc_release_netmem(struct page_pool *pp, netmem_ref netmem)
+{
+       if (WARN_ON_ONCE(!netmem_is_net_iov(netmem)))
+               return false;
+
+       if (page_pool_unref_netmem(netmem, 1) == 0)

Check is redundant, AFAICT. pp would never release a netmem unless the pp refcount is 1.

Good catch, it was applied to v10

Signature · 1 line
Pavel Begunkov
author
#44 lore raw

PATCH v9 15/20 io_uring/zcrx: add io_recvzc request

In reply to David Wei

Add io_uring opcode OP_RECV_ZC for doing zero copy reads out of a socket. Only the connection should be land on the specific rx queue set up for zero copy, and the socket must be handled by the io_uring instance that the rx queue was registered for zero copy with. That's because neither net_iovs / buffers from our queue can be read by outside applications, nor zero copy is possible if traffic for the zero copy connection goes to another queue. This coordination is outside of the scope of this patch series. Also, any traffic directed to the zero copy enabled queue is immediately visible to the application, which is why CAP_NET_ADMIN is required at the registration step.

Of course, no data is actually read out of the socket, it has already been copied by the netdev into userspace memory via DMA. OP_RECV_ZC reads skbs out of the socket and checks that its frags are indeed net_iovs that belong to io_uring. A cqe is queued for each one of these frags.

Recall that each cqe is a big cqe, with the top half being an io_uring_zcrx_cqe. The cqe res field contains the len or error. The lower IORING_ZCRX_AREA_SHIFT bits of the struct io_uring_zcrx_cqe::off field contain the offset relative to the start of the zero copy area. The upper part of the off field is trivially zero, and will be used to carry the area id.

For now, there is no limit as to how much work each OP_RECV_ZC request does. It will attempt to drain a socket of all available data. This request always operates in multishot mode.

---
 include/uapi/linux/io_uring.h |   2 +
 io_uring/io_uring.h           |  10 ++
 io_uring/net.c                |  72 +++++++++++++
 io_uring/opdef.c              |  16 +++
 io_uring/zcrx.c               | 190 +++++++++++++++++++++++++++++++++-
 io_uring/zcrx.h               |  13 +++
 6 files changed, 302 insertions(+), 1 deletion(-)
include/uapi/linux/io_uring.h +2 -0
index e251f28507ce..b919a541d44f 100644
@@ -87,6 +87,7 @@ struct io_uring_sqe {
 	union {
 		__s32	splice_fd_in;
 		__u32	file_index;
+		__u32	zcrx_ifq_idx;
 		__u32	optlen;
 		struct {
 			__u16	addr_len;
@@ -278,6 +279,7 @@ enum io_uring_op {
 	IORING_OP_FTRUNCATE,
 	IORING_OP_BIND,
 	IORING_OP_LISTEN,
+	IORING_OP_RECV_ZC,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
io_uring/io_uring.h +10 -0
index 032758b28d78..2b1ce5539bfe 100644
@@ -184,6 +184,16 @@ static inline bool io_get_cqe(struct io_ring_ctx *ctx, struct io_uring_cqe **ret
 	return io_get_cqe_overflow(ctx, ret, false);
 }
 
+static inline bool io_defer_get_uncommited_cqe(struct io_ring_ctx *ctx,
+					       struct io_uring_cqe **cqe_ret)
+{
+	io_lockdep_assert_cq_locked(ctx);
+
+	ctx->cq_extra++;
+	ctx->submit_state.cq_flush = true;
+	return io_get_cqe(ctx, cqe_ret);
+}
+
 static __always_inline bool io_fill_cqe_req(struct io_ring_ctx *ctx,
 					    struct io_kiocb *req)
 {
io_uring/net.c +72 -0

90 lines not on this page · raw message

io_uring/opdef.c +16 -0
index 3de75eca1c92..6ae00c0af9a8 100644
@@ -36,6 +36,7 @@
 #include "waitid.h"
 #include "futex.h"
 #include "truncate.h"
+#include "zcrx.h"
 
 static int io_no_issue(struct io_kiocb *req, unsigned int issue_flags)
 {
@@ -513,6 +514,18 @@ const struct io_issue_def io_issue_defs[] = {
 		.async_size		= sizeof(struct io_async_msghdr),
 #else
 		.prep			= io_eopnotsupp_prep,
+#endif
+	},
+	[IORING_OP_RECV_ZC] = {
+		.needs_file		= 1,
+		.unbound_nonreg_file	= 1,
+		.pollin			= 1,
+		.ioprio			= 1,
+#if defined(CONFIG_NET)
+		.prep			= io_recvzc_prep,
+		.issue			= io_recvzc,
+#else
+		.prep			= io_eopnotsupp_prep,
 #endif
 	},
 };
@@ -744,6 +757,9 @@ const struct io_cold_def io_cold_defs[] = {
 	[IORING_OP_LISTEN] = {
 		.name			= "LISTEN",
 	},
+	[IORING_OP_RECV_ZC] = {
+		.name			= "RECV_ZC",
+	},
 };
 
 const char *io_uring_get_opcode(u8 opcode)
io_uring/zcrx.c +189 -1

211 lines not on this page · raw message

io_uring/zcrx.h +13 -0
index beacf1ea6380..65e92756720f 100644
@@ -3,6 +3,7 @@
 #define IOU_ZC_RX_H
 
 #include <linux/io_uring_types.h>
+#include <linux/socket.h>
 #include <net/page_pool/types.h>
 #include <net/net_trackers.h>
 
@@ -41,6 +42,9 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
 			 struct io_uring_zcrx_ifq_reg __user *arg);
 void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx);
 void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx);
+int io_zcrx_recv(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
+		 struct socket *sock, unsigned int flags,
+		 unsigned issue_flags);
 #else
 static inline int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
 					struct io_uring_zcrx_ifq_reg __user *arg)
@@ -53,6 +57,15 @@ static inline void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx)
 static inline void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx)
 {
 }
+static inline int io_zcrx_recv(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
+			       struct socket *sock, unsigned int flags,
+			       unsigned issue_flags)
+{
+	return -EOPNOTSUPP;
+}
 #endif
 
+int io_recvzc(struct io_kiocb *req, unsigned int issue_flags);
+int io_recvzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
+
 #endif
Signature · 1 line
2.43.5
author
#45 lore raw

PATCH v9 16/20 io_uring/zcrx: set pp memory provider for an rx queue

In reply to David Wei

Set the page pool memory provider for the rx queue configured for zero copy to io_uring. Then the rx queue is reset using netdev_rx_queue_restart() and netdev core + page pool will take care of filling the rx queue from the io_uring zero copy memory provider.

For now, there is only one ifq so its destruction happens implicitly during io_uring cleanup.

---
 io_uring/zcrx.c | 83 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 75 insertions(+), 8 deletions(-)
io_uring/zcrx.c +75 -8
index 1122c80502d6..756c78c0920e 100644
@@ -10,11 +10,12 @@
 
 #include <net/page_pool/helpers.h>
 #include <net/netlink.h>
-
-#include <trace/events/page_pool.h>
+#include <net/netdev_rx_queue.h>
 #include <net/tcp.h>
 #include <net/rps.h>
 
+#include <trace/events/page_pool.h>
+
 #include <uapi/linux/io_uring.h>
 
 #include "io_uring.h"
@@ -119,6 +120,65 @@ static void io_zcrx_get_niov_uref(struct net_iov *niov)
 	atomic_inc(io_get_user_counter(niov));
 }
 
+static int io_open_zc_rxq(struct io_zcrx_ifq *ifq, unsigned ifq_idx)
+{
+	struct netdev_rx_queue *rxq;
+	struct net_device *dev = ifq->dev;
+	int ret;
+
+	ASSERT_RTNL();
+
+	if (ifq_idx >= dev->num_rx_queues)
+		return -EINVAL;
+	ifq_idx = array_index_nospec(ifq_idx, dev->num_rx_queues);
+
+	rxq = __netif_get_rx_queue(ifq->dev, ifq_idx);
+	if (rxq->mp_params.mp_priv)
+		return -EEXIST;
+
+	ifq->if_rxq = ifq_idx;
+	rxq->mp_params.mp_ops = &io_uring_pp_zc_ops;
+	rxq->mp_params.mp_priv = ifq;
+	ret = netdev_rx_queue_restart(ifq->dev, ifq->if_rxq);
+	if (ret)
+		goto fail;
+	return 0;
+fail:
+	rxq->mp_params.mp_ops = NULL;
+	rxq->mp_params.mp_priv = NULL;
+	ifq->if_rxq = -1;
+	return ret;
+}
+
+static void io_close_zc_rxq(struct io_zcrx_ifq *ifq)
+{
+	struct netdev_rx_queue *rxq;
+	int err;
+
+	if (ifq->if_rxq == -1)
+		return;
+
+	rtnl_lock();
+	if (WARN_ON_ONCE(ifq->if_rxq >= ifq->dev->num_rx_queues)) {
+		rtnl_unlock();
+		return;
+	}
+
+	rxq = __netif_get_rx_queue(ifq->dev, ifq->if_rxq);
+
+	WARN_ON_ONCE(rxq->mp_params.mp_priv != ifq);
+
+	rxq->mp_params.mp_ops = NULL;
+	rxq->mp_params.mp_priv = NULL;
+
+	err = netdev_rx_queue_restart(ifq->dev, ifq->if_rxq);
+	if (err)
+		pr_devel("io_uring: can't restart a queue on zcrx close\n");
+
+	rtnl_unlock();
+	ifq->if_rxq = -1;
+}
+
 static int io_allocate_rbuf_ring(struct io_zcrx_ifq *ifq,
 				 struct io_uring_zcrx_ifq_reg *reg,
 				 struct io_uring_region_desc *rd)
@@ -255,6 +315,8 @@ static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx)
 
 static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq)
 {
+	io_close_zc_rxq(ifq);
+
 	if (ifq->area)
 		io_zcrx_free_area(ifq->area);
 
@@ -317,7 +379,6 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
 		goto err;
 
 	ifq->rq_entries = reg.rq_entries;
-	ifq->if_rxq = reg.if_rxq;
 
 	ret = -ENODEV;
 	ifq->dev = netdev_get_by_index(current->nsproxy->net_ns, reg.if_idx,
@@ -329,16 +390,20 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
 	if (ret)
 		goto err;
 
+	rtnl_lock();
+	ret = io_open_zc_rxq(ifq, reg.if_rxq);
+	rtnl_unlock();
+	if (ret)
+		goto err;
+
 	reg.offsets.rqes = sizeof(struct io_uring);
 	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;
-	}
-	if (copy_to_user(u64_to_user_ptr(reg.area_ptr), &area, sizeof(area))) {
+	    copy_to_user(u64_to_user_ptr(reg.region_ptr), &rd, sizeof(rd)) ||
+	    copy_to_user(u64_to_user_ptr(reg.area_ptr), &area, sizeof(area))) {
+		io_close_zc_rxq(ifq);
 		ret = -EFAULT;
 		goto err;
 	}
@@ -415,6 +480,8 @@ void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx)
 
 	if (ctx->ifq)
 		io_zcrx_scrub(ctx->ifq);
+
+	io_close_zc_rxq(ctx->ifq);
 }
 
 static inline u32 io_zcrx_rqring_entries(struct io_zcrx_ifq *ifq)
Signature · 1 line
2.43.5
author
#46 lore raw

PATCH v9 17/20 io_uring/zcrx: throttle receive requests

In reply to David Wei

From: Pavel Begunkov <[email protected]>

io_zc_rx_tcp_recvmsg() continues until it fails or there is nothing to receive. If the other side sends fast enough, we might get stuck in io_zc_rx_tcp_recvmsg() producing more and more CQEs but not letting the user to handle them leading to unbound latencies.

Break out of it based on an arbitrarily chosen limit, the upper layer will either return to userspace or requeue the request.

---
 io_uring/net.c  | 2 ++
 io_uring/zcrx.c | 9 +++++++++
 2 files changed, 11 insertions(+)
io_uring/net.c +2 -0
index 5d8b9a016766..86eaba37e739 100644
@@ -1267,6 +1267,8 @@ int io_recvzc(struct io_kiocb *req, unsigned int issue_flags)
 	if (unlikely(ret <= 0) && ret != -EAGAIN) {
 		if (ret == -ERESTARTSYS)
 			ret = -EINTR;
+		if (ret == IOU_REQUEUE)
+			return IOU_REQUEUE;
 
 		req_set_fail(req);
 		io_req_set_res(req, ret, 0);
io_uring/zcrx.c +9 -0
index 756c78c0920e..ffa388fbb1e4 100644
@@ -83,10 +83,13 @@ static int io_zcrx_map_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
 
 #define IO_RQ_MAX_ENTRIES		32768
 
+#define IO_SKBS_PER_CALL_LIMIT	20
+
 struct io_zcrx_args {
 	struct io_kiocb		*req;
 	struct io_zcrx_ifq	*ifq;
 	struct socket		*sock;
+	unsigned		nr_skbs;
 };
 
 static const struct memory_provider_ops io_uring_pp_zc_ops;
@@ -702,6 +705,9 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
 	int i, copy, end, off;
 	int ret = 0;
 
+	if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT))
+		return -EAGAIN;
+
 	start = skb_headlen(skb);
 	start_off = offset;
 
@@ -792,6 +798,9 @@ static int io_zcrx_tcp_recvmsg(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
 			ret = -ENOTCONN;
 		else
 			ret = -EAGAIN;
+	} else if (unlikely(args.nr_skbs > IO_SKBS_PER_CALL_LIMIT) &&
+		   (issue_flags & IO_URING_F_MULTISHOT)) {
+		ret = IOU_REQUEUE;
 	} else if (sock_flag(sk, SOCK_DONE)) {
 		/* Make it to retry until it finally gets 0. */
 		if (issue_flags & IO_URING_F_MULTISHOT)
Signature · 1 line
2.43.5
author
#47 lore raw

PATCH v9 18/20 io_uring/zcrx: add copy fallback

In reply to David Wei

From: Pavel Begunkov <[email protected]>

There are scenarios in which the zerocopy path can get a kernel buffer instead of a net_iov and needs to copy it to the user, whether it is because of mis-steering or simply getting an skb with the linear part. In this case, grab a net_iov, copy into it and return it to the user as normally.

At the moment the user doesn't get any indication whether there was a copy or not, which is left for follow up work.

---
 io_uring/zcrx.c | 123 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 117 insertions(+), 6 deletions(-)
io_uring/zcrx.c +117 -6
index ffa388fbb1e4..92b4d91f97f7 100644
@@ -7,6 +7,7 @@
 #include <linux/io_uring.h>
 #include <linux/netdevice.h>
 #include <linux/rtnetlink.h>
+#include <linux/skbuff_ref.h>
 
 #include <net/page_pool/helpers.h>
 #include <net/netlink.h>
@@ -123,6 +124,13 @@ static void io_zcrx_get_niov_uref(struct net_iov *niov)
 	atomic_inc(io_get_user_counter(niov));
 }
 
+static inline struct page *io_zcrx_iov_page(const struct net_iov *niov)
+{
+	struct io_zcrx_area *area = io_zcrx_iov_to_area(niov);
+
+	return area->pages[net_iov_idx(niov)];
+}
+
 static int io_open_zc_rxq(struct io_zcrx_ifq *ifq, unsigned ifq_idx)
 {
 	struct netdev_rx_queue *rxq;
@@ -145,6 +153,7 @@ static int io_open_zc_rxq(struct io_zcrx_ifq *ifq, unsigned ifq_idx)
 	ret = netdev_rx_queue_restart(ifq->dev, ifq->if_rxq);
 	if (ret)
 		goto fail;
+
 	return 0;
 fail:
 	rxq->mp_params.mp_ops = NULL;
@@ -453,6 +462,11 @@ static void io_zcrx_return_niov(struct net_iov *niov)
 {
 	netmem_ref netmem = net_iov_to_netmem(niov);
 
+	if (!niov->pp) {
+		/* copy fallback allocated niovs */
+		io_zcrx_return_niov_freelist(niov);
+		return;
+	}
 	page_pool_put_unrefed_netmem(niov->pp, netmem, -1, false);
 }
 
@@ -668,13 +682,95 @@ static bool io_zcrx_queue_cqe(struct io_kiocb *req, struct net_iov *niov,
 	return true;
 }
 
+static struct net_iov *io_zcrx_alloc_fallback(struct io_zcrx_area *area)
+{
+	struct net_iov *niov = NULL;
+
+	spin_lock_bh(&area->freelist_lock);
+	if (area->free_count)
+		niov = __io_zcrx_get_free_niov(area);
+	spin_unlock_bh(&area->freelist_lock);
+
+	if (niov) {
+		page_pool_fragment_netmem(net_iov_to_netmem(niov), 1);
+		page_pool_clear_pp_info(net_iov_to_netmem(niov));
+	}
+	return niov;
+}
+
+static ssize_t io_zcrx_copy_chunk(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
+				  void *src_base, struct page *src_page,
+				  unsigned int src_offset, size_t len)
+{
+	struct io_zcrx_area *area = ifq->area;
+	size_t copied = 0;
+	int ret = 0;
+
+	while (len) {
+		size_t copy_size = min_t(size_t, PAGE_SIZE, len);
+		const int dst_off = 0;
+		struct net_iov *niov;
+		struct page *dst_page;
+		void *dst_addr;
+
+		niov = io_zcrx_alloc_fallback(area);
+		if (!niov) {
+			ret = -ENOMEM;
+			break;
+		}
+
+		dst_page = io_zcrx_iov_page(niov);
+		dst_addr = kmap_local_page(dst_page);
+		if (src_page)
+			src_base = kmap_local_page(src_page);
+
+		memcpy(dst_addr, src_base + src_offset, copy_size);
+
+		if (src_page)
+			kunmap_local(src_base);
+		kunmap_local(dst_addr);
+
+		if (!io_zcrx_queue_cqe(req, niov, ifq, dst_off, copy_size)) {
+			io_zcrx_return_niov(niov);
+			ret = -ENOSPC;
+			break;
+		}
+
+		io_zcrx_get_niov_uref(niov);
+		src_offset += copy_size;
+		len -= copy_size;
+		copied += copy_size;
+	}
+
+	return copied ? copied : ret;
+}
+
+static int io_zcrx_copy_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
+			     const skb_frag_t *frag, int off, int len)
+{
+	struct page *page = skb_frag_page(frag);
+	u32 p_off, p_len, t, copied = 0;
+	int ret = 0;
+
+	off += skb_frag_off(frag);
+
+	skb_frag_foreach_page(frag, off, len,
+			      page, p_off, p_len, t) {
+		ret = io_zcrx_copy_chunk(req, ifq, NULL, page, p_off, p_len);
+		if (ret < 0)
+			return copied ? copied : ret;
+		copied += ret;
+	}
+	return copied;
+}
+
 static int io_zcrx_recv_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
 			     const skb_frag_t *frag, int off, int len)
 {
 	struct net_iov *niov;
 
 	if (unlikely(!skb_frag_is_net_iov(frag)))
-		return -EOPNOTSUPP;
+		return io_zcrx_copy_frag(req, ifq, frag, off, len);
 
 	niov = netmem_to_net_iov(frag->netmem);
 	if (niov->pp->mp_ops != &io_uring_pp_zc_ops ||
@@ -701,18 +797,33 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
 	struct io_zcrx_ifq *ifq = args->ifq;
 	struct io_kiocb *req = args->req;
 	struct sk_buff *frag_iter;
-	unsigned start, start_off;
+	unsigned start, start_off = offset;
 	int i, copy, end, off;
 	int ret = 0;
 
 	if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT))
 		return -EAGAIN;
 
-	start = skb_headlen(skb);
-	start_off = offset;
+	if (unlikely(offset < skb_headlen(skb))) {
+		ssize_t copied;
+		size_t to_copy;
 
-	if (offset < start)
-		return -EOPNOTSUPP;
+		to_copy = min_t(size_t, skb_headlen(skb) - offset, len);
+		copied = io_zcrx_copy_chunk(req, ifq, skb->data, NULL,
+					    offset, to_copy);
+		if (copied < 0) {
+			ret = copied;
+			goto out;
+		}
+		offset += copied;
+		len -= copied;
+		if (!len)
+			goto out;
+		if (offset != skb_headlen(skb))
+			goto out;
+	}
+
+	start = skb_headlen(skb);
 
 	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
 		const skb_frag_t *frag;
Signature · 1 line
2.43.5
author
#48 lore raw

PATCH v9 19/20 net: add documentation for io_uring zcrx

In reply to David Wei

Add documentation for io_uring zero copy Rx that explains requirements and the user API.

---
 Documentation/networking/index.rst    |   1 +
 Documentation/networking/iou-zcrx.rst | 201 ++++++++++++++++++++++++++
 2 files changed, 202 insertions(+)
 create mode 100644 Documentation/networking/iou-zcrx.rst
Documentation/networking/index.rst +1 -0
index 46c178e564b3..d6ce9c5f179c 100644
@@ -63,6 +63,7 @@ Contents:
    gtp
    ila
    ioam6-sysctl
+   iou-zcrx
    ip_dynaddr
    ipsec
    ip-sysctl
Documentation/networking/iou-zcrx.rst new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
2.43.5
author
#49 lore raw

PATCH v9 20/20 io_uring/zcrx: add selftest

In reply to David Wei

Add a selftest for io_uring zero copy Rx. This test cannot run locally and requires a remote host to be configured in net.config. The remote host must have hardware support for zero copy Rx as listed in the documentation page. The test will restore the NIC config back to before the test and is idempotent.

liburing is required to compile the test and be installed on the remote host running the test.

---
 .../selftests/drivers/net/hw/.gitignore       |   2 +
 .../testing/selftests/drivers/net/hw/Makefile |   6 +
 .../selftests/drivers/net/hw/iou-zcrx.c       | 432 ++++++++++++++++++
 .../selftests/drivers/net/hw/iou-zcrx.py      |  64 +++
 4 files changed, 504 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/net/hw/iou-zcrx.c
 create mode 100755 tools/testing/selftests/drivers/net/hw/iou-zcrx.py
tools/testing/selftests/drivers/net/hw/.gitignore +2 -0
index e9fe6ede681a..6942bf575497 100644
@@ -1 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+iou-zcrx
 ncdevmem
tools/testing/selftests/drivers/net/hw/Makefile +6 -0
index 21ba64ce1e34..5431af8e8210 100644
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0+ OR MIT
 
+TEST_GEN_FILES = iou-zcrx
+
 TEST_PROGS = \
 	csum.py \
 	devlink_port_split.py \
@@ -10,6 +12,7 @@ TEST_PROGS = \
 	ethtool_rmon.sh \
 	hw_stats_l3.sh \
 	hw_stats_l3_gre.sh \
+	iou-zcrx.py \
 	loopback.sh \
 	nic_link_layer.py \
 	nic_performance.py \
@@ -38,3 +41,6 @@ include ../../../lib.mk
 # YNL build
 YNL_GENS := ethtool netdev
 include ../../../net/ynl.mk
+
+$(OUTPUT)/iou-zcrx: CFLAGS += -I/usr/include/
+$(OUTPUT)/iou-zcrx: LDLIBS += -luring
tools/testing/selftests/drivers/net/hw/iou-zcrx.c new file +432 -0

432 lines not on this page · raw message

tools/testing/selftests/drivers/net/hw/iou-zcrx.py new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.43.5