Skip to contentSkip to conversation

net: Add phys_port identifier to struct net_device and export it to sysfs

PATCH In review [email protected] 6 participants 23 messages Jun 17, 2013 – Jul 22, 2013

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

PATCH 1/1 net: Add phys_port identifier to struct net_device and export it to sysfs

It is useful to know if network interfaces from NIC partitions 'map to/use the' same physical port. For example, when creating bonding in fault tolerance mode, if two network interfaces map to/use the same physical port, it might not have the desired result. This information is not available today in a standard format or it is not present. If this information can be made available in a generic way to user space, tools such as NetworkManager or Libteam or Wicked can make smarter bonding decisions (such as warn users when setting up configurations which will not have desired effect).

The requirement is to have a generic interface using which kernel/drivers can provide information/hints to user space about the physical port number used by a network interface.

The following options were explored -

1. 'dev_id' sysfs attribute:

In addition to being used to differentiate between devices that share the same link layer address, it is being used to indicate the physical port number used by a network interface.

As dev_id exists to differentiate between devices sharing the same link layer address, dev_id option is not selected.

2. Re-using 'if_port' field in 'struct net_device':

if_port field exists to indicate the media type(please refer to netdevice.h). It seemed like it was also used to indicate the physical port number.

As re-using 'if_port' might possibly break user space, this option is not selected.

3. Add a new field 'phys_port' to 'struct net_device' and export it to sysfs:

The 'phys_port' will be a universally unique identifier, which would be a MAC-48 or EUI-64 or a 128 bit UUID value, but not restricted to these spaces. It will uniquely identify the physical port used by a network interface. The 'length' of the identifier will be zero if the field is not set for a network interface.

This patch implements option 3. It creates a new sysfs attribute 'phys_port' -

/sys/class/net/<interface name>/phys_port

References: http://marc.info/?l=linux-netdev&m=136920998009209&w=2
References: http://marc.info/?l=linux-netdev&m=136992041432498&w=2

---
Changes from RFC version:

Suggestions from Ben Hutchings -
1. 'struct port_identifier' is changed to be generic instead of restricting it to MAC-48 or EUI-64 or 128 bit UUID.
2. Commit message updated to indicate point 1.
3. 'show_phys_port' function modified to handle zero length instead of returning -EINVAL
4. 'show_phys_port' function made generic to handle all lengths instead 6, 8 or 16 bytes.

Hi Ben, I have retained the commit message to indicate that 'dev_id' is being used to indicate the physical port number also.

Thank you.

 include/linux/netdevice.h | 13 +++++++++++++
 net/core/net-sysfs.c      | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)
include/linux/netdevice.h +13 -0
index 09b4188..ddb14ef 100644
@@ -1062,6 +1062,14 @@ struct net_device_ops {
 						      bool new_carrier);
 };
 
+/* This structure holds a universally unique identifier to
+ * identify the physical port used by a netdevice
+ */
+struct port_identifier {
+	unsigned char port_id[MAX_ADDR_LEN];
+	unsigned port_id_len;
+};
+
 /*
  *	The DEVICE structure.
  *	Actually, this whole structure is a big mistake.  It mixes I/O
@@ -1181,6 +1189,11 @@ struct net_device {
 						 * that share the same link
 						 * layer address
 						 */
+	struct port_identifier	phys_port;	/* Universally unique physical
+						 * port identifier, MAC-48 or
+						 * EUI-64 or 128 bit UUID,
+						 * length is zero if not set
+						 */
 	spinlock_t		addr_list_lock;
 	struct netdev_hw_addr_list	uc;	/* Unicast mac addresses */
 	struct netdev_hw_addr_list	mc;	/* Multicast mac addresses */
net/core/net-sysfs.c +17 -0
index 981fed3..3245e90 100644
@@ -334,6 +334,22 @@ static ssize_t store_group(struct device *dev, struct device_attribute *attr,
 	return netdev_store(dev, attr, buf, len, change_group);
 }
 
+static ssize_t show_phys_port(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct net_device *net = to_net_dev(dev);
+	unsigned char len;
+
+	if (!dev_isalive(net))
+		return -EINVAL;
+
+	len = net->phys_port.port_id_len;
+	if (!len)
+		return 0;
+
+	return sysfs_format_mac(buf, net->phys_port.port_id, len);
+}
+
 static struct device_attribute net_class_attributes[] = {
 	__ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL),
 	__ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
@@ -355,6 +371,7 @@ static struct device_attribute net_class_attributes[] = {
 	__ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
 	       store_tx_queue_len),
 	__ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group),
+	__ATTR(phys_port, S_IRUGO, show_phys_port, NULL),
 	{}
 };
 
Signature · 7 lines
1.8.0.1

-- 
With regards,
Narendra K
Linux Engineering
Dell Inc.
#1 lore raw
Quoted 72 lines · On 06/17/2013 11:10 AM, [email protected] wrote:

It is useful to know if network interfaces from NIC partitions 'map to/use the' same physical port. For example, when creating bonding in fault tolerance mode, if two network interfaces map to/use the same physical port, it might not have the desired result. This information is not available today in a standard format or it is not present. If this information can be made available in a generic way to user space, tools such as NetworkManager or Libteam or Wicked can make smarter bonding decisions (such as warn users when setting up configurations which will not have desired effect).

The requirement is to have a generic interface using which kernel/drivers can provide information/hints to user space about the physical port number used by a network interface.

The following options were explored -

1. 'dev_id' sysfs attribute:

In addition to being used to differentiate between devices that share the same link layer address, it is being used to indicate the physical port number used by a network interface.

As dev_id exists to differentiate between devices sharing the same link layer address, dev_id option is not selected.

2. Re-using 'if_port' field in 'struct net_device':

if_port field exists to indicate the media type(please refer to netdevice.h). It seemed like it was also used to indicate the physical port number.

As re-using 'if_port' might possibly break user space, this option is not selected.

3. Add a new field 'phys_port' to 'struct net_device' and export it to sysfs:

The 'phys_port' will be a universally unique identifier, which would be a MAC-48 or EUI-64 or a 128 bit UUID value, but not restricted to these spaces. It will uniquely identify the physical port used by a network interface. The 'length' of the identifier will be zero if the field is not set for a network interface.

This patch implements option 3. It creates a new sysfs attribute 'phys_port' -

/sys/class/net/<interface name>/phys_port

References: http://marc.info/?l=linux-netdev&m=136920998009209&w=2
References: http://marc.info/?l=linux-netdev&m=136992041432498&w=2

---
Changes from RFC version:

