Skip to contentSkip to conversation

devmem/io_uring: allow more flexibility for ZC DMA devices

PATCH Superseded Dragos Tatulea 3 participants 20 messages Aug 20, 2025 – Aug 21, 2025

Subsystems (7)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover devmem/io_uring: allow more flexibility for ZC DMA devices

For TCP zerocopy rx (io_uring, devmem), there is an assumption that the parent device can do DMA. However that is not always the case:
- Scalable Function netdevs [1] have the DMA device in the grandparent.
- For Multi-PF netdevs [2] queues can be associated to different DMA devices.

The series adds an API for getting the DMA device for a netdev queue. Drivers that have special requirements can implement the newly added queue management op. Otherwise the parent will still be used as before.

This series continues with switching to this API for io_uring zcrx and devmem and adds a ndo_queue_dma_dev op for mlx5.

The last part of the series changes devmem rx bind to get the DMA device per queue and blocks the case when multiple queues use different DMA devices. The tx bind is left as is.

[1] Documentation/networking/device_drivers/ethernet/mellanox/mlx5/switchdev.rst
[2] Documentation/networking/multi-pf-netdev.rst

----
Changes sice v3 [4]:
- Moved ndo_queue_get_dma_dev() from header to own file (patch 1).
- Used real_num_rx_queues for queue bitmap (patch 6).
- Allocate zeroed bitmap (patch 6).
- Validate queue index (patch 6).
- Forward errors from netdev_nl_read_rxq_bitmap() (patch 6).
- Dropped rxq_dma_dev check (patch 7).
- Fixed incorrect handling of extack message on bad dma dev (patch 7).
- Added conflicting queues in error message (patch 7).
- Dropped RFC status as feedback was mostly positive.

Changes sice v2 [3]:
- Downgraded to RFC status until consensus is reached.
- Implemented more generic approach as discussed during v2 review.
- Refactor devmem to get DMA device for multiple rx queues for multi PF netdev support.
- Renamed series with a more generic name.

Changes since v1 [2]:
- Dropped the Fixes tag.
- Added more documentation as requeseted.
- Renamed the patch title to better reflect its purpose.

Changes since RFC [1]:
- Upgraded from RFC status.
- Dropped driver specific bits for generic solution.
- Implemented single patch as a fix as requested in RFC.
- Handling of multi-PF netdevs will be handled in a subsequent patch series.

[1] RFC: https://lore.kernel.org/all/[email protected]/

[2]  v1: https://lore.kernel.org/all/[email protected]/
[3]  v2: https://lore.kernel.org/all/[email protected]/
[4]  v3: https://lore.kernel.org/all/[email protected]/#t

---

Dragos Tatulea (7):
queue_api: add support for fetching per queue DMA dev io_uring/zcrx: add support for custom DMA devices
net: devmem: get netdev DMA device via new API net/mlx5e: add op for getting netdev DMA device
net: devmem: pull out dma_dev out of net_devmem_bind_dmabuf
net: devmem: pre-read requested rx queues during bind
net: devmem: allow binding on rx queues with same DMA devices

 .../net/ethernet/mellanox/mlx5/core/en_main.c |  24 ++++
 include/net/netdev_queues.h                   |   8 ++
 io_uring/zcrx.c                               |   3 +-
 net/core/Makefile                             |   1 +
 net/core/devmem.c                             |   8 +-
 net/core/devmem.h                             |   2 +
 net/core/netdev-genl.c                        | 123 +++++++++++++-----
 net/core/netdev_queues.c                      |  25 ++++
 8 files changed, 163 insertions(+), 31 deletions(-)
 create mode 100644 net/core/netdev_queues.c
Signature · 1 line
2.50.1
#1 lore raw

PATCH v4 1/7 queue_api: add support for fetching per queue DMA dev

For zerocopy (io_uring, devmem), there is an assumption that the parent device can do DMA. However that is not always the case:
- Scalable Function netdevs [1] have the DMA device in the grandparent.
- For Multi-PF netdevs [2] queues can be associated to different DMA devices.

This patch introduces the a queue based interface for allowing drivers to expose a different DMA device for zerocopy.

[1] Documentation/networking/device_drivers/ethernet/mellanox/mlx5/switchdev.rst
[2] Documentation/networking/multi-pf-netdev.rst

---
 include/net/netdev_queues.h |  8 ++++++++
 net/core/Makefile           |  1 +
 net/core/netdev_queues.c    | 25 +++++++++++++++++++++++++
 3 files changed, 34 insertions(+)
 create mode 100644 net/core/netdev_queues.c
