From: Florian Fainelli <f.fainelli@gmail.com>
To: Josua Mayer <josua@solid-run.com>, Jiri Pirko <jiri@resnulli.us>
Cc: Andrew Lunn <andrew@lunn.ch>, 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" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: dsa: mv88e6xxx: add warning for truncated mdio bus id
Date: Wed, 20 Mar 2024 08:13:35 -0700 [thread overview]
Message-ID: <a5b2d1df-cf6e-42b6-8ccf-122be672db24@gmail.com> (raw)
In-Reply-To: <c76c95af-71cb-4eb6-b3af-846ae318d18d@solid-run.com>
On 3/20/2024 7:33 AM, Josua Mayer wrote:
> Am 20.03.24 um 15:09 schrieb Jiri Pirko:
>> Wed, Mar 20, 2024 at 02:48:55PM CET, josua@solid-run.com wrote:
>>> mv88e6xxx supports multiple mdio buses as children, e.g. to model both
>>> internal and external phys. If the child buses mdio ids are truncated,
>>> they might collide which each other leading to an obscure error from
>>> kobject_add.
>>>
>>> The maximum length of bus id is currently defined as 61
>>> (MII_BUS_ID_SIZE). Truncation can occur on platforms with long node
>>> names and multiple levels before the parent bus on whiich the dsa switch
>> s/whiich/which/
>>
>>
>>> sits such as on CN9130 [1].
>>>
>>> Test whether the return value of snprintf exceeds the maximum bus id
>>> length and print a warning.
>>>
>>> [1]
>>> [ 8.324631] mv88e6085 f212a200.mdio-mii:04: switch 0x1760 detected: Marvell 88E6176, revision 1
>>> [ 8.389516] mv88e6085 f212a200.mdio-mii:04: Truncated bus-id may collide.
>>> [ 8.592367] mv88e6085 f212a200.mdio-mii:04: Truncated bus-id may collide.
>>> [ 8.623593] sysfs: cannot create duplicate filename '/devices/platform/cp0/cp0:config-space@f2000000/f212a200.mdio/mdio_bus/f212a200.mdio-mii/f212a200.mdio-mii:04/mdio_bus/!cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdi'
>>> [ 8.785480] kobject: kobject_add_internal failed for !cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdi with -EEXIST, don't try to register things with the same name in the same directory.
>>> [ 8.936514] libphy: mii_bus /cp0/config-space@f2000000/mdio@12a200/ethernet-switch@4/mdi failed to register
>>> [ 8.946300] mdio_bus !cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdi: __mdiobus_register: -22
>>> [ 8.956003] mv88e6085 f212a200.mdio-mii:04: Cannot register MDIO bus (-22)
>>> [ 8.965329] mv88e6085: probe of f212a200.mdio-mii:04 failed with error -22
>>>
>>> Signed-off-by: Josua Mayer <josua@solid-run.com>
>> This is not bug fix, assume you target net-next. Please:
>> 1) Next time, indicate that in the patch subject like this:
>> [patch net-next] xxx
>> 2) net-next is currently closed, repost next week.
> Correct, thanks - will do.
> Just for future reference for those occasional contributors -
> is there such a thing as an lkml calendar?
There is this: https://patchwork.hopto.org/net-next.html
>>
>>> ---
>>> drivers/net/dsa/mv88e6xxx/chip.c | 6 ++++--
>>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
>>> index 614cabb5c1b0..1c40f7631ab1 100644
>>> --- a/drivers/net/dsa/mv88e6xxx/chip.c
>>> +++ b/drivers/net/dsa/mv88e6xxx/chip.c
>>> @@ -3731,10 +3731,12 @@ static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
>>>
>>> if (np) {
>>> bus->name = np->full_name;
>>> - snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
>>> + if (snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np) >= MII_BUS_ID_SIZE)
>>> + dev_warn(chip->dev, "Truncated bus-id may collide.\n");
>> How about instead of warn&fail fallback to some different name in this
>> case?
> Duplicate could be avoided by truncating from the start,
> however I don't know if that is a good idea.
> It affects naming of paths in sysfs, and the root cause is
> difficult to spot.
>>> } else {
>>> bus->name = "mv88e6xxx SMI";
>>> - snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
>>> + if (snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++) >= MII_BUS_ID_SIZE)
>> How exactly this may happen?
> It can happen on switch nodes at deep levels in the device-tree,
> while describing both internal and external mdio buses of a switch.
> E.g. Documentation/devicetree/bindings/net/dsa/marvell,mv88e6xxx.yaml
We should consider moving these types of checks into the MDIO bus core,
or at least introduce a helper function such that it embeds the check in it.
--
Florian
next prev parent reply other threads:[~2024-03-20 15:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 13:48 [PATCH] net: dsa: mv88e6xxx: add warning for truncated mdio bus id Josua Mayer
2024-03-20 14:09 ` Jiri Pirko
2024-03-20 14:33 ` Josua Mayer
2024-03-20 15:13 ` Florian Fainelli [this message]
2024-03-20 16:28 ` Josua Mayer
2024-03-20 16:03 ` Jiri Pirko
2024-03-20 16:41 ` Josua Mayer
2024-03-20 18:57 ` Andrew Lunn
2024-03-21 10:26 ` Josua Mayer
2024-03-21 15:10 ` Andrew Lunn
2024-03-21 15:54 ` Josua Mayer
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=a5b2d1df-cf6e-42b6-8ccf-122be672db24@gmail.com \
--to=f.fainelli@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=josua@solid-run.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@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;
as well as URLs for NNTP newsgroup(s).