Skip to contentSkip to conversation

driver core: Fix device link device name collision

PATCH Superseded Saravana Kannan 2 participants 5 messages Jan 8, 2021 – Jan 9, 2021

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 driver core: Fix device link device name collision

The device link device's name was of the form:
<supplier-dev-name>--<consumer-dev-name>

This can cause name collision as reported here [1] as device names are not globally unique. Since device names have to be unique within the bus/class, add the bus/class name as a prefix to the device names used to construct the device link device name.

So the devuce link device's name will be of the form:
<supplier-bus-name>:<supplier-dev-name>--<consumer-bus-name>:<consumer-dev-name>

[1] - https://lore.kernel.org/lkml/[email protected]/

Fixes 287905e68dd2 ("driver core: Expose device link details in sysfs")
---
 Documentation/ABI/testing/sysfs-class-devlink   |  4 ++--
 .../ABI/testing/sysfs-devices-consumer          |  5 +++--
 .../ABI/testing/sysfs-devices-supplier          |  5 +++--
 drivers/base/core.c                             | 17 +++++++++--------
 include/linux/device.h                          | 12 ++++++++++++
 5 files changed, 29 insertions(+), 14 deletions(-)
Documentation/ABI/testing/sysfs-class-devlink +2 -2
index b662f747c83e..8a21ce515f61 100644
@@ -5,8 +5,8 @@ Description:
 		Provide a place in sysfs for the device link objects in the
 		kernel at any given time.  The name of a device link directory,
 		denoted as ... above, is of the form <supplier>--<consumer>
-		where <supplier> is the supplier device name and <consumer> is
-		the consumer device name.
+		where <supplier> is the supplier bus:device name and <consumer>
+		is the consumer bus:device name.
 
 What:		/sys/class/devlink/.../auto_remove_on
 Date:		May 2020
Documentation/ABI/testing/sysfs-devices-consumer +3 -2
index 1f06d74d1c3c..0809fda092e6 100644
@@ -4,5 +4,6 @@ Contact:	Saravana Kannan <[email protected]>
 Description:
 		The /sys/devices/.../consumer:<consumer> are symlinks to device
 		links where this device is the supplier. <consumer> denotes the
-		name of the consumer in that device link. There can be zero or
-		more of these symlinks for a given device.
+		name of the consumer in that device link and is of the form
+		bus:device name. There can be zero or more of these symlinks
+		for a given device.
Documentation/ABI/testing/sysfs-devices-supplier +3 -2
index a919e0db5e90..207f5972e98d 100644
@@ -4,5 +4,6 @@ Contact:	Saravana Kannan <[email protected]>
 Description:
 		The /sys/devices/.../supplier:<supplier> are symlinks to device
 		links where this device is the consumer. <supplier> denotes the
-		name of the supplier in that device link. There can be zero or
-		more of these symlinks for a given device.
+		name of the supplier in that device link and is of the form
+		bus:device name. There can be zero or more of these symlinks
+		for a given device.
drivers/base/core.c +9 -8
index 25e08e5f40bd..4140a69dfe18 100644
@@ -456,7 +456,9 @@ static int devlink_add_symlinks(struct device *dev,
 	struct device *con = link->consumer;
 	char *buf;
 
-	len = max(strlen(dev_name(sup)), strlen(dev_name(con)));
+	len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)),
+		  strlen(dev_bus_name(con)) + strlen(dev_name(con)));
+	len += strlen(":");
 	len += strlen("supplier:") + 1;
 	buf = kzalloc(len, GFP_KERNEL);
 	if (!buf)
@@ -470,12 +472,12 @@ static int devlink_add_symlinks(struct device *dev,
 	if (ret)
 		goto err_con;
 
-	snprintf(buf, len, "consumer:%s", dev_name(con));
+	snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con));
 	ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf);
 	if (ret)
 		goto err_con_dev;
 
-	snprintf(buf, len, "supplier:%s", dev_name(sup));
+	snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup));
 	ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf);
 	if (ret)
 		goto err_sup_dev;