Suggestions from Ben Hutchings -
1. 'struct port_identifier' is changed to be generic instead of restricting it to MAC-48 or EUI-64 or 128 bit UUID.
2. Commit message updated to indicate point 1.
3. 'show_phys_port' function modified to handle zero length instead of returning -EINVAL
4. 'show_phys_port' function made generic to handle all lengths instead 6, 8 or 16 bytes.

Hi Ben, I have retained the commit message to indicate that 'dev_id' is being used to indicate the physical port number also.

Thank you.

  include/linux/netdevice.h | 13 +++++++++++++
  net/core/net-sysfs.c      | 17 +++++++++++++++++
  2 files changed, 30 insertions(+)

[...]

net/core/net-sysfs.c static ssize_t store_group(struct device *dev, struct device_attribute *attr, · line 336

Quoted 6 lines
net/core/net-sysfs.c +0 -0
@@ -334,6 +334,22 @@ static ssize_t store_group(struct device *dev, struct device_attribute *attr,
  	return netdev_store(dev, attr, buf, len, change_group);
  }
 

Is there some missing locking here?

net/core/net-sysfs.c static ssize_t store_group(struct device *dev, struct device_attribute *attr, · line 342

Quoted 6 lines
net/core/net-sysfs.c +6 -0
+static ssize_t show_phys_port(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct net_device *net = to_net_dev(dev);
+	unsigned char len;
+
        read_lock(&dev_base_lock);

net/core/net-sysfs.c static ssize_t store_group(struct device *dev, struct device_attribute *attr, · line 348

Quoted 6 lines
net/core/net-sysfs.c +6 -0
+	if (!dev_isalive(net))
+		return -EINVAL;
+
+	len = net->phys_port.port_id_len;
+	if (!len)
+		return 0;
	ret = sysfs_format_mac(buf, net->phys_port.port_id, len);
	read_unlock(&dev_base_lock);

	return ret;
}

Please take a look maybe I missed something.

Thanks,
John

Signature · 1 line
John Fastabend         Intel Corporation
#2 lore raw
Quoted 10 lines

-----Original Message-----
From: John Fastabend [mailto:[email protected]]
Sent: Tuesday, June 18, 2013 12:18 AM
To: K, Narendra
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] net: Add phys_port identifier to struct net_device and export it to sysfs

On 06/17/2013 11:10 AM, [email protected] wrote:

[...]

Quoted 70 lines
Quoted 37 lines

3. Add a new field 'phys_port' to 'struct net_device' and export it to sysfs:

The 'phys_port' will be a universally unique identifier, which would be a MAC-48 or EUI-64 or a 128 bit UUID value, but not restricted to these spaces. It will uniquely identify the physical port used by a network interface. The 'length' of the identifier will be zero if the field is not set for a network interface.

This patch implements option 3. It creates a new sysfs attribute 'phys_port' -

/sys/class/net/<interface name>/phys_port

References: http://marc.info/?l=linux-netdev&m=136920998009209&w=2
References: http://marc.info/?l=linux-netdev&m=136992041432498&w=2

---
Changes from RFC version:

Suggestions from Ben Hutchings -
1. 'struct port_identifier' is changed to be generic instead of restricting it to MAC-48 or EUI-64 or 128 bit UUID.
2. Commit message updated to indicate point 1.
3. 'show_phys_port' function modified to handle zero length instead of returning -EINVAL 4. 'show_phys_port' function made generic to handle all lengths instead 6, 8 or 16 bytes.

Hi Ben, I have retained the commit message to indicate that 'dev_id' is being used to indicate the physical port number also.

Thank you.

  include/linux/netdevice.h | 13 +++++++++++++
  net/core/net-sysfs.c      | 17 +++++++++++++++++
  2 files changed, 30 insertions(+)

[...]

net/core/net-sysfs.c static ssize_t store_group(struct device *dev,

Quoted 3 lines
net/core/net-sysfs.c +0 -0
@@ -334,6 +334,22 @@ static ssize_t store_group(struct device *dev,

struct device_attribute *attr,

net/core/net-sysfs.c static ssize_t store_group(struct device *dev, struct device_attribute *attr, · line 336

Quoted 3 lines
net/core/net-sysfs.c +0 -0
  	return netdev_store(dev, attr, buf, len, change_group);
  }
 

Is there some missing locking here?

net/core/net-sysfs.c static ssize_t store_group(struct device *dev, struct device_attribute *attr, · line 342

Quoted 5 lines
net/core/net-sysfs.c +5 -0
+static ssize_t show_phys_port(struct device *dev,
+			      struct device_attribute *attr, char *buf) {
+	struct net_device *net = to_net_dev(dev);
+	unsigned char len;
+
         read_lock(&dev_base_lock);

net/core/net-sysfs.c static ssize_t store_group(struct device *dev, struct device_attribute *attr, · line 348

Quoted 6 lines
net/core/net-sysfs.c +6 -0
+	if (!dev_isalive(net))
+		return -EINVAL;
+
+	len = net->phys_port.port_id_len;
+	if (!len)
+		return 0;
	ret = sysfs_format_mac(buf, net->phys_port.port_id, len);
	read_unlock(&dev_base_lock);

	return ret;
}
Quoted 2 lines

Please take a look maybe I missed something.

Hi John, thanks for the pointer. It seems like we need to hold the ' dev_base_lock' here. I missed this initially as I was looking at ' show_broadcast' function . But looks like the 'show_broadcast' function is also missing the lock. Attributes such as 'dev_id' are read with read_lock(&dev_base_lock) generically in netdev_show function.

While looking at the use of ' dev_base_lock', the 'write_lock' is being held when the 'netdev' is being added to and removed from 'dev_base_head'. It is also being held when the 'dev->operstate' and 'dev->link_mode' are being changed.

The 'read_lock(&dev_base_lock)' needs to be held before the 'dev_isalive(net) ' call because

1. netdev is not removed from 'dev_base_head' when 'show_phys_port' accesses 'netdev->phys_port.port_id' (and port_id_len)
2. show_phys_port function sees a consistent value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' if another execution path changes the value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' with write_lock(&dev_base_lock) held (similar to how dev->operstate is being changed).

Is the above understanding correct ? Sorry, if I missed some detail here.

With regards,
Narendra K
Linux Engineering
Dell Inc.

#3 lore raw

On Wed, 2013-06-19 at 07:29 -0700, [email protected] wrote:
[...]

Quoted 5 lines

2. show_phys_port function sees a consistent value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' if another execution path changes the value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' with write_lock(&dev_base_lock) held (similar to how dev->operstate is being changed).

[...]

If the physical port ID can change dynamically (I hadn't thought of that, but an embedded switch could support such reconfiguration) then any such change also needs to be announced through rtnetlink. Actually, I think the value needs to be included in rtnetlink information anyway.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#4 lore raw
Quoted 16 lines

-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Wednesday, June 19, 2013 9:07 PM
To: K, Narendra
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] net: Add phys_port identifier to struct net_device and export it to sysfs

On Wed, 2013-06-19 at 07:29 -0700, [email protected] wrote:
[...]

Quoted 5 lines

2. show_phys_port function sees a consistent value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' if another execution path changes the value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' with write_lock(&dev_base_lock) held (similar to how dev->operstate is being changed).

Quoted 7 lines

[...]

If the physical port ID can change dynamically (I hadn't thought of that, but an embedded switch could support such reconfiguration) then any such change also needs to be announced through rtnetlink. Actually, I think the value needs to be included in rtnetlink information anyway.

Ok. Thank you Ben. I had not thought about this scenario. I was thinking about the reason to hold the dev_base_lock. Do you think points 1 and 2 are correct reason to hold the dev_base_lock ? If correct, I think the 'show_broadcast' function also needs to be fixed as it is not holding the lock.

With regards,
Narendra K
Linux Engineering
Dell Inc.

#5 lore raw
Quoted 24 lines · On Thu, 2013-06-20 at 00:23 +0530, [email protected] wrote:
Quoted 16 lines

-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Wednesday, June 19, 2013 9:07 PM
To: K, Narendra
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] net: Add phys_port identifier to struct net_device and export it to sysfs

On Wed, 2013-06-19 at 07:29 -0700, [email protected] wrote:
[...]

Quoted 5 lines

2. show_phys_port function sees a consistent value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' if another execution path changes the value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' with write_lock(&dev_base_lock) held (similar to how dev->operstate is being changed).

Quoted 7 lines

[...]

If the physical port ID can change dynamically (I hadn't thought of that, but an embedded switch could support such reconfiguration) then any such change also needs to be announced through rtnetlink. Actually, I think the value needs to be included in rtnetlink information anyway.

Quoted 3 lines

Ok. Thank you Ben. I had not thought about this scenario. I was thinking about the reason to hold the dev_base_lock. Do you think points 1 and 2 are correct reason to hold the dev_base_lock ?

I think so.

Quoted 2 lines

If correct, I think the 'show_broadcast' function also needs to be fixed as it is not holding the lock.

I think the broadcast address should never change during the lifetime of a device, so it doesn't need the lock. That might not be true for all layer 2 protocols though.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#6 lore raw

Having an unique identifier per port, the userspace tools might be able to check if the VFs/partitions are of the same physical port. Just being paranoid, wouldn't it be better to bond VFs/Partitions across NICs instead of across ports of the same NIC?

To be able to check if the VFs/partitions are of the same port & NIC, the unique identifier should probably have two identifiers in it like ABC_XYZ. The ABC uniquely identifying the NIC and XYZ uniquely identifying the port.

Any thoughts?

Thank you
Praveen K Paladugu

#7 lore raw
In reply to Ben Hutchings
Quoted 31 lines · Ben Hutchings
Quoted 24 lines · On Thu, 2013-06-20 at 00:23 +0530, [email protected] wrote:
Quoted 16 lines

-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Wednesday, June 19, 2013 9:07 PM
To: K, Narendra
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] net: Add phys_port identifier to struct net_device and export it to sysfs

On Wed, 2013-06-19 at 07:29 -0700, [email protected] wrote:
[...]

Quoted 5 lines

2. show_phys_port function sees a consistent value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' if another execution path changes the value of 'netdev->phys_port.port_id and netdev->phys_port.port_id_len ' with write_lock(&dev_base_lock) held (similar to how dev->operstate is being changed).

Quoted 7 lines

[...]

If the physical port ID can change dynamically (I hadn't thought of that, but an embedded switch could support such reconfiguration) then any such change also needs to be announced through rtnetlink. Actually, I think the value needs to be included in rtnetlink information anyway.

Quoted 3 lines

Ok. Thank you Ben. I had not thought about this scenario. I was thinking about the reason to hold the dev_base_lock. Do you think points 1 and 2 are correct reason to hold the dev_base_lock ?

I think so.

Quoted 9 lines
Quoted 2 lines

If correct, I think the 'show_broadcast' function also needs to be fixed as it is not holding the lock.

I think the broadcast address should never change during the lifetime of a device, so it doesn't need the lock. That might not be true for all layer 2 protocols though.

Ben.

Also, do you think this will be primarily useful for partitioning devices that expose multiple physical functions? Or do you see a use case for SR-IOV with virtual functions as well. The pyhs_port attribute provides a common interface for both cases which is good I suppose in the VF case however the host can already learn this. I gather from your original post here that you are aware of all this.

quoting:

Quoted 7 lines

I was thinking about the scenario of VF0 and VF1 coming from PF0 in the host Network Controller 1 being direct assigned to a KVM guest via VTD and netdevices from VF0 and VF1 being bonded in the guest. Assuming that physical port number used by VF0 and VF1 is 1, additional information is needed to identify if port number 1 is on Network controller 1 or Network controller 2. (In the host we could use PCI b/d/f to differentiate two Network Controllers). I think it is similar to hybrid guest acceleration on the VF assignment aspect.

I'm curious though why would the host/libvirt assign two VFs from the same PF to a guest like this? Is this really a host mis-configuration that you want a way to detect in the guest?

Thanks,
John

Signature · 1 line
John Fastabend         Intel Corporation
#8 lore raw
Quoted 9 lines

-----Original Message-----
From: John Fastabend [mailto:[email protected]]
Sent: Friday, June 21, 2013 10:41 PM
To: K, Narendra
Cc: Ben Hutchings; [email protected]; [email protected]
Subject: Re: [PATCH net-next] net: Add phys_port identifier to struct net_device and export it to sysfs

On 06/19/2013 12:34 PM, Ben Hutchings wrote:

[...]

Quoted 12 lines
Quoted 11 lines

I think so.

Quoted 2 lines

If correct, I think the 'show_broadcast' function also needs to be fixed as it is not holding the lock.

I think the broadcast address should never change during the lifetime of a device, so it doesn't need the lock. That might not be true for all layer 2 protocols though.

Ben.

Quoted 7 lines

Also, do you think this will be primarily useful for partitioning devices that expose multiple physical functions? Or do you see a use case for SR-IOV with virtual functions as well. The pyhs_port attribute provides a common interface for both cases which is good I suppose in the VF case however the host can already learn this. I gather from your original post here that you are aware of all this.

John, I think it will be useful in the SRIOV scenario also when more than one VF from two NICs are assigned to the guest. phys_port would be helpful in choosing the correct slave interfaces when host details are not available.

With regards,
Narendra K
Linux Engineering
Dell Inc.

#9 lore raw

[...]

Quoted 10 lines
Quoted 8 lines

Also, do you think this will be primarily useful for partitioning devices that expose multiple physical functions? Or do you see a use case for SR-IOV with virtual functions as well. The pyhs_port attribute provides a common interface for both cases which is good I suppose in the VF case however the host can already learn this. I gather from your original post here that you are aware of all this.

John, I think it will be useful in the SRIOV scenario also when more

than one VF from two NICs are assigned to the guest. phys_port would be helpful in choosing the correct slave interfaces when host details are not available.

OK. But I'm not sure why you would assign two VFs from the same NIC to a guest? This doesn't seem like a good configuration for failover because if one VF fails it seems likely both will fail. Maybe there are some benefits for load balancing? Or my assumption both VFs will fail is wrong.

Anyways it does seem useful in the partitioning case with multiple physical functions.

.John

Signature · 1 line
John Fastabend         Intel Corporation
#10 lore raw
Quoted 16 lines · John Fastabend

[...]

Quoted 10 lines
Quoted 8 lines

Also, do you think this will be primarily useful for partitioning devices that expose multiple physical functions? Or do you see a use case for SR-IOV with virtual functions as well. The pyhs_port attribute provides a common interface for both cases which is good I suppose in the VF case however the host can already learn this. I gather from your original post here that you are aware of all this.

John, I think it will be useful in the SRIOV scenario also when more

than one VF from two NICs are assigned to the guest. phys_port would be helpful in choosing the correct slave interfaces when host details are not available.

Quoted 5 lines

OK. But I'm not sure why you would assign two VFs from the same NIC to a guest? This doesn't seem like a good configuration for failover because if one VF fails it seems likely both will fail. Maybe there are some benefits for load balancing? Or my assumption both VFs will fail is wrong.

I believe Narendra is trying to provide hints to the guest that would allow it to avoid such broken bonding configurations. But it is certainly a good question why there would be two VFs assigned in the first place.

I could imagine passing through two VFs for the same physical port that have been assigned to different VLANs. But then you wouldn't want to bond two devices that are on different VLANs, whether or not they're using the same port!

Quoted 2 lines

Anyways it does seem useful in the partitioning case with multiple physical functions.

I was thinking it could also help to support the hybrid guest networking mode. In this mode, the guest gets a PV (e.g. virtio_net) device and a VF bridged to the same physical port, and the VF can be removed before the guest is migrated (and maybe reinserted if there's a VF available on the new host) without a major disruption to the guest. In that case the guest *should* bond together the two net devices that have the same physical port ID but different drivers. This would require the physical port ID to be propagated through macvtap/macvlan and virtio.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#11 lore raw
Quoted 2 lines · Ben Hutchings

On Fri, 2013-06-28 at 09:33 -0700, John Fastabend wrote:

[...]

Quoted 16 lines
Quoted 10 lines
Quoted 1 line

John, I think it will be useful in the SRIOV scenario also when more

than one VF from two NICs are assigned to the guest. phys_port would be helpful in choosing the correct slave interfaces when host details are not available.

OK. But I'm not sure why you would assign two VFs from the same NIC to a guest? This doesn't seem like a good configuration for failover because if one VF fails it seems likely both will fail. Maybe there are some benefits for load balancing? Or my assumption both VFs will fail is wrong.

I believe Narendra is trying to provide hints to the guest that would allow it to avoid such broken bonding configurations. But it is certainly a good question why there would be two VFs assigned in the first place.

Quoted 4 lines

I could imagine passing through two VFs for the same physical port that have been assigned to different VLANs. But then you wouldn't want to bond two devices that are on different VLANs, whether or not they're using the same port!

I was thinking of the following scenario in the guest.

bond0 = NIC1 VF0 + NIC2 VF0
bond1 = NIC1 VF1 + NIC2 VF1

bond0 and bond1 are on different VLANs. The phys_port identifier hint would be helpful to the guest in selecting the correct slaves for the above configuration. Sorry if I missed any detail here.

Quoted 3 lines
Quoted 3 lines

Anyways it does seem useful in the partitioning case with multiple physical functions.

Yes, I agree.

Quoted 22 lines

I was thinking it could also help to support the hybrid guest networking mode. In this mode, the guest gets a PV (e.g. virtio_net) device and a VF bridged to the same physical port, and the VF can be removed before the guest is migrated (and maybe reinserted if there's a VF available on the new host) without a major disruption to the guest. In that case the guest *should* bond together the two net devices that have the same physical port ID but different drivers. This would require the physical port ID to be propagated through macvtap/macvlan and virtio.

Ben.

--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 4 lines
With regards,
Narendra K
Linux Engineering
Dell Inc.
#12 lore raw
In reply to [email protected]
Quoted 37 lines · Mon, Jun 17, 2013 at 08:10:32PM CEST, [email protected] wrote:

It is useful to know if network interfaces from NIC partitions 'map to/use the' same physical port. For example, when creating bonding in fault tolerance mode, if two network interfaces map to/use the same physical port, it might not have the desired result. This information is not available today in a standard format or it is not present. If this information can be made available in a generic way to user space, tools such as NetworkManager or Libteam or Wicked can make smarter bonding decisions (such as warn users when setting up configurations which will not have desired effect).

The requirement is to have a generic interface using which kernel/drivers can provide information/hints to user space about the physical port number used by a network interface.

The following options were explored -

1. 'dev_id' sysfs attribute:

In addition to being used to differentiate between devices that share the same link layer address, it is being used to indicate the physical port number used by a network interface.

As dev_id exists to differentiate between devices sharing the same link layer address, dev_id option is not selected.

2. Re-using 'if_port' field in 'struct net_device':

if_port field exists to indicate the media type(please refer to netdevice.h). It seemed like it was also used to indicate the physical port number.

As re-using 'if_port' might possibly break user space, this option is not selected.

3. Add a new field 'phys_port' to 'struct net_device' and export it to sysfs:

Quoted 8 lines

The 'phys_port' will be a universally unique identifier, which would be a MAC-48 or EUI-64 or a 128 bit UUID value, but not restricted to these spaces. It will uniquely identify the physical port used by a network interface. The 'length' of the identifier will be zero if the field is not set for a network interface.

This patch implements option 3. It creates a new sysfs attribute 'phys_port' -

I think that correct way is to (Ben mentioned already part of it):
1) introduce ndo_phys_port_id() which would be used by core to get the struct port_identifier filled by the driver (struct port_identifier is not really a good name (namespace prefix should be there))

2) add netdev nofitier event type which would allow driver to propagate changes of phys to to rtnetlink code and drivers which might be interested (like bond/bridge/whatever) as well.

3) export phys port id through rtnetlink api to userspace.

I can cook up a patch like this after I return from my weekend trip if you are interested :)

Jiri

Quoted 106 lines

/sys/class/net/<interface name>/phys_port

References: http://marc.info/?l=linux-netdev&m=136920998009209&w=2
References: http://marc.info/?l=linux-netdev&m=136992041432498&w=2

---
Changes from RFC version:

Suggestions from Ben Hutchings -
1. 'struct port_identifier' is changed to be generic instead of restricting it to MAC-48 or EUI-64 or 128 bit UUID.
2. Commit message updated to indicate point 1.
3. 'show_phys_port' function modified to handle zero length instead of returning -EINVAL
4. 'show_phys_port' function made generic to handle all lengths instead 6, 8 or 16 bytes.

Hi Ben, I have retained the commit message to indicate that 'dev_id' is being used to indicate the physical port number also.

Thank you.

include/linux/netdevice.h | 13 +++++++++++++
net/core/net-sysfs.c | 17 +++++++++++++++++

2 files changed, 30 insertions(+)
include/linux/netdevice.h +13 -0
index 09b4188..ddb14ef 100644
@@ -1062,6 +1062,14 @@ struct net_device_ops {
 						      bool new_carrier);
 };
 
+/* This structure holds a universally unique identifier to
+ * identify the physical port used by a netdevice
+ */
+struct port_identifier {
+	unsigned char port_id[MAX_ADDR_LEN];
+	unsigned port_id_len;
+};
+
 /*
 *	The DEVICE structure.
 *	Actually, this whole structure is a big mistake.  It mixes I/O
@@ -1181,6 +1189,11 @@ struct net_device {
 						 * that share the same link
 						 * layer address
 						 */
+	struct port_identifier	phys_port;	/* Universally unique physical
+						 * port identifier, MAC-48 or
+						 * EUI-64 or 128 bit UUID,
+						 * length is zero if not set
+						 */
 	spinlock_t		addr_list_lock;
 	struct netdev_hw_addr_list	uc;	/* Unicast mac addresses */
 	struct netdev_hw_addr_list	mc;	/* Multicast mac addresses */
net/core/net-sysfs.c +17 -0
index 981fed3..3245e90 100644
@@ -334,6 +334,22 @@ static ssize_t store_group(struct device *dev, struct device_attribute *attr,
 	return netdev_store(dev, attr, buf, len, change_group);
 }
 
+static ssize_t show_phys_port(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct net_device *net = to_net_dev(dev);
+	unsigned char len;
+
+	if (!dev_isalive(net))
+		return -EINVAL;
+
+	len = net->phys_port.port_id_len;
+	if (!len)
+		return 0;
+
+	return sysfs_format_mac(buf, net->phys_port.port_id, len);
+}
+
 static struct device_attribute net_class_attributes[] = {
 	__ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL),
 	__ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
@@ -355,6 +371,7 @@ static struct device_attribute net_class_attributes[] = {
 	__ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
 	       store_tx_queue_len),
 	__ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group),
+	__ATTR(phys_port, S_IRUGO, show_phys_port, NULL),
 	{}
 };
 
Signature · 11 lines
1.8.0.1

-- 
With regards,
Narendra K
Linux Engineering
Dell Inc.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw
Quoted 2 lines · Jiri Pirko

Mon, Jun 17, 2013 at 08:10:32PM CEST, [email protected] wrote:

[...]

Quoted 9 lines
Quoted 9 lines

3. Add a new field 'phys_port' to 'struct net_device' and export it to sysfs:

The 'phys_port' will be a universally unique identifier, which would be a MAC-48 or EUI-64 or a 128 bit UUID value, but not restricted to these spaces. It will uniquely identify the physical port used by a network interface. The 'length' of the identifier will be zero if the field is not set for a network interface.

Quoted 7 lines
Quoted 2 lines

This patch implements option 3. It creates a new sysfs attribute 'phys_port' -

I think that correct way is to (Ben mentioned already part of it):
1) introduce ndo_phys_port_id() which would be used by core to get the struct port_identifier filled by the driver (struct port_identifier is

Hi Jiri, thank you for the comments.

I was thinking if ndo_phys_port_id() is required. 'netdev->phys_port.port_id' and port_id_len are set by driver before calling 'register_netdev' and are available to the core. If 'port_id' is changed by driver, then point 2 would notify the interested components and point 3 would notify the userspace. Please let me know if i am missing something.

Quoted 1 line

not really a good name (namespace prefix should be there))

Ok. I have changed it 'struct phys_port_identifier'. Please let me know if it is suitable.

Quoted 4 lines

2) add netdev nofitier event type which would allow driver to propagate changes of phys to to rtnetlink code and drivers which might be interested (like bond/bridge/whatever) as well.

