Skip to contentSkip to conversation

net: openvswitch: Check vport name

PATCH Superseded jun.gu 4 participants 12 messages Apr 13, 2024 – Apr 20, 2024 1 message not in the archive

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

jun.gu

author
#0 lore raw

PATCH 1/1 net: openvswitch: Check vport name

Check vport name from dev_get_by_name, this can avoid to add and remove NIC repeatedly when NIC rename failed at system startup.

---
 net/openvswitch/vport-netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +1 -1
index 903537a5da22..de8977d7f329 100644
@@ -78,7 +78,7 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	if (!vport->dev) || strcmp(name, ovs_vport_name(vport)) {
 		err = -ENODEV;
 		goto error_free_vport;
 	}
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 13 lines · jun.gu

Check vport name from dev_get_by_name, this can avoid to add and remove NIC repeatedly when NIC rename failed at system startup.

---
 net/openvswitch/vport-netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +0 -0
index 903537a5da22..de8977d7f329 100644

net/openvswitch/vport-netdev.c struct vport *ovs_netdev_link(struct vport *vport, const char *name) · line 81

Quoted 5 lines
net/openvswitch/vport-netdev.c +1 -1
@@ -78,7 +78,7 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	if (!vport->dev) || strcmp(name, ovs_vport_name(vport)) {

Hi Jun, not sure if I get the point here, as ovs_vport_name() translates into vport->dev->name.

So are we trying to catch the interface rename between the dev_get_by_name(), and the code below? This rename could happen at any other place, so this check does not guarantee anything. Or am I missing something?

Quoted 10 lines
net/openvswitch/vport-netdev.c +0 -0
 		err = -ENODEV;
 		goto error_free_vport;
 	}
Signature · 6 lines
2.25.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#3 lore raw
Quoted 14 lines · Jun Gu

Hi Chaudron, thanks for your reply. Considerthe following scenario:

- set a net device alias name (such as *enpxx*) into ovs.

- |OVS_VPORT_CMD_NEW -> ||dev_get_by_name can query the net device using *enpxx* name, but the dev->name that return is *ensxx* name. the |net_device|struct including: ``` |struct net_device {

    char			name[IFNAMSIZ];
    RH_KABI_REPLACE(struct hlist_node name_hlist,
    		struct netdev_name_node *name_node)
...
|``` name_hlist include enpxx and ensxx name and both of them point to the same net_device, the net_device's name is ensxx. So when using *enpxx* name to query net device, the ||net device's name that return is *ensxx* name.|
Then, openvswitch.ko will save the net device that name is*ensxx*  to a hash table. So this will cause the below process:
- ovs can'tobtain the enpxx net device by |OVS_VPORT_CMD_GET.|
-|dpif_netlink_port_poll will get a |notification after |OVS_VPORT_CMD_NEW|, but the vport's name is ensxx. ovs will query the ensxx net device from interface table, but nothing. So ovs will run the port_del operation.
- this will cause|OVS_VPORT_CMD_NEW|  and OVS_VPORT_CMD_DEL operation to run repeatedly.
Quoted 1 line

So the above issue can be avoided by the patch.

Thanks for the clarification, I forgot about the alias case. And you are right, OVS userspace does not support using interface aliases.

Maybe you can update the commit message, and add a code comment to clarify this in your next revision?

Cheers,

Eelco

Quoted 37 lines · Eelco Chaudron
Quoted 36 lines · jun.gu
Quoted 14 lines

Check vport name from dev_get_by_name, this can avoid to add and remove NIC repeatedly when NIC rename failed at system startup.

---
  net/openvswitch/vport-netdev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +0 -0
index 903537a5da22..de8977d7f329 100644

net/openvswitch/vport-netdev.c struct vport *ovs_netdev_link(struct vport *vport, const char *name) · line 81

Quoted 5 lines
net/openvswitch/vport-netdev.c +1 -1
@@ -78,7 +78,7 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
  	int err;
 
  	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	if (!vport->dev) || strcmp(name, ovs_vport_name(vport)) {

Hi Jun, not sure if I get the point here, as ovs_vport_name() translates into vport->dev->name.

So are we trying to catch the interface rename between the dev_get_by_name(), and the code below? This rename could happen at any other place, so this check does not guarantee anything. Or am I missing something?

Quoted 10 lines
net/openvswitch/vport-netdev.c +0 -0
  		err = -ENODEV;
  		goto error_free_vport;
  	}