@@ -737,8 +739,9 @@ struct device_link *device_link_add(struct device *consumer,
 
 	link->link_dev.class = &devlink_class;
 	device_set_pm_not_required(&link->link_dev);
-	dev_set_name(&link->link_dev, "%s--%s",
-		     dev_name(supplier), dev_name(consumer));
+	dev_set_name(&link->link_dev, "%s:%s--%s:%s",
+		     dev_bus_name(supplier), dev_name(supplier),
+		     dev_bus_name(consumer), dev_name(consumer));
 	if (device_register(&link->link_dev)) {
 		put_device(consumer);
 		put_device(supplier);
@@ -1808,9 +1811,7 @@ const char *dev_driver_string(const struct device *dev)
 	 * never change once they are set, so they don't need special care.
 	 */
 	drv = READ_ONCE(dev->driver);
-	return drv ? drv->name :
-			(dev->bus ? dev->bus->name :
-			(dev->class ? dev->class->name : ""));
+	return drv ? drv->name : dev_bus_name(dev);
 }
 EXPORT_SYMBOL(dev_driver_string);
 
include/linux/device.h +12 -0
index 89bb8b84173e..1779f90eeb4c 100644
@@ -609,6 +609,18 @@ static inline const char *dev_name(const struct device *dev)
 	return kobject_name(&dev->kobj);
 }
 
+/**
+ * dev_bus_name - Return a device's bus/class name, if at all possible
+ * @dev: struct device to get the bus/class name of
+ *
+ * Will return the name of the bus/class the device is attached to.  If it is
+ * not attached to a bus/class, an empty string will be returned.
+ */
+static inline const char *dev_bus_name(const struct device *dev)
+{
+	return dev->bus ? dev->bus->name : (dev->class ? dev->class->name : "");
+}
+
 __printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...);
 
 #ifdef CONFIG_NUMA
Signature · 1 line
2.29.2.729.g45daf8777d-goog
Tested-by on v3 1/1
#1 lore raw

Am 2021-01-08 02:24, schrieb Saravana Kannan:

Quoted 11 lines

The device link device's name was of the form:
<supplier-dev-name>--<consumer-dev-name>

This can cause name collision as reported here [1] as device names are not globally unique. Since device names have to be unique within the bus/class, add the bus/class name as a prefix to the device names used to construct the device link device name.

So the devuce link device's name will be of the form:
<supplier-bus-name>:<supplier-dev-name>--<consumer-bus-name>:<consumer-dev-name>

Quoted 7 lines

[1] - https://lore.kernel.org/lkml/[email protected]/

Fixes 287905e68dd2 ("driver core: Expose device link details in sysfs")

---

[..]

The changes are missing for the error path and devlink_remove_symlinks(), right?

drivers/base/core.c +6 -4
index 4140a69dfe18..385e16d92874 100644
@@ -485,7 +485,7 @@ static int devlink_add_symlinks(struct device *dev,
 	goto out;
 
 err_sup_dev:
-	snprintf(buf, len, "consumer:%s", dev_name(con));
+	snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con));
 	sysfs_remove_link(&sup->kobj, buf);
 err_con_dev:
 	sysfs_remove_link(&link->link_dev.kobj, "consumer");
@@ -508,7 +508,9 @@ static void devlink_remove_symlinks(struct device *dev,
 	sysfs_remove_link(&link->link_dev.kobj, "consumer");
 	sysfs_remove_link(&link->link_dev.kobj, "supplier");
 
-	len = max(strlen(dev_name(sup)), strlen(dev_name(con)));
+	len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)),
+		  strlen(dev_bus_name(con)) + strlen(dev_name(con)));
+	len += strlen(":");
 	len += strlen("supplier:") + 1;
 	buf = kzalloc(len, GFP_KERNEL);
 	if (!buf) {
@@ -516,9 +518,9 @@ static void devlink_remove_symlinks(struct device *dev,
 		return;
 	}
 
-	snprintf(buf, len, "supplier:%s", dev_name(sup));
+	snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup));
 	sysfs_remove_link(&con->kobj, buf);
