Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH net] net: update RX queue kobjects during device unregistration
@ 2026-11-29  2:47 Haishuang Yan
  2026-11-29  2:57 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Haishuang Yan @ 2026-11-29  2:47 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Kuniyuki Iwashima,
	Stanislav Fomichev, Alexei Starovoitov, Martin Karsten,
	Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez,
	virtualization, linux-kernel

When unregister_netdevice_many_notify() sets NETREG_UNREGISTERING and
calls dev_xdp_uninstall(), a driver that shrinks real_num_rx_queues
(such as virtio_net) hits netif_set_real_num_rx_queues(). Because it
only checks NETREG_REGISTERED, it skips net_rx_queue_update_kobjects()
while still lowering dev->real_num_rx_queues. remove_queue_kobjects()
then leaks the extra RX queue kobjects and their netdev references,
hanging unregister with "waiting for eth0 to become free. Usage count
= 2".

Update RX queue kobjects under NETREG_UNREGISTERING too, matching
netif_set_real_num_tx_queues() from
commit 5c56580b74e5 ("net: Adjust TX queue kobjects if number of queues
changes during unregister").

Found and verified by unbinding virtio_net with XDP attached in an
x86_64 KVM guest (KASAN + NET_DEV_REFCNT_TRACKER).

Fixes: bd0b2e7fe611 ("net: xdp: make the stack take care of the tear down")
Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
---
The root cause was analyzed with the help of an AI coding assistant.

Tested on x86_64 KVM (net e1055cbfd6eb, KASAN + NET_DEV_REFCNT_TRACKER):
- before: unbinding virtio_net with XDP hangs ("Usage count = 2");
- after: unbind with/without XDP and with AF_XDP socket on XDP queue
  all succeed cleanly; W=1 net/core/dev.o clean;
- not tested: other drivers, CONFIG_SYSFS=n, non-x86_64.

 net/core/dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index cd0796a1dbf..09047ae78da 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3341,7 +3341,8 @@ int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq)
 	if (rxq < 1 || rxq > dev->num_rx_queues)
 		return -EINVAL;
 
-	if (dev->reg_state == NETREG_REGISTERED) {
+	if (dev->reg_state == NETREG_REGISTERED ||
+	    dev->reg_state == NETREG_UNREGISTERING) {
 		netdev_assert_locked_ops_compat(dev);
 
 		rc = net_rx_queue_update_kobjects(dev, dev->real_num_rx_queues,

base-commit: e1055cbfd6eb578417f3ce983cf44462e8465267
-- 
2.43.0




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: update RX queue kobjects during device unregistration
  2026-11-29  2:47 [PATCH net] net: update RX queue kobjects during device unregistration Haishuang Yan
@ 2026-11-29  2:57 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29  2:57 UTC (permalink / raw)
  To: Haishuang Yan; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

> When unregister_netdevice_many_notify() sets NETREG_UNREGISTERING and
> calls dev_xdp_uninstall(), a driver that shrinks real_num_rx_queues
> (such as virtio_net) hits netif_set_real_num_rx_queues(). Because it
> only checks NETREG_REGISTERED, it skips net_rx_queue_update_kobjects()
> while still lowering dev->real_num_rx_queues. remove_queue_kobjects()
> then leaks the extra RX queue kobjects and their netdev references,
> hanging unregister with "waiting for eth0 to become free. Usage count
> = 2".
> 
> Update RX queue kobjects under NETREG_UNREGISTERING too, matching
> netif_set_real_num_tx_queues() from
> commit 5c56580b74e5 ("net: Adjust TX queue kobjects if number of queues
> changes during unregister").
> 
> Found and verified by unbinding virtio_net with XDP attached in an
> x86_64 KVM guest (KASAN + NET_DEV_REFCNT_TRACKER).
> 
> Fixes: bd0b2e7fe611 ("net: xdp: make the stack take care of the tear down")
> Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129024754.9593-1-yanhaishuang@cmss.chinamobile.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29  2:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  2:47 [PATCH net] net: update RX queue kobjects during device unregistration Haishuang Yan
2026-11-29  2:57 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox