From: Vladimir Oltean <olteanv@gmail.com>
To: "Russell King (Oracle)" <linux@armlinux.org.uk>
Cc: Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Florian Fainelli <f.fainelli@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
Subject: Re: [PATCH net-next] net: dsa: mark parsed interface mode for legacy switch drivers
Date: Tue, 8 Aug 2023 15:39:01 +0300 [thread overview]
Message-ID: <20230808123901.3jrqsx7pe357hwkh@skbuf> (raw)
In-Reply-To: <ZNI1WA3mGMl93ib8@shell.armlinux.org.uk> <ZNI1WA3mGMl93ib8@shell.armlinux.org.uk>
On Tue, Aug 08, 2023 at 01:30:16PM +0100, Russell King (Oracle) wrote:
> On Tue, Aug 08, 2023 at 03:06:52PM +0300, Vladimir Oltean wrote:
> > Hi Russell,
> >
> > On Tue, Aug 08, 2023 at 12:12:16PM +0100, Russell King (Oracle) wrote:
> > > If we successfully parsed an interface mode with a legacy switch
> > > driver, populate that mode into phylink's supported interfaces rather
> > > than defaulting to the internal and gmii interfaces.
> > >
> > > This hasn't caused an issue so far, because when the interface doesn't
> > > match a supported one, phylink_validate() doesn't clear the supported
> > > mask, but instead returns -EINVAL. phylink_parse_fixedlink() doesn't
> > > check this return value, and merely relies on the supported ethtool
> > > link modes mask being cleared. Therefore, the fixed link settings end
> > > up being allowed despite validation failing.
> > >
> > > Before this causes a problem, arrange for DSA to more accurately
> > > populate phylink's supported interfaces mask so validation can
> > > correctly succeed.
> > >
> > > Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> > > ---
> >
> > How did you notice this? Is there any unconverted DSA switch which has a
> > phy-mode which isn't PHY_INTERFACE_MODE_INTERNAL or PHY_INTERFACE_MODE_NA?
>
> By looking at some of the legacy drivers, finding their DT compatibles
> and then grepping the dts files.
>
> For example, vitesse,vsc73* compatibles show up here:
>
> arch/arm/boot/dts/gemini/gemini-sq201.dts
>
> and generally, the ports are listed as:
>
> port@0 {
> reg = <0>;
> label = "lan1";
> };
>
> except for the CPU port which has:
>
> vsc: port@6 {
> reg = <6>;
> label = "cpu";
> ethernet = <&gmac1>;
> phy-mode = "rgmii";
> fixed-link {
> speed = <1000>;
> full-duplex;
> pause;
> };
> };
>
> Since the vitesse DSA driver doesn't populate .phylink_get_caps, it
> would have been failing as you discovered with dsa_loop before the
> previous patch.
>
> Fixing this by setting GMII and INTERNAL worked around the additional
> check that was using that failure and will work fine for the LAN
> ports as listed above.
>
> However, that CPU port uses "rgmii" which doesn't match the GMII and
> INTERNAL bits in the supported mask.
>
> Since phylink_validate() does this:
>
> const unsigned long *interfaces = pl->config->supported_interfaces;
>
> if (state->interface == PHY_INTERFACE_MODE_NA)
>
> ... it isn't, so we move on...
>
> if (!test_bit(state->interface, interfaces))
> return -EINVAL;
>
> This will trigger and phylink_validate() in phylink_parse_fixedlink()
> will return -EINVAL without touching the passed supported mask.
>
> phylink_parse_fixedlink() does:
>
> bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
> linkmode_copy(pl->link_config.advertising, pl->supported);
> phylink_validate(pl, MLO_AN_FIXED, pl->supported, &pl->link_config);
>
> and then we have:
>
> s = phy_lookup_setting(pl->link_config.speed, pl->link_config.duplex,
> pl->supported, true);
>
> ...
> if (s) {
> ... success ...
> } else {
> phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n",
> pl->link_config.duplex == DUPLEX_FULL ? "full" : "half",
> pl->link_config.speed);
> }
>
> So, since phylink_validate() with an apparently unsupported interface
> exits early with -EINVAL, pl->supported ends up with all bits set,
> and phy_lookup_setting() allows any speed.
>
> If someone decides to fix that phylink_validate() error checking, then
> this will then lead to a warning/failure.
>
> I want to avoid that happening - fixing that latent bug before it
> becomes a problem.
Aha, ok, thanks for explaining.
next prev parent reply other threads:[~2023-08-08 17:00 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 11:12 [PATCH net-next] net: dsa: mark parsed interface mode for legacy switch drivers Russell King (Oracle)
2023-08-08 12:06 ` Vladimir Oltean
2023-08-08 12:30 ` Russell King (Oracle)
2023-08-08 12:39 ` Vladimir Oltean [this message]
2023-08-08 12:57 ` Russell King (Oracle)
2023-08-08 13:52 ` Vladimir Oltean
2023-08-08 14:19 ` Russell King (Oracle)
2023-08-10 15:16 ` Vladimir Oltean
2023-08-12 12:16 ` Russell King (Oracle)
2023-08-13 10:50 ` Vladimir Oltean
2023-08-13 21:56 ` Linus Walleij
2023-08-13 22:17 ` Russell King (Oracle)
2023-08-15 6:41 ` Linus Walleij
2023-08-14 14:59 ` Vladimir Oltean
2023-08-14 15:12 ` Russell King (Oracle)
2023-08-14 15:46 ` Andrew Lunn
2023-08-14 16:27 ` Russell King (Oracle)
2023-08-14 17:05 ` Andrew Lunn
2023-08-14 22:03 ` Russell King (Oracle)
2023-08-14 23:33 ` Andrew Lunn
2023-08-15 10:13 ` Russell King (Oracle)
2023-08-17 18:01 ` Vladimir Oltean
2023-08-17 18:19 ` Vladimir Oltean
2023-08-17 18:27 ` Vladimir Oltean
2023-08-17 18:52 ` Andrew Lunn
2023-08-17 19:17 ` Vladimir Oltean
2023-08-18 11:11 ` Russell King (Oracle)
2023-08-18 11:40 ` Vladimir Oltean
2023-08-18 13:08 ` Linus Walleij
2023-08-18 13:29 ` Russell King (Oracle)
2023-08-18 16:06 ` Linus Walleij
2023-08-18 13:44 ` Vladimir Oltean
2023-08-18 13:10 ` Russell King (Oracle)
2023-08-18 14:21 ` Vladimir Oltean
2023-08-18 16:49 ` Vladimir Oltean
2023-08-14 22:21 ` Linus Walleij
2023-08-14 15:47 ` Vladimir Oltean
2023-08-08 16:35 ` Andrew Lunn
2023-08-08 12:39 ` Vladimir Oltean
2023-08-09 20:20 ` patchwork-bot+netdevbpf
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=20230808123901.3jrqsx7pe357hwkh@skbuf \
--to=olteanv@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--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