Re: [PATCH] net: dsa: mv88e6xxx: properly shutdown PPU re-enable timer on destroy
From: Jakub Kicinski
Date: Sun Nov 03 2024 - 14:35:50 EST
On Tue, 29 Oct 2024 13:42:45 +0100 David Oberhollenzer wrote:
> The mv88e6xxx has an internal PPU that polls PHY state. If we want to
> access the internal PHYs, we need to disable it. Because enable/disable
> of the PPU 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 is easily triggered by deferred probing during boot-up. MDIO bus
> and PHY registration may succeed, but switch registration fails later
> on, because the CPU port depends on a very slow device. In this case,
> probe() fails, but the MDIO subsystem may already have accessed bus
> or the PHYs, arming 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_phy_destroy(), grab the ppu_mutex to make sure the work
> function either has already exited, or (should it run) cannot do
> anything, fails to grab the mutex and returns.
> - In addition to destroying the timer, also destroy the work item, in
> case the timer has already fired.
> - Do all of this synchronously, to make sure timer & work item are
> destroyed and none of the callbacks are running.
Looks good, AFAICT. Could you repost with a Fixes tag added?
To make the job of the stable team easier?