Skip to contentSkip to conversation

net, IB/ipoib: Use dev_port to disambiguate

PATCH In review Arseny Maslennikov 3 participants 7 messages Aug 13, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover net, IB/ipoib: Use dev_port to disambiguate

Pre-3.15 userspace had trouble distinguishing different ports of a NIC on a single PCI bus/device/function. To solve this, a sysfs field `dev_port' was introduced quite a while ago (commit v3.14-rc3-739-g3f85944fe207), and some relevant device drivers were fixed to use it, but not in case of IPoIB.

The convention for some reason never got documented in the kernel, but was immediately adopted by userspace (notably udev[1][2], biosdevname[3])

3/3 documents the sysfs field — that's why I'm CC-ing netdev.

This series was tested on current LTS and 4.18.

[1] https://lists.freedesktop.org/archives/systemd-devel/2014-June/020788.html
[2] https://lists.freedesktop.org/archives/systemd-devel/2014-July/020804.html
[3] https://github.com/CloudAutomationNTools/biosdevname/blob/c795d51dd93a5309652f0d635f12a3ecfabfaa72/src/eths.c#L38

Arseny Maslennikov (3):
IB/ipoib: Use dev_port to expose network interface port numbers IB/ipoib: Stop using dev_id to expose port numbers Documentation/ABI: document /sys/class/net/*/dev_port

 Documentation/ABI/testing/sysfs-class-net | 10 ++++++++++
 drivers/infiniband/ulp/ipoib/ipoib_main.c |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/3 IB/ipoib: Use dev_port to expose network interface port numbers

Some InfiniBand network devices have multiple ports on the same PCI function. This initializes the `dev_port' sysfs field of those network interfaces with their port number.

The use of dev_id' was considered correct until Linux 3.15, when another field, dev_port', was defined for this particular purpose and `dev_id' was reserved for distinguishing stacked ifaces (e.g: VLANs) with the same hardware address as their parent device.

Similar fixes to net/mlx4_en and many other drivers, which started exporting this information through `dev_id' before 3.15, were accepted into the kernel 4 years ago.
See 76a066f2a2a0268b565459c417b59724b5a3197b, commit message:
`net/mlx4_en: Expose port number through sysfs'.

---
 drivers/infiniband/ulp/ipoib/ipoib_main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/infiniband/ulp/ipoib/ipoib_main.c +1 -0
index 26cde95bc0f3..6eb0594fffec 100644
@@ -2253,6 +2253,7 @@ static struct net_device *ipoib_add_port(const char *format,
 
 	SET_NETDEV_DEV(priv->dev, hca->dev.parent);
 	priv->dev->dev_id = port - 1;
+	priv->dev->dev_port = port - 1;
 
 	result = ib_query_port(hca, port, &attr);
 	if (result) {
Signature · 1 line
2.18.0
#2 lore raw

PATCH 2/3 IB/ipoib: Stop using dev_id to expose port numbers

In reply to Arseny Maslennikov

Some InfiniBand network devices have multiple ports on the same PCI function. Prior to this the kernel erroneously used the `dev_id' sysfs field of those network interfaces to convey the port number to userspace.

`dev_id' is currently reserved for distinguishing stacked ifaces (e.g: VLANs) with the same hardware address as their parent device.

Similar fixes to net/mlx4_en and many other drivers, which started exporting this information through `dev_id' before 3.15, were accepted into the kernel 4 years ago.
See 76a066f2a2a0268b565459c417b59724b5a3197b, commit message:
`net/mlx4_en: Expose port number through sysfs'.

I would be OK with this commit not being backported to stable, since it might break admin-supplied udev rules and the likes.

---
 drivers/infiniband/ulp/ipoib/ipoib_main.c | 1 -
 1 file changed, 1 deletion(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +0 -1
index 6eb0594fffec..f64535038147 100644
@@ -2252,7 +2252,6 @@ static struct net_device *ipoib_add_port(const char *format,
 	}
 
 	SET_NETDEV_DEV(priv->dev, hca->dev.parent);
-	priv->dev->dev_id = port - 1;
 	priv->dev->dev_port = port - 1;
 
 	result = ib_query_port(hca, port, &attr);
Signature · 1 line
2.18.0
#5 lore raw

PATCH 3/3 Documentation/ABI: document /sys/class/net/*/dev_port

In reply to Arseny Maslennikov

The sysfs field was introduced 4 years ago along with fixes to various drivers that erroneously used `dev_id' for that purpose, but it was not properly documented anywhere.
See commit v3.14-rc3-739-g3f85944fe207.

---
 Documentation/ABI/testing/sysfs-class-net | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/ABI/testing/sysfs-class-net +10 -0
index 2f1788111cd9..1593d8997ade 100644
@@ -91,6 +91,16 @@ Description:
 		stacked (e.g: VLAN interfaces) but still have the same MAC
 		address as their parent device.
 
+What:		/sys/class/net/<iface>/dev_port
+Date:		February 2014
+KernelVersion:	3.15
+Contact:	[email protected]
+Description:
+		Indicates the port number of this network device, formatted
+		as a decimal value. Some NICs have multiple independent ports
+		on the same PCI bus, device and function. This field allows
+		userspace to distinguish the respective interfaces.
+
 What:		/sys/class/net/<iface>/dormant
 Date:		March 2006
 KernelVersion:	2.6.17
Signature · 1 line
2.18.0
#3 lore raw

Re: [PATCH 2/3] IB/ipoib: Stop using dev_id to expose port numbers

In reply to Arseny Maslennikov
Quoted 26 lines · Arseny Maslennikov

Some InfiniBand network devices have multiple ports on the same PCI function. Prior to this the kernel erroneously used the `dev_id' sysfs field of those network interfaces to convey the port number to userspace.

`dev_id' is currently reserved for distinguishing stacked ifaces (e.g: VLANs) with the same hardware address as their parent device.

Similar fixes to net/mlx4_en and many other drivers, which started exporting this information through `dev_id' before 3.15, were accepted into the kernel 4 years ago.
See 76a066f2a2a0268b565459c417b59724b5a3197b, commit message:
`net/mlx4_en: Expose port number through sysfs'.

I would be OK with this commit not being backported to stable, since it might break admin-supplied udev rules and the likes.

---
 drivers/infiniband/ulp/ipoib/ipoib_main.c | 1 -
 1 file changed, 1 deletion(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +0 -0
index 6eb0594fffec..f64535038147 100644

drivers/infiniband/ulp/ipoib/ipoib_main.c static struct net_device *ipoib_add_port(const char *format, · line 2255

Quoted 4 lines
drivers/infiniband/ulp/ipoib/ipoib_main.c +0 -1
@@ -2252,7 +2252,6 @@ static struct net_device *ipoib_add_port(const char *format,
 	}
 
 	SET_NETDEV_DEV(priv->dev, hca->dev.parent);
-	priv->dev->dev_id = port - 1;

Correct me if i'm wrong here but besides some changes in commit message looks like patch 1/3 is the same as 2/3, isn't it?

Yuval

Quoted 6 lines
drivers/infiniband/ulp/ipoib/ipoib_main.c +0 -0
 	priv->dev->dev_port = port - 1;
 
 	result = ib_query_port(hca, port, &attr);
Signature · 1 line
2.18.0
#4 lore raw

Re: [PATCH 2/3] IB/ipoib: Stop using dev_id to expose port numbers

Quoted 29 lines · Yuval Shaia
Quoted 28 lines · Arseny Maslennikov

Some InfiniBand network devices have multiple ports on the same PCI function. Prior to this the kernel erroneously used the `dev_id' sysfs field of those network interfaces to convey the port number to userspace.

`dev_id' is currently reserved for distinguishing stacked ifaces (e.g: VLANs) with the same hardware address as their parent device.

Similar fixes to net/mlx4_en and many other drivers, which started exporting this information through `dev_id' before 3.15, were accepted into the kernel 4 years ago.
See 76a066f2a2a0268b565459c417b59724b5a3197b, commit message:
`net/mlx4_en: Expose port number through sysfs'.

I would be OK with this commit not being backported to stable, since it might break admin-supplied udev rules and the likes.

---
 drivers/infiniband/ulp/ipoib/ipoib_main.c | 1 -
 1 file changed, 1 deletion(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +0 -0
index 6eb0594fffec..f64535038147 100644
@@ -2252,7 +2252,6 @@ static struct net_device *ipoib_add_port(const char *format,
 	}
 
Quoted 8 lines

drivers/infiniband/ulp/ipoib/ipoib_main.c static struct net_device *ipoib_add_port(const char *format, · line 2255

Quoted 2 lines
drivers/infiniband/ulp/ipoib/ipoib_main.c +0 -1
 	SET_NETDEV_DEV(priv->dev, hca->dev.parent);
-	priv->dev->dev_id = port - 1;

Correct me if i'm wrong here but besides some changes in commit message looks like patch 1/3 is the same as 2/3, isn't it?

Yuval

1/3 has an extra line, 2/3 removes a different line.

(a) If you apply both 1/3 and 2/3, the port number can be seen at /sys/class/net/*/dev_port and not at .../dev_id.

(b) If you apply only 1/3, the port number can be seen at _both_ .../dev_port and .../dev_id (to preserve backward compatibility with e.g. existing udev rules that rely on "ATTR{dev_id}")

By splitting those up we have both options (a) and (b) available, so the maintainers are free to decide which one is wiser.

Quoted 6 lines
Quoted 6 lines
drivers/infiniband/ulp/ipoib/ipoib_main.c +0 -0
 	priv->dev->dev_port = port - 1;
 
 	result = ib_query_port(hca, port, &attr);
Signature · 1 line
2.18.0
#6 lore raw
In reply to Arseny Maslennikov
Quoted 16 lines · Arseny Maslennikov

Pre-3.15 userspace had trouble distinguishing different ports of a NIC on a single PCI bus/device/function. To solve this, a sysfs field `dev_port' was introduced quite a while ago (commit v3.14-rc3-739-g3f85944fe207), and some relevant device drivers were fixed to use it, but not in case of IPoIB.

The convention for some reason never got documented in the kernel, but was immediately adopted by userspace (notably udev[1][2], biosdevname[3])

3/3 documents the sysfs field — that's why I'm CC-ing netdev.

This series was tested on current LTS and 4.18.

[1] https://lists.freedesktop.org/archives/systemd-devel/2014-June/020788.html
[2] https://lists.freedesktop.org/archives/systemd-devel/2014-July/020804.html
[3] https://github.com/CloudAutomationNTools/biosdevname/blob/c795d51dd93a5309652f0d635f12a3ecfabfaa72/src/eths.c#L38

Quoted 8 lines

Arseny Maslennikov (3):
IB/ipoib: Use dev_port to expose network interface port numbers IB/ipoib: Stop using dev_id to expose port numbers Documentation/ABI: document /sys/class/net/*/dev_port

 Documentation/ABI/testing/sysfs-class-net | 10 ++++++++++
 drivers/infiniband/ulp/ipoib/ipoib_main.c |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

This series doesn't apply to rdma for-next, and it is the merge window now.

Can you resubmit this aginst 4.19-rc1 in two weeks? Thanks

Jason