Signature · 6 lines
2.25.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev
author
#4 lore raw

PATCH v2 1/1 net: openvswitch: Check vport net device name

Check vport net device name to avoid the name that be used to query is inconsistent the retured name.

Consider net device supports alias, the alias can be set to interface table in ovs userspace. Consider the following process:
- set a net device alias to interface table.
- ovs userspace run OVS_VPORT_CMD_NEW cmd to kernel, kernel will use net device alias to query net device by dev_get_by_name, but the net device name that return is inconsistent the name used to query.
- the returned net device name is saved a hash table.
- ovs userspace found that the name saved to interface table is inconsistent the name saved kernel hash table, it will run OVS_VPORT_CMD_DEL cmd to kernel and remove vport.

ovs userspace will run OVS_VPORT_CMD_NEW and OVS_VPORT_CMD_DEL cmd repeatedly. So the patch will check vport net device name from dev_get_by_name to avoid the above issue.

---
 net/openvswitch/vport-netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +1 -1
index 903537a5da22..de8977d7f329 100644
@@ -78,7 +78,7 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	if (!vport->dev) || strcmp(name, ovs_vport_name(vport)) {
 		err = -ENODEV;
 		goto error_free_vport;
 	}
Signature · 1 line
2.25.1
maintainer
#5 lore raw

Re: [PATCH v2] net: openvswitch: Check vport net device name

Quoted 14 lines · jun.gu

Check vport net device name to avoid the name that be used to query is inconsistent the retured name.

Consider net device supports alias, the alias can be set to interface table in ovs userspace. Consider the following process:
- set a net device alias to interface table.
- ovs userspace run OVS_VPORT_CMD_NEW cmd to kernel, kernel will use net device alias to query net device by dev_get_by_name, but the net device name that return is inconsistent the name used to query.
- the returned net device name is saved a hash table.
- ovs userspace found that the name saved to interface table is inconsistent the name saved kernel hash table, it will run OVS_VPORT_CMD_DEL cmd to kernel and remove vport.

Quoted 3 lines

ovs userspace will run OVS_VPORT_CMD_NEW and OVS_VPORT_CMD_DEL cmd repeatedly. So the patch will check vport net device name from dev_get_by_name to avoid the above issue.

Maybe the commit message needs a rewrite to be more clear (shorter)? I’ll leave this up to the maintainers to judge.

net/openvswitch/vport-netdev.c struct vport *ovs_netdev_link(struct vport *vport, const char *name) · line 80

Quoted 13 lines
---
 net/openvswitch/vport-netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +0 -0
index 903537a5da22..de8977d7f329 100644
@@ -78,7 +78,7 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);

I was eluding to a comment here, something like:

        /* Ensure that the device exists and that the provided
         * name is not one of its aliases.
         */
