sst-linux/drivers/net/dsa
David Oberhollenzer 5eaa143ba3 net: dsa: mv88e6xxx: propperly shutdown PPU re-enable timer on destroy
[ Upstream commit a58d882841a0750da3c482cd3d82432b1c7edb77 ]

The mv88e6xxx has an internal PPU that polls PHY state. If we want to
access the internal PHYs, we need to disable the PPU first. Because
that is a slow operation, a 10ms timer is used to re-enable it,
canceled with every access, so bulk operations effectively only
disable it once and re-enable it some 10ms after the last access.

If a PHY is accessed and then the mv88e6xxx module is removed before
the 10ms are up, the PPU re-enable ends up accessing a dangling pointer.

This especially affects probing during bootup. The MDIO bus and PHY
registration may succeed, but registration with the DSA framework
may fail later on (e.g. because the CPU port depends on another,
very slow device that isn't done probing yet, returning -EPROBE_DEFER).
In this case, probe() fails, but the MDIO subsystem may already have
accessed the MIDO bus or PHYs, arming the timer.

This is fixed as follows:
 - If probe fails after mv88e6xxx_phy_init(), make sure we also call
   mv88e6xxx_phy_destroy() before returning
 - In mv88e6xxx_remove(), make sure we do the teardown in the correct
   order, calling mv88e6xxx_phy_destroy() after unregistering the
   switch device.
 - In mv88e6xxx_phy_destroy(), destroy both the timer and the work item
   that the timer might schedule, synchronously waiting in case one of
   the callbacks already fired and destroying the timer first, before
   waiting for the work item.
 - Access to the PPU is guarded by a mutex, the worker acquires it
   with a mutex_trylock(), not proceeding with the expensive shutdown
   if that fails. We grab the mutex in mv88e6xxx_phy_destroy() to make
   sure the slow PPU shutdown is already done or won't even enter, when
   we wait for the work item.

Fixes: 2e5f032095 ("dsa: add support for the Marvell 88E6131 switch chip")
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Link: https://patch.msgid.link/20250401135705.92760-1-david.oberhollenzer@sigma-star.at
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-04-10 14:33:41 +02:00
..
b53 net: dsa: b53: fix jumbo frames on 10/100 ports 2024-10-17 15:22:21 +02:00
hirschmann
microchip net: dsa: microchip: Fix LAN937X set_ageing_time function 2025-01-09 13:29:58 +01:00
mv88e6xxx net: dsa: mv88e6xxx: propperly shutdown PPU re-enable timer on destroy 2025-04-10 14:33:41 +02:00
ocelot net: dsa: felix: fix stuck CPU-injected packets with short taprio windows 2024-12-19 18:08:56 +01:00
qca dsa: qca8k: Use nested lock to avoid splat 2024-12-14 19:54:44 +01:00
realtek
sja1105
xrs700x
bcm_sf2_cfp.c
bcm_sf2_regs.h
bcm_sf2.c net: dsa: bcm_sf2: Fix a possible memory leak in bcm_sf2_mdio_register() 2024-08-14 13:52:44 +02:00
bcm_sf2.h
dsa_loop_bdinfo.c
dsa_loop.c
dsa_loop.h
Kconfig
lan9303_i2c.c
lan9303_mdio.c
lan9303-core.c net: dsa: lan9303: ensure chip reset and wait for READY status 2024-10-17 15:22:27 +02:00
lan9303.h
lantiq_gswip.c
lantiq_pce.h
Makefile
mt7530.c
mt7530.h
mv88e6060.c
mv88e6060.h
rzn1_a5psw.c
rzn1_a5psw.h
vitesse-vsc73xx-core.c net: dsa: vsc73xx: fix possible subblocks range of CAPT block 2024-09-12 11:10:22 +02:00
vitesse-vsc73xx-platform.c
vitesse-vsc73xx-spi.c
vitesse-vsc73xx.h