Skip to contentSkip to conversation

virtio-net: Add check for mac address while peer is vdpa

PATCH Applied Cindy Lu 2 participants 5 messages Oct 23, 2020 – Oct 27, 2020

v2 of 5 Applied Latest is v5 →

lore
Share & tools
lore

Cindy Lu

author
#0 lore raw

PATCH v2 1/1 virtio-net: Add check for mac address while peer is vdpa

Sometime vdpa get an all 0 mac address from the hardware, this will cause the traffic down So we add the check for this part.
if we get an 0 mac address we will use the default mac address instead

---
 hw/net/virtio-net.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +6 -1
index 9179013ac4..f1648fc47d 100644
@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
     VirtIONet *n = VIRTIO_NET(vdev);
     struct virtio_net_config netcfg;
     NetClientState *nc = qemu_get_queue(n->nic);
+    static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
 
     int ret = 0;
     memset(&netcfg, 0 , sizeof(struct virtio_net_config));
@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
         ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg,
                                    n->config_size);
         if (ret != -1) {
-            memcpy(config, &netcfg, n->config_size);
+            if (memcmp(&netcfg.mac, &zero, sizeof(zero)) != 0) {
+                memcpy(config, &netcfg, n->config_size);
+        } else {
+                error_report("Get an all zero mac address from hardware");
+            }
         }
     }
 }
Signature · 1 line
2.21.3
Applied
#1 lore raw
Quoted 24 lines · Cindy Lu

Sometime vdpa get an all 0 mac address from the hardware, this will cause the traffic down So we add the check for this part.
if we get an 0 mac address we will use the default mac address instead

---
  hw/net/virtio-net.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +1 -0
index 9179013ac4..f1648fc47d 100644
@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
      VirtIONet *n = VIRTIO_NET(vdev);
      struct virtio_net_config netcfg;
      NetClientState *nc = qemu_get_queue(n->nic);
+    static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
 
      int ret = 0;
      memset(&netcfg, 0 , sizeof(struct virtio_net_config));
@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
          ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg,
                                     n->config_size);

hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 162

Quoted 10 lines
hw/net/virtio-net.c +5 -1
          if (ret != -1) {
-            memcpy(config, &netcfg, n->config_size);
+            if (memcmp(&netcfg.mac, &zero, sizeof(zero)) != 0) {
+                memcpy(config, &netcfg, n->config_size);
+        } else {
+                error_report("Get an all zero mac address from hardware");
+            }
          }
      }
  }

Applied.

Thanks

#2 lore raw
Quoted 42 lines · Jason Wang
Quoted 34 lines · Cindy Lu

Sometime vdpa get an all 0 mac address from the hardware, this will cause the traffic down So we add the check for this part.
if we get an 0 mac address we will use the default mac address instead

---
  hw/net/virtio-net.c | 7 ++++++-

  1 file changed, 6 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +6 -1
index 9179013ac4..f1648fc47d 100644
@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice 
 *vdev, uint8_t *config)
       VirtIONet *n = VIRTIO_NET(vdev);
       struct virtio_net_config netcfg;
       NetClientState *nc = qemu_get_queue(n->nic);
+    static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
         int ret = 0;
       memset(&netcfg, 0 , sizeof(struct virtio_net_config));
@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice 
 *vdev, uint8_t *config)
           ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg,
                                      n->config_size);
           if (ret != -1) {
-            memcpy(config, &netcfg, n->config_size);
+            if (memcmp(&netcfg.mac, &zero, sizeof(zero)) != 0) {
+                memcpy(config, &netcfg, n->config_size);
+        } else {
+                error_report("Get an all zero mac address from 
 hardware");
+            }
           }
Quoted 2 lines

      }
  }

Applied.

Quoted 3 lines

Thanks

Speak too fast. Some questions:

1) Any reason that you do such check or get_config() instead of doing it once in device initalization
2) the indentation looks wrong
3) There's no need for an error here since we can workaround it

Thanks

author
#3 lore raw

Hi jason

Quoted 46 lines · Jason Wang
Quoted 44 lines · Jason Wang
Quoted 37 lines · Cindy Lu