include/net/netdev_queues.h +8 -0
index 6e835972abd1..f648de4ca03e 100644
@@ -127,6 +127,10 @@ void netdev_stat_queue_sum(struct net_device *netdev,
  * @ndo_queue_stop:	Stop the RX queue at the specified index. The stopped
  *			queue's memory is written at the specified address.
  *
+ * @ndo_queue_get_dma_dev: Get dma device for zero-copy operations to be used
+ *			   for this queue. When such device is not available,
+ *			   the function will return NULL.
+ *
  * Note that @ndo_queue_mem_alloc and @ndo_queue_mem_free may be called while
  * the interface is closed. @ndo_queue_start and @ndo_queue_stop will only
  * be called for an interface which is open.
@@ -144,6 +148,8 @@ struct netdev_queue_mgmt_ops {
 	int			(*ndo_queue_stop)(struct net_device *dev,
 						  void *per_queue_mem,
 						  int idx);
+	struct device *		(*ndo_queue_get_dma_dev)(struct net_device *dev,
+							 int idx);
 };
 
 /**
@@ -321,4 +327,6 @@ static inline void netif_subqueue_sent(const struct net_device *dev,
 					 get_desc, start_thrs);		\
 	})
 
+struct device *netdev_queue_get_dma_dev(struct net_device *dev, int idx);
+
 #endif
net/core/Makefile +1 -0
index b2a76ce33932..9ef2099c5426 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
 obj-y += net-sysfs.o
 obj-y += hotdata.o
 obj-y += netdev_rx_queue.o
+obj-y += netdev_queues.o
 obj-$(CONFIG_PAGE_POOL) += page_pool.o page_pool_user.o
 obj-$(CONFIG_PROC_FS) += net-procfs.o
 obj-$(CONFIG_NET_PKTGEN) += pktgen.o
net/core/netdev_queues.c new file +25 -0
new file mode 100644
index 000000000000..d00f071e0edf
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <net/netdev_queues.h>
+
+/**
+ * netdev_queue_get_dma_dev() - get dma device for zero-copy operations
+ * @dev:	net_device
+ * @idx:	queue index
+ *
+ * Get dma device for zero-copy operations to be used for this queue.
+ * When such device is not available or valid, the function will return NULL.
+ */
+struct device *netdev_queue_get_dma_dev(struct net_device *dev, int idx)
+{
+	const struct netdev_queue_mgmt_ops *queue_ops = dev->queue_mgmt_ops;
+	struct device *dma_dev;
+
+	if (queue_ops && queue_ops->ndo_queue_get_dma_dev)
+		dma_dev = queue_ops->ndo_queue_get_dma_dev(dev, idx);
+	else
+		dma_dev = dev->dev.parent;
+
+	return dma_dev && dma_dev->dma_mask ? dma_dev : NULL;
+}
+EXPORT_SYMBOL(netdev_queue_get_dma_dev);
\ No newline at end of file
Signature · 1 line
2.50.1
Reviewed-by on v4 1/7
#2 lore raw

Re: [PATCH net-next v4 1/7] queue_api: add support for fetching per queue DMA dev

Quoted 7 lines · Dragos Tatulea

For zerocopy (io_uring, devmem), there is an assumption that the parent device can do DMA. However that is not always the case:
- Scalable Function netdevs [1] have the DMA device in the grandparent.
- For Multi-PF netdevs [2] queues can be associated to different DMA devices.

Quoted 8 lines

This patch introduces the a queue based interface for allowing drivers to expose a different DMA device for zerocopy.

[1] Documentation/networking/device_drivers/ethernet/mellanox/mlx5/switchdev.rst
[2] Documentation/networking/multi-pf-netdev.rst

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

Re: [PATCH net-next v4 1/7] queue_api: add support for fetching per queue DMA dev

In reply to Dragos Tatulea
Quoted 3 lines · On Wed, 20 Aug 2025 20:11:52 +0300 Dragos Tatulea wrote:

+ * @ndo_queue_get_dma_dev: Get dma device for zero-copy operations to be used
+ * for this queue. When such device is not available,
+ * the function will return NULL.

nit: I think you're using a different tense/grammar than the doc for other callbacks (which is admittedly somewhat unusual :$) Also should we indicate that "not available" is an error? Maybe just:

Get dma device for zero-copy operations to be used for this queue. Return NULL on error.

Quoted 11 lines

* Note that @ndo_queue_mem_alloc and @ndo_queue_mem_free may be called while
* the interface is closed. @ndo_queue_start and @ndo_queue_stop will only
* be called for an interface which is open.

+/**
+ * netdev_queue_get_dma_dev() - get dma device for zero-copy operations
+ * @dev: net_device
+ * @idx: queue index
+ *
+ * Get dma device for zero-copy operations to be used for this queue.
+ * When such device is not available or valid, the function will return NULL.

Unfortunately kdoc really wants us to add Return: statements to all functions...

Quoted 5 lines

+ */

net/core/netdev_queues.c new file +4 -0
+struct device *netdev_queue_get_dma_dev(struct net_device *dev, int idx)
+{
+	const struct netdev_queue_mgmt_ops *queue_ops = dev->queue_mgmt_ops;
+	struct device *dma_dev;

net/core/netdev_queues.c line 25

Quoted 10 lines
net/core/netdev_queues.c new file +9 -0
+
+	if (queue_ops && queue_ops->ndo_queue_get_dma_dev)
+		dma_dev = queue_ops->ndo_queue_get_dma_dev(dev, idx);
+	else
+		dma_dev = dev->dev.parent;
+
+	return dma_dev && dma_dev->dma_mask ? dma_dev : NULL;
+}
+EXPORT_SYMBOL(netdev_queue_get_dma_dev);
\ No newline at end of file

This is in desperate need of a terminating new line.

But also -- why the export? iouring and devmem can't be modules.

#4 lore raw

Re: [PATCH net-next v4 1/7] queue_api: add support for fetching per queue DMA dev

Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 20 Aug 2025 20:11:52 +0300 Dragos Tatulea wrote:

+ * @ndo_queue_get_dma_dev: Get dma device for zero-copy operations to be used
+ * for this queue. When such device is not available,
+ * the function will return NULL.

Quoted 7 lines

nit: I think you're using a different tense/grammar than the doc for other callbacks (which is admittedly somewhat unusual :$) Also should we indicate that "not available" is an error? Maybe just:

Get dma device for zero-copy operations to be used for this queue. Return NULL on error.

Sure. Will fix.

Quoted 12 lines
Quoted 11 lines

* Note that @ndo_queue_mem_alloc and @ndo_queue_mem_free may be called while
* the interface is closed. @ndo_queue_start and @ndo_queue_stop will only
* be called for an interface which is open.

+/**
+ * netdev_queue_get_dma_dev() - get dma device for zero-copy operations
+ * @dev: net_device
+ * @idx: queue index
+ *
+ * Get dma device for zero-copy operations to be used for this queue.
+ * When such device is not available or valid, the function will return NULL.

Quoted 3 lines

Unfortunately kdoc really wants us to add Return: statements to all functions...

Ack. Will fix.

Quoted 9 lines
Quoted 9 lines

+ */

net/core/netdev_queues.c new file +8 -0
+struct device *netdev_queue_get_dma_dev(struct net_device *dev, int idx)
+{
+	const struct netdev_queue_mgmt_ops *queue_ops = dev->queue_mgmt_ops;
+	struct device *dma_dev;
+
+	if (queue_ops && queue_ops->ndo_queue_get_dma_dev)
+		dma_dev = queue_ops->ndo_queue_get_dma_dev(dev, idx);
+	else
Quoted 9 lines

net/core/netdev_queues.c line 25

Quoted 6 lines
net/core/netdev_queues.c new file +5 -0
+		dma_dev = dev->dev.parent;
+
+	return dma_dev && dma_dev->dma_mask ? dma_dev : NULL;
+}
+EXPORT_SYMBOL(netdev_queue_get_dma_dev);
\ No newline at end of file

This is in desperate need of a terminating new line.

Ack. Will fix.

Quoted 1 line

But also -- why the export? iouring and devmem can't be modules.

Oh, right! Will replace with a newline.

Thanks,
Dragos

#5 lore raw

PATCH v4 2/7 io_uring/zcrx: add support for custom DMA devices

In reply to Dragos Tatulea

Use the new API for getting a DMA device for a specific netdev queue.

This patch will allow io_uring zero-copy rx to work with devices where the DMA device is not stored in the parent device. mlx5 SFs are an example of such a device.

---
 io_uring/zcrx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
io_uring/zcrx.c +2 -1
index e5ff49f3425e..319eddfd30e0 100644
@@ -12,6 +12,7 @@
 #include <net/page_pool/helpers.h>
 #include <net/page_pool/memory_provider.h>
 #include <net/netlink.h>
+#include <net/netdev_queues.h>
 #include <net/netdev_rx_queue.h>
 #include <net/tcp.h>
 #include <net/rps.h>
@@ -599,7 +600,7 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
 		goto err;
 	}
 
