From: netdev-bot+sashiko@kernel.org
To: mail@birger-koblitz.de
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, linux@armlinux.org.uk, andrew@lunn.ch,
hkallweit1@gmail.com, chenhuacai@kernel.org, kernel@xen0n.name,
edumazet@kernel.org, linux-usb@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
loongarch@lists.linux.dev, neuromoments@gmail.com,
beganovic.emir@gmail.com
Subject: Re: [PATCH net-next v20 01/13] phylink: Add phylink_mac_interrupt
Date: Tue, 10 Nov 2026 01:38:29 +0000 [thread overview]
Message-ID: <179427470922.994134.16776316201780098943@kernel.org> (raw)
In-Reply-To: <20261106-ax88179a-v20-1-37b5a1189983@birger-koblitz.de>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] phylink_mac_interrupt() (drivers/net/phy/phylink.c:1629-1637)
loads pl->phydev with no lock, no RCU and no reference, then calls…
- [Low] phylink_mac_interrupt() reads pl->phydev with a plain load (`phy
= pl->phydev;`) and no lock.
--
phylink: Add phylink_mac_interrupt
This commit adds phylink_mac_interrupt(), an exported wrapper that passes a
link-change interrupt received by the MAC to phylib by calling
phy_mac_interrupt() on the PHY attached to the phylink instance. It is meant
for drivers that want to stop polling the PHY.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index e885da1c28311..a87eaa2f3db5b 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -1616,6 +1616,26 @@ static bool phylink_link_is_up(struct phylink *pl)
> return pl->netdev ? netif_carrier_ok(pl->netdev) : pl->old_link_state;
> }
>
> +/**
> + * phylink_mac_interrupt() - wrapper for phy_mac_interrupt()
> + * @pl: a pointer to a &struct phylink returned from phylink_create()
> + *
> + * Passes a link-change interrupt received by the MAC to phylib.
> + * This function may be called in interrupt context, and therefore cannot take
> + * a mutex. However, it is safe to assume that the reference to phy does not
> + * disappear during the call, as only an SFP module may be unplugged to make a
> + * PHY disappear. SFP modules however do not support interrupts.
> + */
> +void phylink_mac_interrupt(struct phylink *pl)
> +{
> + struct phy_device *phy;
> +
> + phy = pl->phydev;
> + if (phy)
> + phy_mac_interrupt(phy);
[Severity: Medium]
Is the lifetime argument in the kernel-doc above accurate? It says:
"it is safe to assume that the reference to phy does not disappear
during the call, as only an SFP module may be unplugged to make a PHY
disappear. SFP modules however do not support interrupts."
phylink_disconnect_phy() is not specific to SFP. Any MAC driver can call it
under RTNL at runtime, for example from ndo_stop or on unbind.
Also, the interrupt here comes from the MAC, not the PHY. Whether an SFP PHY
supports interrupts doesn't seem to matter, and phylink_mac_interrupt() has
no check on phy->is_on_sfp_module or phy->irq.
phylink_disconnect_phy() clears pl->phydev under locks that this IRQ path
never takes. It then stops the PHY without waiting for lockless readers:
drivers/net/phy/phylink.c:phylink_disconnect_phy() {
...
mutex_lock(&phy->lock);
mutex_lock(&pl->state_mutex);
pl->phydev = NULL;
...
if (phy) {
flush_work(&pl->resolve);
phy_disconnect(phy);
}
}
Could this interleaving happen?
CPU0 (MAC IRQ) CPU1
phylink_mac_interrupt()
phy = pl->phydev;
phylink_disconnect_phy()
pl->phydev = NULL;
phy_disconnect(phy)
phy_stop_machine()
cancel_delayed_work_sync(
&phydev->state_queue);
phy_mac_interrupt(phy)
phy_trigger_machine()
phy_queue_state_machine()
mod_delayed_work(..., &phydev->state_queue, ...);
If so, state_queue gets re-armed after the cancel has already finished.
On SFP module removal, sfp_sm_phy_detach() frees the phy_device right after
the disconnect:
drivers/net/phy/sfp.c:sfp_sm_phy_detach() {
sfp_remove_phy(sfp->sfp_bus);
phy_device_remove(sfp->mod_phy);
phy_device_free(sfp->mod_phy);
...
}
sfp_remove_phy() reaches phylink_disconnect_phy() through
phylink_sfp_disconnect_phy(), and phy_device_remove() does not cancel
state_queue. Would this leave a delayed work queued inside a freed
phy_device? On the non-SFP paths, it would restart the state machine on a
stopped, detached PHY.
The only caller in this series, ax88179a_status(), does not seem to hit
this today. usbnet_stop()->usbnet_status_stop() kills the interrupt URB
before ax88179a_unbind() disconnects the PHY.
This is an exported, generic API, though. Should the kernel-doc tell
callers to quiesce their interrupt source before calling
phylink_disconnect_phy()? Or should phylink synchronize this itself, for
example with RCU and a grace period before phy_disconnect()?
[Severity: Low]
pl->phydev is read here with a plain load and no lock held.
phylink_bringup_phy() and phylink_disconnect_phy() write it with plain
stores under phydev_mutex and state_mutex. Will KCSAN report this as a data
race?
Without READ_ONCE(), the compiler may also reload pl->phydev after the NULL
check. The pointer passed to phy_mac_interrupt() could then differ from the
one that was tested. If a writer stored NULL in between, could
mod_delayed_work() end up called on &NULL->state_queue?
The current caller, ax88179a_status(), does not race with connect or
disconnect. Even so, would READ_ONCE() (or rcu_dereference()) here, paired
with WRITE_ONCE() (or rcu_assign_pointer()) in the writers, be appropriate?
> +}
> +EXPORT_SYMBOL_GPL(phylink_mac_interrupt);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106-ax88179a-v20-0-37b5a1189983%40birger-koblitz.de
next prev parent reply other threads:[~2026-11-10 1:38 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 7:21 [PATCH net-next v20 00/13] ax88179_178a: Add support for AX88179A-based chips Birger Koblitz
2026-11-06 7:21 ` [PATCH net-next v20 01/13] phylink: Add phylink_mac_interrupt Birger Koblitz
2026-11-06 10:11 ` Maxime Chevallier
2026-11-06 15:32 ` Birger Koblitz
2026-11-06 15:55 ` Andrew Lunn
2026-11-10 1:38 ` netdev-bot+sashiko [this message]
2026-11-06 7:21 ` [PATCH net-next v20 02/13] phylib: Add support for PHYs with broken forced mode Birger Koblitz
2026-11-06 7:21 ` [PATCH net-next v20 03/13] ax88179_178a: Split driver into library and device specific code Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 04/13] ax88179_178a: Add HW support for AX179A-based chips Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 05/13] ax88179_178a: Add EEE configuration support for AX88179A MACs Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 06/13] ax88179_178a: Add EEE configuration support for AX88179A PHYs Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 07/13] ax88179_178a: Add VLAN offload support for AX88179A Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 08/13] ax88179_178a: Add AX179A/AX279 multicast configuration Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 09/13] ax88179_178a: Add Suspend/resume support for AX88179A/772D/279 Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 10/13] ax88179_178a: Add ethtool get_drvinfo Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 11/13] ax88179_178a: Update driver name and information Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 12/13] ax88179_178a: Add support for AX88179A/772D/279 EEPROM access Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
2026-11-06 7:21 ` [PATCH net-next v20 13/13] ax88796b: Add support for AX88772D, AX88179A and AX88279 Birger Koblitz
2026-11-10 1:38 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179427470922.994134.16776316201780098943@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=beganovic.emir@gmail.com \
--cc=chenhuacai@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=kernel@xen0n.name \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=loongarch@lists.linux.dev \
--cc=mail@birger-koblitz.de \
--cc=netdev@vger.kernel.org \
--cc=neuromoments@gmail.com \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®