net: make memory provider install / close paths more common
Subsystems (3)
Jakub Kicinski
maintainerv2 cover net: make memory provider install / close paths more common
We seem to be fixing bugs in config path for devmem which also exist in the io_uring ZC path. Let's try to make the two paths more common, otherwise this is bound to keep happening.
Found by code inspection and compile tested only.
v2:
- [patch 1] add to commit msg
- [patch 1] fix arg naming in the header
- [patch 2] don't split the registration check, it may cause a race if we just bail on the registration state and not on the MP being present, as we drop and re-take the instance lock after setting reg_state
v1: https://lore.kernel.org/[email protected]
Jakub Kicinski (2):
net: move mp dev config validation to __net_mp_open_rxq()
net: avoid false positive warnings in __net_mp_close_rxq()
include/net/page_pool/memory_provider.h | 6 +++ net/core/devmem.c | 64 +++++++------------------ net/core/netdev-genl.c | 6 --- net/core/netdev_rx_queue.c | 53 +++++++++++++++----- 4 files changed, 63 insertions(+), 66 deletions(-)
Signature · 1 line
2.49.0
Jakub Kicinski
maintainerPATCH v2 1/2 net: move mp dev config validation to __net_mp_open_rxq()
devmem code performs a number of safety checks to avoid having to reimplement all of them in the drivers. Move those to __net_mp_open_rxq() and reuse that function for binding to make sure that io_uring ZC also benefits from them.
While at it rename the queue ID variable to rxq_idx in __net_mp_open_rxq(), we touch most of the relevant lines.
The XArray insertion is reordered after the netdev_rx_queue_restart() call, otherwise we'd need to duplicate the queue index check or risk inserting an invalid pointer. The XArray allocation failures should be extremely rare.
---
v2:
- add to commit msg
- fix arg naming in the header (Stan)
v1: https://lore.kernel.org/[email protected]
--- include/net/page_pool/memory_provider.h | 6 +++ net/core/devmem.c | 52 ++++++------------------- net/core/netdev-genl.c | 6 --- net/core/netdev_rx_queue.c | 49 +++++++++++++++++------ 4 files changed, 55 insertions(+), 58 deletions(-)
include/net/page_pool/memory_provider.h +6 -0
@@ -6,6 +6,7 @@#include <net/page_pool/types.h> struct netdev_rx_queue ; +struct netlink_ext_ack ;struct sk_buff ;struct memory_provider_ops {
@@ -24,8 +25,13 @@ void net_mp_niov_clear_page_pool(struct net_iov *niov);int net_mp_open_rxq (struct net_device *dev,unsigned ifq_idx,struct pp_memory_provider_params *p); +int __net_mp_open_rxq (struct net_device *dev,unsigned int rxq_idx, +const struct pp_memory_provider_params *p, +struct netlink_ext_ack *extack);void net_mp_close_rxq (struct net_device *dev,unsigned ifq_idx,struct pp_memory_provider_params *old_p); +void __net_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx, +const struct pp_memory_provider_params *old_p);/** * net_mp_netmem_place_in_cache() - give a netmem to a page pool
net/core/devmem.c +11 -41
75 lines not on this page · raw message
net/core/netdev-genl.c +0 -6
@@ -874,12 +874,6 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) goto err_unlock; } -if (dev_xdp_prog_count (netdev)) { -NL_SET_ERR_MSG (info->extack,"unable to bind dmabuf to device with XDP program attached" ); - err = -EEXIST ; - goto err_unlock; - } - binding =net_devmem_bind_dmabuf (netdev, dmabuf_fd, info->extack);if (IS_ERR (binding)) { err =PTR_ERR (binding);
net/core/netdev_rx_queue.c +38 -11
86 lines not on this page · raw message
Signature · 1 line
2.49.0
Jakub Kicinski
maintainerPATCH v2 2/2 net: avoid false positive warnings in __net_mp_close_rxq()
In reply to Jakub KicinskiCommit under Fixes solved the problem of spurious warnings when we uninstall an MP from a device while its down. The __net_mp_close_rxq() which is used by io_uring was not fixed. Move the fix over and reuse __net_mp_close_rxq() in the devmem path.
---
v2:
- don't split the registration check, it may cause a race if we just bail on the registration state and not on the MP being present, as we drop and re-take the instance lock after setting reg_state
v1: https://lore.kernel.org/[email protected]
--- net/core/devmem.c | 12 +++++------- net/core/netdev_rx_queue.c | 4 +++- 2 files changed, 8 insertions(+), 8 deletions(-)
net/core/devmem.c +5 -7
@@ -116,21 +116,19 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)struct netdev_rx_queue *rxq;unsigned long xa_idx;unsigned int rxq_idx; -int err;if (binding->list.next)list_del (&binding->list);xa_for_each (&binding->bound_rxqs, xa_idx, rxq) { -WARN_ON (rxq->mp_params.mp_priv != binding); - - rxq->mp_params.mp_priv =NULL ; - rxq->mp_params.mp_ops =NULL ; +const struct pp_memory_provider_params mp_params = { + .mp_priv = binding, + .mp_ops = &dmabuf_devmem_ops, + }; rxq_idx =get_netdev_rx_queue_index (rxq); - err =netdev_rx_queue_restart (binding->dev, rxq_idx); -WARN_ON (err && err != -ENETDOWN ); +__net_mp_close_rxq (binding->dev, rxq_idx, &mp_params); }xa_erase (&net_devmem_dmabuf_bindings, binding->id);
net/core/netdev_rx_queue.c +3 -1
@@ -154,6 +154,7 @@ void __net_mp_close_rxq(struct net_device *dev, unsigned int ifq_idx, const struct pp_memory_provider_params *old_p) {struct netdev_rx_queue *rxq; +int err;if (WARN_ON_ONCE (ifq_idx >= dev->real_num_rx_queues))return ;
@@ -173,7 +174,8 @@ void __net_mp_close_rxq(struct net_device *dev, unsigned int ifq_idx, rxq->mp_params.mp_ops =NULL ; rxq->mp_params.mp_priv =NULL ; -WARN_ON (netdev_rx_queue_restart (dev, ifq_idx)); + err =netdev_rx_queue_restart (dev, ifq_idx); +WARN_ON (err && err != -ENETDOWN ); } void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx,
Signature · 1 line
2.49.0
Re: [PATCH net v2 2/2] net: avoid false positive warnings in __net_mp_close_rxq()
Quoted 9 lines · Jakub Kicinski
Commit under Fixes solved the problem of spurious warnings when we uninstall an MP from a device while its down. The
__net_mp_close_rxq()which is used byio_uringwas not fixed. Move the fix over and reuse__net_mp_close_rxq()in the devmem path.Fixes a70f891e0fa0 ("net: devmem: do not WARN conditionally after netdev_rx_queue_restart()")Signed-off-by Jakub Kicinski <[email protected]>
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 15 lines · On Wed, 2 Apr 2025 18:34:03 -0700 you wrote:
We seem to be fixing bugs in config path for devmem which also exist in the
io_uringZC path. Let's try to make the two paths more common, otherwise this is bound to keep happening.Found by code inspection and compile tested only.
v2:
- [patch 1] add to commit msg
- [patch 1] fix arg naming in the header
- [patch 2] don't split the registration check, it may cause a race if we just bail on the registration state and not on the MP being present, as we drop and re-take the instance lock after settingreg_state
v1: https://lore.kernel.org/[email protected]
Quoted 1 line
[...]
Here is the summary with links:
- [net,v2,1/2] net: move mp dev config validation to __net_mp_open_rxq()
https://git.kernel.org/netdev/net/c/ec304b70d46b - [net,v2,2/2] net: avoid false positive warnings in __net_mp_close_rxq() https://git.kernel.org/netdev/net/c/34f71de3f548
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html