-	snprintf(buf, len, "consumer:%s", dev_name(con));
+	snprintf(buf, len, "consumer:%s:%s", dev_bus_name(sup), dev_name(con));
 	sysfs_remove_link(&sup->kobj, buf);
 	kfree(buf);
 }

With these changes:

This at least make the warning go away.
BUT, there is somesthing strange or at least I don't get it:

# find /sys/bus/pci/devices/0000:00:00.0/ -name "consumer\:*"
# find /sys/bus/pci/devices/0000:00:00.1/ -name "consumer\:*"
/sys/bus/pci/devices/0000:00:00.1/consumer:mdio_bus:0000:00:00.1:04
/sys/bus/pci/devices/0000:00:00.1/consumer:mdio_bus:0000:00:00.1

enetc0 (0000:00:00.0) has no consumers while enetc1 (0000:00:00.1) has ones. Although both have PHYs connected. Here are the corresonding device tree entries:

enetc0:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts?h=v5.11-rc2#n81

enetc1:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts?h=v5.11-rc2#n21

Why is there a link between enetc1 and its PHY (and MDIO bus) but not for enetc0?

btw, here are all links:

# ls /sys/class/devlink/
pci:0000:00:00.1--mdio_bus:0000:00:00.1
platform:5000000.iommu--pci:0000:00:00.0
platform:5000000.iommu--pci:0000:00:00.1
platform:5000000.iommu--pci:0000:00:00.2
platform:5000000.iommu--pci:0000:00:00.3
platform:5000000.iommu--pci:0000:00:00.5
platform:5000000.iommu--pci:0000:00:00.6
platform:5000000.iommu--pci:0001:00:00.0
platform:5000000.iommu--pci:0002:00:00.0
platform:5000000.iommu--platform:2140000.mmc
platform:5000000.iommu--platform:2150000.mmc
platform:5000000.iommu--platform:22c0000.dma-controller
platform:5000000.iommu--platform:3100000.usb
platform:5000000.iommu--platform:3110000.usb
platform:5000000.iommu--platform:3200000.sata
platform:5000000.iommu--platform:8000000.crypto
platform:5000000.iommu--platform:8380000.dma-controller
platform:5000000.iommu--platform:f080000.display
platform:f1f0000.clock-controller--platform:f080000.display
regulator:regulator.0--i2c:0-0050
regulator:regulator.0--i2c:1-0057
regulator:regulator.0--i2c:2-0050
regulator:regulator.0--platform:3200000.sata
Signature · 1 line
-michael
#2 lore raw
Quoted 23 lines · Michael Walle

Am 2021-01-08 02:24, schrieb Saravana Kannan:

Quoted 15 lines

The device link device's name was of the form:
<supplier-dev-name>--<consumer-dev-name>

This can cause name collision as reported here [1] as device names are not globally unique. Since device names have to be unique within the bus/class, add the bus/class name as a prefix to the device names used to
construct the device link device name.

So the devuce link device's name will be of the form:
<supplier-bus-name>:<supplier-dev-name>--<consumer-bus-name>:<consumer-dev-name>

[1] -
https://lore.kernel.org/lkml/[email protected]/

Quoted 6 lines
Fixes 287905e68dd2 ("driver core: Expose device link details in

sysfs")

---

Quoted 5 lines

[..]

The changes are missing for the error path and
devlink_remove_symlinks(),
right?

Removing symlinks doesn't need the name. Just needs the "handle". So we are good there.

Quoted 41 lines
drivers/base/core.c +1 -1
index 4140a69dfe18..385e16d92874 100644
@@ -485,7 +485,7 @@ static int devlink_add_symlinks(struct device *dev,
        goto out;
 
  err_sup_dev:
-       snprintf(buf, len, "consumer:%s", dev_name(con));
+       snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con),
 dev_name(con));
        sysfs_remove_link(&sup->kobj, buf);
  err_con_dev:
        sysfs_remove_link(&link->link_dev.kobj, "consumer");
