lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 5 Jan 2021 20:03:43 +0100
From:   Andrew Lunn <andrew@...n.ch>
To:     Marek Vasut <marex@...x.de>
Cc:     netdev@...r.kernel.org, Florian Fainelli <f.fainelli@...il.com>,
        "David S . Miller" <davem@...emloft.net>,
        Heiner Kallweit <hkallweit1@...il.com>
Subject: Re: [PATCH] [RFC] net: phy: smsc: Add magnetics VIO regulator support

On Tue, Jan 05, 2021 at 06:53:48PM +0100, Marek Vasut wrote:
> On 1/5/21 6:38 PM, Andrew Lunn wrote:
> > > +static void smsc_link_change_notify(struct phy_device *phydev)
> > > +{
> > > +	struct smsc_phy_priv *priv = phydev->priv;
> > > +
> > > +	if (!priv->vddio)
> > > +		return;
> > > +
> > > +	if (phydev->state == PHY_HALTED)
> > > +		regulator_disable(priv->vddio);
> > > +
> > > +	if (phydev->state == PHY_NOLINK)
> > > +		regulator_enable(priv->vddio);
> > 
> > NOLINK is an interesting choice. Could you explain that please.
> 
> It's the first state after interface is up.

No, not really. phy_start() actually sets it to PHY_UP. When the state
machine runs, it kicks off auto-neg and immediately reads the link
state. If the link is down, it transitions to PHY_NOLINK, at which
point this code will enable the regulator.

> > I fear this is not going to be very robust to state machine
> > changes. And since it is hidden away in a driver, it is going to be
> > forgotten about. You might want to think about making it more robust.
> 
> I marked the patch as RFC because I would like input on how to implement
> this properly. Note that since the regulator supplies the magnetics, which
> might be shared between multiple ports with different PHYs, I don't think
> this code should even be in the PHY driver, but somewhere else -- but I
> don't know where.

Being shared should not be a problem. The regulator API does reference
counting. Any one driver turning the regulator on will enable it. But
it will not be turned off until all the drivers disable it after
enabling it. But that also means you need to balance the calls to
regulator_enable() and regulator_disable().

If for whatever reason this function is called for PHY_HALTED more
times than for PHY_NOLINK, the counter can go negative, and bad things
would happen. So i would actually had a bool to smsc_phy_priv
indicating if the regulator has been enabled. And for each
phydev->state, decide if the regulator should be enabled, check if it
is enabled according to the bool, and enable it is not. Same with
states which indicate it should be disabled. The code is then not
dependent on specific transitions, but on actual states. That should
be more robust to changes.

You also need to think about this regulator being shared. Say some
other PHY has enabled the regulator. phy_start() might be able to skip
PHY_NOLINK state and so this PHY never calls regulator_enable(). If
that other PHY is then configured down, it will disable the regulator,
and this PHY looses link. That probably is enough for this PHY to
re-enable the regulator, but it is not ideal.

	  Andrew

Powered by blists - more mailing lists