Article View: linux.kernel.netdev
Article #3327[PATCH net v4] xsk: freeze deferred pool teardown without blocking unregister
From: James Hilliard
Date: Wed, 14 Oct 2026 18:33
Date: Wed, 14 Oct 2026 18:33
220 lines
16311 bytes
16311 bytes
Deferred pool destruction calls ndo_bpf() under RTNL. system_wq is
not frozen during system sleep, so that callback can run after a
device has suspended and gated its clocks. Use system_freezable_wq
so running destruction finishes before device suspend and new work
waits until process thaw.
Keep assigned pools visible to NETDEV_UNREGISTER independently of
the socket list. A released socket has already left that list, but
its final pool put can queue destruction after workqueues freeze.
A resume-time unregister would then wait for a device reference
whose release cannot run until the resume completes.
Track assigned pools per netdev with netdev operations locking and detach
remaining pools after the notifier socket walk, including copy-mode pools.
This also covers leased queues without scanning pools from unrelated
devices or network namespaces. Remove the entry on assignment failure and
normal teardown. The deferred worker still owns the pool and later observes
the cleared device pointer, avoiding a second driver detach or put.
The lifetime problem was identified by code inspection of the deferred
release and system-sleep paths.
Fixes: 1c1efc2af158 ("xsk: Create and free buffer pool independently from umem")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
---
Assisted-by: Codex:gpt-6-astra
Changes in v4:
- Drop the redundant ASSERT_RTNL() in xp_assign_dev() and the extra
operations-lock assertion in xp_clear_dev_all(), as requested by
Stanislav Fomichev.
- Add the Reviewed-by tags from Björn Töpel and Jason Xing and the
Acked-by tag from Stanislav Fomichev.
- Link to v3: https://patch.msgid.link/20261013-xsk-suspend-teardown-v3-1-2d6be7602947@gmail.com
Changes in v3:
- Protect the per-netdev pool list with netdev operations locking, as
requested by Stanislav Fomichev and Björn Töpel.
- Assert operations locking for copy-mode assignment too, and share a
locked detach helper so unregister holds the lock across the pool walk.
- Rebase onto current net.
- Link to v2: https://patch.msgid.link/20261005-xsk-suspend-teardown-v2-1-2d87228f4329@gmail.com
Changes in v2:
- Track assigned pools per netdev instead of scanning a global pool list.
- Keep deferred releases visible across queue changes and queue leases.
- Rebase onto current net.
- Link to v1: https://patch.msgid.link/20260930-xsk-suspend-teardown-v1-1-a6cac8c030be@gmail.com
---
include/linux/netdevice.h | 5 +++++
include/net/xsk_buff_pool.h | 3 +++
net/xdp/xsk.c | 5 +++++
net/xdp/xsk_buff_pool.c | 46 +++++++++++++++++++++++++++++++++++++--------
4 files changed, 51 insertions(+), 8 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 3cff2174dc03..ac257221c7c5 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2545,6 +2545,11 @@ struct net_device {
/* protected by rtnl_lock */
struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE];
+#ifdef CONFIG_XDP_SOCKETS
+ /** @xsk_pools: assigned AF_XDP pools, ops protected */
+ struct hlist_head xsk_pools;
+#endif
+
u8 dev_addr_shadow[MAX_ADDR_LEN];
netdevice_tracker linkwatch_dev_tracker;
netdevice_tracker watchdog_dev_tracker;
diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h
index a7df573784fd..02e89350faf9 100644
--- a/include/net/xsk_buff_pool.h
+++ b/include/net/xsk_buff_pool.h
@@ -48,6 +48,8 @@ struct xsk_buff_pool {
struct device *dev;
struct net_device *netdev;
struct list_head xsk_tx_list;
+ /* Assigned pools, including deferred releases; ops protected. */
+ struct hlist_node dev_node;
/* Protects modifications to the xsk_tx_list */
spinlock_t xsk_tx_list_lock;
refcount_t users;
@@ -119,6 +121,7 @@ bool xp_put_pool(struct xsk_buff_pool *pool);
void xp_clear_dev(struct xsk_buff_pool *pool);
void xp_add_xsk(struct xsk_buff_pool *pool, struct xdp_sock *xs);
void xp_del_xsk(struct xsk_buff_pool *pool, struct xdp_sock *xs);
+void xp_clear_dev_all(struct net_device *dev);
/* AF_XDP, and XDP core. */
void xp_free(struct xdp_buff_xsk *xskb);
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 33475b180ea6..781ba46eb152 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -2145,6 +2145,11 @@ static int xsk_notifier(struct notifier_block *this,
mutex_unlock(&xs->mutex);
}
mutex_unlock(&net->xdp.lock);
+ /*
+ * A released socket is no longer on xdp.list. Its pool can still
+ * hold a device reference on the frozen release workqueue.
+ */
+ xp_clear_dev_all(dev);
break;
}
return NOTIFY_DONE;
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 9d2d94f1fb75..0ebd4d46f7ab 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -172,7 +172,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
u32 frame_size;
int err = 0;
- ASSERT_RTNL();
+ netdev_assert_locked_ops_compat(netdev);
force_zc = flags & XDP_ZEROCOPY;
force_copy = flags & XDP_COPY;
@@ -204,6 +204,11 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
pool->cached_need_wakeup = XDP_WAKEUP_TX;
dev_hold(netdev);
+ /*
+ * Socket removal precedes the final pool put. Keep the pool visible to
+ * NETDEV_UNREGISTER even while release work is waiting for process thaw.
+ */
+ hlist_add_head(&pool->dev_node, &netdev->xsk_pools);
if (force_copy)
/* For copy-mode, we are done. */
@@ -244,7 +249,6 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
bpf.xsk.pool = pool;
bpf.xsk.queue_id = queue_id;
- netdev_assert_locked_ops_compat(netdev);
err = netdev->netdev_ops->ndo_bpf(netdev, &bpf);
if (err)
goto err_unreg_pool;
@@ -265,6 +269,8 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
err = 0; /* fallback to copy mode */
if (err) {
xsk_clear_pool_at_qid(netdev, queue_id);
+ hlist_del(&pool->dev_node);
+ pool->netdev = NULL;
dev_put(netdev);
}
return err;
@@ -287,19 +293,39 @@ int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_sock *umem_xs,
return xp_assign_dev(pool, dev, queue_id, flags);
}
+static void __xp_clear_dev(struct xsk_buff_pool *pool)
+{
+ struct net_device *netdev = pool->netdev;
+
+ netdev_assert_locked_ops_compat(netdev);
+ xp_disable_drv_zc(pool);
+ xsk_clear_pool_at_qid(netdev, pool->queue_id);
+ hlist_del(&pool->dev_node);
+ pool->netdev = NULL;
+ dev_put(netdev);
+}
+
void xp_clear_dev(struct xsk_buff_pool *pool)
{
struct net_device *netdev = pool->netdev;
- if (!pool->netdev)
+ if (!netdev)
return;
netdev_lock_ops(netdev);
- xp_disable_drv_zc(pool);
- xsk_clear_pool_at_qid(pool->netdev, pool->queue_id);
- pool->netdev = NULL;
+ __xp_clear_dev(pool);
netdev_unlock_ops(netdev);
- dev_put(netdev);
+}
+
+void xp_clear_dev_all(struct net_device *dev)
+{
+ struct xsk_buff_pool *pool;
+ struct hlist_node *next;
+
+ netdev_lock_ops(dev);
+ hlist_for_each_entry_safe(pool, next, &dev->xsk_pools, dev_node)
+ __xp_clear_dev(pool);
+ netdev_unlock_ops(dev);
}
static void xp_release_deferred(struct work_struct *work)
@@ -337,7 +363,11 @@ bool xp_put_pool(struct xsk_buff_pool *pool)
if (refcount_dec_and_test(&pool->users)) {
INIT_WORK(&pool->work, xp_release_deferred);
- schedule_work(&pool->work);
+ /*
+ * Teardown calls ndo_bpf(), which may need powered hardware.
+ * RTNL alone does not exclude the device's system PM callbacks.
+ */
+ queue_work(system_freezable_wq, &pool->work);
return true;
}
---
base-commit: 513444cc62e231a11c9b15ea88de0890da9b2b4f
change-id: 20260930-xsk-suspend-teardown-902f98408c93
Best regards,
--
James Hilliard <james.hilliard1@gmail.com>
Technical Details
Message-ID:
<20261014-xsk-suspend-teardown-v4-1-27795582e4a3@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346401-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346401-linux-kernel-netdev=dewy.ru
From: james.hilliard1@gmail.com (James Hilliard)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v4] xsk: freeze deferred pool teardown without blocking
unregister
Date: Wed, 14 Oct 2026 12:33:48 -0600
Organization: Usenet Network
Message-ID: <20261014-xsk-suspend-teardown-v4-1-27795582e4a3@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2361187"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nQtLw3EaU7Zg/2jNd829D4skOXc= sha256:sHnaZU54lxfNudgadGt/156uGOuMoHDFZKDWVT5IOCU=
sha1:BCQwNiv8W+sOMH1kSV7aV70Mk2E= sha256:ObR/4/JejbYFkDPyi40oJB1/ggWs3BoyroxR7BbN9Ys=
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 644111101A0; Wed, 14 Oct 2026 21:35:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.748
X-Spam-Status: No, score=-0.748 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.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 H-Uw4XzuvRJO;
Wed, 14 Oct 2026 21:35:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-346401-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 5915611018D; Wed, 14 Oct 2026 21:35:39 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by tor.lore.kernel.org (Postfix) with ESMTP id 7B71032186; Wed, 14 Oct 2026 18:34:05 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E76C569F1B;
Wed, 14 Oct 2026 18:34:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PeTdbXt4"
X-Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.52])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6EBC5625EA
for <netdev@vger.kernel.org>; Wed, 14 Oct 2026 18:33:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.52
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792002841; cv=none; b=b1SVNTYQy/nqEsykneWtLmQpxBSgCFv9prKQ9RMoA+YVUQmHdf6Dj55sSl+/h0QUo10D95oVlmfuDcql8pPRTO8WdCWE4cmFcxTyuojxLQMuH+59U6ucxqDviQKQNOpQr+JT7ENz6Sb8RkZ6Wy0k04JQnGGVe2yYHcB+sjUbVcU=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792002841; c=relaxed/simple;
bh=/sDi7HIsx/bYASmJoVclnjRDXtNkZuaHYuJuvQyPZQM=;
h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=WnC2G8XCJP21boFjLLkD0+k/7jFgO1W3dL8kDLZB+f+fBeWRNVHnKIkbEByAcmTgsQp4Sr3EO04wq6SfZj0qQQldywUngQ3NuG40f+oh3gUoHjLHpyvFvQeJxNnWDVp15xK4iufbKkDaK/0dViUZfAuwswqR41cpyzZ1avKolK4=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PeTdbXt4; arc=none smtp.client-ip=209.85.160.52
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-486f013db83so1192195fac.0
for <netdev@vger.kernel.org>; Wed, 14 Oct 2026 11:33:58 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792002837; x=1792607637; darn=vger.kernel.org;
h=cc:to:message-id:content-transfer-encoding:content-type
:mime-version:subject:date:from:from:to:cc:subject:date:message-id
:reply-to:content-type;
bh=8Z2E7pmsMMG7kkmYzB5uMqTLRrXawygd2jz4XpEAkRM=;
b=PeTdbXt4Kdp0lPPTVTEPWXc6A4IA44zQcKj++T9dbsBUwACEYCpBXTAdLEsIRDHsur
FCYouaIH0oXsHwgD5GnVgJis/8+btipTICwz0YdH90BPHFVnPX8PWDdt77XruFZEFH6K
8dZ5cTYvgnJ0ChAA2Q80l+DotAWej41P56QwIFiKDJsSln3IX5zVV6S5E2E9LsUgwdTU
YoU6PH36nzzghs5Ir4ksN/jzZk/E9Ep5Zb65tc0s7JcO66zX+kWpfH0TaQTRmeQhb9J8
zD+fhCON+hrUgGlK3V1bxwtmbLtbMDccQEdYulSgQCRefdQexwnlalTpk4tHlxQ7tXgs
mLHg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792002837; x=1792607637;
h=cc:to:message-id:content-transfer-encoding:content-type
:mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to
:cc:subject:date:message-id:reply-to:content-type;
bh=8Z2E7pmsMMG7kkmYzB5uMqTLRrXawygd2jz4XpEAkRM=;
b=AfdL5JnDOwJwuXdcEWmcea2b4SOJSnkjFG4qTuTDOyzF4TYQUFuA3etID1zGwBS/Ud
FsndQldrEGd9qadzv9kOfuT/Mt8cFFRbHeFCbKV1vf/uwDPl5MPxOiDge+B9pS8oPIMA
DYZsy/lQrdo19uQh8VjtI7rtj1IpN7Cyw3kK+NSIu5wZNgC4/DBWBX8f5qTAHbk5Rc+c
Q7ow2vjUluIwvwyoPOALmJm87qnuyzxo3eQX4THA+A12pHyA3/zQUCrjm7XwMy3u0vZt
bMV5eo3YFAwDMPzBadnTupl0OH+qoHNoFyhgoEqQCIM3NCpM4hr/Uwqc58J9i/h9Yvm7
J6uw==
X-Gm-Message-State: AFq9FYIwvI3tRfPKXqD7HcXFwuENAf3Cl4wSYfpLaHCfOCCiQ5P5BqeP
CvzoZ8AbqgyeA/dIjOURN0yXxujaLHDGeUmTxoe6ZazmKs62h+GSmiAi
X-Gm-Gg: AYBFou3qOkF+ysWjrplV3fFE5KevyuirGjXnjomcTZxBpLYTKpHWWpSnpIe+zyPPc2C
R0MQBVTiQKSh/g9MCvo+qcG1vY7pR3Y4Ga2MsY2Y6FMEtBYnjqPydwzcH0JocZ7Uov+DG/ITWid
QGz5EfJeJDvcOEZvmty0c43sAxeo9qK7kGNuTgakwIvptDaDMjfiawX11XQEZL3EQgEdR6l4Viw
W38jyNh31Ig0YnHtbN6OI0mlQ2P0hqrFzYLIdQAFF5hE1tqrTcpNVkFHJt291y2tKeAUKxPF5yn
L95OWyKu7ApQBP7WnZHKPvviRet5zO2BkKWtM6fuF+LQCFVQl3g9ax3cmXFBFqUvgFGiF26bYOG
M0I7LBPFDwO/YCL7ER8Cyn+3MFQ0/3qPv1wDWmIQ62okED8joSmPP7BisCHu/WsaJhfdX1jTmSA
xMH9FN/2TW1+fqNK3SgUMKcOHzHfITRaCYdHm902SLWoeLmxQ87DDkEd7gTZ/28+sTkVVx/o/g9
7QOriIytdGqQStwd2BCusLMoVMdOeZNWL80cYHFVH53khWrXD0MWlJgE1hj0X31i0EZzPXpi/8L
Bbxqm3yTWfL/Nf668fW14cFKzv7mwqCaaZhnTFe4mlrJW4yO5ocGh9WR2RTHhFnC4E8G87bAekt
AZgrro41T0pQ+ImDBOx4G
X-Received: by 2002:a05:6871:2e81:b0:488:b68c:681a with SMTP id 586e51a60fabf-4a2a88cf33dmr13119867fac.38.1792002837397;
Wed, 14 Oct 2026 11:33:57 -0700 (PDT)
X-Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49])
by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4a6dfbca439sm2609137fac.8.2026.10.14.11.33.54
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 14 Oct 2026 11:33:55 -0700 (PDT)
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-B4-Tracking: v=1; b=H4sIAAAAAAAC/33NQQ7CIBAF0Ks0rMUMQ23BlfcwLpBOlWhpA7XWm
N5dwsIYE13++Zn3nyxScBTZtniyQJOLrvcplKuC2bPxJ+KuSZkhYAVaAp/jhcdbHMg3fCQTmv7
uuQZstSpBWS1Zeh0CtW7O7J55GtkhHc8ujn145KlJ5Oq/OgkuuKmsscqChCPtTp1x17XtuwxO+
EYEwOYHggnBRtWIqi0l6m9EfiBC/kBkRqoj1RWgLutPZFmWF2BgPkxHAQAA
X-Change-ID: 20260930-xsk-suspend-teardown-902f98408c93
X-Cc: bpf@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Björn Töpel <bjorn@kernel.org>,
linux-kernel@vger.kernel.org, Jason Xing <kerneljasonxing@gmail.com>,
James Hilliard <james.hilliard1@gmail.com>
X-Mailer: b4 0.15.2