Re: [PATCH net 2/2] r8169: fix deadlock in "r8169_phylink_handler"

From: Heiner Kallweit
Date: Mon Nov 27 2023 - 14:39:00 EST


On 27.11.2023 18:57, ChunHao Lin wrote:
> In "r8169_phylink_handler", for rtl8125, it will call "rtl_reset_work"->
> "rtl_hw_start"->"rtl_jumbo_config"->"phy_start_aneg". When call
> "r8169_phylink_handler", PHY lock is acquired. But "phy_start_aneg"
> will also try to acquire PHY lock. That will cause deadlock.
>
> In this path, use "_phy_start_aneg", unlocked version "phy_start_aneg",
> to prevent deadlock in "r8169_phylink_handler".
>
> Fixes: 453a77894efa ("r8169: don't advertise pause in jumbo mode")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: ChunHao Lin <hau@xxxxxxxxxxx>
> ---
> drivers/net/ethernet/realtek/r8169_main.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index 473b3245754f..2e3e42a98edd 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -2415,11 +2415,22 @@ static void rtl_jumbo_config(struct rtl8169_private *tp)
>
> /* Chip doesn't support pause in jumbo mode */
> if (jumbo) {
> + int lock;
> +
> linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT,
> tp->phydev->advertising);
> linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
> tp->phydev->advertising);
> - phy_start_aneg(tp->phydev);
> +
> + if (!mutex_trylock(&tp->phydev->lock))
> + lock = 0;
> + else
> + lock = 1;
> +
> + _phy_start_aneg(tp->phydev);
> +
> + if (lock)
> + mutex_unlock(&tp->phydev->lock);
> }
> }
>

Hi Hau,
the deadlock issue has been reported by few users, and I submitted a fix already.
It's waiting to be applied.