Ok. I have added 'NETDEV_CHANGE_PHYS_PORT' event type which could be used by drivers.

Quoted 2 lines

3) export phys port id through rtnetlink api to userspace.

It is implemented in this patch here -
[RFC,net-next] net: Include phys_port identifier in the RTM_NEWLINK message
http://patchwork.ozlabs.org/patch/255435/

Please find the patch with the changes incorporated. If the changes look good, i will incorporate them in the next version of the patch.

[PATCH net-next ] Add phys_port identifier to struct net_device
and export it to sysfs

It is useful to know if network interfaces from NIC partitions 'map to/use the' same physical port. For example, when creating bonding in fault tolerance mode, if two network interfaces map to/use the same physical port, it might not have the desired result. This information is not available today in a standard format or it is not present. If this information can be made available in a generic way to user space, tools such as NetworkManager or Libteam or Wicked can make smarter bonding decisions (such as warn users when setting up configurations which will not have desired effect).

The requirement is to have a generic interface using which kernel/drivers can provide information/hints to user space about the physical port number used by a network interface.

The following options were explored -

1. 'dev_id' sysfs attribute:

In addition to being used to differentiate between devices that share the same link layer address, it is being used to indicate the physical port number used by a network interface.

As dev_id exists to differentiate between devices sharing the same link layer address, dev_id option is not selected.

