* [PATCH net v2 0/6] net: dsa: mt7530: fix remaining swallowed MDIO access errors
@ 2026-08-04 3:10 Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 1/6] net: pcs: mtk-lynxi: check regmap reads in mtk_pcs_lynxi_get_state() Daniel Golle
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Daniel Golle @ 2026-08-04 3:10 UTC (permalink / raw)
To: Chester A. Unal, Daniel Golle, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, AngeloGioacchino Del Regno, Alexander Couzens,
Heiner Kallweit, Russell King, Russell King, Sean Wang,
Landen Chao, Florian Fainelli, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
The original series, "net: dsa: mt7530: fix swallowed MDIO read
errors", landed on net as its v1 [1] just before its v2 [2] was sent.
This series started from the fixes in that original v2 which its v1
had not already carried: the two standalone patches that original v2
grew from the Sashiko AI review of its v1 (the mtk-lynxi read check
and the regmap IRQ serialization), plus, split into patches of their
own, the companion fixes original v2 had folded into the
already-applied patches -- the unchecked bus->read() in core_rmw() and
the unchecked PHY_IAC command writes in the MT7531 indirect PHY access
functions.
The Sashiko AI review of this series' own v1 [3] then flagged two more
swallowed MDIO errors of the same kind, added here as patches of their
own: the unchecked CORE_PLL_GROUP4 read-modify-write in mt7531_setup(),
and the unchecked ATC/VTCR command-register writes in mt7530_fdb_cmd()
and mt7530_vlan_cmd().
The remaining non-fix changes from the original v2, dropping a
redundant read-back and improving the poll failure messages, will
follow via net-next.
Changes in this series (v2), relative to its v1 [3]:
* patch 1: also report the link as down (state->link = false) on the
failed-read path; phylink presets state->link, so the previous bare
return reported a failed read as link-up (Sashiko AI review). Kept
Andrew's Reviewed-by given the small, in-spirit change -- please
re-confirm.
* new patch 4: check the CORE_PLL_GROUP4 read-modify-write in
mt7531_setup(), the call site exposed once patch 3 makes the MT7531
indirect c45 access propagate command-write failures.
* new patch 5: propagate MT7530_ATC / MT7530_VTCR command-register
write errors in mt7530_fdb_cmd() and mt7530_vlan_cmd() instead of
polling a BUSY bit that a failed write never set.
* collected Reviewed-by: Andrew Lunn on patches 1-3 and 6.
[1] https://lore.kernel.org/netdev/cover.1785213071.git.daniel@makrotopia.org/
[2] https://lore.kernel.org/netdev/cover.1785368701.git.daniel@makrotopia.org/
[3] https://lore.kernel.org/netdev/cover.1785427248.git.daniel@makrotopia.org/
Daniel Golle (6):
net: pcs: mtk-lynxi: check regmap reads in mtk_pcs_lynxi_get_state()
net: dsa: mt7530: check bus->read() error in core_rmw()
net: dsa: mt7530: error out on failed PHY_IAC command writes
net: dsa: mt7530: check CORE_PLL_GROUP4 access in mt7531_setup()
net: dsa: mt7530: check command register writes in fdb and vlan cmd
net: dsa: mt7530: serialize the regmap IRQ chip like every other user
drivers/net/dsa/mt7530.c | 86 +++++++++++++++++++++++++++------
drivers/net/pcs/pcs-mtk-lynxi.c | 7 ++-
2 files changed, 75 insertions(+), 18 deletions(-)
base-commit: af39eb111ce6b5eba9c08513b62c4868eb7e7fd5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v2 1/6] net: pcs: mtk-lynxi: check regmap reads in mtk_pcs_lynxi_get_state()
2026-08-04 3:10 [PATCH net v2 0/6] net: dsa: mt7530: fix remaining swallowed MDIO access errors Daniel Golle
@ 2026-08-04 3:10 ` Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 2/6] net: dsa: mt7530: check bus->read() error in core_rmw() Daniel Golle
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Daniel Golle @ 2026-08-04 3:10 UTC (permalink / raw)
To: Chester A. Unal, Daniel Golle, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, AngeloGioacchino Del Regno, Alexander Couzens,
Heiner Kallweit, Russell King, Russell King, Sean Wang,
Landen Chao, Florian Fainelli, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
mtk_pcs_lynxi_get_state() ignores regmap_read()'s return value; a
failed read leaves bm and adv holding uninitialized stack values
which are then decoded into the reported link state. The regmaps
backing the MT7531 SGMII PCS instances sit on an MDIO bus where
reads can fail. Check both reads and report the link as down on
error; phylink presets state->link before the callback, so a bare
return would leave a failed read reported as link-up.
Fixes: 4765a9722e09 ("net: pcs: add driver for MediaTek SGMII PCS")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
v2:
* set state->link = false on the failed-read path so a read error
reports the link as down instead of leaving phylink's preset
link-up (Sashiko AI review)
drivers/net/pcs/pcs-mtk-lynxi.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/net/pcs/pcs-mtk-lynxi.c b/drivers/net/pcs/pcs-mtk-lynxi.c
index a753bd88cbc2..7290fc3e5d18 100644
--- a/drivers/net/pcs/pcs-mtk-lynxi.c
+++ b/drivers/net/pcs/pcs-mtk-lynxi.c
@@ -113,8 +113,11 @@ static void mtk_pcs_lynxi_get_state(struct phylink_pcs *pcs,
unsigned int bm, adv;
/* Read the BMSR and LPA */
- regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &bm);
- regmap_read(mpcs->regmap, SGMSYS_PCS_ADVERTISE, &adv);
+ if (regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &bm) ||
+ regmap_read(mpcs->regmap, SGMSYS_PCS_ADVERTISE, &adv)) {
+ state->link = false;
+ return;
+ }
phylink_mii_c22_pcs_decode_state(state, neg_mode,
FIELD_GET(SGMII_BMSR, bm),
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 2/6] net: dsa: mt7530: check bus->read() error in core_rmw()
2026-08-04 3:10 [PATCH net v2 0/6] net: dsa: mt7530: fix remaining swallowed MDIO access errors Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 1/6] net: pcs: mtk-lynxi: check regmap reads in mtk_pcs_lynxi_get_state() Daniel Golle
@ 2026-08-04 3:10 ` Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 3/6] net: dsa: mt7530: error out on failed PHY_IAC command writes Daniel Golle
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Daniel Golle @ 2026-08-04 3:10 UTC (permalink / raw)
To: Chester A. Unal, Daniel Golle, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, AngeloGioacchino Del Regno, Alexander Couzens,
Heiner Kallweit, Russell King, Russell King, Sean Wang,
Landen Chao, Florian Fainelli, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
core_rmw() accesses the MMD core registers directly rather than
through the regmap and has the same unchecked bus->read() as the
one just fixed in the MDIO regmap backend: a negative errno is
consumed as register data, modified and written back to the switch.
Check the read and bail out like the surrounding bus accesses do.
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
v2: no changes
drivers/net/dsa/mt7530.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index aa33d94e11b5..9be6fb63c311 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -124,8 +124,12 @@ core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
goto err;
/* Read the content of the MMD's selected register */
- val = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
+ ret = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
MII_MMD_DATA);
+ if (ret < 0)
+ goto err;
+ val = ret;
+
val &= ~mask;
val |= set;
/* Write the data into MMD's selected register */
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 3/6] net: dsa: mt7530: error out on failed PHY_IAC command writes
2026-08-04 3:10 [PATCH net v2 0/6] net: dsa: mt7530: fix remaining swallowed MDIO access errors Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 1/6] net: pcs: mtk-lynxi: check regmap reads in mtk_pcs_lynxi_get_state() Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 2/6] net: dsa: mt7530: check bus->read() error in core_rmw() Daniel Golle
@ 2026-08-04 3:10 ` Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 4/6] net: dsa: mt7530: check CORE_PLL_GROUP4 access in mt7531_setup() Daniel Golle
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Daniel Golle @ 2026-08-04 3:10 UTC (permalink / raw)
To: Chester A. Unal, Daniel Golle, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, AngeloGioacchino Del Regno, Alexander Couzens,
Heiner Kallweit, Russell King, Russell King, Sean Wang,
Landen Chao, Florian Fainelli, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
MT7531_PHY_ACS_ST is only ever set by the command write that precedes
each poll in the MT7531 indirect PHY access functions, and that
write's return value is discarded. A failed write leaves ACS_ST at 0
from the previous access, so the poll succeeds on its first iteration
and the functions return stale IAC contents as if they were fresh PHY
data. Check the writes and bail out before polling.
Fixes: c288575f7810 ("net: dsa: mt7530: Add the support of MT7531 switch")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
v2: no changes
drivers/net/dsa/mt7530.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 9be6fb63c311..2a17696e6a45 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -565,7 +565,9 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad,
reg = MT7531_MDIO_CL45_ADDR | MT7531_MDIO_PHY_ADDR(port) |
MT7531_MDIO_DEV_ADDR(devad) | regnum;
- mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ if (ret < 0)
+ goto out;
ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val,
!(val & MT7531_PHY_ACS_ST), 20, 100000);
@@ -576,7 +578,9 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad,
reg = MT7531_MDIO_CL45_READ | MT7531_MDIO_PHY_ADDR(port) |
MT7531_MDIO_DEV_ADDR(devad);
- mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ if (ret < 0)
+ goto out;
ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val,
!(val & MT7531_PHY_ACS_ST), 20, 100000);
@@ -610,7 +614,9 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad,
reg = MT7531_MDIO_CL45_ADDR | MT7531_MDIO_PHY_ADDR(port) |
MT7531_MDIO_DEV_ADDR(devad) | regnum;
- mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ if (ret < 0)
+ goto out;
ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val,
!(val & MT7531_PHY_ACS_ST), 20, 100000);
@@ -621,7 +627,9 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad,
reg = MT7531_MDIO_CL45_WRITE | MT7531_MDIO_PHY_ADDR(port) |
MT7531_MDIO_DEV_ADDR(devad) | data;
- mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ if (ret < 0)
+ goto out;
ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val,
!(val & MT7531_PHY_ACS_ST), 20, 100000);
@@ -654,7 +662,9 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum)
val = MT7531_MDIO_CL22_READ | MT7531_MDIO_PHY_ADDR(port) |
MT7531_MDIO_REG_ADDR(regnum);
- mt7530_mii_write(priv, MT7531_PHY_IAC, val | MT7531_PHY_ACS_ST);
+ ret = mt7530_mii_write(priv, MT7531_PHY_IAC, val | MT7531_PHY_ACS_ST);
+ if (ret < 0)
+ goto out;
ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, val,
!(val & MT7531_PHY_ACS_ST), 20, 100000);
@@ -689,7 +699,9 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum,
reg = MT7531_MDIO_CL22_WRITE | MT7531_MDIO_PHY_ADDR(port) |
MT7531_MDIO_REG_ADDR(regnum) | data;
- mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ ret = mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
+ if (ret < 0)
+ goto out;
ret = regmap_read_poll_timeout(priv->regmap, MT7531_PHY_IAC, reg,
!(reg & MT7531_PHY_ACS_ST), 20, 100000);
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 4/6] net: dsa: mt7530: check CORE_PLL_GROUP4 access in mt7531_setup()
2026-08-04 3:10 [PATCH net v2 0/6] net: dsa: mt7530: fix remaining swallowed MDIO access errors Daniel Golle
` (2 preceding siblings ...)
2026-08-04 3:10 ` [PATCH net v2 3/6] net: dsa: mt7530: error out on failed PHY_IAC command writes Daniel Golle
@ 2026-08-04 3:10 ` Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 5/6] net: dsa: mt7530: check command register writes in fdb and vlan cmd Daniel Golle
2026-08-04 3:11 ` [PATCH net v2 6/6] net: dsa: mt7530: serialize the regmap IRQ chip like every other user Daniel Golle
5 siblings, 0 replies; 7+ messages in thread
From: Daniel Golle @ 2026-08-04 3:10 UTC (permalink / raw)
To: Chester A. Unal, Daniel Golle, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, AngeloGioacchino Del Regno, Alexander Couzens,
Heiner Kallweit, Russell King, Russell King, Sean Wang,
Landen Chao, Florian Fainelli, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
mt7531_setup() reads CORE_PLL_GROUP4 through the MT7531 indirect c45
PHY access, modifies it and writes it back to enable the PHY core
PLL, but checks neither the read nor the write. Now that the indirect
access functions propagate command-write failures, a failed read
returns a negative errno that would be bit-modified and written back
into the PLL register, and a failed write-back would go unnoticed.
Check both and bail out. The adjacent EEE advertisement writes push a
constant value and cannot corrupt state, so they are left as is.
Fixes: c288575f7810 ("net: dsa: mt7530: Add the support of MT7531 switch")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
v2: new patch
drivers/net/dsa/mt7530.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 2a17696e6a45..69cee61564cb 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2781,14 +2781,20 @@ mt7531_setup(struct dsa_switch *ds)
* phy_[read,write]_mmd_indirect is called, we provide our own
* mt7531_ind_mmd_phy_[read,write] to complete this function.
*/
- val = mt7531_ind_c45_phy_read(priv,
+ ret = mt7531_ind_c45_phy_read(priv,
MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
MDIO_MMD_VEND2, CORE_PLL_GROUP4);
+ if (ret < 0)
+ return ret;
+
+ val = ret;
val |= MT7531_RG_SYSPLL_DMY2 | MT7531_PHY_PLL_BYPASS_MODE;
val &= ~MT7531_PHY_PLL_OFF;
- mt7531_ind_c45_phy_write(priv,
- MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
- MDIO_MMD_VEND2, CORE_PLL_GROUP4, val);
+ ret = mt7531_ind_c45_phy_write(priv,
+ MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
+ MDIO_MMD_VEND2, CORE_PLL_GROUP4, val);
+ if (ret < 0)
+ return ret;
/* Disable EEE advertisement on the switch PHYs. */
for (i = MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr);
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 5/6] net: dsa: mt7530: check command register writes in fdb and vlan cmd
2026-08-04 3:10 [PATCH net v2 0/6] net: dsa: mt7530: fix remaining swallowed MDIO access errors Daniel Golle
` (3 preceding siblings ...)
2026-08-04 3:10 ` [PATCH net v2 4/6] net: dsa: mt7530: check CORE_PLL_GROUP4 access in mt7531_setup() Daniel Golle
@ 2026-08-04 3:10 ` Daniel Golle
2026-08-04 3:11 ` [PATCH net v2 6/6] net: dsa: mt7530: serialize the regmap IRQ chip like every other user Daniel Golle
5 siblings, 0 replies; 7+ messages in thread
From: Daniel Golle @ 2026-08-04 3:10 UTC (permalink / raw)
To: Chester A. Unal, Daniel Golle, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, AngeloGioacchino Del Regno, Alexander Couzens,
Heiner Kallweit, Russell King, Russell King, Sean Wang,
Landen Chao, Florian Fainelli, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
mt7530_fdb_cmd() and mt7530_vlan_cmd() start a command by writing the
BUSY bit to MT7530_ATC / MT7530_VTCR, then poll for it to clear.
mt7530_write() discards the write's return value, so a failed command
write leaves BUSY unset and the poll succeeds on its first read,
reporting a command that never ran as done -- returning stale FDB data
or silently dropping a VLAN table update.
Return mt7530_mii_write()'s error from mt7530_write() and check it in
both command helpers.
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
v2: new patch
drivers/net/dsa/mt7530.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 69cee61564cb..c0437273270b 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -185,14 +185,18 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg)
return val;
}
-static void
+static int
mt7530_write(struct mt7530_priv *priv, u32 reg, u32 val)
{
+ int ret;
+
mt7530_mutex_lock(priv);
- mt7530_mii_write(priv, reg, val);
+ ret = mt7530_mii_write(priv, reg, val);
mt7530_mutex_unlock(priv);
+
+ return ret;
}
static u32
@@ -249,7 +253,9 @@ mt7530_fdb_cmd(struct mt7530_priv *priv, enum mt7530_fdb_cmd cmd, u32 *rsp)
/* Set the command operating upon the MAC address entries */
val = ATC_BUSY | ATC_MAT(0) | cmd;
- mt7530_write(priv, MT7530_ATC, val);
+ ret = mt7530_write(priv, MT7530_ATC, val);
+ if (ret)
+ return ret;
mt7530_mutex_lock(priv);
@@ -1632,7 +1638,9 @@ mt7530_vlan_cmd(struct mt7530_priv *priv, enum mt7530_vlan_cmd cmd, u16 vid)
int ret;
val = VTCR_BUSY | VTCR_FUNC(cmd) | vid;
- mt7530_write(priv, MT7530_VTCR, val);
+ ret = mt7530_write(priv, MT7530_VTCR, val);
+ if (ret)
+ return ret;
mt7530_mutex_lock(priv);
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 6/6] net: dsa: mt7530: serialize the regmap IRQ chip like every other user
2026-08-04 3:10 [PATCH net v2 0/6] net: dsa: mt7530: fix remaining swallowed MDIO access errors Daniel Golle
` (4 preceding siblings ...)
2026-08-04 3:10 ` [PATCH net v2 5/6] net: dsa: mt7530: check command register writes in fdb and vlan cmd Daniel Golle
@ 2026-08-04 3:11 ` Daniel Golle
5 siblings, 0 replies; 7+ messages in thread
From: Daniel Golle @ 2026-08-04 3:11 UTC (permalink / raw)
To: Chester A. Unal, Daniel Golle, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, AngeloGioacchino Del Regno, Alexander Couzens,
Heiner Kallweit, Russell King, Russell King, Sean Wang,
Landen Chao, Florian Fainelli, netdev, linux-kernel,
linux-arm-kernel, linux-mediatek
The switch register regmap is created with .disable_locking = true;
every other user in this driver calls mt7530_mutex_lock()/unlock()
around it, which takes priv->bus->mdio_lock, since the underlying
mt7530_regmap_read()/write() issue raw, unserialized bus->read()/
write() MDIO transactions.
mt7530_setup_irq() hands this same unlocked regmap straight to
devm_regmap_add_irq_chip_fwnode(), whose threaded IRQ handler then
calls regmap_read()/regmap_update_bits() on it without ever calling
mt7530_mutex_lock(). An interrupt firing while another thread is
mid-transaction on the same regmap (e.g. a paged register access, or
an indirect PHY access) can interleave with the IRQ handler's own
paged access and corrupt page selection on either side.
Use struct regmap_irq_chip's handle_mask_sync hook to call
mt7530_mutex_lock()/unlock() around the mask register write regmap-irq
issues whenever a consumer of one of the mapped sub-IRQs enables,
disables, requests or frees its line. This needs a per-device copy of
mt7530_regmap_irq_chip, since devm_regmap_add_irq_chip_fwnode() keeps
a pointer to it rather than copying it.
handle_pre_irq/handle_post_irq, which would additionally cover the
status read and ack write the threaded handler does directly, bracket
the whole handler including its handle_nested_irq() calls. Lockdep
caught this on hardware: those calls reach phy_interrupt() for the
per-port PHY IRQ lines mapped through this chip, which takes
phydev->lock, while phy_attach_direct() and this driver's own indirect
PHY access already establish the opposite order (phydev->lock, then
priv->bus->mdio_lock) elsewhere. Using them here would close that
cycle, so they are not used.
regmap_irq_sync_unlock() also has its own init_ack_masked path, used
by this chip, which unconditionally does its own regmap_write() to ack
currently-masked IRQs; that path has no per-driver hook. Together with
the threaded handler's own status read and ack write, these stay
unprotected -- a narrower, harder-to-hit gap than the recurring mask
sync above -- and will be closed once the switch regmap moves to
regmap's own locking in the driver-wide register access cleanup.
Fixes: 254f6b272e3b ("dsa: mt7530: Utilize REGMAP_IRQ for interrupt handling")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
v2: no changes
drivers/net/dsa/mt7530.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index c0437273270b..0b39f2348115 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2319,6 +2319,21 @@ static const struct regmap_irq mt7530_irqs[] = {
REGMAP_IRQ_REG_LINE(31, 32), /* ACL */
};
+/* Serialize regmap-irq's mask sync like every other regmap user */
+static int mt7530_irq_mask_sync(int index, unsigned int mask_buf_def,
+ unsigned int mask_buf, void *irq_drv_data)
+{
+ struct mt7530_priv *priv = irq_drv_data;
+ int ret;
+
+ mt7530_mutex_lock(priv);
+ ret = regmap_update_bits(priv->regmap, MT7530_SYS_INT_EN,
+ mask_buf_def, ~mask_buf);
+ mt7530_mutex_unlock(priv);
+
+ return ret;
+}
+
static const struct regmap_irq_chip mt7530_regmap_irq_chip = {
.name = KBUILD_MODNAME,
.status_base = MT7530_SYS_INT_STS,
@@ -2328,12 +2343,14 @@ static const struct regmap_irq_chip mt7530_regmap_irq_chip = {
.irqs = mt7530_irqs,
.num_irqs = ARRAY_SIZE(mt7530_irqs),
.num_regs = 1,
+ .handle_mask_sync = mt7530_irq_mask_sync,
};
static int
mt7530_setup_irq(struct mt7530_priv *priv)
{
struct regmap_irq_chip_data *irq_data;
+ struct regmap_irq_chip *chip;
struct device *dev = priv->dev;
struct device_node *np = dev->of_node;
int irq, ret;
@@ -2353,10 +2370,17 @@ mt7530_setup_irq(struct mt7530_priv *priv)
if (priv->id == ID_MT7530 || priv->id == ID_MT7621)
mt7530_set(priv, MT7530_TOP_SIG_CTRL, TOP_SIG_CTRL_NORMAL);
+ chip = devm_kmemdup(dev, &mt7530_regmap_irq_chip, sizeof(*chip),
+ GFP_KERNEL);
+ if (!chip)
+ return -ENOMEM;
+
+ chip->irq_drv_data = priv;
+
ret = devm_regmap_add_irq_chip_fwnode(dev, dev_fwnode(dev),
priv->regmap, irq,
IRQF_ONESHOT,
- 0, &mt7530_regmap_irq_chip,
+ 0, chip,
&irq_data);
if (ret)
return ret;
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-08-04 3:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-04 3:10 [PATCH net v2 0/6] net: dsa: mt7530: fix remaining swallowed MDIO access errors Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 1/6] net: pcs: mtk-lynxi: check regmap reads in mtk_pcs_lynxi_get_state() Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 2/6] net: dsa: mt7530: check bus->read() error in core_rmw() Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 3/6] net: dsa: mt7530: error out on failed PHY_IAC command writes Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 4/6] net: dsa: mt7530: check CORE_PLL_GROUP4 access in mt7531_setup() Daniel Golle
2026-08-04 3:10 ` [PATCH net v2 5/6] net: dsa: mt7530: check command register writes in fdb and vlan cmd Daniel Golle
2026-08-04 3:11 ` [PATCH net v2 6/6] net: dsa: mt7530: serialize the regmap IRQ chip like every other user Daniel Golle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox