Skip to content

Commit c91baa2

Browse files
AgentDjfvogel
authored andcommitted
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: 2e5f032 ("dsa: add support for the Marvell 88E6131 switch chip") Signed-off-by: David Oberhollenzer <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 9dec9dacaeeda0b87c9833fa85d8a015677fa65a) Signed-off-by: Jack Vogel <[email protected]>
1 parent e189c87 commit c91baa2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7301,13 +7301,13 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
73017301
err = mv88e6xxx_switch_reset(chip);
73027302
mv88e6xxx_reg_unlock(chip);
73037303
if (err)
7304-
goto out;
7304+
goto out_phy;
73057305

73067306
if (np) {
73077307
chip->irq = of_irq_get(np, 0);
73087308
if (chip->irq == -EPROBE_DEFER) {
73097309
err = chip->irq;
7310-
goto out;
7310+
goto out_phy;
73117311
}
73127312
}
73137313

@@ -7326,7 +7326,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
73267326
mv88e6xxx_reg_unlock(chip);
73277327

73287328
if (err)
7329-
goto out;
7329+
goto out_phy;
73307330

73317331
if (chip->info->g2_irqs > 0) {
73327332
err = mv88e6xxx_g2_irq_setup(chip);
@@ -7360,6 +7360,8 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
73607360
mv88e6xxx_g1_irq_free(chip);
73617361
else
73627362
mv88e6xxx_irq_poll_free(chip);
7363+
out_phy:
7364+
mv88e6xxx_phy_destroy(chip);
73637365
out:
73647366
if (pdata)
73657367
dev_put(pdata->netdev);
@@ -7382,7 +7384,6 @@ static void mv88e6xxx_remove(struct mdio_device *mdiodev)
73827384
mv88e6xxx_ptp_free(chip);
73837385
}
73847386

7385-
mv88e6xxx_phy_destroy(chip);
73867387
mv88e6xxx_unregister_switch(chip);
73877388

73887389
mv88e6xxx_g1_vtu_prob_irq_free(chip);
@@ -7395,6 +7396,8 @@ static void mv88e6xxx_remove(struct mdio_device *mdiodev)
73957396
mv88e6xxx_g1_irq_free(chip);
73967397
else
73977398
mv88e6xxx_irq_poll_free(chip);
7399+
7400+
mv88e6xxx_phy_destroy(chip);
73987401
}
73997402

74007403
static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)

drivers/net/dsa/mv88e6xxx/phy.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ static void mv88e6xxx_phy_ppu_state_init(struct mv88e6xxx_chip *chip)
229229

230230
static void mv88e6xxx_phy_ppu_state_destroy(struct mv88e6xxx_chip *chip)
231231
{
232+
mutex_lock(&chip->ppu_mutex);
232233
del_timer_sync(&chip->ppu_timer);
234+
cancel_work_sync(&chip->ppu_work);
235+
mutex_unlock(&chip->ppu_mutex);
233236
}
234237

235238
int mv88e6185_phy_ppu_read(struct mv88e6xxx_chip *chip, struct mii_bus *bus,

0 commit comments

Comments
 (0)