Skip to contentSkip to conversation

vhost: Fix last queue index of devices with no cvq

PATCH Superseded Eugenio Pérez 3 participants 5 messages Nov 2, 2021 – Nov 3, 2021

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover vhost: Fix last queue index of devices with no cvq

The -1 assumes that all devices with no cvq have an spare vq allocated for them, but with no offer of VIRTIO_NET_F_CTRL_VQ. This is an invalid device by the standard, so just stick to the right number of device models.

This is not a problem to vhost-net, but it is to vhost-vdpa, which device model trust to reach the last index to finish starting the device.

Tested with vp_vdpa with host's vhost=on and vhost=off.

v2:
* Delete all the conditional code instead of ROUND_DOWN in a deinitely too-bit-tricky way.

Eugenio Pérez (1):
vhost: Fix last queue index of devices with no cvq

 hw/net/vhost_net.c | 4 ----
 1 file changed, 4 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 1/1 vhost: Fix last queue index of devices with no cvq

The -1 assumes that all devices with no cvq have an spare vq allocated for them, but with no offer of VIRTIO_NET_F_CTRL_VQ. This is an invalid device by the standard, so just stick to the right number of device models.

This is not a problem to vhost-net, but it is to vhost-vdpa, which device model trust to reach the last index to finish starting the device.

Tested with vp_vdpa with host's vhost=on and vhost=off.

Fixes 049eb15b5fc9 ("vhost: record the last virtqueue index for the virtio device")
---
 hw/net/vhost_net.c | 4 ----
 1 file changed, 4 deletions(-)
hw/net/vhost_net.c +0 -4
index 0d888f29a6..a859cc943d 100644
@@ -329,10 +329,6 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     int r, e, i, last_index = data_queue_pairs * 2;
     NetClientState *peer;
 
-    if (!cvq) {
-        last_index -= 1;
-    }
-
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
         return -ENOSYS;
Signature · 1 line
2.27.0
#2 lore raw

Eugenio Pérez <[email protected]> wrote:
Y> The -1 assumes that all devices with no cvq have an spare vq allocated

Quoted 8 lines

for them, but with no offer of VIRTIO_NET_F_CTRL_VQ. This is an invalid device by the standard, so just stick to the right number of device models.

This is not a problem to vhost-net, but it is to vhost-vdpa, which device model trust to reach the last index to finish starting the device.

Quoted 6 lines

Tested with vp_vdpa with host's vhost=on and vhost=off.

Fixes 049eb15b5fc9 ("vhost: record the last virtqueue index for the

virtio device")

Much clearer, thanks.

#3 lore raw
In reply to Eugenio Pérez
Quoted 24 lines · Eugenio Pérez

The -1 assumes that all devices with no cvq have an spare vq allocated for them, but with no offer of VIRTIO_NET_F_CTRL_VQ. This is an invalid device by the standard, so just stick to the right number of device models.

This is not a problem to vhost-net, but it is to vhost-vdpa, which device model trust to reach the last index to finish starting the device.

Tested with vp_vdpa with host's vhost=on and vhost=off.

Fixes 049eb15b5fc9 ("vhost: record the last virtqueue index for the virtio device")
---
 hw/net/vhost_net.c | 4 ----
 1 file changed, 4 deletions(-)
hw/net/vhost_net.c +0 -0
index 0d888f29a6..a859cc943d 100644

hw/net/vhost_net.c int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, · line 335

Quoted 7 lines
hw/net/vhost_net.c +0 -4
@@ -329,10 +329,6 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     int r, e, i, last_index = data_queue_pairs * 2;
     NetClientState *peer;
 
-    if (!cvq) {
-        last_index -= 1;
-    }
-

So I think the math is wrong at least from the perspective of virtio:
If we had a device with 1 queue pair without cvq, last_index is 2 but should be 1.

Another thing is that it may break the device with cvq. If we have a device with 1 queue pair + cvq, last_index is 2.

We will start the device before cvq vhost_net is initialized. Since for the first vhost_net device (first queue pair) we meet the:

dev->vq_index + dev->nvqs == dev->last_index (0 + 2 == 2).

Then we set DRIVER_OK before initializing cvq.

Thanks

Quoted 6 lines
hw/net/vhost_net.c +0 -1
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
         return -ENOSYS;
--

2.27.0

#4 lore raw
Quoted 29 lines · Jason Wang
Quoted 27 lines · Eugenio Pérez

The -1 assumes that all devices with no cvq have an spare vq allocated for them, but with no offer of VIRTIO_NET_F_CTRL_VQ. This is an invalid device by the standard, so just stick to the right number of device models.

This is not a problem to vhost-net, but it is to vhost-vdpa, which device model trust to reach the last index to finish starting the device.

Tested with vp_vdpa with host's vhost=on and vhost=off.

Fixes 049eb15b5fc9 ("vhost: record the last virtqueue index for the virtio device")
---
 hw/net/vhost_net.c | 4 ----
 1 file changed, 4 deletions(-)
hw/net/vhost_net.c +0 -0
index 0d888f29a6..a859cc943d 100644
@@ -329,10 +329,6 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     int r, e, i, last_index = data_queue_pairs * 2;
     NetClientState *peer;
 
Quoted 9 lines

hw/net/vhost_net.c int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, · line 335

Quoted 4 lines
hw/net/vhost_net.c +0 -4
-    if (!cvq) {
-        last_index -= 1;
-    }
-

So I think the math is wrong at least from the perspective of virtio:
If we had a device with 1 queue pair without cvq, last_index is 2 but should be 1.

At this moment, last_index is the last queue index. By the vhost_vdpa_dev_start test:

    if (dev->vq_index + dev->nvqs != dev->last_index)

--

I'd say that last_index should remain that way so device models with arbitrary number of virtqueues are better supported. I'd rename last_index to last_queue_index though.

So with *this* patch applied, yes, last_index is 2 if (!cvq), 4 if multiqueue & !cvq, ... It's the way virtio_vdpa works at this moment regarding dev->vq_index and dev->last_index: everything uses virtqueue as base as far as I can see.

If we want to work with devices, we should include a new field in vhost_dev like "dev_index", and rename "last_index" to "last_dev_index". But I'd say it is better to keep using virtqueues as the base.

Quoted 10 lines

Another thing is that it may break the device with cvq. If we have a device with 1 queue pair + cvq, last_index is 2.

We will start the device before cvq vhost_net is initialized. Since for the first vhost_net device (first queue pair) we meet the:

dev->vq_index + dev->nvqs == dev->last_index (0 + 2 == 2).

Then we set DRIVER_OK before initializing cvq.

This part is totally right.

If we stick with s/last_index/last_vq_index/, the right patch should be to ADD one index for cvq to last_index, so the patch should actually be if(cvq) { last_index += 1; }.

Does it make sense to both renaming last_index to last_queue_index and to replace the conditional that way?

Thanks!

Quoted 9 lines

Thanks

Quoted 6 lines
hw/net/vhost_net.c +0 -1
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
         return -ENOSYS;
--

2.27.0