drivers/base/core.c +3 -1
@@ -508,7 +508,9 @@ static void devlink_remove_symlinks(struct device
 *dev,
        sysfs_remove_link(&link->link_dev.kobj, "consumer");
        sysfs_remove_link(&link->link_dev.kobj, "supplier");
 
-       len = max(strlen(dev_name(sup)), strlen(dev_name(con)));
+       len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)),
+                 strlen(dev_bus_name(con)) + strlen(dev_name(con)));
+       len += strlen(":");
        len += strlen("supplier:") + 1;
        buf = kzalloc(len, GFP_KERNEL);
        if (!buf) {
drivers/base/core.c +2 -2
@@ -516,9 +518,9 @@ static void devlink_remove_symlinks(struct device
 *dev,
                return;
        }
 
-       snprintf(buf, len, "supplier:%s", dev_name(sup));
+       snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup),
 dev_name(sup));
        sysfs_remove_link(&con->kobj, buf);
-       snprintf(buf, len, "consumer:%s", dev_name(con));
+       snprintf(buf, len, "consumer:%s:%s", dev_bus_name(sup),
 dev_name(con));
        sysfs_remove_link(&sup->kobj, buf);
        kfree(buf);
Quoted 5 lines

}

With these changes:

Greg,

I think it's good to pick up this version if you don't see any issues.

Quoted 2 lines

This at least make the warning go away.

Phew!

Quoted 11 lines

BUT, there is somesthing strange or at least I don't get it:

# find /sys/bus/pci/devices/0000:00:00.0/ -name "consumer\:*"
# find /sys/bus/pci/devices/0000:00:00.1/ -name "consumer\:*"
/sys/bus/pci/devices/0000:00:00.1/consumer:mdio_bus:0000:00:00.1:04
/sys/bus/pci/devices/0000:00:00.1/consumer:mdio_bus:0000:00:00.1

enetc0 (0000:00:00.0) has no consumers while enetc1 (0000:00:00.1) has ones. Although both have PHYs connected. Here are the corresonding device tree entries:

Quoted 8 lines

enetc0:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts?h=v5.11-rc2#n81

enetc1:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts?h=v5.11-rc2#n21

Why is there a link between enetc1 and its PHY (and MDIO bus) but not for enetc0?

So a lot of subtle things could be going on here that make it look like it's not working correctly but it's actually working fine. Since fw_devlink=permissive is the default mode, all links that are created are SYNC_STATE_ONLY links. These links are deleted after their consumers probe. So if you really want to see all the "real" links persist, try booting with fw_devlink=on. You might have boot issues though -- I'm working on that separately [1]. Also, SYNC_STATE_ONLY links can be created between the parent of a consumer and the supplier (I won't get into the why here) depending on some ordering -- so that might be causing some spurious looking links, but they aren't.

Another way to do what you are trying to do is to enable the logs in device_link_add() and look at them to see if all the links are created as you'd expect.

Quoted 18 lines

btw, here are all links:

# ls /sys/class/devlink/
pci:0000:00:00.1--mdio_bus:0000:00:00.1
platform:5000000.iommu--pci:0000:00:00.0
platform:5000000.iommu--pci:0000:00:00.1
platform:5000000.iommu--pci:0000:00:00.2
platform:5000000.iommu--pci:0000:00:00.3
platform:5000000.iommu--pci:0000:00:00.5
platform:5000000.iommu--pci:0000:00:00.6
platform:5000000.iommu--pci:0001:00:00.0
platform:5000000.iommu--pci:0002:00:00.0
platform:5000000.iommu--platform:2140000.mmc
platform:5000000.iommu--platform:2150000.mmc
platform:5000000.iommu--platform:22c0000.dma-controller
platform:5000000.iommu--platform:3100000.usb
platform:5000000.iommu--platform:3110000.usb
platform:5000000.iommu--platform:3200000.sata
Quoted 8 lines
platform:5000000.iommu--platform:8000000.crypto
platform:5000000.iommu--platform:8380000.dma-controller
platform:5000000.iommu--platform:f080000.display
platform:f1f0000.clock-controller--platform:f080000.display
regulator:regulator.0--i2c:0-0050
regulator:regulator.0--i2c:1-0057
regulator:regulator.0--i2c:2-0050
regulator:regulator.0--platform:3200000.sata

