Thread (13 messages) 13 messages, 4 authors, 2025-05-14

Re: [PATCH net-next 3/3] net: phy: dp83869: Support 1000Base-X SFP modules

From: Romain Gantois <romain.gantois@bootlin.com>
Date: 2025-05-14 10:01:08
Also in: lkml

On Wednesday, 14 May 2025 11:01:07 CEST Antoine Tenart wrote:
On Wed, May 14, 2025 at 09:49:59AM +0200, Romain Gantois wrote:
quoted
+static int dp83869_port_configure_serdes(struct phy_port *port, bool
enable, +					 phy_interface_t interface)
+{
+	struct phy_device *phydev = port_phydev(port);
+	struct dp83869_private *dp83869;
+	int ret;
+
+	if (!enable)
+		return 0;
+
+	dp83869 = phydev->priv;
+
+	switch (interface) {
+	case PHY_INTERFACE_MODE_1000BASEX:
+		dp83869->mode = DP83869_RGMII_1000_BASE;
+		break;
+	default:
+		phydev_err(phydev, "Incompatible SFP module inserted\n");
+		return -EINVAL;
+	}
+
+	ret = dp83869_configure_mode(phydev, dp83869);
+	if (ret)
+		return ret;
+
+	/* Update advertisement */
+	if (mutex_trylock(&phydev->lock)) {
+		ret = dp83869_config_aneg(phydev);
+		mutex_unlock(&phydev->lock);
+	}
Just skimmed through this quickly and it's not clear to me why aneg is
restarted only if there was no contention on the global phydev lock;
it's not guaranteed a concurrent holder would do the same. If this is
intended, a comment would be welcomed.
The reasoning here is that there are code paths which call 
dp83869_port_configure_serdes() with phydev->lock already held, for example:

phy_start() -> sfp_upstream_start() -> sfp_start() -> \
	sfp_sm_event() -> __sfp_sm_event() -> sfp_sm_module() -> \ 
	sfp_module_insert() -> phy_sfp_module_insert() -> \
	dp83869_port_configure_serdes()

so taking this lock could result in a deadlock.

mutex_trylock() is definitely not a perfect solution though, but I went with it
partly because the marvell-88x2222 driver already does it this way, and partly 
because if phydev->lock() is held, then there's a solid chance that the phy 
state machine is already taking care of reconfiguring the advertisement. 
However, I'll admit that this is a bit of a shaky argument.

If someone has a better solution in mind, I'll gladly hear it out, but for now 
I guess I'll just add a comment explaining why trylock() is being used.

Thanks!

-- 
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help