2. Re-using 'if_port' field in 'struct net_device':

if_port field exists to indicate the media type(please refer to netdevice.h). It seemed like it was also used to indicate the physical port number.

As re-using 'if_port' might possibly break user space, this option is not selected.

3. Add a new field 'phys_port' to 'struct net_device' and export it to sysfs:

The 'phys_port' will be a universally unique identifier, which would be a MAC-48 or EUI-64 or a 128 bit UUID value, but not restricted to these spaces. It will uniquely identify the physical port used by a network interface. The 'length' of the identifier will be zero if the field is not set for a network interface.

This patch implements option 3. It creates a new sysfs attribute 'phys_port' -

/sys/class/net/<interface name>/phys_port

References: http://marc.info/?l=linux-netdev&m=136920998009209&w=2
References: http://marc.info/?l=linux-netdev&m=136992041432498&w=2

---
 include/linux/netdevice.h | 14 ++++++++++++++
 net/core/net-sysfs.c      | 22 ++++++++++++++++++++++
 2 files changed, 36 insertions(+)
include/linux/netdevice.h +14 -0
index 0741a1e..17db7e5 100644
@@ -1062,6 +1062,14 @@ struct net_device_ops {
 						      bool new_carrier);
 };
 
+/* This structure holds a universally unique identifier to
+ * identify the physical port used by a netdevice
+ */
+struct phys_port_identifier {
+	unsigned char port_id[MAX_ADDR_LEN];
+	unsigned char port_id_len;
+};
+
 /*
  *	The DEVICE structure.
  *	Actually, this whole structure is a big mistake.  It mixes I/O
@@ -1181,6 +1189,11 @@ struct net_device {
 						 * that share the same link
 						 * layer address
 						 */
