From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387959; b=mBvi2SJPbbjbAVCzFcYlKrje/i9XRsU9G3jyWFiu9rE2WEDsR3dTlDF+2KnD3ayddfkd zwwBx/aTvot8jzG4jeJun5ougCjydj9XrnsWpZBZjbWEJJfv50tSH6iwg8iOViPXVgUja azQqSmL+H4lOXbLfvKT14ZvdAVwUdxxJh1lpKOx1bEb6ke8gT0a2+O4qahvKKd3euMT4i qtdCv9CU+2jRf2cXHz9UfpWYYDbzhmvBFsMpTjG7ouYw8su2V32alb0cH4zOT6hxqsf3t 1I6ItypujGFlICXERzc5pJVHIg1Mnie0vnesjZqfNtb4kPmCNui758eUP21ABhiAVKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387959; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=SyJkPI6wTp0C/8fQM2EJjz6QR1uGFJUmmODSNesqTHo=; b=WfdfGkIQctm/gWUGYFrcPHFxRuhdwghs3o1+nd+z1po90ebT2VH9eztlwcnPNKMIlR2N YjkFEY1/05vQ0CXSrnlzjH2N9g+IzHDMSgXhcZeoO2lISe6Xnc8bpzsfvFjWiJCtVyAYs iG9Bh3DaTKZylni0FbPzuT6IwHtLiFzBN60QhYSHMvApDpS9fTPVGJa6FfckVQ1PRi36i aY/x3MUftjpPGQRBYr0uQit3I6mphWTiNrXDQ57yMlKk7I+QiEWjEn7hb9ThKMjGfXlGG Jwl1fay8mCcFjXZY91YvbF2kIAMApP+9D5t78834wRHFJe/hTK43j6wZyH9Sh1BAWgA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bguksKZQ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 624FC606A33C; Fri, 4 Dec 2026 12:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bguksKZQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81D0B1F00897; Fri, 4 Dec 2026 12:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387958; bh=SyJkPI6wTp0C/8fQM2EJjz6QR1uGFJUmmODSNesqTHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bguksKZQm8C/b+ICGMx3eULtc0eWWg9HpFtbRbuPv6ls3IpaHtIyFzwqUCQ22o4wj jruoZuPiaOJucWpp6dOeMO9u9pOAN4fsQY2V2UZ48BfcUIjpKwiMs0fvqhi2I2YoVt zgzw3mw0isRRf7lj00eseXfE3PpiyXFc70GHNH4A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, James Hilliard , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Jason Xing , Stanislav Fomichev , Paolo Abeni , Sasha Levin Subject: [PATCH 6.1 0428/1059] xsk: freeze deferred pool teardown without blocking unregister Date: Fri, 4 Dec 2026 18:59:19 +0900 Message-ID: <20261204100655.412504332@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: James Hilliard [ Upstream commit fece8420e76fe53ee84f0439f18d026b4c7641da ] 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 Reviewed-by: Björn Töpel Reviewed-by: Jason Xing Acked-by: Stanislav Fomichev Link: https://patch.msgid.link/20261014-xsk-suspend-teardown-v4-1-27795582e4a3@gmail.com Signed-off-by: Paolo Abeni [ sashal: Replaced the missing ops-lock helpers by using ASSERT_RTNL() for the assertions and dropping the netdev_lock_ops()/netdev_unlock_ops() calls, since RTNL already protects these paths. ] Signed-off-by: Sasha Levin --- include/linux/netdevice.h | 5 +++++ include/net/xsk_buff_pool.h | 3 +++ net/xdp/xsk.c | 5 +++++ net/xdp/xsk_buff_pool.c | 39 ++++++++++++++++++++++++++++++++----- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 683896a9af446..d563eb164d295 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2377,6 +2377,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 e436363c21922..0139d6f35193c 100644 --- a/include/net/xsk_buff_pool.h +++ b/include/net/xsk_buff_pool.h @@ -43,6 +43,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; @@ -106,6 +108,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 e55e153377c82..44115a24c69f2 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -1370,6 +1370,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 b2004a8bf67fc..39d2bc1657142 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -174,6 +174,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. */ @@ -208,6 +213,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; @@ -230,15 +237,33 @@ 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; + + ASSERT_RTNL(); + 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) { if (!pool->netdev) return; - xp_disable_drv_zc(pool); - xsk_clear_pool_at_qid(pool->netdev, pool->queue_id); - dev_put(pool->netdev); - pool->netdev = NULL; + __xp_clear_dev(pool); +} + +void xp_clear_dev_all(struct net_device *dev) +{ + struct xsk_buff_pool *pool; + struct hlist_node *next; + + hlist_for_each_entry_safe(pool, next, &dev->xsk_pools, dev_node) + __xp_clear_dev(pool); } static void xp_release_deferred(struct work_struct *work) @@ -276,7 +301,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; } -- 2.53.0