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]
Message-Id: <20220513233640.2518337-3-vladimir.oltean@nxp.com>
Date:   Sat, 14 May 2022 02:36:40 +0300
From:   Vladimir Oltean <vladimir.oltean@....com>
To:     netdev@...r.kernel.org
Cc:     Jakub Kicinski <kuba@...nel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Paolo Abeni <pabeni@...hat.com>,
        Eric Dumazet <edumazet@...gle.com>,
        Florian Fainelli <f.fainelli@...il.com>,
        Vivien Didelot <vivien.didelot@...il.com>,
        Andrew Lunn <andrew@...n.ch>,
        Vladimir Oltean <olteanv@...il.com>,
        devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
        Saravana Kannan <saravanak@...gle.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Robin Murphy <robin.murphy@....com>,
        Geert Uytterhoeven <geert+renesas@...der.be>,
        Rob Herring <robh+dt@...nel.org>,
        Frank Rowand <frowand.list@...il.com>,
        John Stultz <jstultz@...gle.com>,
        Alvin Šipraga <alsi@...g-olufsen.dk>,
        Russell King <rmk+kernel@...linux.org.uk>,
        Heiner Kallweit <hkallweit1@...il.com>
Subject: [RFC PATCH net 2/2] net: dsa: wait for PHY to defer probe

DSA is among the 3 drivers which call phylink.*phy_connect() during
probe time (vs 11 doing so during ndo_open). So there is no guarantee
that the PHY driver will have finished probing by the time we connect to
it.

Use the newly introduced phylink_of_phy_connect_probe() to wait for this
to happen, and propagate the error code all the way to dsa_register_switch(),
which switch drivers call from their own probe function.

Notably, in dsa_tree_setup_ports() we treat errors on slave interface
registration as "soft" and continue probing the ports that didn't fail.
This is useful on systems which have riser cards with PHYs, and some of
these cards can be missing. But this logic needs to be adapted, since
-EPROBE_DEFER is an error we want to propagate regardless.

Fixes: 25396f680dd6 ("net: phylink: introduce phylink_fwnode_phy_connect()")
Signed-off-by: Vladimir Oltean <vladimir.oltean@....com>
---
 net/dsa/dsa2.c  |  2 ++
 net/dsa/port.c  |  6 ++++--
 net/dsa/slave.c | 10 +++++-----
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index cf933225df32..3a2983a1a7dd 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -1011,6 +1011,8 @@ static int dsa_tree_setup_ports(struct dsa_switch_tree *dst)
 	list_for_each_entry(dp, &dst->ports, list) {
 		if (dsa_port_is_user(dp) || dsa_port_is_unused(dp)) {
 			err = dsa_port_setup(dp);
+			if (err == -EPROBE_DEFER)
+				goto teardown;
 			if (err) {
 				err = dsa_port_reinit_as_unused(dp);
 				if (err)
diff --git a/net/dsa/port.c b/net/dsa/port.c
index 075a8db536c6..8a2fc99ca0ad 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -1628,9 +1628,11 @@ static int dsa_port_phylink_register(struct dsa_port *dp)
 	if (err)
 		return err;
 
-	err = phylink_of_phy_connect(dp->pl, port_dn, 0);
+	err = phylink_of_phy_connect_probe(dp->pl, port_dn, 0);
 	if (err && err != -ENODEV) {
-		pr_err("could not attach to PHY: %d\n", err);
+		dev_err_probe(ds->dev, err,
+			      "DSA/CPU port %d could not attach to PHY: %pe\n",
+			      dp->index, ERR_PTR(err));
 		goto err_phy_connect;
 	}
 
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 5ee0aced9410..a5407e717c68 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -2252,18 +2252,18 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
 	if (ds->ops->get_phy_flags)
 		phy_flags = ds->ops->get_phy_flags(ds, dp->index);
 
-	ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
+	ret = phylink_of_phy_connect_probe(dp->pl, port_dn, phy_flags);
 	if (ret == -ENODEV && ds->slave_mii_bus) {
 		/* We could not connect to a designated PHY or SFP, so try to
 		 * use the switch internal MDIO bus instead
 		 */
 		ret = dsa_slave_phy_connect(slave_dev, dp->index, phy_flags);
 	}
-	if (ret) {
+	if (ret && ret != -EPROBE_DEFER)
 		netdev_err(slave_dev, "failed to connect to PHY: %pe\n",
 			   ERR_PTR(ret));
+	if (ret)
 		phylink_destroy(dp->pl);
-	}
 
 	return ret;
 }
@@ -2386,12 +2386,12 @@ int dsa_slave_create(struct dsa_port *port)
 	netif_carrier_off(slave_dev);
 
 	ret = dsa_slave_phy_setup(slave_dev);
-	if (ret) {
+	if (ret && ret != -EPROBE_DEFER)
 		netdev_err(slave_dev,
 			   "error %d setting up PHY for tree %d, switch %d, port %d\n",
 			   ret, ds->dst->index, ds->index, port->index);
+	if (ret)
 		goto out_gcells;
-	}
 
 	rtnl_lock();
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