+	struct phys_port_identifier	phys_port; /* Universally unique physical
+						    * port identifier, MAC-48 or
+						    * EUI-64 or 128 bit UUID,
+						    * length is zero if not set
+						    */
 	spinlock_t		addr_list_lock;
 	struct netdev_hw_addr_list	uc;	/* Unicast mac addresses */
 	struct netdev_hw_addr_list	mc;	/* Multicast mac addresses */
@@ -1633,6 +1646,7 @@ struct packet_offload {
 #define NETDEV_NOTIFY_PEERS	0x0013
 #define NETDEV_JOIN		0x0014
 #define NETDEV_CHANGEUPPER	0x0015
+#define NETDEV_CHANGE_PHYS_PORT	0x0016
 
 extern int register_netdevice_notifier(struct notifier_block *nb);
 extern int unregister_netdevice_notifier(struct notifier_block *nb);
net/core/net-sysfs.c +22 -0
index 981fed3..b77ebe6 100644
@@ -334,6 +334,27 @@ static ssize_t store_group(struct device *dev, struct device_attribute *attr,
 	return netdev_store(dev, attr, buf, len, change_group);
 }
 
+static ssize_t show_phys_port(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct net_device *net = to_net_dev(dev);
+	ssize_t ret = -EINVAL;
+	unsigned char len;
+
+	read_lock(&dev_base_lock);
+	if (dev_isalive(net)) {
+		len = net->phys_port.port_id_len;
+		if (!len)
+			ret = 0;
+		else
+			ret = sysfs_format_mac(buf, net->phys_port.port_id,
+					       len);
+	}
+	read_unlock(&dev_base_lock);
+
+	return ret;
+}
+
 static struct device_attribute net_class_attributes[] = {
 	__ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL),
 	__ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
@@ -355,6 +376,7 @@ static struct device_attribute net_class_attributes[] = {
 	__ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
 	       store_tx_queue_len),
 	__ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group),
