πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25737

[PATCH net v2] net: update RX queue kobjects during device unregistration

#25737
From: Haishuang Yan
Date: Wed, 02 Dec 2026 10:27
87 lines
12826 bytes
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").

Like netdev_queue_update_kobjects(), warn in
net_rx_queue_update_kobjects() if new_num > old_num during
NETREG_UNREGISTERING. Also return -EINVAL there: once
remove_queue_kobjects() has released dev->queues_kset and set
real_num_rx_queues to 0, any later call would add kobjects to the
released kset and take netdev references that are never dropped.
No in-tree caller is known to grow RX queues 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>
---
v2:
  - warn and return -EINVAL in net_rx_queue_update_kobjects() if
    new_num > old_num during NETREG_UNREGISTERING (Sashiko review)
  - add missing BPF/XDP maintainers to Cc (cc_maintainers)
v1: https://lore.kernel.org/netdev/20261129024754.9593-1-yanhaishuang@cmss.chinamobile.com/

The root cause was analyzed with the help of an AI coding assistant.

Testing on x86_64 KVM (net e1055cbfd6eb, KASAN + NET_DEV_REFCNT_TRACKER;
net/core/dev.c and net-sysfs.c are unchanged up to ef3e21c61baa):
- before: unbinding virtio_net with XDP hangs ("Usage count = 2");
- v2: unbind with XDP, without XDP, and with an AF_XDP socket on the XDP
  queue all succeed with no KASAN, WARN or ref_tracker reports;
- W=1 net/core/{dev,net-sysfs}.o clean on x86_64 and arm64;
- not tested: the new grow-during-unregister guard itself (no in-tree
  caller reaches it), other drivers, CONFIG_SYSFS=n.

 net/core/dev.c       | 3 ++-
 net/core/net-sysfs.c | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index cd0796a1dbfdf..09047ae78da76 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,
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 5c0402389c6d1..69e9966069b1f 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1328,6 +1328,14 @@ net_rx_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)
 	int i;
 	int error = 0;
 
+	/* Rx queue kobjects are allowed to be updated when a device is being
+	 * unregistered, but solely to remove queues. Any path adding queues
+	 * should be fixed.
+	 */
+	if (WARN(dev->reg_state == NETREG_UNREGISTERING && new_num > old_num,
+		 "New queues can't be registered after device unregistration."))
+		return -EINVAL;
+
 #ifndef CONFIG_RPS
 	if (!dev->sysfs_rx_queue_group)
 		return 0;

base-commit: ef3e21c61baa74e39a49b75318bd4541562ec43f
-- 
2.43.0
Technical Details
Message-ID: <20261202102744.31020-1-yanhaishuang@cmss.chinamobile.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375721-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375721-linux-kernel-netdev=dewy.ru
From: yanhaishuang@cmss.chinamobile.com (Haishuang Yan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] net: update RX queue kobjects during device unregistration
Date: Wed,  2 Dec 2026 02:27:44 -0800
Organization: Usenet Network
Message-ID: <20261202102744.31020-1-yanhaishuang@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1948401"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:d+nLuKe5+z+izWKAdbECuu+AbvQ= sha256:b0KH8OFt8hh+M9Yj3vfyY7mB5OdxzN91PNlftI4hxok=
	sha1:vN2aTuPqUenZvlkKu9fdfybpC7c= sha256:PPOnOklDWPYZQ+XBbpRcAsBenAAxcieVbQ5Dr9xaA0E=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id A30481175FA; Wed,  2 Dec 2026 13:28:45 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.85
