From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Daniel Golle <daniel@makrotopia.org>,
Hauke Mehrtens <hauke@hauke-m.de>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Rasmus Villemoes <ravi@prevas.dk>,
"Benny (Ying-Tsan) Weng" <yweng@maxlinear.com>,
John Crispin <john@phrozen.org>
Subject: Re: [PATCH net v3] net: dsa: mxl-gsw1xx: manually clear RANEG bit
Date: Mon, 8 Dec 2025 15:52:02 +0000 [thread overview]
Message-ID: <aTb0IqktR9gbZFdn@shell.armlinux.org.uk> (raw)
In-Reply-To: <586e6fe2-60af-4a8f-9727-98ad7d6b9593@lunn.ch>
On Mon, Dec 08, 2025 at 02:37:38PM +0100, Andrew Lunn wrote:
> On Mon, Dec 08, 2025 at 12:47:51PM +0000, Russell King (Oracle) wrote:
> > On Mon, Dec 08, 2025 at 01:27:04AM +0000, Daniel Golle wrote:
> > > static void gsw1xx_remove(struct mdio_device *mdiodev)
> > > {
> > > struct gswip_priv *priv = dev_get_drvdata(&mdiodev->dev);
> > > + struct gsw1xx_priv *gsw1xx_priv;
> > >
> > > if (!priv)
> > > return;
> > >
> > > + gsw1xx_priv = container_of(priv, struct gsw1xx_priv, gswip);
> > > + cancel_delayed_work_sync(&gsw1xx_priv->clear_raneg);
> > > +
> > > gswip_disable_switch(priv);
> > >
> > > dsa_unregister_switch(priv->ds);
> >
> > Can we please pay attention to ->remove methods, and code them properly
> > please?
> >
> > There are two golden rules of driver programming.
> >
> > 1. Do not publish the device during probe until hardware setup is
> > complete. If you publish before hardware setup is complete, userspace
> > is free to race with the hardware setup and start using the device.
> > This is especially true of recent systems which use hotplug events
> > via udev and systemd to do stuff.
> >
> > 2. Do not start tearing down a device until the user interfaces have
> > been unpublished. Similar to (1), while the user interface is
> > published, uesrspace is completely free to interact with the device
> > in any way it sees fit.
> >
> > In this case, what I'm concerned with is the call above to
> > cancel_delayed_work_sync() before dsa_unregister_switch(). While
> > cancel_delayed_work_sync() will stop this work and wait for the handler
> > to finish running before returning (which is safe) there is a window
> > between this call and dsa_unregister_switch() where the user _could_
> > issue a badly timed ethtool command which invokes
> > gsw1xx_pcs_an_restart(), which would re-schedule the delayed work,
> > thus undoing the cancel_delayed_work_sync() effect in this path.
>
> And this is why is was pushing for the much simpler msleep(10), or
> io_poll.h polling to see if it self clears. It is hard to get that
> wrong, where as delayed work is much easier to get wrong.
It's not specific to delayed work. Looking at the context around
the ->remove() method, it's already wrong:
gswip_disable_switch(priv);
dsa_unregister_switch(priv->ds);
gswip_disable_switch() writes to a register:
regmap_clear_bits(priv->mdio, GSWIP_MDIO_GLOB, GSWIP_MDIO_GLOB_ENABLE);
and I wonder what that does in terms of MDIO bis accesses that will
still be active at this point (because the DSA switch is still
registered.)
I see that gswip_setup() enables the switch before it configures the
MDIO bus and registers it, so the disable-then-unregister looks very
suspicious to me.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
prev parent reply other threads:[~2025-12-08 15:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 1:27 [PATCH net v3] net: dsa: mxl-gsw1xx: manually clear RANEG bit Daniel Golle
2025-12-08 12:47 ` Russell King (Oracle)
2025-12-08 13:37 ` Andrew Lunn
2025-12-08 15:52 ` Russell King (Oracle) [this message]
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=aTb0IqktR9gbZFdn@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=andrew@lunn.ch \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hauke@hauke-m.de \
--cc=john@phrozen.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=ravi@prevas.dk \
--cc=yweng@maxlinear.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;
as well as URLs for NNTP newsgroup(s).