Skip to contentSkip to conversation

Return -EINVAL if device's ack is VIRTIO_NET_ERR

RFC PATCH Superseded Hawkins Jiawei 3 participants 6 messages Jun 14, 2023 – Jul 4, 2023 Networking

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Return -EINVAL if device's ack is VIRTIO_NET_ERR

This patch fixes the problem that vhost_net_start_one() doesn't cancel the device startup and returns 0 even if the device's ack is VIRTIO_NET_ERR in net->nc->info->load().

Note that this problem also exists in
patch "vdpa: Add vhost_vdpa_net_load_offloads()" at [1]. Because this patch has not been merged yet, so I will submit the v2 patch to fix the problem in that patch once the pending patch
has been successfully merged.

[1]. https://lists.nongnu.org/archive/html/qemu-devel/2023-06/msg00504.html

Hawkins Jiawei (1):
vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR

 net/vhost-vdpa.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

RFC PATCH 1/1 vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR

According to VirtIO standard, "The class, command and command-specific-data are set by the driver, and the device sets the ack byte.
There is little it can do except issue a diagnostic if ack is not VIRTIO_NET_OK."

Therefore, QEMU should stop sending the queued SVQ commands and cancel the device startup if the device's ack is not VIRTIO_NET_OK.

Yet the problem is that, vhost_vdpa_net_load_x() returns 1 based on *s->status != VIRTIO_NET_OK when the device's ack is VIRTIO_NET_ERR. As a result, net->nc->info->load() also returns 1, this makes vhost_net_start_one() incorrectly assume the device state is successfully loaded by vhost_vdpa_net_load() and return 0, instead of goto fail label to cancel the device startup, as vhost_net_start_one() only cancels the device startup when net->nc->info->load() returns a negative value.

This patch fixes this problem by returning -EINVAL when the device's ack is not VIRTIO_NET_OK.

Fixes f73c0c43ac ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load")
Fixes f64c7cda69 ("vdpa: Add vhost_vdpa_net_load_mq")
---
 net/vhost-vdpa.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +7 -3
index 37cdc84562..630c9bf71e 100644
@@ -651,8 +651,9 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
         if (unlikely(dev_written < 0)) {
             return dev_written;
         }
-
-        return *s->status != VIRTIO_NET_OK;
+        if (*s->status != VIRTIO_NET_OK) {
+            return -EINVAL;
+        }
     }
 
     return 0;
@@ -676,8 +677,11 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
     if (unlikely(dev_written < 0)) {
         return dev_written;
     }
+    if (*s->status != VIRTIO_NET_OK) {
+        return -EINVAL;
+    }
 
-    return *s->status != VIRTIO_NET_OK;
+    return 0;
 }
 
 static int vhost_vdpa_net_load(NetClientState *nc)
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#2 lore raw

Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR

Quoted 19 lines · Hawkins Jiawei

According to VirtIO standard, "The class, command and command-specific-data are set by the driver, and the device sets the ack byte.
There is little it can do except issue a diagnostic if ack is not VIRTIO_NET_OK."

Therefore, QEMU should stop sending the queued SVQ commands and cancel the device startup if the device's ack is not VIRTIO_NET_OK.

Yet the problem is that, vhost_vdpa_net_load_x() returns 1 based on *s->status != VIRTIO_NET_OK when the device's ack is VIRTIO_NET_ERR. As a result, net->nc->info->load() also returns 1, this makes vhost_net_start_one() incorrectly assume the device state is successfully loaded by vhost_vdpa_net_load() and return 0, instead of goto fail label to cancel the device startup, as vhost_net_start_one() only cancels the device startup when net->nc->info->load() returns a negative value.

Quoted 6 lines

This patch fixes this problem by returning -EINVAL when the device's ack is not VIRTIO_NET_OK.

Fixes f73c0c43ac ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load")
Fixes f64c7cda69 ("vdpa: Add vhost_vdpa_net_load_mq")