As you can see, most of the links that fw_devlink created are gone. Because all the consumers probed. Any remaining ones you see here are non-SYNC_STATE_ONLY links created by the driver/frameworks or cases where consumers haven't probed. My guess is that only the first one is of this criteria and it doesn't hurt anything here. Try booting with fw_devlink=on and check this list. That'll give you a better idea.

-Saravana

#3 lore raw

Am 2021-01-08 18:22, schrieb Saravana Kannan:

Quoted 24 lines · Michael Walle
Quoted 23 lines

Am 2021-01-08 02:24, schrieb Saravana Kannan:

Quoted 21 lines

The device link device's name was of the form:
<supplier-dev-name>--<consumer-dev-name>

This can cause name collision as reported here [1] as device names are not globally unique. Since device names have to be unique within the bus/class, add the bus/class name as a prefix to the device names used to
construct the device link device name.

So the devuce link device's name will be of the form:
<supplier-bus-name>:<supplier-dev-name>--<consumer-bus-name>:<consumer-dev-name>

[1] -
https://lore.kernel.org/lkml/[email protected]/

Fixes 287905e68dd2 ("driver core: Expose device link details in

sysfs")

---

Quoted 8 lines
Quoted 5 lines

[..]

The changes are missing for the error path and
devlink_remove_symlinks(),
right?

Removing symlinks doesn't need the name. Just needs the "handle". So we are good there.

I don't get it. What is the "handle"? Without the patch below kernfs_remove_by_name() in sysfs_remove_link will return -ENOENT. With the patch it will return 0.

And even if it would work, how is this even logical:

	snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con));
	ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf);
	if (ret)
		goto err_con_dev;
	snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup));
	ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf);
	if (ret)
		goto err_sup_dev;
[..]
err_sup_dev:
	snprintf(buf, len, "consumer:%s", dev_name(con));
	sysfs_remove_link(&sup->kobj, buf);

You call sysfs_create_link("consumer:bus_name:dev_name") but the corresponding rollback is sysfs_remove_link("consumer:dev_name"), that is super confusing.

Quoted 32 lines
Quoted 32 lines
drivers/base/core.c +1 -1
index 4140a69dfe18..385e16d92874 100644
@@ -485,7 +485,7 @@ static int devlink_add_symlinks(struct device 
 *dev,
        goto out;
 
  err_sup_dev:
-       snprintf(buf, len, "consumer:%s", dev_name(con));
+       snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con),
 dev_name(con));
        sysfs_remove_link(&sup->kobj, buf);
  err_con_dev:
        sysfs_remove_link(&link->link_dev.kobj, "consumer");
drivers/base/core.c +3 -1
@@ -508,7 +508,9 @@ static void devlink_remove_symlinks(struct device
 *dev,
        sysfs_remove_link(&link->link_dev.kobj, "consumer");
        sysfs_remove_link(&link->link_dev.kobj, "supplier");
 
-       len = max(strlen(dev_name(sup)), strlen(dev_name(con)));
+       len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)),
+                 strlen(dev_bus_name(con)) + strlen(dev_name(con)));
+       len += strlen(":");
        len += strlen("supplier:") + 1;
        buf = kzalloc(len, GFP_KERNEL);
        if (!buf) {
drivers/base/core.c +0 -0
@@ -516,9 +518,9 @@ static void devlink_remove_symlinks(struct device
 *dev,
                return;
        }
 
Quoted 7 lines

drivers/base/core.c static void devlink_remove_symlinks(struct device · line 526

Quoted 7 lines
drivers/base/core.c +2 -2
-       snprintf(buf, len, "supplier:%s", dev_name(sup));
+       snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup),
 dev_name(sup));
        sysfs_remove_link(&con->kobj, buf);
-       snprintf(buf, len, "consumer:%s", dev_name(con));
+       snprintf(buf, len, "consumer:%s:%s", dev_bus_name(sup),
 dev_name(con));

