Skip to contentSkip to conversation

net: make memory provider install / close paths more common

PATCH Superseded Jakub Kicinski 5 participants 13 messages Mar 31, 2025 – Apr 3, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

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.

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              | 66 ++++++++++++++++++-------
 4 files changed, 69 insertions(+), 73 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 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.

Fixes 6e18ed929d3b ("net: add helpers for setting a memory provider on an rx queue")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [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
index b3e665897767..3724ac3c9fb2 100644
@@ -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 ifq_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 ifq_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
index fd1cfa9707dc..8ad4a944f368 100644
@@ -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
author maintainer
#7 lore raw

PATCH 2/2 net: avoid false positive warnings in __net_mp_close_rxq()

In reply to 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 by io_uring was 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()")
---
 net/core/devmem.c          | 12 +++++-------
 net/core/netdev_rx_queue.c | 17 +++++++++--------
 2 files changed, 14 insertions(+), 15 deletions(-)
net/core/devmem.c +5 -7
index f2ce3c2ebc97..6e27a47d0493 100644
@@ -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 +9 -8
index 556b5393ec9f..3e906c2950bd 100644
@@ -154,17 +154,13 @@ 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;
 
 	rxq = __netif_get_rx_queue(dev, ifq_idx);
-
-	/* Callers holding a netdev ref may get here after we already
-	 * went thru shutdown via dev_memory_provider_uninstall().
-	 */
-	if (dev->reg_state > NETREG_REGISTERED &&
-	    !rxq->mp_params.mp_ops)
+	if (!rxq->mp_params.mp_ops)
 		return;
 
 	if (WARN_ON_ONCE(rxq->mp_params.mp_ops != old_p->mp_ops ||
@@ -173,13 +169,18 @@ 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,
 		      struct pp_memory_provider_params *old_p)
 {
 	netdev_lock(dev);
-	__net_mp_close_rxq(dev, ifq_idx, old_p);
+	/* Callers holding a netdev ref may get here after we already
+	 * went thru shutdown via dev_memory_provider_uninstall().
+	 */
+	if (dev->reg_state <= NETREG_REGISTERED)
+		__net_mp_close_rxq(dev, ifq_idx, old_p);
 	netdev_unlock(dev);
 }
Signature · 1 line
2.49.0
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH net 1/2] net: move mp dev config validation to __net_mp_open_rxq()

In reply to Jakub Kicinski
Quoted 36 lines · Jakub Kicinski

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.

Fixes 6e18ed929d3b ("net: add helpers for setting a memory provider on an rx queue")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [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 +1 -0
index b3e665897767..3724ac3c9fb2 100644
@@ -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 {

include/net/page_pool/memory_provider.h void net_mp_niov_clear_page_pool(struct net_iov *niov); · line 30

Quoted 6 lines
include/net/page_pool/memory_provider.h +3 -0
@@ -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 ifq_idx,
+		      const struct pp_memory_provider_params *p,
+		      struct netlink_ext_ack *extack);

Nit: you keep using ifq_idx here, but in the .c file you rename it to rxq_idx. Not worth the respin..

Acked-by on v1 2/2
#8 lore raw

Re: [PATCH net 2/2] net: avoid false positive warnings in __net_mp_close_rxq()

In reply to Jakub Kicinski
Quoted 7 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 by io_uring was 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()")
#3 lore raw

Re: [PATCH net 1/2] net: move mp dev config validation to __net_mp_open_rxq()

In reply to Jakub Kicinski
Quoted 7 lines · Jakub Kicinski

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.

Looks good, one question below

...

Quoted 5 lines
net/core/devmem.c +0 -0
index ee145a2aa41c..f2ce3c2ebc97 100644
@@ -8,7 +8,6 @@

...

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 155

Quoted 6 lines
net/core/devmem.c +1 -3
-
-	err = xa_alloc(&binding->bound_rxqs, &xa_idx, rxq, xa_limit_32b,
-		       GFP_KERNEL);
+	err = __net_mp_open_rxq(dev, rxq_idx, &mp_params, extack);
  	if (err)
  		return err;

Was reversing the order b/w open and xa_alloc intentional? It didn't need __net_mp_close_rxq() before, which is a good thing considering the error handling in __net_mp_close_rxq is a bit flaky (i.e. the WARN_ON at the end).

Quoted 23 lines
net/core/devmem.c +6 -10
-	rxq->mp_params.mp_priv = binding;
-	rxq->mp_params.mp_ops = &dmabuf_devmem_ops;
-
-	err = netdev_rx_queue_restart(dev, rxq_idx);
+	rxq = __netif_get_rx_queue(dev, rxq_idx);
+	err = xa_alloc(&binding->bound_rxqs, &xa_idx, rxq, xa_limit_32b,
+		       GFP_KERNEL);
  	if (err)
-		goto err_xa_erase;
+		goto err_close_rxq;
 
  	return 0;
 
-err_xa_erase:
-	rxq->mp_params.mp_priv = NULL;
-	rxq->mp_params.mp_ops = NULL;
-	xa_erase(&binding->bound_rxqs, xa_idx);
-
+err_close_rxq:
+	__net_mp_close_rxq(dev, rxq_idx, &mp_params);
  	return err;
  }
Signature · 1 line
Pavel Begunkov
author maintainer
#4 lore raw

Re: [PATCH net 1/2] net: move mp dev config validation to __net_mp_open_rxq()

Quoted 10 lines · On Tue, 1 Apr 2025 12:37:34 +0100 Pavel Begunkov wrote:

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 155

Quoted 5 lines
net/core/devmem.c +1 -2
-	err = xa_alloc(&binding->bound_rxqs, &xa_idx, rxq, xa_limit_32b,
-		       GFP_KERNEL);
+	err = __net_mp_open_rxq(dev, rxq_idx, &mp_params, extack);
  	if (err)
  		return err;  

Was reversing the order b/w open and xa_alloc intentional? It didn't need __net_mp_close_rxq() before, which is a good thing considering the error handling in __net_mp_close_rxq is a bit flaky (i.e. the WARN_ON at the end).

Should have mentioned.. yes, intentional, otherwise we'd either have to insert a potentially invalid rxq pointer into the xarray or duplicate the rxq bounds check. Inserting invalid pointer and deleting it immediately should be okay, since readers take the instance lock, but felt a little dirty. In practice xa_alloc() failures should be extremely rare here so I went with the reorder.

#5 lore raw

Re: [PATCH net 1/2] net: move mp dev config validation to __net_mp_open_rxq()

Quoted 12 lines · Jakub Kicinski
Quoted 10 lines · On Tue, 1 Apr 2025 12:37:34 +0100 Pavel Begunkov wrote:

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 155

Quoted 5 lines
net/core/devmem.c +1 -2
-	err = xa_alloc(&binding->bound_rxqs, &xa_idx, rxq, xa_limit_32b,
-		       GFP_KERNEL);
+	err = __net_mp_open_rxq(dev, rxq_idx, &mp_params, extack);
   	if (err)
   		return err;

Was reversing the order b/w open and xa_alloc intentional? It didn't need __net_mp_close_rxq() before, which is a good thing considering the error handling in __net_mp_close_rxq is a bit flaky (i.e. the WARN_ON at the end).

Quoted 6 lines

Should have mentioned.. yes, intentional, otherwise we'd either have to insert a potentially invalid rxq pointer into the xarray or duplicate the rxq bounds check. Inserting invalid pointer and deleting it immediately should be okay, since readers take the instance lock, but felt a little dirty. In practice xa_alloc() failures should be extremely rare here so I went with the reorder.

I see, sgtm

Signature · 1 line
Pavel Begunkov
#12 lore raw
In reply to Jakub Kicinski
Quoted 1 line · Jakub Kicinski

Hi Jakub,
Thanks a lot for this fix!

Quoted 5 lines

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.

I tested this patchset with my RFC[1].
This works well, and I can't see any splat by kmemleak, lockdep, etc.

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

Thanks a lot!
Taehee Yoo

Quoted 14 lines

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              | 66 ++++++++++++++++++-------
 4 files changed, 69 insertions(+), 73 deletions(-)

--
2.49.0

Reviewed-by
#6 lore raw

Re: [PATCH net 1/2] net: move mp dev config validation to __net_mp_open_rxq()

In reply to Jakub Kicinski
Quoted 13 lines · Jakub Kicinski
Quoted 10 lines · On Tue, 1 Apr 2025 12:37:34 +0100 Pavel Begunkov wrote:

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 155

Quoted 5 lines
net/core/devmem.c +1 -2
-   err = xa_alloc(&binding->bound_rxqs, &xa_idx, rxq, xa_limit_32b,
-                  GFP_KERNEL);
+   err = __net_mp_open_rxq(dev, rxq_idx, &mp_params, extack);
    if (err)
            return err;

Was reversing the order b/w open and xa_alloc intentional? It didn't need __net_mp_close_rxq() before, which is a good thing considering the error handling in __net_mp_close_rxq is a bit flaky (i.e. the WARN_ON at the end).

Quoted 6 lines

Should have mentioned.. yes, intentional, otherwise we'd either have to insert a potentially invalid rxq pointer into the xarray or duplicate the rxq bounds check. Inserting invalid pointer and deleting it immediately should be okay, since readers take the instance lock, but felt a little dirty. In practice xa_alloc() failures should be extremely rare here so I went with the reorder.

FWIW yes I imagine accessors of binding->bound_rxqs should all have binding->dev locked at that point (and rtnl_locked before the locking changes), and I preferred the other order just because restarting the queue seemed like a heavy operation with all the ndos it calls, even if it doesn't hit the WARN_ON.

But the error path should be rare anyway, and I think that works too. I could not find other issues in the patch.

Signature · 2 lines
Thanks,
Mina
#9 lore raw

Re: [PATCH net 2/2] net: avoid false positive warnings in __net_mp_close_rxq()

In reply to Jakub Kicinski
Quoted 77 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 by io_uring was 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()")
---
 net/core/devmem.c          | 12 +++++-------
 net/core/netdev_rx_queue.c | 17 +++++++++--------
 2 files changed, 14 insertions(+), 15 deletions(-)
net/core/devmem.c +5 -7
index f2ce3c2ebc97..6e27a47d0493 100644
@@ -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 +4 -7
index 556b5393ec9f..3e906c2950bd 100644
@@ -154,17 +154,13 @@ 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;
 
        rxq = __netif_get_rx_queue(dev, ifq_idx);
-
-       /* Callers holding a netdev ref may get here after we already
-        * went thru shutdown via dev_memory_provider_uninstall().
-        */
-       if (dev->reg_state > NETREG_REGISTERED &&
-           !rxq->mp_params.mp_ops)
+       if (!rxq->mp_params.mp_ops)
                return;
 
        if (WARN_ON_ONCE(rxq->mp_params.mp_ops != old_p->mp_ops ||
@@ -173,13 +169,18 @@ 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);
 }
 

net/core/netdev_rx_queue.c void __net_mp_close_rxq(struct net_device *dev, unsigned int ifq_idx, · line 184

Quoted 10 lines
net/core/netdev_rx_queue.c +5 -1
 void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx,
                      struct pp_memory_provider_params *old_p)
 {
        netdev_lock(dev);
-       __net_mp_close_rxq(dev, ifq_idx, old_p);
+       /* Callers holding a netdev ref may get here after we already
+        * went thru shutdown via dev_memory_provider_uninstall().
+        */
+       if (dev->reg_state <= NETREG_REGISTERED)
+               __net_mp_close_rxq(dev, ifq_idx, old_p);

Not obvious to me why this check was moved. Do you expect to call __net_mp_close_rxq on an unregistered netdev and expect it to succeed in io_uring binding or something?

Signature · 2 lines
Thanks,
Mina
author maintainer
#10 lore raw

Re: [PATCH net 2/2] net: avoid false positive warnings in __net_mp_close_rxq()

Quoted 11 lines · On Wed, 2 Apr 2025 11:52:50 -0700 Mina Almasry wrote:

Review

Quoted 7 lines
        netdev_lock(dev);
(quoted diff) +5 -1
-       __net_mp_close_rxq(dev, ifq_idx, old_p);
+       /* Callers holding a netdev ref may get here after we already
+        * went thru shutdown via dev_memory_provider_uninstall().
+        */
+       if (dev->reg_state <= NETREG_REGISTERED)
+               __net_mp_close_rxq(dev, ifq_idx, old_p);  

Not obvious to me why this check was moved. Do you expect to call __net_mp_close_rxq on an unregistered netdev and expect it to succeed in io_uring binding or something?

Yes, iouring state is under spin lock it can't call in here atomically. device unregister may race with iouring shutdown.

Now that I look at it I think we need

net/core/dev.c +1 -1
index be17e0660144..0a70080a1209 100644
@@ -11947,6 +11947,7 @@ void unregister_netdevice_many_notify(struct list_head *head,
                unlist_netdevice(dev);
                netdev_lock(dev);
                WRITE_ONCE(dev->reg_state, NETREG_UNREGISTERING);
+               dev_memory_provider_uninstall(dev);
                netdev_unlock(dev);
        }
        flush_all_backlogs();
@@ -11961,7 +11962,6 @@ void unregister_netdevice_many_notify(struct list_head *head,
                dev_tcx_uninstall(dev);
                netdev_lock_ops(dev);
                dev_xdp_uninstall(dev);
-               dev_memory_provider_uninstall(dev);
                netdev_unlock_ops(dev);
                bpf_dev_bound_netdev_unregister(dev);
 

since 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations") we drop the lock after setting UNREGISTERING so we may call .uninstall after iouring torn down its side.

Right, Stan?

author maintainer
#11 lore raw

Re: [PATCH net 2/2] net: avoid false positive warnings in __net_mp_close_rxq()

Quoted 42 lines · On Wed, 2 Apr 2025 16:24:28 -0700 Jakub Kicinski wrote:
Quoted 11 lines · On Wed, 2 Apr 2025 11:52:50 -0700 Mina Almasry wrote:

Review

Quoted 7 lines
        netdev_lock(dev);
(quoted diff) +5 -1
-       __net_mp_close_rxq(dev, ifq_idx, old_p);
+       /* Callers holding a netdev ref may get here after we already
+        * went thru shutdown via dev_memory_provider_uninstall().
+        */
+       if (dev->reg_state <= NETREG_REGISTERED)
+               __net_mp_close_rxq(dev, ifq_idx, old_p);    

Not obvious to me why this check was moved. Do you expect to call __net_mp_close_rxq on an unregistered netdev and expect it to succeed in io_uring binding or something?

Yes, iouring state is under spin lock it can't call in here atomically. device unregister may race with iouring shutdown.

Now that I look at it I think we need

net/core/dev.c +1 -1
index be17e0660144..0a70080a1209 100644
@@ -11947,6 +11947,7 @@ void unregister_netdevice_many_notify(struct list_head *head,
                unlist_netdevice(dev);
                netdev_lock(dev);
                WRITE_ONCE(dev->reg_state, NETREG_UNREGISTERING);
+               dev_memory_provider_uninstall(dev);
                netdev_unlock(dev);
        }
        flush_all_backlogs();
@@ -11961,7 +11962,6 @@ void unregister_netdevice_many_notify(struct list_head *head,
                dev_tcx_uninstall(dev);
                netdev_lock_ops(dev);
                dev_xdp_uninstall(dev);
-               dev_memory_provider_uninstall(dev);
                netdev_unlock_ops(dev);
                bpf_dev_bound_netdev_unregister(dev);
 

since 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations") we drop the lock after setting UNREGISTERING so we may call .uninstall after iouring torn down its side.

Quoted 1 line

Right, Stan?

Actually, if I don't split the check here things will just work. Let me do that in v2. Thanks for flagging!