Sometime vdpa get an all 0 mac address from the hardware, this will cause the traffic down
So we add the check for this part.
if we get an 0 mac address we will use the default mac address instead

---
  hw/net/virtio-net.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +6 -1
index 9179013ac4..f1648fc47d 100644
@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice
 *vdev, uint8_t *config)
      VirtIONet *n = VIRTIO_NET(vdev);
      struct virtio_net_config netcfg;
      NetClientState *nc = qemu_get_queue(n->nic);
+    static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
        int ret = 0;
      memset(&netcfg, 0 , sizeof(struct virtio_net_config));
@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice
 *vdev, uint8_t *config)
          ret = vhost_net_get_config(get_vhost_net(nc->peer),
 (uint8_t *)&netcfg,
                                     n->config_size);
          if (ret != -1) {
-            memcpy(config, &netcfg, n->config_size);
+            if (memcmp(&netcfg.mac, &zero, sizeof(zero)) != 0) {
+                memcpy(config, &netcfg, n->config_size);
+        } else {
+                error_report("Get an all zero mac address from
 hardware");
+            }
          }
      }
Quoted 1 line

}

Applied.

Quoted 9 lines
Quoted 3 lines

Thanks

Speak too fast. Some questions:

1) Any reason that you do such check or get_config() instead of doing it once in device initalization

get_config() was called before the device realized. If we check in the device initalization, the mac address is already overwritten to 0 and we lost the default mac address
Also for my understanding. the mac address read from hardware should never been 0, so we need to check it every time we got it, Just in case it will change to 0 and overwrite the mac address while the qemu running or some other case

Quoted 2 lines

2) the indentation looks wrong

sure will fix this

Quoted 1 line

3) There's no need for an error here since we can workaround it

sure, I will change it to log

Quoted 7 lines

Thanks

#4 lore raw

----- Original Message -----

Quoted 55 lines

Hi jason

Quoted 50 lines · Jason Wang
Quoted 47 lines · Jason Wang
Quoted 37 lines · Cindy Lu

Sometime vdpa get an all 0 mac address from the hardware, this will cause the traffic down
So we add the check for this part.
if we get an 0 mac address we will use the default mac address instead

---
  hw/net/virtio-net.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +6 -1
index 9179013ac4..f1648fc47d 100644
@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice
 *vdev, uint8_t *config)
      VirtIONet *n = VIRTIO_NET(vdev);
      struct virtio_net_config netcfg;
      NetClientState *nc = qemu_get_queue(n->nic);
+    static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
        int ret = 0;
      memset(&netcfg, 0 , sizeof(struct virtio_net_config));
@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice
 *vdev, uint8_t *config)
          ret = vhost_net_get_config(get_vhost_net(nc->peer),
 (uint8_t *)&netcfg,
                                     n->config_size);
          if (ret != -1) {
-            memcpy(config, &netcfg, n->config_size);
+            if (memcmp(&netcfg.mac, &zero, sizeof(zero)) != 0) {
+                memcpy(config, &netcfg, n->config_size);
+        } else {
+                error_report("Get an all zero mac address from
 hardware");
+            }
          }
      }
Quoted 1 line

}

Applied.

Thanks

Quoted 6 lines
Quoted 5 lines

Speak too fast. Some questions:

1) Any reason that you do such check or get_config() instead of doing it once in device initalization

get_config() was called before the device realized.

Intersting, any reason that we need call get_config() even before device is realized?

Quoted 5 lines

If we check in the
device initalization, the mac address is already overwritten to 0 and we lost the default mac address
Also for my understanding. the mac address read from hardware should never been 0, so we need to check it every time we got it,

This sounds self-contradict.

Quoted 3 lines

Just in case it will
change to 0 and overwrite the mac address while the qemu running or some other case

This looks like a bug in the device or driver.

Even if this is true, you can only detect it via get_config(). And I don't think we need to workaround a buggy device.

Thanks

Quoted 17 lines
Quoted 3 lines

2) the indentation looks wrong

sure will fix this

Quoted 1 line

3) There's no need for an error here since we can workaround it

sure, I will change it to log

Quoted 7 lines

Thanks