+	__ATTR(phys_port, S_IRUGO, show_phys_port, NULL),
 	{}
 };
 
Signature · 7 lines
1.8.0.1

-- 
With regards,
Narendra K
Linux Engineering
Dell Inc.
#14 lore raw

On Mon, Jul 15, 2013 at 6:34 PM, <[email protected]> wrote:
[...]

Quoted 51 lines

It is implemented in this patch here -
[RFC,net-next] net: Include phys_port identifier in the RTM_NEWLINK message http://patchwork.ozlabs.org/patch/255435/

Please find the patch with the changes incorporated. If the changes look good, i will incorporate them in the next version of the patch.

[PATCH net-next ] Add phys_port identifier to struct net_device and export it to sysfs

It is useful to know if network interfaces from NIC partitions 'map to/use the' same physical port. For example, when creating bonding in fault tolerance mode, if two network interfaces map to/use the same physical port, it might not have the desired result. This information is not available today in a standard format or it is not present. If this information can be made available in a generic way to user space, tools such as NetworkManager or Libteam or Wicked can make smarter bonding decisions (such as warn users when setting up configurations which will not have desired effect).

The requirement is to have a generic interface using which kernel/drivers can provide information/hints to user space about the physical port number used by a network interface.

The following options were explored -

1. 'dev_id' sysfs attribute:

In addition to being used to differentiate between devices that share the same link layer address, it is being used to indicate the physical port number used by a network interface.

As dev_id exists to differentiate between devices sharing the same link layer address, dev_id option is not selected.

2. Re-using 'if_port' field in 'struct net_device':

if_port field exists to indicate the media type(please refer to netdevice.h). It seemed like it was also used to indicate the physical port number.

As re-using 'if_port' might possibly break user space, this option is not selected.

3. Add a new field 'phys_port' to 'struct net_device' and export it to sysfs:

The 'phys_port' will be a universally unique identifier, which would be a MAC-48 or EUI-64 or a 128 bit UUID value, but not restricted to these spaces. It will uniquely identify the physical port used by a network interface. The 'length' of the identifier will be zero if the field is not set for a network interface.

Quoted 4 lines

This patch implements option 3. It creates a new sysfs attribute 'phys_port' -

/sys/class/net/<interface name>/phys_port

Hi Narendra, John, Ben, Jiri,

Before diving to the eswitch use cases of this patch/approach, I was wondering if/how the new
phys_port field could be of use for drivers that just want to place there an INT saying if this interface
is associated with port #N of the PCI device (e.g N={1,2}). I wasn't sure how this is supposted
to be done if the semantics of the new field is the one mentioned above in the change long
(MAC-48 or EUI-64 or a 128 bit UUID value). Both mlx4 and ipoib driver use the dev_id field and would
be happily ported to the new interface once introduced in a way that allows to meet the integer requirement.

Or.

Quoted 110 lines

References: http://marc.info/?l=linux-netdev&m=136920998009209&w=2
References: http://marc.info/?l=linux-netdev&m=136992041432498&w=2

---
 include/linux/netdevice.h | 14 ++++++++++++++
 net/core/net-sysfs.c      | 22 ++++++++++++++++++++++
 2 files changed, 36 insertions(+)
include/linux/netdevice.h +8 -0
index 0741a1e..17db7e5 100644
@@ -1062,6 +1062,14 @@ struct net_device_ops {
                                                      bool new_carrier);
 };
 
+/* This structure holds a universally unique identifier to
+ * identify the physical port used by a netdevice
+ */
+struct phys_port_identifier {
+       unsigned char port_id[MAX_ADDR_LEN];
+       unsigned char port_id_len;
+};
+
 /*
  *     The DEVICE structure.
  *     Actually, this whole structure is a big mistake.  It mixes I/O
@@ -1181,6 +1189,11 @@ struct net_device {
                                                 * that share the same

link
* layer address */
+ struct phys_port_identifier phys_port; /* Universally unique
physical
+ * port identifier,
MAC-48 or
+ * EUI-64 or 128 bit
UUID,
+ * length is zero if
not set
+ */
spinlock_t addr_list_lock;
struct netdev_hw_addr_list uc; /* Unicast mac addresses
*/
struct netdev_hw_addr_list mc; /* Multicast mac addresses
*/

