๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17730

Re: [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock

#17730
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 09:15
143 lines
13180 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 1 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix is incomplete: b44 still makes sleeping phylib calls
  while holding a spinlock with IRQs off.
- [Medium] The commit message says 'External PHY register accesses are
  serialized by the MDIO bus mutex'.

--

net: b44: keep phylib ioctls outside the spinlock

With this patch, b44_ioctl() holds bp->lock only around
generic_mii_ioctl() for the internal PHY. The external PHY path now
calls phy_mii_ioctl() without the spinlock and relies on the MDIO bus
mutex for serialization.

> diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c
> index f994636fbd5f1..e9f116dfaad99 100644
> --- a/drivers/net/ethernet/broadcom/b44.c
> +++ b/drivers/net/ethernet/broadcom/b44.c
> @@ -2126,14 +2126,14 @@ static int b44_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
>  	if (!netif_running(dev))
>  		goto out;
>  
> -	spin_lock_irq(&bp->lock);

[Severity: Medium]
The commit message says:

  External PHY register accesses are serialized by the MDIO bus mutex, as
  they already are when called from the PHY state machine.

Does that hold for b44? b44_mdio_read_phylib() and
b44_mdio_write_phylib() call __b44_readphy() and __b44_writephy(). Each
of those runs a multi-step sequence on Ethernet core registers:

drivers/net/ethernet/broadcom/b44.c:__b44_readphy() {
	bw32(bp, B44_EMAC_ISTAT, EMAC_INT_MII);
	bw32(bp, B44_MDIO_DATA, (MDIO_DATA_SB_START |
	...
	err = b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
	*val = br32(bp, B44_MDIO_DATA) & MDIO_DATA_DATA;
	...
}

Two other paths touch the same hardware while holding only bp->lock,
without the mdio_lock:

b44_chip_reset() calls ssb_device_enable() and
ssb_pcicore_dev_irqvecs_enable(). On older SSB-PCI cores the second call
can switch the BAR0 window to the PCI core. b44_chip_reset() then
rewrites B44_MDIO_CTRL.

b44_setup_phy() calls b44_wap54g10_workaround() before the
B44_FLAG_EXTERNAL_PHY early return. That function does raw
__b44_readphy() and __b44_writephy() calls on PHY 0 and bypasses the
mii_bus.

Both paths can run without rtnl, from b44_tx_timeout() and from the RFO
and ISTAT_ERRORS recovery paths in b44_poll():

b44_tx_timeout()
    spin_lock_irq(&bp->lock);
    b44_halt(bp);
    b44_init_rings(bp);
    b44_init_hw(bp, B44_FULL_RESET);

Before this patch, the spin_lock_irq() in b44_ioctl() stopped a
SIOCGMIIREG or SIOCSMIIREG transaction from overlapping these paths.
Now the transaction runs under only rtnl and mdio_lock.

Can a TX timeout or NAPI error recovery interleave with the ioctl's MDIO
sequence? If so, the read could return a wrong value, b44_wait_bit()
could time out, or a SIOCSMIIREG write could be lost while
phy_mii_ioctl() still updates phydev->autoneg and advertising.

Also, ssb_pci_read32() checks bus->mapped_device and then calls
ioread32() with no lock in between. Could a concurrent window switch
send the MDIO register access to the PCI core's registers?

The PHY state machine already has this gap. This patch adds a path that
userspace can trigger. Would it make sense to serialize inside the b44
MDIO accessors instead, for example with a short
spin_lock_irqsave(&bp->lock) around the udelay-only sequence? That would
also mean dropping bp->lock in b44_set_link_ksettings().

>  	if (bp->flags & B44_FLAG_EXTERNAL_PHY) {
>  		BUG_ON(!dev->phydev);
>  		err = phy_mii_ioctl(dev->phydev, ifr, cmd);

[Severity: High]
Is this fix complete? On the external PHY path, b44_set_link_ksettings()
still calls into phylib with bp->lock held and interrupts disabled:

drivers/net/ethernet/broadcom/b44.c:b44_set_link_ksettings() {
	...
	if (bp->flags & B44_FLAG_EXTERNAL_PHY) {
		BUG_ON(!dev->phydev);
		spin_lock_irq(&bp->lock);
		if (netif_running(dev))
			b44_setup_phy(bp);

		ret = phy_ethtool_ksettings_set(dev->phydev, cmd);

		spin_unlock_irq(&bp->lock);

		return ret;
	}
	...
}

Once its argument checks pass, phy_ethtool_ksettings_set() calls
mutex_lock(&phydev->lock). It then calls phy_trigger_machine() or
_phy_start_aneg(), and the aneg path does MDIO I/O under the bus
mdio_lock.

An ordinary "ethtool -s <dev> speed 100 duplex full autoneg off" on a
b44 with B44_FLAG_EXTERNAL_PHY gets here. ethtool does a get before the
set, and b44_get_link_ksettings() fills phy_address from
phy_ethtool_ksettings_get(), so the phy_address check passes.

Doesn't this hit the same sleeping-in-atomic problem that the commit
message describes for phy_mii_ioctl()?

If phydev->lock is contended, for example by phy_state_machine(), the
task would schedule with bp->lock held and interrupts off. Then
b44_interrupt() or b44_timer() on that CPU could spin on bp->lock
forever.

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-submit-phy-mii-reset-v1-v1-0-02a55f352a91%40gmail.com
Technical Details
Message-ID: <179490695291.3136.15807458064775996761@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365092-linux-kernel-netdev=dewy.ru
References: <20261113-submit-phy-mii-reset-v1-v1-1-02a55f352a91@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365092-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock
Date: Tue, 17 Nov 2026 09:15:52 +0000
Organization: Usenet Network
Message-ID: <179490695291.3136.15807458064775996761@kernel.org>
References: <20261113-submit-phy-mii-reset-v1-v1-1-02a55f352a91@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2288581"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:p9mWxMac+DulVnV6AlC/7gPOs4I= sha256:uWCF5yni8PG0C3wPrCivBLJwz31QVBZPu8iRgiCyng0=
	sha1:HMdfelvGVTzlJHXc4xSxzx1Wtcw= sha256:AJXyfHEYdZuV8YUZDYKpFknBqz+pJUSPard+qIem+pw=
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 4636A114EB4; Tue, 17 Nov 2026 12:16:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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=kernel.org
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 s6zsVs8JJ04S;
	Tue, 17 Nov 2026 12:16:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-365092-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id BC2DB114EBA; Tue, 17 Nov 2026 12:16:13 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id E9A6C3120F; Tue, 17 Nov 2026 09:16:05 +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=1794906960;
	b=XtM4Vfa9rqrKnb0h9Yan9L2DpBC864BVTM3TEg9wUOGo5vqcHEX1hpqQJbtZrKK/++JV
	 mOB1ZYxWRj+BDNwJUR2jmhX+IqiKOeCvcbu6V9wmXxwBGvor/2QOKYHHkvGudSGuXsjQF
	 2+kPT8VksALCoVA9QvqFYFOkdeneXFsNNGUelUllfpp2GI/GmF11cZZJMwnV6OrvaZ5I/
	 vMmAors8WJZEDUYpMZgTF04068GI7rqBO06GYVKWq49igSlAg2KjzvCh55QGh0O50HQZq
	 4w7Aby7nHW8mk27w9yGZLOPmZDQfoVxGkX5b9fk4ipOCiWA8xZYTrm6CWvo6R8spZ0A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794906960;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=PX2VvPQO8YKsW8EYaHPbFnPMhO0EfsOhGHaguUach5g=;
	b=qc9il3SZPHHlY5y9//4Y64pxAx+ecVJPOt/7UGU+lzSS+unVt3hiVgrDln+xADAnw2P/
	 ZWTe6CI/3dASuwQnIpBcgFQCvaVam3FnLlTwukR0b+PhKf/XeQwm9wevMUxvHOXpJ6TkL
	 MAEN26jntdNre/JMrPudVsvfBqAxnmL9lEp0N8unoinYAjEYR+7YfhCpXQL6wyfThe//l
	 LjM2G5KmNebiWtpn7hvxbBHpRzXXGr5pkD6+iVmHp4w4d+q6/jqAAf0KY2OAPxjVCzmYc
	 UNQn5mvo/hWPZXYVTTwJlhq4/3Mm/XNIAxYFemEW+T6uSkQMu9rX04/KJYBHLO4zDSA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R0rkTW99;
	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 48E0B606A881;
	Tue, 17 Nov 2026 09:16:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R0rkTW99
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794906954;
	b=xdPY4LUEctrRZl3t1aUF6lFLzKbONa2dZgygqsMpUfV5DM0nW0B7hKkr/Y5eh/WdugTZ
	 aDqOS0Xjffig7KFrW/2bbtG2Bk3codO0DV/mNs9fq2q8OS2iKuCxBuGFShJdbppnX94n7
	 NX2+BFItIMsHrtZ4nbnwoMxDS0OjqwmiAcqSz+cfK1To846u0lI6XVknEvg0faSZx73dj
	 Li84qNtWawtnE9m/6TnTo1ZM3Sd60+96DNmq+5ydxOni4lyPxvY7AaaBbP78sQuOtlNYh
	 8MoQMzBSCnYG7zkQB4Cy6gQWG31AisFclutrci0QJfE5mmw+AYfSWkSm8VZAnCRme2w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794906954;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=PX2VvPQO8YKsW8EYaHPbFnPMhO0EfsOhGHaguUach5g=;
	b=cGTx+LuiigzehLw15FOnKyYZomKaaEWbl2ii1WkgMa2zU3K5HAxzgYRRMho+5zM5Pgh4
	 d5H1d9ydmrGqqVqxLhSAreoWdMdkiCB02Rv3chyxBpgMH9ST7aYYem6z45m075v7jLSPl
	 VWgUMubjvsO7KWpq9ELA4OCFbEQBTBMVnomX3xSRfRhpGZeHy5D2yodaDIhyy5lAhVXAx
	 vPUnjXOgi8C9aaJVIKUcQThjAIq5G57utGgAAOCYHkgvCES6uygR2a7gwZhQGzN35PFu0
	 tQztfQc7L7Yp6DhuM0a9soM4WyTP/cZigHNAoO0DfyNl4AWUiD0yVB8dx1wqP+X9qCg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R0rkTW99;
	arc=none smtp.remote-ip=100.103.45.18
X-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 692A0606A329;
	Tue, 17 Nov 2026 09:15:54 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60A651F000C4;
	Tue, 17 Nov 2026 09:15:53 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794906954;
	bh=PX2VvPQO8YKsW8EYaHPbFnPMhO0EfsOhGHaguUach5g=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=R0rkTW99bPmRAQ2whS7C3K2Hu03Up/r/qgqwgDP9MQ2GMSPib/TRGC04jte5aibLl
	 7hICu9PRgWCd1RdUgwGNjJzqxxPGMBEBfMH/zy5ysjbrZqYmlTPz0LakLuqbdDBa7d
	 mRJd+K5V4kMw9qedl/yYqQk/ScuWyew2l22QueIasEW/DkKluBSbTxWq7SXBOQniE7
	 HcrMqGzHhUPBhJktk1OdIqX1wwi5c0C1/w9VQNKe3NHykZ7oirdbMqBvIAueg3xZ8L
	 19jOfjt4cSP6EIOE0zfv2DlsBY7rscjuwIfl7vHfLWsqnnpBHAR5JKArhieMmS0QlC
	 Ork/DuyBlT0sQ==
X-Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 michael.chan@broadcom.com, hauke@hauke-m.de, andrew@lunn.ch,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261113-submit-phy-mii-reset-v1-v1-1-02a55f352a91@gmail.com>
X-sashiko-severity: High
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