X-Spam-Status: No, score=-2.85 tagged_above=-9999 required=6.31
	tests=[DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key)
	reason="fail (body has been altered)" header.d=cmss.chinamobile.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id mQPB0BsGJy9F;
	Wed,  2 Dec 2026 13:28:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375721-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id CD1A71175F5; Wed,  2 Dec 2026 13:28:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 61FD62A819; Wed,  2 Dec 2026 10:28:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796207308;
	b=Tuu4R8n8pHQfNzq4P58A92HZQtppIhEy/0qYMRtBE60t4hrAl5ctAAEInpaVqy6DGqgG
	 kgHcJkQeFxBKPo1DnGsuXZb+uGSDfoWaJoBoSfi/c1u3xozGjZD92h6DE5Oo740+qeP95
	 qODfib9HpnhZTBEC2NlWeON9IewdH4K2nqANoqFwGgn0/750PM4KzDeqaAUHutDv2VMOm
	 3WGtG3YSj0pB2VdamX6ynu79XtWQtnU0l0ErpCjwDGdlsoNCSzhqPhRMLTG8R0Jv8a41T
	 vcu1s4OrYQIGnVOlDkrX/MuMiyJ/UATG2ImKYqNuIolFP0okGSww2LI081NyZDvi+sg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796207308;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo:
	 X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:
	 Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=tAXBbEUBG+DGl5h6UgA/k0yEnFvEpuwCjVWpH/tSfQg=;
	b=E3A+luQlldFErMMJMY8VG3wam7zZNotZNhJCD59iSZIsu3QF4l803WczfEqQSyxb6lYv
	 9I64GIACXjYHB/cAd5nKaDqg2XYf9pVdltK4/UlrpntGsHkVdM2a5yBKNpbnVHvf8l+M6
	 Ay9FTbWn51Ot8p6FYMdFJ1jFj/NjZ54dJ6/tlSsOMFqoEtXlDE8ScWE3ISCoZJ9mbUVh9
	 06fmRkf77K6c10pyy9bzJ2AKF8jjSlsuifys0VqfkBcyS3jVHJlj3xEdZ//vqfEFRV9m8
	 Hz/SVsW7+KJUJDOtdWLl8oQKVz7eb3dO3HYT8tcaeNIeSx8cx2WOK5im1zZE4gjRUzA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=OmMqHldA;
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 83B57606A33D;
	Wed,  2 Dec 2026 10:28:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=OmMqHldA
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.137
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796207297;
	b=WKuofN8knMrbmP6CdrO1ti0APAT/abrHYWOnR0Gw3BDERr2EiPSDyO45G/BZI/xgibwo
	 tOFiLFdfcR/3UlPjMeEw9CK/eu1Z+LhRRn4JoDr7EKpGrMifrTMlPgdyZq0xlHowIRS7J
	 7jeG21drXFMwCSAJILbEFRlVNzQPiRCfLBSIoLKuJPLyPGiXJHIzKTEj0OvXNjK4Z7bvJ
	 kQdCQlwt/9wmiNdLXnxAUg5UC2zpS79wjgCSaAN24xxZW/BepZUCO4U+hLaicJx5cK/oq
	 gysunwPuaKvzg2SOraV9qYPk4hchRhl/Oi1jhUUszkE9wVo5KYZVh5N4bNNtgyMCIwQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796207297;
	h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:
	 X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From:
	 To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
	 Content-Transfer-Encoding;
	bh=tAXBbEUBG+DGl5h6UgA/k0yEnFvEpuwCjVWpH/tSfQg=;
	b=rrSjlwvBj/NT7uQqXxwQoFnEM0gSbFD9nLSpcCUfpkxoQ8infsceZbI/II8cNXiPUNBh
	 ODI8V0b03kYEpW8Wfr9QgYrIWzzjhcxhC/q0pQ+Ra+H+pX8cUzac9VHn1xfAjtGT1bWu1
	 x+lwUGxYuE7xcPmUcJeGFni9bOam9hHBYcsqnIU4l0jelhJjBceQY19ev2gP7D59KSlGT
	 TdvulFGmVHl6SRHdf+oERLKzaZwzd0pDzsnIlgIQIkSmhzovC3LJ44jrkHFcWKOSGA4ev
	 oUmcaTgYZBhEGRX7ZuzgBWU1Ktbb0w4ElTRV72+CngYyjbhw2Zy+CEFnhAizyB5xIbg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=OmMqHldA;
	arc=none smtp.remote-ip=111.22.67.137
X-Received: from cmccmta4.chinamobile.com (cmccmta4.chinamobile.com [111.22.67.137])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 29D5E606A31A;
	Wed,  2 Dec 2026 10:28:15 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 29D5E606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=cmss.chinamobile.com; s=default; l=0;
	h=from:subject:message-id:to:cc:mime-version;
	bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
	b=OmMqHldAX5dIoDzpgnB2QJy4r8nEVWlTlfetA2IJAKm6m8tM6TUQifV54p7s08GMDard8+7RgZwDC
	 MgdAImK/qi8cNmuYvqMGWaOk2K5ZzGZ/itkoVBe5JNKp4LcVkWLmWY0k4PTcK9/XOWW8gjbclMkh+p
	 dd/WMx49j93ZQp2s=
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87])
	by rmmx-syy-dmz-app08-12008 (RichMail) with SMTP id 2ee86b0ff2b8f97-30d93;
	Wed, 02 Dec 2026 18:28:08 +0800 (CST)
X-RM-TRANSID: 2ee86b0ff2b8f97-30d93
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from openEuler-24.03.03 (unknown[104.224.130.48])
	by rmsmtp-syy-appsvr08-12008 (RichMail) with SMTP id 2ee86b0ff2a10f2-42dcd;
	Wed, 02 Dec 2026 18:28:08 +0800 (CST)
X-RM-TRANSID: 2ee86b0ff2a10f2-42dcd
X-Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Quentin Monnet <qmo@kernel.org>,
	Martin Karsten <mkarsten@uwaterloo.ca>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowangio@gmail.com>,
	Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
	Eugenio PΓ©rez <eperezma@redhat.com>,
	virtualization@lists.linux.dev,
	bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.43.0
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list