include/linux/netdevice.h +1 -0
@@ -1633,6 +1646,7 @@ struct packet_offload {
 #define NETDEV_NOTIFY_PEERS    0x0013
 #define NETDEV_JOIN            0x0014
 #define NETDEV_CHANGEUPPER     0x0015
+#define NETDEV_CHANGE_PHYS_PORT        0x0016
 
 extern int register_netdevice_notifier(struct notifier_block *nb);
 extern int unregister_netdevice_notifier(struct notifier_block *nb);
net/core/net-sysfs.c +21 -0
index 981fed3..b77ebe6 100644
@@ -334,6 +334,27 @@ static ssize_t store_group(struct device *dev, struct
 device_attribute *attr,
        return netdev_store(dev, attr, buf, len, change_group);
 }
 
+static ssize_t show_phys_port(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       struct net_device *net = to_net_dev(dev);
+       ssize_t ret = -EINVAL;
+       unsigned char len;
+
+       read_lock(&dev_base_lock);
+       if (dev_isalive(net)) {
+               len = net->phys_port.port_id_len;
+               if (!len)
+                       ret = 0;
+               else
+                       ret = sysfs_format_mac(buf,
 net->phys_port.port_id,
+                                              len);
+       }
+       read_unlock(&dev_base_lock);
+
+       return ret;
+}
+
 static struct device_attribute net_class_attributes[] = {

__ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL), __ATTR(addr_len, S_IRUGO, show_addr_len, NULL),

net/core/net-sysfs.c +1 -1
@@ -355,6 +376,7 @@ static struct device_attribute net_class_attributes[]
 = {
        __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
               store_tx_queue_len),
        __ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group),
+       __ATTR(phys_port, S_IRUGO, show_phys_port, NULL),
        {}
 };
 
--

1.8.0.1

--
With regards,
Narendra K
Linux Engineering
Dell Inc.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw
Quoted 60 lines · Sun, Jul 21, 2013 at 07:55:41AM CEST, [email protected] wrote:

On Mon, Jul 15, 2013 at 6:34 PM, <[email protected]> wrote:
[...]

Quoted 51 lines

It is implemented in this patch here -
[RFC,net-next] net: Include phys_port identifier in the RTM_NEWLINK message http://patchwork.ozlabs.org/patch/255435/

Please find the patch with the changes incorporated. If the changes look good, i will incorporate them in the next version of the patch.

[PATCH net-next ] Add phys_port identifier to struct net_device and export it to sysfs

It is useful to know if network interfaces from NIC partitions 'map to/use the' same physical port. For example, when creating bonding in fault tolerance mode, if two network interfaces map to/use the same physical port, it might not have the desired result. This information is not available today in a standard format or it is not present. If this information can be made available in a generic way to user space, tools such as NetworkManager or Libteam or Wicked can make smarter bonding decisions (such as warn users when setting up configurations which will not have desired effect).

The requirement is to have a generic interface using which kernel/drivers can provide information/hints to user space about the physical port number used by a network interface.

The following options were explored -

1. 'dev_id' sysfs attribute:

In addition to being used to differentiate between devices that share the same link layer address, it is being used to indicate the physical port number used by a network interface.

As dev_id exists to differentiate between devices sharing the same link layer address, dev_id option is not selected.

2. Re-using 'if_port' field in 'struct net_device':

if_port field exists to indicate the media type(please refer to netdevice.h). It seemed like it was also used to indicate the physical port number.

As re-using 'if_port' might possibly break user space, this option is not selected.

3. Add a new field 'phys_port' to 'struct net_device' and export it to sysfs:

The 'phys_port' will be a universally unique identifier, which would be a MAC-48 or EUI-64 or a 128 bit UUID value, but not restricted to these spaces. It will uniquely identify the physical port used by a network interface. The 'length' of the identifier will be zero if the field is not set for a network interface.

Quoted 4 lines

This patch implements option 3. It creates a new sysfs attribute 'phys_port' -

/sys/class/net/<interface name>/phys_port

Hi Narendra, John, Ben, Jiri,

Quoted 12 lines

Before diving to the eswitch use cases of this patch/approach, I was wondering if/how the new
phys_port field could be of use for drivers that just want to place there an INT saying if this interface
is associated with port #N of the PCI device (e.g N={1,2}). I wasn't sure how this is supposted
to be done if the semantics of the new field is the one mentioned above in the change long
(MAC-48 or EUI-64 or a 128 bit UUID value). Both mlx4 and ipoib driver use the dev_id field and would
be happily ported to the new interface once introduced in a way that allows to meet the integer requirement.

The value could be anything. But note that you have to have different values for card1-port1,2 and card2-port1,2

Quoted 113 lines

Or.

Quoted 110 lines

References: http://marc.info/?l=linux-netdev&m=136920998009209&w=2
References: http://marc.info/?l=linux-netdev&m=136992041432498&w=2

---
 include/linux/netdevice.h | 14 ++++++++++++++
 net/core/net-sysfs.c      | 22 ++++++++++++++++++++++
 2 files changed, 36 insertions(+)
include/linux/netdevice.h +8 -0
index 0741a1e..17db7e5 100644
@@ -1062,6 +1062,14 @@ struct net_device_ops {
                                                      bool new_carrier);
 };
 
+/* This structure holds a universally unique identifier to
+ * identify the physical port used by a netdevice
+ */
+struct phys_port_identifier {
+       unsigned char port_id[MAX_ADDR_LEN];
+       unsigned char port_id_len;
+};
+
 /*
  *     The DEVICE structure.
  *     Actually, this whole structure is a big mistake.  It mixes I/O
@@ -1181,6 +1189,11 @@ struct net_device {
                                                 * that share the same

link
* layer address */
+ struct phys_port_identifier phys_port; /* Universally unique
physical
+ * port identifier,
MAC-48 or
+ * EUI-64 or 128 bit
UUID,
+ * length is zero if
not set
+ */
spinlock_t addr_list_lock;
struct netdev_hw_addr_list uc; /* Unicast mac addresses
*/
struct netdev_hw_addr_list mc; /* Multicast mac addresses
*/

