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=1796388961; b=aUOf2hoieY2dmhoalQUJusDw3V6i6S3nyDYtKBmBY5F8jyouSkNIIPVSKt1B2morE3dH 55foT1CNFSA2pWmwZS1AJmROdpp6/aqZr0CfY6td8ZxZNGwiPtF5g0fNYDnGexJAPiVIk ClU2T3L2+GUiakvl9nb5dI9FTcTGt5hmavqSi29+pz36tjJiPQY2YvfEbzMA0jwZ7Km9D d34rUwGp91p7cX3Cc+ted95yxs7lokYle+3LAuRddfGoXMf2SgiOh5PCmsmX76aiLVOMi ux4Kx2gqtfRKPcRXm7AQoOdlhg5UBjhD/IUMPkgclK+CWkCI5ot9u9If8AAoLn/Q50w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388961; 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-Transfer-Encoding; bh=BxOVFCNmpCRJpmVPSSIppY/s1BQAOL8mL2whxXExgg8=; b=0RBmlO+AN+pYGYcUEw4zPXCN7wkNOW6+qmxq/ix/vudioL3IDZCwKcCndTozowjtbZ/F NTLQmtZIOj9leFC+sg8Engle3oXeEj0YkF+eazHwfkLUYpXr/HC3JUPNgjByGcgTKlbO0 R1xvm0DwcBaSS26Isq+8376dQUywrlEuX75ZjnY34zQwCyiLrHzxzwqOkQiq2dllKZ5yq +xer/0hdpIxPOEp0ERM2g4JML/IQpzS1fHfvjcyhLQzT9Z4zst1p75+syJLq8kFbOFJRb ifPnjxdEcw6t2HussA/Hju1Yg90hJBnpwdx/xteIue/OuUFZRHGWB/3XQiab5lOyyGw== 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=mla+P9QT; 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 C1B4F606A32D; Fri, 4 Dec 2026 12:56:01 +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=mla+P9QT Received: by smtp.kernel.org (Postfix) with ESMTPSA id E32831F000C2; Fri, 4 Dec 2026 12:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388961; bh=BxOVFCNmpCRJpmVPSSIppY/s1BQAOL8mL2whxXExgg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mla+P9QTQdtZo9zUD8e5oCc3AXdJhBBnaCUB/R5n7K2bXvSZMb5MsDvURMrslnG+Q 3tSVYQhb/z41f+2ZZ12XXf5NeU5vLRYQk3cZ2hCGt2ST1+Iw4YW01sJ5B6NJMSYcrt K2qpdHfzThAt3dC4+5hLdb2oN8k1lM5II3A18RNo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kordian Chmielewski , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 0816/1059] net: bcm4908_enet: order the TX ring index accesses Date: Fri, 4 Dec 2026 19:05:47 +0900 Message-ID: <20261204100705.164881793@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: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kordian Chmielewski [ Upstream commit ebe31472ad0a08e19a31a6647b99c6b51f90026c ] Since the TX interrupt was added, poll_tx() runs in its own NAPI and does not take the TX queue lock, so it and start_xmit() share the TX ring with only the two indexes between them. Nothing orders the accesses around those indexes: - poll_tx() reads write_idx, then the descriptor and the slot. On arm64 the later loads may be satisfied first, so poll_tx() may see the new write_idx together with the previous lap's descriptor, which has no OWN, and the previous lap's slot. It would then unmap and free a frame the DMA has not sent yet, or free the old skb a second time. - poll_tx() publishes read_idx once it is done with the slots it freed, but that store is not ordered after its loads from those slots, so start_xmit() may refill a slot before poll_tx() has read it. Publish each index with smp_store_release() and read the other side's index with smp_load_acquire() before touching the slots. start_xmit() now publishes write_idx right after the descriptor, before the MMIO write that kicks the DMA rather than after it, which narrows the window in which the DMA can complete a frame that poll_tx() cannot see yet. Sashiko's review of the previous version of this series pointed this out; I have not seen it on the hardware. Fixes: 12bb508bfe5a ("net: broadcom: bcm4908_enet: support TX interrupt") Signed-off-by: Kordian Chmielewski Link: https://patch.msgid.link/20261113235847.517308-8-kudzo51@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/broadcom/bcm4908_enet.c | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c index 610fac1244e3a..6675aed11319c 100644 --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c @@ -565,7 +565,9 @@ static int bcm4908_enet_stop(struct net_device *netdev) */ static int bcm4908_enet_tx_free_descs(struct bcm4908_enet_dma_ring *ring) { - int free = READ_ONCE(ring->read_idx) - READ_ONCE(ring->write_idx) - 1; + /* Pairs with smp_store_release() in bcm4908_enet_poll_tx() */ + int free = smp_load_acquire(&ring->read_idx) - + READ_ONCE(ring->write_idx) - 1; return free < 0 ? free + ring->length : free; } @@ -616,12 +618,14 @@ static netdev_tx_t bcm4908_enet_start_xmit(struct sk_buff *skb, struct net_devic dma_wmb(); buf_desc->ctl = cpu_to_le32(tmp); - bcm4908_enet_dma_tx_ring_enable(enet, &enet->tx_ring); + /* Publish the slot and the descriptor before the index; pairs with + * smp_load_acquire() in bcm4908_enet_poll_tx() + */ + smp_store_release(&ring->write_idx, + ring->write_idx < ring->length - 1 ? + ring->write_idx + 1 : 0); - if (ring->write_idx == ring->length - 1) - WRITE_ONCE(ring->write_idx, 0); - else - WRITE_ONCE(ring->write_idx, ring->write_idx + 1); + bcm4908_enet_dma_tx_ring_enable(enet, &enet->tx_ring); /* poll_tx() wakes the queue once there is room again */ netif_txq_maybe_stop(txq, bcm4908_enet_tx_free_descs(ring), 1, 1); @@ -715,7 +719,10 @@ static int bcm4908_enet_poll_tx(struct napi_struct *napi, int weight) unsigned int bytes = 0; int handled = 0; - while (handled < weight && read_idx != READ_ONCE(tx_ring->write_idx)) { + while (handled < weight) { + /* Pairs with the release in bcm4908_enet_start_xmit() */ + if (read_idx == smp_load_acquire(&tx_ring->write_idx)) + break; buf_desc = &tx_ring->buf_desc[read_idx]; if (le32_to_cpu(buf_desc->ctl) & DMA_CTL_STATUS_OWN) break; @@ -730,7 +737,10 @@ static int bcm4908_enet_poll_tx(struct napi_struct *napi, int weight) if (++read_idx == tx_ring->length) read_idx = 0; } - WRITE_ONCE(tx_ring->read_idx, read_idx); + /* Be done with the slots before start_xmit() may reuse them; pairs + * with smp_load_acquire() in bcm4908_enet_tx_free_descs() + */ + smp_store_release(&tx_ring->read_idx, read_idx); enet->netdev->stats.tx_packets += handled; enet->netdev->stats.tx_bytes += bytes; -- 2.53.0