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=1796385165; b=HhnM1+vmPmFYg5WWscirJM8VMwS+xw8msPy0F3Y3joOoYOwctW8YoYoAqQ9GpczXXyzM K0lNq9o5ZETRUSPhZGz00oCrtf0wVN3wFcgMsq0uFJM+Y6htl4/TqKB8ElDYW3tC/f+Lh iAuVHcHuJGRE3zRiLEALCus2dMfiChNulkR2nwezZl1sVA2ryjilvrPycO+qFPqQauEiM 5JDIPXjHs7W+i8jSQwVzY2g9si3/XC+wZuAbC0edcA7ctaWVl2gYlcZTFFSmaQbCof1H3 ssUs1mhoZogoHwQq6gCk19Yk/Y1lzjk9EjkGcVHo1wKLvN1JasmFcjMDOcAITXqrTAg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385165; 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=pgwBNvAcQNIC6ksvRj8pPw3frffdri58IdDNTrUf8wE=; b=Q/rtak6UuTPAF20ndhPuqx1JQrWhUBm74zCauBl5k5DLGLzg3n28I/EIdiYdStc7Aq0O BGDppWG97oOoYE1CK7BB1hzk+Z5ipX4WGRtNyXrgoNk1012+csJww7LOaGgpqrh/1UFFx 8oQFSFuW7/JFr+zb3tBXzarAvoKemxv+uA2r/36S7ryGUDBVhN3xBCXIlX4lxSGmBxQCH GnPe7CFLQ+iT9gimNZ/nmGtqbT/KFVel5BPH1hQCxBWk1uPefmDRNGgNuPsDEa4MlvyC3 yLb+eRQiHPv84/1LFrjbsX+iMaVwrAUcV58hAJ9c0Au+3eKYPigQrrtHul4BXnp1kJg== 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=jjNsuLx7; 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 40D2B606A32C; Fri, 4 Dec 2026 11:52:44 +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=jjNsuLx7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FE7F1F000C2; Fri, 4 Dec 2026 11:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385164; bh=pgwBNvAcQNIC6ksvRj8pPw3frffdri58IdDNTrUf8wE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jjNsuLx77gyG2NSymPjluFxvmSdvZ9l3LmQsZF734iSc8gJQ1Ee0P8BIHcNP5EY2C dG36VVCaAmi/i8IfrHngXj8uTQkOBaTPQ9q9ShtTPVcqzgrIlTflz3+U8cbez2P4aH iqWgX+NYtORDnmzPCqjjf2FvvpEdTDThaJQPMbdM= 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.6 0444/1167] xsk: freeze deferred pool teardown without blocking unregister Date: Fri, 4 Dec 2026 18:57:51 +0900 Message-ID: <20261204100713.582016162@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev 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.6-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 netdev ops locking calls with RTNL equivalents (ASSERT_RTNL() in the helpers, no lock/unlock pair), since this tree lacks netdev_lock_ops() and relies on RTNL. ] 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 | 44 ++++++++++++++++++++++++++++++++----- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 61f1a64b72293..87f4e1f6e435a 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2431,6 +2431,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 d3a109a79a1d6..67801913fdb27 100644 --- a/include/net/xsk_buff_pool.h +++ b/include/net/xsk_buff_pool.h @@ -47,6 +47,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; @@ -111,6 +113,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 95944ad2eaae6..6fa2320f751c7 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -1618,6 +1618,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 e4261004c2c9d..1395dc3f4640d 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -189,6 +189,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,6 +249,8 @@ int xp_assign_dev(struct xsk_buff_pool *pool, if (err) { pool->umem->flags = umem_flags; xsk_clear_pool_at_qid(netdev, queue_id); + hlist_del(&pool->dev_node); + pool->netdev = NULL; dev_put(netdev); } return err; @@ -270,15 +277,36 @@ int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_sock *umem_xs, return xp_assign_dev(pool, dev, queue_id, flags); } -void xp_clear_dev(struct xsk_buff_pool *pool) +static void __xp_clear_dev(struct xsk_buff_pool *pool) { - if (!pool->netdev) - return; + struct net_device *netdev = pool->netdev; + ASSERT_RTNL(); xp_disable_drv_zc(pool); - xsk_clear_pool_at_qid(pool->netdev, pool->queue_id); - dev_put(pool->netdev); + 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 (!netdev) + return; + + __xp_clear_dev(pool); +} + +void xp_clear_dev_all(struct net_device *dev) +{ + struct xsk_buff_pool *pool; + struct hlist_node *next; + + ASSERT_RTNL(); + 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) @@ -316,7 +344,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