Skip to contentSkip to conversation

vhost-vdpa: check vhost_vdpa_set_vring_ready() return value

PATCH In review Stefano Garzarella 2 participants 2 messages Mar 22, 2024 Networking

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vhost-vdpa: check vhost_vdpa_set_vring_ready() return value

vhost_vdpa_set_vring_ready() could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues before DRIVER_OK when VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK is not negotiated.

So better check its return value anyway.

[1] https://lore.kernel.org/virtualization/[email protected]/T/#u

---
Based-on: [email protected]

v1: https://patchew.org/QEMU/[email protected]/
v2:
- added acks
- rebased on top of https://patchew.org/QEMU/[email protected]/

---
 net/vhost-vdpa.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +12 -3
index 85e73dd6a7..eda714d1a4 100644
@@ -399,7 +399,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc)
     }
 
     for (int i = 0; i < v->dev->nvqs; ++i) {
-        vhost_vdpa_set_vring_ready(v, i + v->dev->vq_index);
+        int ret = vhost_vdpa_set_vring_ready(v, i + v->dev->vq_index);
+        if (ret < 0) {
+            return ret;
+        }
     }
     return 0;
 }
@@ -1238,7 +1241,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)
 
     assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
 
-    vhost_vdpa_set_vring_ready(v, v->dev->vq_index);
+    r = vhost_vdpa_set_vring_ready(v, v->dev->vq_index);
+    if (unlikely(r < 0)) {
+        return r;
+    }
 
     if (v->shadow_vqs_enabled) {
         n = VIRTIO_NET(v->dev->vdev);
@@ -1277,7 +1283,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)
     }
 
     for (int i = 0; i < v->dev->vq_index; ++i) {
-        vhost_vdpa_set_vring_ready(v, i);
+        r = vhost_vdpa_set_vring_ready(v, i);
+        if (unlikely(r < 0)) {
+            return r;
+        }
     }
 
     return 0;
Signature · 1 line
2.44.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines · Stefano Garzarella

vhost_vdpa_set_vring_ready() could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues before DRIVER_OK when VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK is not negotiated.

So better check its return value anyway.

[1] https://lore.kernel.org/virtualization/[email protected]/T/#u

---
Based-on: [email protected]

Quoted 7 lines

v1: https://patchew.org/QEMU/[email protected]/
v2:
- added acks
- rebased on top of https://patchew.org/QEMU/[email protected]/

---
  net/vhost-vdpa.c | 15 ++++++++++++---
  1 file changed, 12 insertions(+), 3 deletions(-)