From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0135C98318 for ; Thu, 24 Sep 2026 17:45:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=f1PwaHwj9rfBVEy3YdGHV1C8wVDTJmsR2WRPtw2545g=; b=06yOn6mQGbuUQmSqCng52TOHRH jz+pjnNYXt46mQ2dFpziVPAvMHIEZhx/o+a7l4K2QzgKnUeJct7daaXMm+R9SHKeC9olJ1uClBHaL Cjg9lTx+rFENPUUBzksNVO3ArZCaMCtGFhYp5t5jMNol24YGbYcjG3J0jF+5U9++FQaUoAeOnKNYW AwxLioLGlXsplzza7emq4CpboptixcT88l+GGghJd0urt1up0YgvdXHJpX4b+gl+rVe0J+5XDbBLl Cta30jQllPTMK9ETP1aM0aTK+3SC6IG5NVEISJ0UJgH9BCLxxKwKHkgGSlJV/IZ8vv9krVlKq91PW B1tfqoIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x9nVj-0000000BoiF-1Uyi; Thu, 24 Sep 2026 17:45:31 +0000 Received: from mail-oa2-x10.google.com ([2607:f8b0:4864:30::10]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x9nV4-0000000BoMh-1KQX for linux-arm-kernel@lists.infradead.org; Thu, 24 Sep 2026 17:44:51 +0000 Received: by mail-oa2-x10.google.com with SMTP id 586e51a60fabf-47b5043f191so90827fac.3 for ; Thu, 24 Sep 2026 10:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790271889; x=1790876689; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=f1PwaHwj9rfBVEy3YdGHV1C8wVDTJmsR2WRPtw2545g=; b=AwKf5AUoVae1sbN4hP+tNCwMR/dDJf840Nxw26yMNM+fRxMZeIliGNKLAn3tv3TvYb o4FgI691YUu2zlWSwYcddlIqBWoTAKhN2TfoHKB2kBwEvVZ/Axi2I+jsOrLj0zDjjTTc H5ou9bLAkEtmboDVpyODXbFpSopQ1Scu0BPkn5ckEOT/pnr89k9vKgPAVIyKFYvPkomZ 960U8bL12V3qLkhmAx0a9QB3vMa9UZVNphIQ0nMouSWAAafWR691QNAnSgCe3F7nVQVm zj0woUHai3917/j5cns5TKBFfjNcxQE3k4AmoB6A1maW/GmHztqDD9zFbjgWkBi0iCu1 /hDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790271889; x=1790876689; h=cc:to:in-reply-to:references: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=f1PwaHwj9rfBVEy3YdGHV1C8wVDTJmsR2WRPtw2545g=; b=dmR3PqP14iAa6eruI77W7WupVxI7GF5jZ6K3QqrFXJ9kC7N4+9VymSDdbmGKAo5ISp +7iFfv/YKKvvd93VN9GahRUGrzjGZOr4QO7OA1xZR/J0k2+kDeC+AzGziyteMGqEiNGP oJ6j0Krh6re4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Bh4SCAj4iooatnYCwMKyXb71COTpcqRZ0zRWqT4tiZ2L/PDYIhYIod0CT2lAGscnk4 PyRAPoc8S3uT/QaILlQtF4A== X-Received: by 2002:a05:6870:46a4:b0:485:d1ab:7936 with SMTP id 586e51a60fabf-491e517f415mr3158477fac.23.1790271889262; Thu, 24 Sep 2026 10:44:49 -0700 (PDT) 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-491e8f8d14asm3027802fac.0.2026.09.24.10.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 10:44:48 -0700 (PDT) From: James Hilliard Date: Thu, 24 Sep 2026 11:44:38 -0600 Subject: [PATCH net v3 08/10] net: stmmac: use the tracked datapath restart for XSK pool changes MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260924-submit-stmmac-reset-fixes-v1-v3-8-c031e3f3a282@gmail.com> References: <20260924-submit-stmmac-reset-fixes-v1-v3-0-c031e3f3a282@gmail.com> In-Reply-To: <20260924-submit-stmmac-reset-fixes-v1-v3-0-c031e3f3a282@gmail.com> To: Russell King , Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Joakim Zhang , "Russell King (Oracle)" , Maxime Chevallier , Andrew Lunn , Maxime Coquelin , Alexandre Torgue , Christian Marangi , Tiezhu Yang , Huacai Chen , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Serge Semin , Suraj Jaiswal , Richard Cochran , Joao Pinto , Vladimir Oltean , Ong Boon Leong , Voon Weifeng , "Song, Yoong Siang" Cc: Richard Genoud , Alastair D'Silva , Maxime Ripard , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org, ZhaoJinming , Lorenzo Bianconi , Ding Hui , James Hilliard X-Mailer: b4 0.15.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260924_104450_460345_D6ED85A7 X-CRM114-Status: GOOD ( 18.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Live XSK pool changes free and replace individual RX/TX queues through void helpers. An allocation failure is only logged and the caller enables NAPI over missing rings. The TX queue and its timer also remain available while their storage is being freed. Use the XDP datapath release/open pair instead. Quiesce all NAPI contexts, transmitters, IRQ handlers and timers while the old program and pool bitmap still describe the active layout. Only then change the bitmap and rebuild the queues. This pauses all queues during a pool change, but avoids a partially running datapath and shares its failure and ownership handling with program changes instead of maintaining a second queue-level lifetime. Undo the new pool's bitmap bit and DMA mapping if reopening for attachment fails. For removal, free every reference to the pool before unmapping it and return success even if rebuilding the ordinary queues fails: socket teardown must not leave the departing pool reachable. In both cases failed reopening leaves the interface detached for down/up recovery. Remove the unused per-queue allocation/enable helpers. Preserve their TBS programming when using the full XDP reopen path, and clear the released TX pool pointer alongside its RX counterpart. Fixes: bba2556efad6 ("net: stmmac: Enable RX via AF_XDP zero-copy") Signed-off-by: James Hilliard --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 4 - drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 105 +--------------------- drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c | 44 +++++---- 3 files changed, 24 insertions(+), 129 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index ab5157fccc46..f07623a1285c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -437,10 +437,6 @@ static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv) return !!priv->xdp_prog; } -void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue); -void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue); -void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue); -void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue); int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags); struct timespec64 stmmac_calc_tas_basetime(ktime_t old_base_time, ktime_t current_time, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 467f471874cf..d56b7f911db0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2232,6 +2232,7 @@ static void __free_dma_tx_desc_resources(struct stmmac_priv *priv, tx_q->dma_etx = NULL; tx_q->dma_entx = NULL; tx_q->dma_tx = NULL; + tx_q->xsk_pool = NULL; } static void free_dma_tx_desc_resources(struct stmmac_priv *priv, @@ -7148,107 +7149,6 @@ static int stmmac_xdp_xmit(struct net_device *dev, int num_frames, return nxmit; } -void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue) -{ - struct stmmac_channel *ch = &priv->channel[queue]; - unsigned long flags; - - spin_lock_irqsave(&ch->lock, flags); - stmmac_disable_dma_irq(priv, priv->ioaddr, queue, 1, 0); - spin_unlock_irqrestore(&ch->lock, flags); - - stmmac_stop_rx_dma(priv, queue); - __free_dma_rx_desc_resources(priv, priv->dma_conf, queue); -} - -void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue) -{ - struct stmmac_rx_queue *rx_q = &priv->dma_conf->rx_queue[queue]; - struct stmmac_channel *ch = &priv->channel[queue]; - unsigned long flags; - int ret; - - ret = __alloc_dma_rx_desc_resources(priv, priv->dma_conf, queue); - if (ret) { - netdev_err(priv->dev, "Failed to alloc RX desc.\n"); - return; - } - - ret = __init_dma_rx_desc_rings(priv, priv->dma_conf, queue, GFP_KERNEL); - if (ret) { - __free_dma_rx_desc_resources(priv, priv->dma_conf, queue); - netdev_err(priv->dev, "Failed to init RX desc.\n"); - return; - } - - stmmac_reset_rx_queue(priv, queue); - stmmac_clear_rx_descriptors(priv, priv->dma_conf, queue); - - stmmac_init_rx_chan(priv, priv->ioaddr, priv->plat->dma_cfg, - rx_q->dma_rx_phy, queue); - - stmmac_set_queue_rx_tail_ptr(priv, rx_q, queue, rx_q->buf_alloc_num); - - stmmac_set_queue_rx_buf_size(priv, rx_q, queue); - - stmmac_start_rx_dma(priv, queue); - - spin_lock_irqsave(&ch->lock, flags); - stmmac_enable_dma_irq(priv, priv->ioaddr, queue, 1, 0); - spin_unlock_irqrestore(&ch->lock, flags); -} - -void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue) -{ - struct stmmac_channel *ch = &priv->channel[queue]; - unsigned long flags; - - spin_lock_irqsave(&ch->lock, flags); - stmmac_disable_dma_irq(priv, priv->ioaddr, queue, 0, 1); - spin_unlock_irqrestore(&ch->lock, flags); - - stmmac_stop_tx_dma(priv, queue); - __free_dma_tx_desc_resources(priv, priv->dma_conf, queue); -} - -void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue) -{ - struct stmmac_tx_queue *tx_q = &priv->dma_conf->tx_queue[queue]; - struct stmmac_channel *ch = &priv->channel[queue]; - unsigned long flags; - int ret; - - ret = __alloc_dma_tx_desc_resources(priv, priv->dma_conf, queue); - if (ret) { - netdev_err(priv->dev, "Failed to alloc TX desc.\n"); - return; - } - - ret = __init_dma_tx_desc_rings(priv, priv->dma_conf, queue); - if (ret) { - __free_dma_tx_desc_resources(priv, priv->dma_conf, queue); - netdev_err(priv->dev, "Failed to init TX desc.\n"); - return; - } - - stmmac_reset_tx_queue(priv, queue); - stmmac_clear_tx_descriptors(priv, priv->dma_conf, queue); - - stmmac_init_tx_chan(priv, priv->ioaddr, priv->plat->dma_cfg, - tx_q->dma_tx_phy, queue); - - if (tx_q->tbs & STMMAC_TBS_AVAIL) - stmmac_enable_tbs(priv, priv->ioaddr, 1, queue); - - stmmac_set_queue_tx_tail_ptr(priv, tx_q, queue, 0); - - stmmac_start_tx_dma(priv, queue); - - spin_lock_irqsave(&ch->lock, flags); - stmmac_enable_dma_irq(priv, priv->ioaddr, queue, 0, 1); - spin_unlock_irqrestore(&ch->lock, flags); -} - void stmmac_xdp_release(struct net_device *dev) { struct stmmac_priv *priv = netdev_priv(dev); @@ -7345,6 +7245,9 @@ int stmmac_xdp_open(struct net_device *dev) stmmac_set_queue_tx_tail_ptr(priv, tx_q, chan, 0); + if (tx_q->tbs & STMMAC_TBS_AVAIL) + stmmac_enable_tbs(priv, priv->ioaddr, 1, chan); + hrtimer_setup(&tx_q->txtimer, stmmac_tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c index 7ecb7addd2ea..907ac49a1b76 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c @@ -9,7 +9,6 @@ static int stmmac_xdp_enable_pool(struct stmmac_priv *priv, struct xsk_buff_pool *pool, u16 queue) { - struct stmmac_channel *ch = &priv->channel[queue]; bool need_update; u32 frame_size; int err; @@ -34,23 +33,23 @@ static int stmmac_xdp_enable_pool(struct stmmac_priv *priv, need_update = priv->datapath == STMMAC_DATAPATH_RUNNING && stmmac_xdp_is_enabled(priv); - if (need_update) { - napi_disable(&ch->rx_napi); - napi_disable(&ch->tx_napi); - stmmac_disable_rx_queue(priv, queue); - stmmac_disable_tx_queue(priv, queue); - } + if (need_update) + stmmac_xdp_release(priv->dev); set_bit(queue, priv->af_xdp_zc_qps); if (need_update) { - stmmac_enable_rx_queue(priv, queue); - stmmac_enable_tx_queue(priv, queue); - napi_enable(&ch->rxtx_napi); - - err = stmmac_xsk_wakeup(priv->dev, queue, XDP_WAKEUP_RX); - if (err) + err = stmmac_xdp_open(priv->dev); + if (err) { + clear_bit(queue, priv->af_xdp_zc_qps); + xsk_pool_dma_unmap(pool, STMMAC_RX_DMA_ATTR); + netdev_err(priv->dev, "failed reopening after XSK pool attach: %pe; interface remains detached\n", + ERR_PTR(err)); return err; + } + + /* The pool is installed even if link resolution is still pending. */ + napi_schedule(&priv->channel[queue].rxtx_napi); } return 0; @@ -58,9 +57,9 @@ static int stmmac_xdp_enable_pool(struct stmmac_priv *priv, static int stmmac_xdp_disable_pool(struct stmmac_priv *priv, u16 queue) { - struct stmmac_channel *ch = &priv->channel[queue]; struct xsk_buff_pool *pool; bool need_update; + int err; if (queue >= priv->plat->rx_queues_to_use || queue >= priv->plat->tx_queues_to_use) @@ -73,24 +72,21 @@ static int stmmac_xdp_disable_pool(struct stmmac_priv *priv, u16 queue) need_update = priv->datapath == STMMAC_DATAPATH_RUNNING && stmmac_xdp_is_enabled(priv); - if (need_update) { - napi_disable(&ch->rxtx_napi); - stmmac_disable_rx_queue(priv, queue); - stmmac_disable_tx_queue(priv, queue); - synchronize_rcu(); - } + if (need_update) + stmmac_xdp_release(priv->dev); xsk_pool_dma_unmap(pool, STMMAC_RX_DMA_ATTR); clear_bit(queue, priv->af_xdp_zc_qps); if (need_update) { - stmmac_enable_rx_queue(priv, queue); - stmmac_enable_tx_queue(priv, queue); - napi_enable(&ch->rx_napi); - napi_enable(&ch->tx_napi); + err = stmmac_xdp_open(priv->dev); + if (err) + netdev_err(priv->dev, "failed reopening after XSK pool removal: %pe; interface remains detached\n", + ERR_PTR(err)); } + /* Socket teardown must be able to unmap and free the removed pool. */ return 0; } -- 2.53.0