-	ifq->dev = ifq->netdev->dev.parent;
+	ifq->dev = netdev_queue_get_dma_dev(ifq->netdev, ifq->if_rxq);
 	if (!ifq->dev) {
 		ret = -EOPNOTSUPP;
 		goto err;
Signature · 1 line
2.50.1
#6 lore raw

PATCH v4 3/7 net: devmem: get netdev DMA device via new API

In reply to Dragos Tatulea

Switch to the new API for fetching DMA devices for a netdev. The API is called with queue index 0 for now which is equivalent with the previous behavior.

This patch will allow devmem to work with devices where the DMA device is not stored in the parent device. mlx5 SFs are an example of such a device.

Multi-PF netdevs are still problematic (as they were before this change). Upcoming patches will address this for the rx binding.

---
 net/core/devmem.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
net/core/devmem.c +9 -1
index 24c591ab38ae..d66cb0a63bd6 100644
@@ -182,6 +182,7 @@ net_devmem_bind_dmabuf(struct net_device *dev,
 {
 	struct net_devmem_dmabuf_binding *binding;
 	static u32 id_alloc_next;
+	struct device *dma_dev;
 	struct scatterlist *sg;
 	struct dma_buf *dmabuf;
 	unsigned int sg_idx, i;
@@ -192,6 +193,13 @@ net_devmem_bind_dmabuf(struct net_device *dev,
 	if (IS_ERR(dmabuf))
 		return ERR_CAST(dmabuf);
 
+	dma_dev = netdev_queue_get_dma_dev(dev, 0);
+	if (!dma_dev) {
+		err = -EOPNOTSUPP;
+		NL_SET_ERR_MSG(extack, "Device doesn't support dma");
+		goto err_put_dmabuf;
+	}
+
 	binding = kzalloc_node(sizeof(*binding), GFP_KERNEL,
 			       dev_to_node(&dev->dev));
 	if (!binding) {
@@ -209,7 +217,7 @@ net_devmem_bind_dmabuf(struct net_device *dev,
 	binding->dmabuf = dmabuf;
 	binding->direction = direction;
 
-	binding->attachment = dma_buf_attach(binding->dmabuf, dev->dev.parent);
+	binding->attachment = dma_buf_attach(binding->dmabuf, dma_dev);
 	if (IS_ERR(binding->attachment)) {
 		err = PTR_ERR(binding->attachment);
 		NL_SET_ERR_MSG(extack, "Failed to bind dmabuf to device");
Signature · 1 line
2.50.1
maintainer
#7 lore raw

Re: [PATCH net-next v4 3/7] net: devmem: get netdev DMA device via new API

net/core/devmem.c net_devmem_bind_dmabuf(struct net_device *dev, · line 199

Quoted 1 line · On Wed, 20 Aug 2025 20:11:54 +0300 Dragos Tatulea wrote:
net/core/devmem.c +1 -0
+		NL_SET_ERR_MSG(extack, "Device doesn't support dma");

nit: s/dma/DMA/

#8 lore raw

PATCH v4 4/7 net/mlx5e: add op for getting netdev DMA device

In reply to Dragos Tatulea

For zero-copy (devmem, io_uring), the netdev DMA device used is the parent device of the net device. However that is not always accurate for mlx5 devices:
- SFs: The parent device is an auxdev.
- Multi-PF netdevs: The DMA device should be determined by the queue.

This change implements the DMA device queue API that returns the DMA device appropriately for all cases.

---
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +24 -0
index 21bb88c5d3dc..0e48065a46eb 100644
@@ -5625,12 +5625,36 @@ static int mlx5e_queue_start(struct net_device *dev, void *newq,
 	return 0;
 }
 
+static struct device *mlx5e_queue_get_dma_dev(struct net_device *dev,
+					      int queue_index)
+{
+	struct mlx5e_priv *priv = netdev_priv(dev);
+	struct mlx5e_channels *channels;
+	struct device *pdev = NULL;
+	struct mlx5e_channel *ch;
+
+	channels = &priv->channels;
+
+	mutex_lock(&priv->state_lock);
+
+	if (queue_index >= channels->num)
+		goto out;
+
+	ch = channels->c[queue_index];
+	pdev = ch->pdev;
+out:
+	mutex_unlock(&priv->state_lock);
+
+	return pdev;
+}
+
 static const struct netdev_queue_mgmt_ops mlx5e_queue_mgmt_ops = {
 	.ndo_queue_mem_size	=	sizeof(struct mlx5_qmgmt_data),
 	.ndo_queue_mem_alloc	=	mlx5e_queue_mem_alloc,
 	.ndo_queue_mem_free	=	mlx5e_queue_mem_free,
 	.ndo_queue_start	=	mlx5e_queue_start,
 	.ndo_queue_stop		=	mlx5e_queue_stop,
+	.ndo_queue_get_dma_dev	=	mlx5e_queue_get_dma_dev,
 };
 
 static void mlx5e_build_nic_netdev(struct net_device *netdev)
Signature · 1 line
2.50.1
#9 lore raw

PATCH v4 5/7 net: devmem: pull out dma_dev out of net_devmem_bind_dmabuf

In reply to Dragos Tatulea

Fetch the DMA device before calling net_devmem_bind_dmabuf() and pass it on as a parameter.

This is needed for an upcoming change which will read the DMA device per queue.

This patch has no functional changes.

---
 net/core/devmem.c      | 14 ++++++--------
 net/core/devmem.h      |  2 ++
 net/core/netdev-genl.c | 12 ++++++++----
 3 files changed, 16 insertions(+), 12 deletions(-)
net/core/devmem.c +6 -8
index d66cb0a63bd6..c7ca16c9fc04 100644
@@ -176,30 +176,28 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 
 struct net_devmem_dmabuf_binding *
 net_devmem_bind_dmabuf(struct net_device *dev,
+		       struct device *dma_dev,
 		       enum dma_data_direction direction,
 		       unsigned int dmabuf_fd, struct netdev_nl_sock *priv,
 		       struct netlink_ext_ack *extack)
 {
 	struct net_devmem_dmabuf_binding *binding;
 	static u32 id_alloc_next;
-	struct device *dma_dev;
 	struct scatterlist *sg;
 	struct dma_buf *dmabuf;
 	unsigned int sg_idx, i;
 	unsigned long virtual;
 	int err;
 
-	dmabuf = dma_buf_get(dmabuf_fd);
-	if (IS_ERR(dmabuf))
-		return ERR_CAST(dmabuf);
-
-	dma_dev = netdev_queue_get_dma_dev(dev, 0);
 	if (!dma_dev) {
-		err = -EOPNOTSUPP;
 		NL_SET_ERR_MSG(extack, "Device doesn't support dma");
-		goto err_put_dmabuf;
+		return ERR_PTR(-EOPNOTSUPP);
 	}
 
+	dmabuf = dma_buf_get(dmabuf_fd);
+	if (IS_ERR(dmabuf))
+		return ERR_CAST(dmabuf);
+
 	binding = kzalloc_node(sizeof(*binding), GFP_KERNEL,
 			       dev_to_node(&dev->dev));
 	if (!binding) {
net/core/devmem.h +2 -0
index 41cd6e1c9141..101150d761af 100644
@@ -85,6 +85,7 @@ struct dmabuf_genpool_chunk_owner {
 void __net_devmem_dmabuf_binding_free(struct work_struct *wq);
 struct net_devmem_dmabuf_binding *
 net_devmem_bind_dmabuf(struct net_device *dev,
+		       struct device *dma_dev,
 		       enum dma_data_direction direction,
 		       unsigned int dmabuf_fd, struct netdev_nl_sock *priv,
 		       struct netlink_ext_ack *extack);
@@ -170,6 +171,7 @@ static inline void net_devmem_put_net_iov(struct net_iov *niov)
 
 static inline struct net_devmem_dmabuf_binding *
 net_devmem_bind_dmabuf(struct net_device *dev,
+		       struct device *dma_dev,
 		       enum dma_data_direction direction,
 		       unsigned int dmabuf_fd,
 		       struct netdev_nl_sock *priv,
net/core/netdev-genl.c +8 -4
index 6314eb7bdf69..3e2d6aa6e060 100644
@@ -876,6 +876,7 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 	u32 ifindex, dmabuf_fd, rxq_idx;
 	struct netdev_nl_sock *priv;
 	struct net_device *netdev;
+	struct device *dma_dev;
 	struct sk_buff *rsp;
 	struct nlattr *attr;
 	int rem, err = 0;
@@ -921,8 +922,9 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 		goto err_unlock;
 	}
 
-	binding = net_devmem_bind_dmabuf(netdev, DMA_FROM_DEVICE, dmabuf_fd,
-					 priv, info->extack);
+	dma_dev = netdev_queue_get_dma_dev(netdev, 0);
+	binding = net_devmem_bind_dmabuf(netdev, dma_dev, DMA_FROM_DEVICE,
+					 dmabuf_fd, priv, info->extack);
 	if (IS_ERR(binding)) {
 		err = PTR_ERR(binding);
 		goto err_unlock;
@@ -986,6 +988,7 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 	struct net_devmem_dmabuf_binding *binding;
 	struct netdev_nl_sock *priv;
 	struct net_device *netdev;
+	struct device *dma_dev;
 	u32 ifindex, dmabuf_fd;
 	struct sk_buff *rsp;
 	int err = 0;
@@ -1032,8 +1035,9 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 		goto err_unlock_netdev;
 	}
 
-	binding = net_devmem_bind_dmabuf(netdev, DMA_TO_DEVICE, dmabuf_fd, priv,
-					 info->extack);
+	dma_dev = netdev_queue_get_dma_dev(netdev, 0);
+	binding = net_devmem_bind_dmabuf(netdev, dma_dev, DMA_TO_DEVICE,
+					 dmabuf_fd, priv, info->extack);
 	if (IS_ERR(binding)) {
 		err = PTR_ERR(binding);
 		goto err_unlock_netdev;
Signature · 1 line
2.50.1
#10 lore raw

PATCH v4 6/7 net: devmem: pre-read requested rx queues during bind

In reply to Dragos Tatulea

Instead of reading the requested rx queues after binding the buffer, read the rx queues in advance in a bitmap and iterate over them when needed.

This is a preparation for fetching the DMA device for each queue.

This patch has no functional changes besides adding an extra rq index bounds check.

---
 net/core/netdev-genl.c | 83 ++++++++++++++++++++++++++++--------------
 1 file changed, 56 insertions(+), 27 deletions(-)
net/core/netdev-genl.c +56 -27
index 3e2d6aa6e060..0df9c159e515 100644
@@ -869,17 +869,53 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,
 	return err;
 }
 
-int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
+static int netdev_nl_read_rxq_bitmap(struct genl_info *info,
+				     u32 rxq_bitmap_len,
+				     unsigned long *rxq_bitmap)
 {
 	struct nlattr *tb[ARRAY_SIZE(netdev_queue_id_nl_policy)];
+	struct nlattr *attr;
+	int rem, err = 0;
+	u32 rxq_idx;
+
+	nla_for_each_attr_type(attr, NETDEV_A_DMABUF_QUEUES,
+			       genlmsg_data(info->genlhdr),
+			       genlmsg_len(info->genlhdr), rem) {
+		err = nla_parse_nested(
+			tb, ARRAY_SIZE(netdev_queue_id_nl_policy) - 1, attr,
+			netdev_queue_id_nl_policy, info->extack);
+		if (err < 0)
+			return err;
+
+		if (NL_REQ_ATTR_CHECK(info->extack, attr, tb, NETDEV_A_QUEUE_ID) ||
+		    NL_REQ_ATTR_CHECK(info->extack, attr, tb, NETDEV_A_QUEUE_TYPE))
+			return -EINVAL;
+
+		if (nla_get_u32(tb[NETDEV_A_QUEUE_TYPE]) != NETDEV_QUEUE_TYPE_RX) {
+			NL_SET_BAD_ATTR(info->extack, tb[NETDEV_A_QUEUE_TYPE]);
+			return -EINVAL;
+		}
+
+		rxq_idx = nla_get_u32(tb[NETDEV_A_QUEUE_ID]);
+		if (rxq_idx >= rxq_bitmap_len)
+			return -EINVAL;
+
+		bitmap_set(rxq_bitmap, rxq_idx, 1);
+	}
+
+	return 0;
+}
+
+int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
+{
 	struct net_devmem_dmabuf_binding *binding;
 	u32 ifindex, dmabuf_fd, rxq_idx;
 	struct netdev_nl_sock *priv;
 	struct net_device *netdev;
+	unsigned long *rxq_bitmap;
 	struct device *dma_dev;
 	struct sk_buff *rsp;
-	struct nlattr *attr;
-	int rem, err = 0;
+	int err = 0;
 	void *hdr;
 
 	if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_DEV_IFINDEX) ||
@@ -922,37 +958,26 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 		goto err_unlock;
 	}
 
+	rxq_bitmap = bitmap_zalloc(netdev->real_num_rx_queues, GFP_KERNEL);
+	if (!rxq_bitmap) {
+		err = -ENOMEM;
+		goto err_unlock;
+	}
+
+	err = netdev_nl_read_rxq_bitmap(info, netdev->real_num_rx_queues,
+					rxq_bitmap);
+	if (err)
+		goto err_rxq_bitmap;
+
 	dma_dev = netdev_queue_get_dma_dev(netdev, 0);
 	binding = net_devmem_bind_dmabuf(netdev, dma_dev, DMA_FROM_DEVICE,
 					 dmabuf_fd, priv, info->extack);
 	if (IS_ERR(binding)) {
 		err = PTR_ERR(binding);
-		goto err_unlock;
+		goto err_rxq_bitmap;
 	}
 
-	nla_for_each_attr_type(attr, NETDEV_A_DMABUF_QUEUES,
-			       genlmsg_data(info->genlhdr),
-			       genlmsg_len(info->genlhdr), rem) {
-		err = nla_parse_nested(
-			tb, ARRAY_SIZE(netdev_queue_id_nl_policy) - 1, attr,
-			netdev_queue_id_nl_policy, info->extack);
-		if (err < 0)
-			goto err_unbind;
-
-		if (NL_REQ_ATTR_CHECK(info->extack, attr, tb, NETDEV_A_QUEUE_ID) ||
-		    NL_REQ_ATTR_CHECK(info->extack, attr, tb, NETDEV_A_QUEUE_TYPE)) {
-			err = -EINVAL;
-			goto err_unbind;
-		}
-
-		if (nla_get_u32(tb[NETDEV_A_QUEUE_TYPE]) != NETDEV_QUEUE_TYPE_RX) {
-			NL_SET_BAD_ATTR(info->extack, tb[NETDEV_A_QUEUE_TYPE]);
-			err = -EINVAL;
-			goto err_unbind;
-		}
-
-		rxq_idx = nla_get_u32(tb[NETDEV_A_QUEUE_ID]);
-
+	for_each_set_bit(rxq_idx, rxq_bitmap, netdev->real_num_rx_queues) {
 		err = net_devmem_bind_dmabuf_to_queue(netdev, rxq_idx, binding,
 						      info->extack);
 		if (err)
@@ -966,6 +991,8 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 	if (err)
 		goto err_unbind;
 
+	bitmap_free(rxq_bitmap);
+
 	netdev_unlock(netdev);
 
 	mutex_unlock(&priv->lock);
@@ -974,6 +1001,8 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 
 err_unbind:
 	net_devmem_unbind_dmabuf(binding);
+err_rxq_bitmap:
+	bitmap_free(rxq_bitmap);
 err_unlock:
 	netdev_unlock(netdev);
 err_unlock_sock:
Signature · 1 line
2.50.1
Reviewed-by on v4 6/7
#11 lore raw

Re: [PATCH net-next v4 6/7] net: devmem: pre-read requested rx queues during bind

Quoted 11 lines · Dragos Tatulea

Instead of reading the requested rx queues after binding the buffer, read the rx queues in advance in a bitmap and iterate over them when needed.

This is a preparation for fetching the DMA device for each queue.

This patch has no functional changes besides adding an extra rq index bounds check.

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

Re: [PATCH net-next v4 6/7] net: devmem: pre-read requested rx queues during bind

In reply to Dragos Tatulea

net/core/netdev-genl.c int netdev_nl_qstats_get_dumpit(struct sk_buff *skb, · line 885

Quoted 10 lines · On Wed, 20 Aug 2025 20:11:57 +0300 Dragos Tatulea wrote:
net/core/netdev-genl.c +9 -0
 	struct nlattr *tb[ARRAY_SIZE(netdev_queue_id_nl_policy)];
+	struct nlattr *attr;
+	int rem, err = 0;
+	u32 rxq_idx;
+
+	nla_for_each_attr_type(attr, NETDEV_A_DMABUF_QUEUES,
+			       genlmsg_data(info->genlhdr),
+			       genlmsg_len(info->genlhdr), rem) {
+		err = nla_parse_nested(
+			tb, ARRAY_SIZE(netdev_queue_id_nl_policy) - 1, attr,

While you're touching this line, could you perhaps clean up the line wrap? Save ARRAY_SIZE(netdev_queue_id_nl_policy) - 1 to a const and then:

		err = nla_parse_nested(tb, maxtype, attr, 
				       netdev_queue_id_nl_policy, info->extack);

or some such.

#13 lore raw

Re: [PATCH net-next v4 6/7] net: devmem: pre-read requested rx queues during bind

Quoted 16 lines · Jakub Kicinski

net/core/netdev-genl.c int netdev_nl_qstats_get_dumpit(struct sk_buff *skb, · line 885

Quoted 10 lines · On Wed, 20 Aug 2025 20:11:57 +0300 Dragos Tatulea wrote:
net/core/netdev-genl.c +9 -0
 	struct nlattr *tb[ARRAY_SIZE(netdev_queue_id_nl_policy)];
+	struct nlattr *attr;
+	int rem, err = 0;
+	u32 rxq_idx;
+
+	nla_for_each_attr_type(attr, NETDEV_A_DMABUF_QUEUES,
+			       genlmsg_data(info->genlhdr),
+			       genlmsg_len(info->genlhdr), rem) {
+		err = nla_parse_nested(
+			tb, ARRAY_SIZE(netdev_queue_id_nl_policy) - 1, attr,

While you're touching this line, could you perhaps clean up the line wrap? Save ARRAY_SIZE(netdev_queue_id_nl_policy) - 1 to a const and then:

Quoted 4 lines
		err = nla_parse_nested(tb, maxtype, attr, 
				       netdev_queue_id_nl_policy, info->extack);

or some such.

Will clean up.

Thanks,
Dragos

#14 lore raw

PATCH v4 7/7 net: devmem: allow binding on rx queues with same DMA devices

In reply to Dragos Tatulea

Multi-PF netdevs have queues belonging to different PFs which also means different DMA devices. This means that the binding on the DMA buffer can be done to the incorrect device.

This change allows devmem binding to multiple queues only when the queues have the same DMA device. Otherwise an error is returned.

---
 net/core/netdev-genl.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
net/core/netdev-genl.c +33 -1
index 0df9c159e515..a8c27f636453 100644
@@ -906,6 +906,33 @@ static int netdev_nl_read_rxq_bitmap(struct genl_info *info,
 	return 0;
 }
 
+static struct device *netdev_nl_get_dma_dev(struct net_device *netdev,
+					    unsigned long *rxq_bitmap,
+					    struct netlink_ext_ack *extack)
+{
+	struct device *dma_dev = NULL;
+	u32 rxq_idx, prev_rxq_idx;
+
+	for_each_set_bit(rxq_idx, rxq_bitmap, netdev->real_num_rx_queues) {
+		struct device *rxq_dma_dev;
+
+		rxq_dma_dev = netdev_queue_get_dma_dev(netdev, rxq_idx);
+		/* Multi-PF netdev queues can belong to different DMA devoces.
+		 * Block this case.
+		 */
+		if (dma_dev && rxq_dma_dev != dma_dev) {
+			NL_SET_ERR_MSG_FMT(extack, "Queue %u has a different dma device than queue %u",
+					   rxq_idx, prev_rxq_idx);
+			return ERR_PTR(-EOPNOTSUPP);
+		}
+
+		dma_dev = rxq_dma_dev;
+		prev_rxq_idx = rxq_idx;
+	}
+
+	return dma_dev;
+}
+
 int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct net_devmem_dmabuf_binding *binding;
@@ -969,7 +996,12 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 	if (err)
 		goto err_rxq_bitmap;
 
-	dma_dev = netdev_queue_get_dma_dev(netdev, 0);
+	dma_dev = netdev_nl_get_dma_dev(netdev, rxq_bitmap, info->extack);
+	if (IS_ERR(dma_dev)) {
+		err = PTR_ERR(dma_dev);
+		goto err_rxq_bitmap;
+	}
+
 	binding = net_devmem_bind_dmabuf(netdev, dma_dev, DMA_FROM_DEVICE,
 					 dmabuf_fd, priv, info->extack);
 	if (IS_ERR(binding)) {
Signature · 1 line
2.50.1
#15 lore raw

Re: [PATCH net-next v4 7/7] net: devmem: allow binding on rx queues with same DMA devices

Quoted 52 lines · Dragos Tatulea

Multi-PF netdevs have queues belonging to different PFs which also means different DMA devices. This means that the binding on the DMA buffer can be done to the incorrect device.

This change allows devmem binding to multiple queues only when the queues have the same DMA device. Otherwise an error is returned.

---
 net/core/netdev-genl.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
net/core/netdev-genl.c +27 -0
index 0df9c159e515..a8c27f636453 100644
@@ -906,6 +906,33 @@ static int netdev_nl_read_rxq_bitmap(struct genl_info *info,
        return 0;
 }
 
+static struct device *netdev_nl_get_dma_dev(struct net_device *netdev,
+                                           unsigned long *rxq_bitmap,
+                                           struct netlink_ext_ack *extack)
+{
+       struct device *dma_dev = NULL;
+       u32 rxq_idx, prev_rxq_idx;
+
+       for_each_set_bit(rxq_idx, rxq_bitmap, netdev->real_num_rx_queues) {
+               struct device *rxq_dma_dev;
+
+               rxq_dma_dev = netdev_queue_get_dma_dev(netdev, rxq_idx);
+               /* Multi-PF netdev queues can belong to different DMA devoces.
+                * Block this case.
+                */
+               if (dma_dev && rxq_dma_dev != dma_dev) {
+                       NL_SET_ERR_MSG_FMT(extack, "Queue %u has a different dma device than queue %u",
+                                          rxq_idx, prev_rxq_idx);
+                       return ERR_PTR(-EOPNOTSUPP);
+               }
+
+               dma_dev = rxq_dma_dev;
+               prev_rxq_idx = rxq_idx;
+       }
+
+       return dma_dev;
+}
+
 int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 {
        struct net_devmem_dmabuf_binding *binding;

net/core/netdev-genl.c int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) · line 1000

Quoted 6 lines
net/core/netdev-genl.c +2 -1
@@ -969,7 +996,12 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
        if (err)
                goto err_rxq_bitmap;
 
-       dma_dev = netdev_queue_get_dma_dev(netdev, 0);
+       dma_dev = netdev_nl_get_dma_dev(netdev, rxq_bitmap, info->extack);
+       if (IS_ERR(dma_dev)) {

Does this need to be IS_ERR_OR_NULL? AFAICT if all the ndos return NULL, then dma_dev will also be NULL, and NULL is not a valid value to pass to bind_dmabuf below.

Signature · 2 lines
Thanks,
Mina
#16 lore raw

Re: [PATCH net-next v4 7/7] net: devmem: allow binding on rx queues with same DMA devices

Quoted 56 lines · Mina Almasry
Quoted 55 lines · Dragos Tatulea

Multi-PF netdevs have queues belonging to different PFs which also means different DMA devices. This means that the binding on the DMA buffer can be done to the incorrect device.

This change allows devmem binding to multiple queues only when the queues have the same DMA device. Otherwise an error is returned.

---
 net/core/netdev-genl.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
net/core/netdev-genl.c +27 -0
index 0df9c159e515..a8c27f636453 100644
@@ -906,6 +906,33 @@ static int netdev_nl_read_rxq_bitmap(struct genl_info *info,
        return 0;
 }
 
+static struct device *netdev_nl_get_dma_dev(struct net_device *netdev,
+                                           unsigned long *rxq_bitmap,
+                                           struct netlink_ext_ack *extack)
+{
+       struct device *dma_dev = NULL;
+       u32 rxq_idx, prev_rxq_idx;
+
+       for_each_set_bit(rxq_idx, rxq_bitmap, netdev->real_num_rx_queues) {
+               struct device *rxq_dma_dev;
+
+               rxq_dma_dev = netdev_queue_get_dma_dev(netdev, rxq_idx);
+               /* Multi-PF netdev queues can belong to different DMA devoces.
+                * Block this case.
+                */
+               if (dma_dev && rxq_dma_dev != dma_dev) {
+                       NL_SET_ERR_MSG_FMT(extack, "Queue %u has a different dma device than queue %u",
+                                          rxq_idx, prev_rxq_idx);
+                       return ERR_PTR(-EOPNOTSUPP);
+               }
+
+               dma_dev = rxq_dma_dev;
+               prev_rxq_idx = rxq_idx;
+       }
+
+       return dma_dev;
+}
+
 int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
 {
        struct net_devmem_dmabuf_binding *binding;
@@ -969,7 +996,12 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
        if (err)
                goto err_rxq_bitmap;
 
Quoted 8 lines

net/core/netdev-genl.c int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) · line 1000

Quoted 3 lines
net/core/netdev-genl.c +2 -1
-       dma_dev = netdev_queue_get_dma_dev(netdev, 0);
+       dma_dev = netdev_nl_get_dma_dev(netdev, rxq_bitmap, info->extack);
+       if (IS_ERR(dma_dev)) {

Does this need to be IS_ERR_OR_NULL? AFAICT if all the ndos return NULL, then dma_dev will also be NULL, and NULL is not a valid value to pass to bind_dmabuf below.

netdev_nl_get_dma_dev() signals DMA device mismatch though EOPNOTSUPP. That's why it is IS_ERR_OR_NULL. I find that doing this at the calling site would be possible but less accurate.

Or did you mean something else?

Thannks,
Dragos

maintainer
#17 lore raw

Re: [PATCH net-next v4 7/7] net: devmem: allow binding on rx queues with same DMA devices

In reply to Dragos Tatulea

net/core/netdev-genl.c static int netdev_nl_read_rxq_bitmap(struct genl_info *info, · line 911

Quoted 3 lines · On Wed, 20 Aug 2025 20:11:58 +0300 Dragos Tatulea wrote:
net/core/netdev-genl.c +3 -0
+static struct device *netdev_nl_get_dma_dev(struct net_device *netdev,
+					    unsigned long *rxq_bitmap,
+					    struct netlink_ext_ack *extack)

break after type if it's long and multi line:

static struct device *
netdev_nl_get_dma_dev(struct net_device *netdev, unsigned long *rxq_bitmap,
struct netlink_ext_ack *extack)

net/core/netdev-genl.c static int netdev_nl_read_rxq_bitmap(struct genl_info *info, · line 920

Quoted 9 lines
net/core/netdev-genl.c +9 -0
+{
+	struct device *dma_dev = NULL;
+	u32 rxq_idx, prev_rxq_idx;
+
+	for_each_set_bit(rxq_idx, rxq_bitmap, netdev->real_num_rx_queues) {
+		struct device *rxq_dma_dev;
+
+		rxq_dma_dev = netdev_queue_get_dma_dev(netdev, rxq_idx);
+		/* Multi-PF netdev queues can belong to different DMA devoces.

typo: devoces

net/core/netdev-genl.c static int netdev_nl_read_rxq_bitmap(struct genl_info *info, · line 924

Quoted 4 lines
net/core/netdev-genl.c +4 -0
+		 * Block this case.
+		 */
+		if (dma_dev && rxq_dma_dev != dma_dev) {
+			NL_SET_ERR_MSG_FMT(extack, "Queue %u has a different dma device than queue %u",

s/dma/DMA/
I think we may want to bubble up the Multi-PF thing from the comment to the user. This could be quite confusing to people. How about:

"DMA device mismatch between queue %u and %u (multi-PF device?)"

#18 lore raw

Re: [PATCH net-next v4 7/7] net: devmem: allow binding on rx queues with same DMA devices

Quoted 11 lines · Jakub Kicinski

net/core/netdev-genl.c static int netdev_nl_read_rxq_bitmap(struct genl_info *info, · line 911

Quoted 3 lines · On Wed, 20 Aug 2025 20:11:58 +0300 Dragos Tatulea wrote:
net/core/netdev-genl.c +3 -0
+static struct device *netdev_nl_get_dma_dev(struct net_device *netdev,
+					    unsigned long *rxq_bitmap,
+					    struct netlink_ext_ack *extack)

break after type if it's long and multi line:

static struct device *
netdev_nl_get_dma_dev(struct net_device *netdev, unsigned long *rxq_bitmap,
struct netlink_ext_ack *extack)

Will fix. Hope to remember for next times as well.

Quoted 12 lines

net/core/netdev-genl.c static int netdev_nl_read_rxq_bitmap(struct genl_info *info, · line 920

Quoted 9 lines
net/core/netdev-genl.c +9 -0
+{
+	struct device *dma_dev = NULL;
+	u32 rxq_idx, prev_rxq_idx;
+
+	for_each_set_bit(rxq_idx, rxq_bitmap, netdev->real_num_rx_queues) {
+		struct device *rxq_dma_dev;
+
+		rxq_dma_dev = netdev_queue_get_dma_dev(netdev, rxq_idx);
+		/* Multi-PF netdev queues can belong to different DMA devoces.

typo: devoces

Thanks!

Quoted 10 lines

net/core/netdev-genl.c static int netdev_nl_read_rxq_bitmap(struct genl_info *info, · line 924

Quoted 4 lines
net/core/netdev-genl.c +4 -0
+		 * Block this case.
+		 */
+		if (dma_dev && rxq_dma_dev != dma_dev) {
+			NL_SET_ERR_MSG_FMT(extack, "Queue %u has a different dma device than queue %u",

s/dma/DMA/
I think we may want to bubble up the Multi-PF thing from the comment to the user. This could be quite confusing to people. How about:

"DMA device mismatch between queue %u and %u (multi-PF device?)"

Sounds good. Do we still need the comment? A similar remark is done in the commit message as well.

Thanks,
Dragos

maintainer
#19 lore raw

Re: [PATCH net-next v4 7/7] net: devmem: allow binding on rx queues with same DMA devices

Quoted 6 lines · On Thu, 21 Aug 2025 11:10:57 +0000 Dragos Tatulea wrote:
Quoted 4 lines

I think we may want to bubble up the Multi-PF thing from the comment to the user. This could be quite confusing to people. How about:

"DMA device mismatch between queue %u and %u (multi-PF device?)"

Sounds good. Do we still need the comment? A similar remark is done in the commit message as well.

I think the comment can go away with the better user-facing message. The commit msg LGTM as is, doesn't count as extra LoC..