Maybe we could split the fixes? Either way:

Thanks!

Quoted 36 lines
---
 net/vhost-vdpa.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +7 -4
index 37cdc84562..630c9bf71e 100644
@@ -651,8 +651,9 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
         if (unlikely(dev_written < 0)) {
             return dev_written;
         }
-
-        return *s->status != VIRTIO_NET_OK;
+        if (*s->status != VIRTIO_NET_OK) {
+            return -EINVAL;
+        }
     }
 
     return 0;
@@ -676,8 +677,11 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
     if (unlikely(dev_written < 0)) {
         return dev_written;
     }
+    if (*s->status != VIRTIO_NET_OK) {
+        return -EINVAL;
+    }
 
-    return *s->status != VIRTIO_NET_OK;
+    return 0;
 }
 
 static int vhost_vdpa_net_load(NetClientState *nc)
--

2.25.1

#3 lore raw

Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR

Quoted 20 lines · Eugenio Perez Martin
Quoted 19 lines · Hawkins Jiawei

According to VirtIO standard, "The class, command and command-specific-data are set by the driver, and the device sets the ack byte.
There is little it can do except issue a diagnostic if ack is not VIRTIO_NET_OK."

Therefore, QEMU should stop sending the queued SVQ commands and cancel the device startup if the device's ack is not VIRTIO_NET_OK.

Yet the problem is that, vhost_vdpa_net_load_x() returns 1 based on *s->status != VIRTIO_NET_OK when the device's ack is VIRTIO_NET_ERR. As a result, net->nc->info->load() also returns 1, this makes vhost_net_start_one() incorrectly assume the device state is successfully loaded by vhost_vdpa_net_load() and return 0, instead of goto fail label to cancel the device startup, as vhost_net_start_one() only cancels the device startup when net->nc->info->load() returns a negative value.

Quoted 8 lines
Quoted 6 lines

This patch fixes this problem by returning -EINVAL when the device's ack is not VIRTIO_NET_OK.

Fixes f73c0c43ac ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load")
Fixes f64c7cda69 ("vdpa: Add vhost_vdpa_net_load_mq")

Maybe we could split the fixes? Either way:

OK, I will split these fixes according to your suggestion.

Thanks!

Quoted 42 lines

Thanks!

Quoted 36 lines
---
  net/vhost-vdpa.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +7 -4
index 37cdc84562..630c9bf71e 100644
@@ -651,8 +651,9 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
          if (unlikely(dev_written < 0)) {
              return dev_written;
          }
-
-        return *s->status != VIRTIO_NET_OK;
+        if (*s->status != VIRTIO_NET_OK) {
+            return -EINVAL;
+        }
      }
 
      return 0;
@@ -676,8 +677,11 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
      if (unlikely(dev_written < 0)) {
          return dev_written;
      }
+    if (*s->status != VIRTIO_NET_OK) {
+        return -EINVAL;
+    }
 
-    return *s->status != VIRTIO_NET_OK;
+    return 0;
  }
 
  static int vhost_vdpa_net_load(NetClientState *nc)
--

2.25.1

#4 lore raw

Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR

In reply to Hawkins Jiawei
Quoted 45 lines · Hawkins Jiawei

According to VirtIO standard, "The class, command and command-specific-data are set by the driver, and the device sets the ack byte.
There is little it can do except issue a diagnostic if ack is not VIRTIO_NET_OK."

Therefore, QEMU should stop sending the queued SVQ commands and cancel the device startup if the device's ack is not VIRTIO_NET_OK.

Yet the problem is that, vhost_vdpa_net_load_x() returns 1 based on *s->status != VIRTIO_NET_OK when the device's ack is VIRTIO_NET_ERR. As a result, net->nc->info->load() also returns 1, this makes vhost_net_start_one() incorrectly assume the device state is successfully loaded by vhost_vdpa_net_load() and return 0, instead of goto fail label to cancel the device startup, as vhost_net_start_one() only cancels the device startup when net->nc->info->load() returns a negative value.