include/linux/netdevice.h +1 -0
@@ -1633,6 +1646,7 @@ struct packet_offload {
 #define NETDEV_NOTIFY_PEERS    0x0013
 #define NETDEV_JOIN            0x0014
 #define NETDEV_CHANGEUPPER     0x0015
+#define NETDEV_CHANGE_PHYS_PORT        0x0016
 
 extern int register_netdevice_notifier(struct notifier_block *nb);
 extern int unregister_netdevice_notifier(struct notifier_block *nb);
net/core/net-sysfs.c +21 -0
index 981fed3..b77ebe6 100644
@@ -334,6 +334,27 @@ static ssize_t store_group(struct device *dev, struct
 device_attribute *attr,
        return netdev_store(dev, attr, buf, len, change_group);
 }
 
+static ssize_t show_phys_port(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       struct net_device *net = to_net_dev(dev);
+       ssize_t ret = -EINVAL;
+       unsigned char len;
+
+       read_lock(&dev_base_lock);
+       if (dev_isalive(net)) {
+               len = net->phys_port.port_id_len;
+               if (!len)
+                       ret = 0;
+               else
+                       ret = sysfs_format_mac(buf,
 net->phys_port.port_id,
+                                              len);
+       }
+       read_unlock(&dev_base_lock);
+
+       return ret;
+}
+
 static struct device_attribute net_class_attributes[] = {

__ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL), __ATTR(addr_len, S_IRUGO, show_addr_len, NULL),

net/core/net-sysfs.c +1 -1
@@ -355,6 +376,7 @@ static struct device_attribute net_class_attributes[]
 = {
        __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
               store_tx_queue_len),
        __ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group),
+       __ATTR(phys_port, S_IRUGO, show_phys_port, NULL),
        {}
 };
 
--

1.8.0.1

--
With regards,
Narendra K
Linux Engineering
Dell Inc.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw

On Sun, Jul 21, 2013 at 10:24 AM, Jiri Pirko <[email protected]> wrote:
[...]

Sorry, I missed that fact that initially you responded on this thread

Quoted 2 lines

The value could be anything. But note that you have to have different values for card1-port1,2 and card2-port1,2

why?

Or.

#17 lore raw
Quoted 9 lines · Or Gerlitz

On Sun, Jul 21, 2013 at 10:24 AM, Jiri Pirko <[email protected]> wrote:
[...]

Sorry, I missed that fact that initially you responded on this thread

Quoted 2 lines

The value could be anything. But note that you have to have different values for card1-port1,2 and card2-port1,2

why?

The intent is to identify physical ports uniquely, so userland can tell whether two devices are backed by the same physical port.

But there's no requirement on the format, so you could ensure that one byte of this identifier is the port number on the board.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#18 lore raw
Quoted 6 lines · Ben Hutchings
Quoted 5 lines · Or Gerlitz

On Sun, Jul 21, 2013 at 10:24 AM, Jiri Pirko <[email protected]> wrote:
[...]

Sorry, I missed that fact that initially you responded on this thread

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The value could be anything. But note that you have to have different values for card1-port1,2 and card2-port1,2

why?

The intent is to identify physical ports uniquely, so userland can tell whether two devices are backed by the same physical port.

OK this makes sense, and I understand that there are also some SRIOV aspects / use cases where this field could be usefu, still I don't understamd the direct relation to virtual functions, as mentioned in the 1st patch.

Quoted 11 lines

But there's no requirement on the format, so you could ensure that one byte of this identifier is the port number on the board.

Ben.

--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.

#19 lore raw
Quoted 13 lines · Or Gerlitz
Quoted 11 lines · Ben Hutchings
Quoted 9 lines · Or Gerlitz

On Sun, Jul 21, 2013 at 10:24 AM, Jiri Pirko <[email protected]> wrote:
[...]

Sorry, I missed that fact that initially you responded on this thread

Quoted 2 lines

The value could be anything. But note that you have to have different values for card1-port1,2 and card2-port1,2

why?

Quoted 7 lines
Quoted 2 lines

The intent is to identify physical ports uniquely, so userland can tell whether two devices are backed by the same physical port.

OK this makes sense, and I understand that there are also some SRIOV aspects / use cases where this field could be usefu, still I don't understamd the direct relation to virtual functions, as mentioned in the 1st patch.

Well the motivating problem was that a guest can't tell which VFs connect to which ports or whether it has multiple VFs connected to the same port. The host can already see work out that they're associated based on PCIe config and topology.

This can also apply to PFs if you pass them through to guests, or if you have multiple PFs connected to the same port, but that's rather less common.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#20 lore raw
In reply to Ben Hutchings
Quoted 10 lines · Ben Hutchings
Quoted 8 lines · Or Gerlitz

On Sun, Jul 21, 2013 at 10:24 AM, Jiri Pirko <[email protected]> wrote:
[...]

Sorry, I missed that fact that initially you responded on this thread

Quoted 2 lines

The value could be anything. But note that you have to have different values for card1-port1,2 and card2-port1,2

Quoted 7 lines
Quoted 1 line

why?

The intent is to identify physical ports uniquely, so userland can tell whether two devices are backed by the same physical port.

But there's no requirement on the format, so you could ensure that one byte of this identifier is the port number on the board.

Would it be useful to embed the port number at a known offset to ensure uniformity across all drivers, if a driver choses to embed port number as part of phys_port_id ?

Signature · 4 lines
With regards,
Narendra K
Linux Engineering
Dell Inc.
#21 lore raw
Quoted 16 lines · Mon, Jul 22, 2013 at 01:46:01PM CEST, [email protected] wrote:
Quoted 15 lines · Ben Hutchings
Quoted 9 lines · Or Gerlitz

On Sun, Jul 21, 2013 at 10:24 AM, Jiri Pirko <[email protected]> wrote:
[...]

Sorry, I missed that fact that initially you responded on this thread

Quoted 2 lines

The value could be anything. But note that you have to have different values for card1-port1,2 and card2-port1,2

why?

The intent is to identify physical ports uniquely, so userland can tell whether two devices are backed by the same physical port.

Quoted 6 lines
Quoted 2 lines

But there's no requirement on the format, so you could ensure that one byte of this identifier is the port number on the board.

Would it be useful to embed the port number at a known offset to ensure uniformity across all drivers, if a driver choses to embed port number as part of phys_port_id ?

I would not do that. Just let it be meaningless number. That is best for security reasons as well.

Quoted 6 lines
Signature · 5 lines
-- 
With regards,
Narendra K
Linux Engineering
Dell Inc.
#22 lore raw
Quoted 8 lines · Jiri Pirko
Quoted 3 lines · Mon, Jul 22, 2013 at 01:46:01PM CEST, [email protected] wrote:

Would it be useful to embed the port number at a known offset to ensure uniformity across all drivers, if a driver choses to embed port number as part of phys_port_id ?

I would not do that. Just let it be meaningless number. That is best for security reasons as well.

What's wrong with uniformity on port number or even on the overall concept?

Or.