Article View: linux.kernel.netdev
Article #6382[PATCH RFC net 1/6] net: macb: take bp->lock around NCR read-modify-writes
From: Steffen Dirkwinkel
Date: Thu, 22 Oct 2026 09:38
Date: Thu, 22 Oct 2026 09:38
101 lines
13018 bytes
13018 bytes
From: Théo Lebrun <theo.lebrun@bootlin.com>
NCR is read-modify-written from many contexts:
- macb_mac_link_down() clears RE|TE,
- macb_mac_link_up() sets RE|TE|PTPUNI,
- macb_hresp_error_task() clears then re-sets RE|TE,
- macb_start_xmit() / macb_tx_restart() / macb_tx_error_task() set
TSTART (already under bp->lock),
- macb_interrupt() might toggle RE (also under bp->lock).
The first three risk concurrent RMW with anyone from the list as they
don't grab bp->lock.
Theoretical bugfix only, it has never reproduced on hardware. Also note
it does *not* take the lock hoping to protect against full races
inbetween BH scheduling concurrently. We only want to ensure consistent
NCR RMW operations.
Fixes: 7897b071ac3b ("net: macb: convert to phylink")
Cc: stable@vger.kernel.org
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/ethernet/cadence/macb_main.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 261a7e87520a..4b5037867537 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -777,6 +777,7 @@ static void macb_mac_link_down(struct phylink_config *config, unsigned int mode,
struct net_device *netdev = to_net_dev(config->dev);
struct macb *bp = netdev_priv(netdev);
struct macb_queue *queue;
+ unsigned long flags;
unsigned int q;
u32 ctrl;
@@ -786,8 +787,10 @@ static void macb_mac_link_down(struct phylink_config *config, unsigned int mode,
bp->rx_intr_mask | MACB_TX_INT_FLAGS | MACB_BIT(HRESP));
/* Disable Rx and Tx */
+ spin_lock_irqsave(&bp->lock, flags);
ctrl = macb_readl(bp, NCR) & ~(MACB_BIT(RE) | MACB_BIT(TE));
macb_writel(bp, NCR, ctrl);
+ spin_unlock_irqrestore(&bp->lock, flags);
netif_tx_stop_all_queues(netdev);
}
@@ -940,11 +943,13 @@ static void macb_mac_link_up(struct phylink_config *config,
}
/* Enable Rx and Tx; Enable PTP unicast */
+ spin_lock_irqsave(&bp->lock, flags);
ctrl = macb_readl(bp, NCR);
if (gem_has_ptp(bp))
ctrl |= MACB_BIT(PTPUNI);
macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE));
+ spin_unlock_irqrestore(&bp->lock, flags);
netif_tx_wake_all_queues(netdev);
}
@@ -1995,6 +2000,7 @@ static void macb_hresp_error_task(struct work_struct *work)
struct macb *bp = from_work(bp, work, hresp_err_bh_work);
struct net_device *netdev = bp->netdev;
struct macb_queue *queue;
+ unsigned long flags;
unsigned int q;
u32 ctrl;
@@ -2003,9 +2009,11 @@ static void macb_hresp_error_task(struct work_struct *work)
MACB_TX_INT_FLAGS |
MACB_BIT(HRESP));
}
+ spin_lock_irqsave(&bp->lock, flags);
ctrl = macb_readl(bp, NCR);
ctrl &= ~(MACB_BIT(RE) | MACB_BIT(TE));
macb_writel(bp, NCR, ctrl);
+ spin_unlock_irqrestore(&bp->lock, flags);
netif_tx_stop_all_queues(netdev);
netif_carrier_off(netdev);
@@ -2022,8 +2030,10 @@ static void macb_hresp_error_task(struct work_struct *work)
MACB_TX_INT_FLAGS |
MACB_BIT(HRESP));
- ctrl |= MACB_BIT(RE) | MACB_BIT(TE);
- macb_writel(bp, NCR, ctrl);
+ spin_lock_irqsave(&bp->lock, flags);
+ ctrl = MACB_BIT(RE) | MACB_BIT(TE);
+ macb_writel(bp, NCR, macb_readl(bp, NCR) | ctrl);
+ spin_unlock_irqrestore(&bp->lock, flags);
netif_carrier_on(netdev);
netif_tx_start_all_queues(netdev);
--
2.56.0
Technical Details
Message-ID:
<20261022-std-macb-v14-send-v1-1-9187bc545bf6@beckhoff.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350485-linux-kernel-netdev=dewy.ruReferences:
<20261022-std-macb-v14-send-v1-0-9187bc545bf6@beckhoff.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350485-linux-kernel-netdev=dewy.ru From: lists@steffen.cc (Steffen Dirkwinkel) Newsgroups: linux.kernel.netdev Subject: [PATCH RFC net 1/6] net: macb: take bp->lock around NCR read-modify-writes Date: Thu, 22 Oct 2026 11:38:46 +0200 Organization: Usenet Network Message-ID: <20261022-std-macb-v14-send-v1-1-9187bc545bf6@beckhoff.com> References: <20261022-std-macb-v14-send-v1-0-9187bc545bf6@beckhoff.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="179660"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:RTZwe1Qs0JKgU3E2DUFq01inG9Q= sha256:CFGjVJLB5KcnWKfgDSVeC5JvmRR8W4ykn+8V/pNErIk= sha1:qJDF2gJCdN6Axn7hFXAfRVIIYKE= sha256:PTt4Zb1lY0lYwxtPDal1Db2PFvNskyzXO0ImZK9+MkQ= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id CB3FF11121F; Thu, 22 Oct 2026 12:45:08 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.15 X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=steffen.cc X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id njldLsuGk-cU; Thu, 22 Oct 2026 12:45:06 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-350485-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=steffen.cc X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 6A8B811121A; Thu, 22 Oct 2026 12:44:58 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 9C4F860D1E8; Thu, 22 Oct 2026 09:40:32 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1792661962; b=EaNI6Nk3cFxDLHSrgTbBZvbmQg/OZMLrPpO91BL9DntYbju4TSj1ey7bcLqLhCbgI0af YthGmFwOITyPq7GxxpPJi5SrH5xDmeKnj8ZX78xyW77ciEjPo7LkOFopC4E2kpB/fT8St hDsLqrDKyGyuMJzb7hgetd4Uim/cBS4B2e0aGe9YiMqHW1+I8hGYh5Wd+nuUwsZ4ERk8B X7BBbS+ah1VoSBNoyujeE/RghiFN89Sflxx7j7eYuyROGGNQqTOFkUJzqCOzpHkOppDXs 4R7BQYYJmVb6AiguCQSAKTLJcdDv3is1bO6bK84/jNuRw6XtdE6cFyQr9vtLBDV7GYw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792661962; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From: Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Rspamd-Queue-Id; bh=n8VLqU8X1/rvJlMP8QTqyuejzFMpUVHeeiGzG9y9yC8=; b=Pky3ZC/S7kvvtx6MzLFJaXqZK8Vd8w8i+N8qyF+5ISp10jjTBJxVmTRSkxyQ+t1TSQAx 8Z7K2GWebpZIBSyc4gzhhIKtZyb1nDMKm9s94Jqg2ApXlGGACnfz9mk2nqee8erC70WZ5 mnlZ6dHrVRvMLHdW0Q5CXOs765gXT0HqkM0zVvEbPbDrh+yMIXwEQsgUlrKFuYhB3qkiw fkUz1kf7+eQwKaUzOF6SvCzIQ+3rKdK7zDU93dBvLHfqtZNlTacSkEGJu6KagGA2V6oO7 hEpwpsHXLRWCQenMxsl67sfX54NltDnO4v3h9lTPGDbEWX78aFQQhk1sOSVQzsg5BPQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=steffen.cc header.i=@steffen.cc header.a=rsa-sha256 header.s=MBO0001 header.b=vnFKD6Zo; dmarc=pass header.from=steffen.cc; spf=pass smtp.mailfrom=steffen.cc; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5ED0960A5BD5; Thu, 22 Oct 2026 09:39:22 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=steffen.cc header.i=@steffen.cc header.a=rsa-sha256 header.s=MBO0001 header.b=vnFKD6Zo X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.151 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792661951; b=1J+u6sftvcW4TmqgXPBNx84kMvzeNXk4rkbAVVj1fK8tKEHfYEboWNucbfjdyj8XzZo4 Mw9NCi9ZTOIoRVTGpgJVwE1tgIQBitK01hd03mPRsYffacsc30ZOwOQOJhdNsWlAqZvVH PILZZDJtqFtvCfCITvpXGjwzseulGn2X+SdoOeGK+PAuakANEw90FjQ0EYMOvojffbMob Vy4Sy5d2lhXU9ZQMr2gTl/Htorcg30cIKG0ld4+UeLM9tXSQMKiyj5oUnP0BRIaB+2NrV aHskaqT+T1tspUsANOknbvXg2F4myfDwT3LoWLtbNShJ035waYySVA3XXsxQc1a+2gw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792661951; h=DMARC-Filter:Received:DKIM-Signature:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Rspamd-Queue-Id; bh=n8VLqU8X1/rvJlMP8QTqyuejzFMpUVHeeiGzG9y9yC8=; b=OjeGRTh+PyljnSf09RhQatTeQ2dsgpSYKFWDgxd7tJx9tJuythaul5Q4Gd594Bj9BANk Eeqy+ABEaJNQ5wvSivC5W7bFobOX6qjzz72u/yhY2KwKiXKjpLACwy/G3IoGLWJYAPBFt fFT9zRV//expdheGr0NdVv9ALGUM/vOYSEMCN63fUs4+urwB7XNwBRV7pFD589AZnIT0n KZOrbL/QnkhUBoJZwnH4aWRGql/ayc7if0s8wewcbuOhjyhqLAKiSchAApAT7XLjudKmT 34WJCpHtOBEILd1TvI+9Mf2naujTeJYDRP5PcpUV3BwyhPINeuWSUrV7FQQUpN0KymQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=steffen.cc; spf=pass smtp.mailfrom=steffen.cc; dkim=pass header.d=steffen.cc header.i=@steffen.cc header.a=rsa-sha256 header.s=MBO0001 header.b=vnFKD6Zo; arc=none smtp.remote-ip=80.241.56.151 X-Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69C9860A2622; Thu, 22 Oct 2026 09:39:10 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69C9860A2622 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=steffen.cc X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=steffen.cc X-Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4j9Lh558qKz8v0b; Thu, 22 Oct 2026 11:39:01 +0200 (CEST) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=steffen.cc; s=MBO0001; t=1792661941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n8VLqU8X1/rvJlMP8QTqyuejzFMpUVHeeiGzG9y9yC8=; b=vnFKD6ZoZXIGOFHK4r+eYFOu5U8S1za/28aieN54KmhIDjzob0MeFMGcjieL5DKYaTz8MG +tc5ksZVpwvMIrSoWEzHgphAnLrtWh8y2kLpOh83k0hqXXBkB5Za770LRPCBkDybUbBeaw juB1SzZJVJxxX0rsgU15wQC3mHKlgalJeLZLf61lpzwNY4l9wAk8rE5CtS9OjaBLQbrqYR d+dUJixtlkqB2PctOvkz/JYyNxwpaOUOrlHTwiSkRp0G9aJk6P2uNYq4yb8QOamSlCFg8E sZ6jjAGJHXd3exFfktgiUb7u1n29RhntosvELNfQOci/KbIe6oDLNIvFPjCDlg== X-Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of lists@steffen.cc designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=lists@steffen.cc X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261022-std-macb-v14-send-v1-0-9187bc545bf6@beckhoff.com> X-Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Christian Taedcke <christian.taedcke@weidmueller.com>, Nicolai Buchwitz <nb@tipi-net.de>, Andrea della Porta <andrea.porta@suse.com>, stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1792661936; l=3510; i=s.dirkwinkel@beckhoff.com; s=20260625; h=from:subject:message-id; bh=JAFcJ/X0rEVHNId3QslLF0CCZGplzoClBUV8j/p/9fk=; b=mReO/ATBuedMrogAYTppWW+7skEJ++GIjWGJaR2eRPRENi46qDxSf7JZc+pdRtu/FuWpPYA1E gO05pO+HB+WBxz0hnBa0TNHvzQMzKpDLVqRmLcCCzFGb80xR3bp/IGh X-Developer-Key: i=s.dirkwinkel@beckhoff.com; a=ed25519; pk=5DcsaSpVtmm7nCi3Bnw5A4vbXI+sg3hBgt8e2A2U/gw= X-Rspamd-Queue-Id: 4j9Lh558qKz8v0b