Subject: Re: [RFC PATCH net] net: dsa: tear down devlink port regions when tearing down the devlink port on error

From: Leon Romanovsky <[email-masked]>
Date: Sun, 5 Sep 2021 10:07:45 +0300

On Fri, Sep 03, 2021 at 02:17:38AM +0300, Vladimir Oltean wrote:
> Commit 86f8b1c01a0a ("net: dsa: Do not make user port errors fatal")
> decided it was fine to ignore errors on certain ports that fail to
> probe, and go on with the ports that do probe fine.
> 
> Commit fb6ec87f7229 ("net: dsa: Fix type was not set for devlink port")
> noticed that devlink_port_type_eth_set(dlp, dp->slave); does not get
> called, and devlink notices after a timeout of 3700 seconds and prints a
> WARN_ON. So it went ahead to unregister the devlink port. And because
> there exists an UNUSED port flavour, we actually re-register the devlink
> port as UNUSED.
> 
> Commit 08156ba430b4 ("net: dsa: Add devlink port regions support to
> DSA") added devlink port regions, which are set up by the driver and not
> by DSA.
> 
> When we trigger the devlink port deregistration and reregistration as
> unused, devlink now prints another WARN_ON, from here:
> 
> devlink_port_unregister:
> 	WARN_ON(!list_empty(&devlink_port->region_list));
> 
> So the port still has regions, which makes sense, because they were set
> up by the driver, and the driver doesn't know we're unregistering the
> devlink port.
> 
> Somebody needs to tear them down, and optionally (actually it would be
> nice, to be consistent) set them up again for the new devlink port.
> 
> But DSA's layering stays in our way quite badly here.

I don't know anything about DSA and what led to the decision to ignore
devlink registration errors, but devlink core is relying on the simple
assumption that everything is initialized correctly.

So if DSA needs to have not-initialized port, it should do all the needed
hacks internally.

Thanks