This patch fixes this problem by returning -EINVAL when the device's ack is not VIRTIO_NET_OK.

Fixes f73c0c43ac ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load")
Fixes f64c7cda69 ("vdpa: Add vhost_vdpa_net_load_mq")
---
 net/vhost-vdpa.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +3 -2
index 37cdc84562..630c9bf71e 100644
@@ -651,8 +651,9 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
         if (unlikely(dev_written < 0)) {
             return dev_written;
         }
-
-        return *s->status != VIRTIO_NET_OK;
+        if (*s->status != VIRTIO_NET_OK) {
+            return -EINVAL;
+        }
     }
 
     return 0;

net/vhost-vdpa.c static int vhost_vdpa_net_load_mq(VhostVDPAState *s, · line 685

Quoted 10 lines
net/vhost-vdpa.c +4 -1
@@ -676,8 +677,11 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
     if (unlikely(dev_written < 0)) {
         return dev_written;
     }
+    if (*s->status != VIRTIO_NET_OK) {
+        return -EINVAL;
+    }
 
-    return *s->status != VIRTIO_NET_OK;
+    return 0;
 }

I think EIO would be better, we have too many EINVAL cases, making things hard to debug.

Quoted 4 lines
net/vhost-vdpa.c +0 -0
 static int vhost_vdpa_net_load(NetClientState *nc)
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR

Quoted 53 lines · Michael S. Tsirkin
Quoted 52 lines · Hawkins Jiawei

According to VirtIO standard, "The class, command and command-specific-data are set by the driver, and the device sets the ack byte.
There is little it can do except issue a diagnostic if ack is not VIRTIO_NET_OK."

Therefore, QEMU should stop sending the queued SVQ commands and cancel the device startup if the device's ack is not VIRTIO_NET_OK.

Yet the problem is that, vhost_vdpa_net_load_x() returns 1 based on *s->status != VIRTIO_NET_OK when the device's ack is VIRTIO_NET_ERR. As a result, net->nc->info->load() also returns 1, this makes vhost_net_start_one() incorrectly assume the device state is successfully loaded by vhost_vdpa_net_load() and return 0, instead of goto fail label to cancel the device startup, as vhost_net_start_one() only cancels the device startup when net->nc->info->load() returns a negative value.

This patch fixes this problem by returning -EINVAL when the device's ack is not VIRTIO_NET_OK.

Fixes f73c0c43ac ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load")
Fixes f64c7cda69 ("vdpa: Add vhost_vdpa_net_load_mq")
---
  net/vhost-vdpa.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +6 -2
index 37cdc84562..630c9bf71e 100644
@@ -651,8 +651,9 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
          if (unlikely(dev_written < 0)) {
              return dev_written;
          }
-
-        return *s->status != VIRTIO_NET_OK;
+        if (*s->status != VIRTIO_NET_OK) {
+            return -EINVAL;
+        }
      }
 
      return 0;
@@ -676,8 +677,11 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
      if (unlikely(dev_written < 0)) {
          return dev_written;
      }
+    if (*s->status != VIRTIO_NET_OK) {
+        return -EINVAL;
+    }
 
Quoted 6 lines

net/vhost-vdpa.c static int vhost_vdpa_net_load_mq(VhostVDPAState *s, · line 685

Quoted 3 lines
net/vhost-vdpa.c +1 -1
-    return *s->status != VIRTIO_NET_OK;
+    return 0;
  }

I think EIO would be better, we have too many EINVAL cases, making things hard to debug.

I will refactor this patch to return -EIO according to your suggestion.

Thanks!

Quoted 8 lines
Quoted 7 lines
net/vhost-vdpa.c +0 -1
  static int vhost_vdpa_net_load(NetClientState *nc)
--

2.25.1