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=1796381920; b=Ige7lNJjfH4QNZO6DBRC4tTgbgr9vBGZ0AXqbSgCfOgeF1w3ut/iuXvpZoEtwt+WCsu6 +R9AE6NDRQ4OV3od1iIhCuUsmcviq0zSVY4sTWsalHzcDSd/FencqEtudKJ1CbdNKbu41 V1gM7B65rsEYKurUi89NnilGW3FQtdBhWrDzWeHQXeqggyh8v6pg4wdvFihgwC4ABEoX9 2PN/U83TSEN47TB22fjKgT9bItrLA5rF1G/6XJ5LqrBAZfjwazehuAFEd0/51Unx3msra h0mjkJjrHLiU1TOIDvLdcRNi4i9m4qwBjM7q3yf9TQlKjBGt3gSitsTS7cLNeEvm6bg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381920; 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=GjvaoCQHDwkdMCaQCVQLj2pD1Nogg80bhZ0Nzx9UH7w=; b=jGrID3P2wSvsyoZ3MCMBqCjXtS7tGTnfdRuh4FwFBdkU7voSsSP+zOsOVhJjMKqbAoL5 IOxMM0k07n4LY5CWFqEsZ2FM2R4s/ReodyUJ1JUuWdXKyq3O8LDp2oTIQ/p73P6yDoRoP /ta42dGKczw1UjIJ2SIfvxivmQTVN/CbDTIf92NS+O2C05WC53C8Z9cBhmIXDAuQZdEg0 M7U3pmAEzA+hRtrQr34KPLgcEY2fuHfNlQIl40AQ/s0SDOG1SZq74UGz4zpahTUFN4RuL OxmL6FyFvvCJTSQ6unSwcBrS+6Nelplo3cTObdpTg9gjaR+50B1Sjd6rLHfBE1Pqxmw== 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=gytJpGDz; 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 8F82E606A322; Fri, 4 Dec 2026 10:58:40 +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=gytJpGDz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 026A21F000C2; Fri, 4 Dec 2026 10:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381920; bh=GjvaoCQHDwkdMCaQCVQLj2pD1Nogg80bhZ0Nzx9UH7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gytJpGDzjOG94yavBxji37tojKXs1F5aZ4VIWRMWU/bjiSPF/I0xp3xqOrRCT2YF/ DuLGmuKVdy/Pf2bMU9mg/ind+CVCilGsHLJ0s0Hzk9kvq8Uglo5p+Pk+Uy4LjuK4l4 z7gKZAiVdcHvykSEOZJmLXbgizY2az9ieGtDsyO4= 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.18 189/703] net: bcm4908_enet: order the TX ring index accesses Date: Fri, 4 Dec 2026 19:01:28 +0900 Message-ID: <20261204100632.887794006@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 0ac778e40a8f1..d7e0be44d1210 100644 --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c @@ -566,7 +566,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; } @@ -619,12 +621,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); @@ -718,7 +722,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; @@ -733,7 +740,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