btw this should be dev_bus_name(con).

Quoted 11 lines
Quoted 7 lines
        sysfs_remove_link(&sup->kobj, buf);
        kfree(buf);

}

With these changes:

Greg,

I think it's good to pick up this version if you don't see any issues.

Why so fast?

Quoted 66 lines
Quoted 1 line

This at least make the warning go away.

Phew!

Quoted 11 lines

BUT, there is somesthing strange or at least I don't get it:

# find /sys/bus/pci/devices/0000:00:00.0/ -name "consumer\:*"
# find /sys/bus/pci/devices/0000:00:00.1/ -name "consumer\:*"
/sys/bus/pci/devices/0000:00:00.1/consumer:mdio_bus:0000:00:00.1:04
/sys/bus/pci/devices/0000:00:00.1/consumer:mdio_bus:0000:00:00.1

enetc0 (0000:00:00.0) has no consumers while enetc1 (0000:00:00.1) has ones. Although both have PHYs connected. Here are the corresonding device tree entries:

Quoted 8 lines

enetc0:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts?h=v5.11-rc2#n81

enetc1:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts?h=v5.11-rc2#n21

Why is there a link between enetc1 and its PHY (and MDIO bus) but not for enetc0?

So a lot of subtle things could be going on here that make it look like it's not working correctly but it's actually working fine. Since fw_devlink=permissive is the default mode, all links that are created are SYNC_STATE_ONLY links. These links are deleted after their consumers probe. So if you really want to see all the "real" links persist, try booting with fw_devlink=on. You might have boot issues though -- I'm working on that separately [1]. Also, SYNC_STATE_ONLY links can be created between the parent of a consumer and the supplier (I won't get into the why here) depending on some ordering -- so that might be causing some spurious looking links, but they aren't.

Another way to do what you are trying to do is to enable the logs in device_link_add() and look at them to see if all the links are created as you'd expect.

Quoted 18 lines

btw, here are all links:

# ls /sys/class/devlink/
pci:0000:00:00.1--mdio_bus:0000:00:00.1
platform:5000000.iommu--pci:0000:00:00.0
platform:5000000.iommu--pci:0000:00:00.1
platform:5000000.iommu--pci:0000:00:00.2
platform:5000000.iommu--pci:0000:00:00.3
platform:5000000.iommu--pci:0000:00:00.5
platform:5000000.iommu--pci:0000:00:00.6
platform:5000000.iommu--pci:0001:00:00.0
platform:5000000.iommu--pci:0002:00:00.0
platform:5000000.iommu--platform:2140000.mmc
platform:5000000.iommu--platform:2150000.mmc
platform:5000000.iommu--platform:22c0000.dma-controller
platform:5000000.iommu--platform:3100000.usb
platform:5000000.iommu--platform:3110000.usb
platform:5000000.iommu--platform:3200000.sata
Quoted 8 lines
platform:5000000.iommu--platform:8000000.crypto
platform:5000000.iommu--platform:8380000.dma-controller
platform:5000000.iommu--platform:f080000.display
platform:f1f0000.clock-controller--platform:f080000.display
regulator:regulator.0--i2c:0-0050
regulator:regulator.0--i2c:1-0057
regulator:regulator.0--i2c:2-0050
regulator:regulator.0--platform:3200000.sata
Quoted 6 lines

As you can see, most of the links that fw_devlink created are gone. Because all the consumers probed. Any remaining ones you see here are non-SYNC_STATE_ONLY links created by the driver/frameworks or cases where consumers haven't probed. My guess is that only the first one is of this criteria and it doesn't hurt anything here. Try booting with fw_devlink=on and check this list. That'll give you a better idea.

Thanks for explaining. I'll try that.

-michael

#4 lore raw
Quoted 32 lines · Michael Walle

Am 2021-01-08 18:22, schrieb Saravana Kannan:

Quoted 30 lines · Michael Walle
Quoted 28 lines

Am 2021-01-08 02:24, schrieb Saravana Kannan:

Quoted 15 lines

The device link device's name was of the form:
<supplier-dev-name>--<consumer-dev-name>

