Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] phylink_destroy() in drivers/net/phy/phylink.c now writes through
pl->pcs with `rcu_assign_pointer(pl->pcs->phylink, NULL)` (lines…
--
net: phylink: make PCS phylink instance access RCU protected
This patch makes the phylink back-pointer in struct phylink_pcs RCU
protected. phylink_pcs_change() now reads it under rcu_read_lock().
phylink_destroy() also clears the pointer on the currently selected PCS
and calls synchronize_rcu() before freeing the phylink instance.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index d1f1142a98a4e..d736604b86f48 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -2157,6 +2158,16 @@ void phylink_destroy(struct phylink *pl)
> if (pl->link_gpio)
> gpiod_put(pl->link_gpio);
>
> + if (pl->pcs)
> + rcu_assign_pointer(pl->pcs->phylink, NULL);
[Severity: Low]
Does this add a new lifetime requirement on the PCS for callers of
phylink_destroy()?
Before this patch, phylink_destroy() never touched the PCS. pl->pcs is
only reassigned in phylink_major_config() and is not cleared by
phylink_stop(). So at destroy time it still points at the last PCS
returned by mac_select_pcs().
If a MAC or DSA driver freed its PCS after phylink_stop() and before
phylink_destroy() (via xpcs_destroy_pcs(), lynx_pcs_destroy(),
mtk_pcs_lynxi_destroy() and so on), that order used to be harmless. With
this change it becomes a write into freed memory.
I couldn't find an in-tree caller that uses this order today. stmmac,
txgbe, altera_tse, enetc, dpaa and the DSA teardown paths all call
phylink_destroy() before they free the PCS. So this is about the API
contract rather than a current trigger.
The kernel-doc for phylink_destroy() still only says:
* Destroy a phylink instance. Any PHY that has been attached must have been
* cleaned up via phylink_disconnect_phy() prior to calling this function.
Should it also say that the last selected PCS must still be allocated
when phylink_destroy() is called? This is a Fixes: tagged patch, so
external drivers on stable kernels would pick up the new requirement.
The same requirement remains later in the series. There, phylink_destroy()
goes through phylink_detach_pcss(), which keeps the dereference for the
legacy mac_select_pcs path:
if (pl->pcs) {
rcu_assign_pointer(pl->pcs->phylink, NULL);
WRITE_ONCE(pl->pcs, NULL);
}
The phylink_destroy() kernel-doc is still unchanged at that point.
> +
> + /*
> + * Unconditionally wait for readers that may have obtained this
> + * phylink through a PCS while phylink_major_config() was clearing
> + * the association.
> + */
> + synchronize_rcu();
> +
> cancel_work_sync(&pl->resolve);
> kfree(pl);
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40gmail.com