Quoted 7 lines
net/openvswitch/vport-netdev.c +1 -1
-	if (!vport->dev) {
+	if (!vport->dev) || strcmp(name, ovs_vport_name(vport)) {
 		err = -ENODEV;
 		goto error_free_vport;
 	}
Signature · 1 line
2.25.1
author
#6 lore raw

PATCH v3 1/1 net: openvswitch: Check vport net device name

Check vport net device name to ensure the provided name is not one of its aliases. This can avoid that ovs userspace create and destroy vport repeatedly.

---
 net/openvswitch/vport-netdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +4 -1
index 903537a5da22..7003e76b8172 100644
@@ -78,7 +78,10 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	/* Ensure that the device exists and that the provided
+	 * name is not one of its aliases.
+	 */
+	if ((!vport->dev) || strcmp(name, ovs_vport_name(vport))) {
 		err = -ENODEV;
 		goto error_free_vport;
 	}
Signature · 1 line
2.25.1
maintainer Acked-by on v3 1/1
#7 lore raw

Re: [PATCH net-next v3] net: openvswitch: Check vport net device name

Quoted 3 lines · jun.gu

Check vport net device name to ensure the provided name is not one of its aliases. This can avoid that ovs userspace create and destroy vport repeatedly.

How about changing the text to the following?

Ensure that the provided netdev name is not one of its aliases to prevent unnecessary creation and destruction of the vport by ovs-vswitchd.

Maybe the maintainers are fine with the current text, in that case:

Quoted 24 lines
---
 net/openvswitch/vport-netdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +4 -1
index 903537a5da22..7003e76b8172 100644
@@ -78,7 +78,10 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	/* Ensure that the device exists and that the provided
+	 * name is not one of its aliases.
+	 */
+	if ((!vport->dev) || strcmp(name, ovs_vport_name(vport))) {
 		err = -ENODEV;
 		goto error_free_vport;
 	}
Signature · 1 line
2.25.1
author
#8 lore raw

PATCH v4 1/1 net: openvswitch: Check vport netdev name

Ensure that the provided netdev name is not one of its aliases to prevent unnecessary creation and destruction of the vport by ovs-vswitchd.

---
 net/openvswitch/vport-netdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +4 -1
index 903537a5da22..7003e76b8172 100644
@@ -78,7 +78,10 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	/* Ensure that the device exists and that the provided
+	 * name is not one of its aliases.
+	 */
+	if ((!vport->dev) || strcmp(name, ovs_vport_name(vport))) {
 		err = -ENODEV;
 		goto error_free_vport;
 	}
Signature · 1 line
2.25.1
maintainer
#9 lore raw

Re: [PATCH net-next v4] net: openvswitch: Check vport netdev name

net/openvswitch/vport-netdev.c struct vport *ovs_netdev_link(struct vport *vport, const char *name) · line 84

Quoted 1 line · On Thu, 18 Apr 2024 10:32:42 +0800 jun.gu wrote:
net/openvswitch/vport-netdev.c +1 -0
+	if ((!vport->dev) || strcmp(name, ovs_vport_name(vport))) {

Please drop the unnecessary brackets.
When you repost, start a new thread, do not post new version in-reply-to.

Signature · 1 line
pw-bot: cr
author
#10 lore raw

PATCH v4 1/1 net: openvswitch: Check vport netdev name

In reply to jun.gu

From: "jun.gu" <[email protected]>

Ensure that the provided netdev name is not one of its aliases to prevent unnecessary creation and destruction of the vport by ovs-vswitchd.

---
 net/openvswitch/vport-netdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +4 -1
index 903537a5da22..618edc346c0f 100644
@@ -78,7 +78,10 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	/* Ensure that the device exists and that the provided
+	 * name is not one of its aliases.
+	 */
+	if (!vport->dev || strcmp(name, ovs_vport_name(vport))) {
 		err = -ENODEV;
 		goto error_free_vport;
 	}
Signature · 1 line
2.25.1
maintainer
#11 lore raw

Re: [PATCH net-next v4] net: openvswitch: Check vport netdev name

Quoted 8 lines · On Fri, 19 Apr 2024 12:31:33 +0800 Jun Gu wrote:

From: "jun.gu" <[email protected]>

Ensure that the provided netdev name is not one of its aliases to prevent unnecessary creation and destruction of the vport by ovs-vswitchd.

I said: When you repost, start a new thread, do not post new version in-reply-to.

If you don't understand what something means - ask :| Now try again.

Signature · 1 line
pw-bot: cr
maintainer
#12 lore raw
In reply to jun.gu
Quoted 13 lines · jun.gu

Check vport name from dev_get_by_name, this can avoid to add and remove NIC repeatedly when NIC rename failed at system startup.

---
 net/openvswitch/vport-netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +0 -0
index 903537a5da22..de8977d7f329 100644

net/openvswitch/vport-netdev.c struct vport *ovs_netdev_link(struct vport *vport, const char *name) · line 81

Quoted 5 lines
net/openvswitch/vport-netdev.c +1 -1
@@ -78,7 +78,7 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name)
 	int err;
 
 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
-	if (!vport->dev) {
+	if (!vport->dev) || strcmp(name, ovs_vport_name(vport)) {
	  ^^

Missing open bracket here, and close bracket towards the end. Please build and test your patch before submitting the next revision.

Please also include the target tree ('net-next') in the subj prefix when you will submit it.

And update the commit message as per Eelco's request.

Thanks,

Paolo