This can cause name collision as reported here [1] as device names are not globally unique. Since device names have to be unique within the bus/class, add the bus/class name as a prefix to the device names used to
construct the device link device name.

So the devuce link device's name will be of the form:
<supplier-bus-name>:<supplier-dev-name>--<consumer-bus-name>:<consumer-dev-name>

[1] -
https://lore.kernel.org/lkml/[email protected]/

Quoted 6 lines
Fixes 287905e68dd2 ("driver core: Expose device link details in

sysfs")

---

[..]

The changes are missing for the error path and
devlink_remove_symlinks(),
right?

Quoted 8 lines
Quoted 2 lines

Removing symlinks doesn't need the name. Just needs the "handle". So we are good there.

I don't get it. What is the "handle"? Without the patch below kernfs_remove_by_name() in sysfs_remove_link will return -ENOENT. With the patch it will return 0.

And even if it would work, how is this even logical:

Ah sorry, I confused it with removing device attrs. I need to fix up the symlink remove path.

Quoted 50 lines
        snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con));
        ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf);
        if (ret)
                goto err_con_dev;
        snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup));
        ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf);
        if (ret)
                goto err_sup_dev;
[..]
err_sup_dev:
        snprintf(buf, len, "consumer:%s", dev_name(con));
        sysfs_remove_link(&sup->kobj, buf);

You call sysfs_create_link("consumer:bus_name:dev_name") but the corresponding rollback is sysfs_remove_link("consumer:dev_name"), that is super confusing.

Quoted 32 lines
Quoted 32 lines
drivers/base/core.c +1 -1
index 4140a69dfe18..385e16d92874 100644
@@ -485,7 +485,7 @@ static int devlink_add_symlinks(struct device
 *dev,
        goto out;
 
  err_sup_dev:
-       snprintf(buf, len, "consumer:%s", dev_name(con));
+       snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con),
 dev_name(con));
        sysfs_remove_link(&sup->kobj, buf);
  err_con_dev:
        sysfs_remove_link(&link->link_dev.kobj, "consumer");
drivers/base/core.c +3 -1
@@ -508,7 +508,9 @@ static void devlink_remove_symlinks(struct device
 *dev,
        sysfs_remove_link(&link->link_dev.kobj, "consumer");
        sysfs_remove_link(&link->link_dev.kobj, "supplier");
 
-       len = max(strlen(dev_name(sup)), strlen(dev_name(con)));
+       len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)),
+                 strlen(dev_bus_name(con)) + strlen(dev_name(con)));
+       len += strlen(":");
        len += strlen("supplier:") + 1;
        buf = kzalloc(len, GFP_KERNEL);
        if (!buf) {
drivers/base/core.c +0 -0
@@ -516,9 +518,9 @@ static void devlink_remove_symlinks(struct device
 *dev,
                return;
        }
 
Quoted 7 lines
Quoted 7 lines

drivers/base/core.c static void devlink_remove_symlinks(struct device · line 526

Quoted 7 lines
drivers/base/core.c +2 -2
-       snprintf(buf, len, "supplier:%s", dev_name(sup));
+       snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup),
 dev_name(sup));
        sysfs_remove_link(&con->kobj, buf);
-       snprintf(buf, len, "consumer:%s", dev_name(con));
+       snprintf(buf, len, "consumer:%s:%s", dev_bus_name(sup),
 dev_name(con));

Ah I completely skimmed over this code thinking it was code from my patch. Like I said, I was struggling with the length of the email due to the logs. Anyway, I'll fix up the remove symlink path too. Thanks for catching that.

Quoted 8 lines

btw this should be dev_bus_name(con).

Quoted 6 lines
Quoted 6 lines
        sysfs_remove_link(&sup->kobj, buf);
        kfree(buf);

}

With these changes:

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Greg,

I think it's good to pick up this version if you don't see any issues.

Why so fast?

Sorry, didn't mean to rush. I was just trying to say I wasn't planning on a v4 because I thought your Tested-by was for my unchanged v4, but clearly I need to send a v4.

-Saravana