vhost: Fix last queue index of devices with no cvq
v3 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.
v3:
* Recover cvq devices.
* Rename last_index to last_vq_index
v2:
* Delete all the conditional code instead of ROUND_DOWN in a deinitely too-bit-tricky way.
Eugenio Pérez (2):
vhost: Rename last_index to last_vq_index
vhost: Fix last vq queue index of devices with no cvq
include/hw/virtio/vhost.h | 2 +- hw/net/vhost_net.c | 8 ++++---- hw/virtio/vhost-vdpa.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.27.0
PATCH v3 2/2 vhost: Fix last vq queue index of devices with no cvq
The -1 assumes that last index counts all vhost device models as having two queues, but they count only the ones that models the data queues.
Because of that, the right change in last_index is to actually add the cvq, not to remove the missing one.
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, with ctrl_vq=on and ctrl_vq=off.
--- hw/net/vhost_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/net/vhost_net.c +2 -2
@@ -329,8 +329,8 @@ 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 (cvq) { + last_index +=1 ; }if (!k->set_guest_notifiers) {
Signature · 1 line
2.27.0
PATCH v3 1/2 vhost: Rename last_index to last_vq_index
In reply to Eugenio PérezThe doc of this field points out that last_index is the last vq index. Since last_index can cause confusion if seen out of context, renaming to last_vq_index, aligning with vq_index.
--- include/hw/virtio/vhost.h | 2 +- hw/net/vhost_net.c | 4 ++-- hw/virtio/vhost-vdpa.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/hw/virtio/vhost.h +1 -1
@@ -75,7 +75,7 @@ struct vhost_dev {/* the first virtqueue which would be used by this vhost dev */ int vq_index;/* the last vq index for the virtio device (not vhost) */ -int last_index; +int last_vq_index;/* if non-zero, minimum required value for max_queues */ int num_queues;uint64_t features;
hw/net/vhost_net.c +2 -2
@@ -232,10 +232,10 @@ fail: }static void vhost_net_set_vq_index (struct vhost_net *net,int vq_index, -int last_index) +int last_vq_index) { net->dev.vq_index = vq_index; - net->dev.last_index = last_index; + net->dev.last_vq_index = last_vq_index; } static int vhost_net_start_one(struct vhost_net *net,
hw/virtio/vhost-vdpa.c +1 -1
@@ -632,7 +632,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)vhost_vdpa_host_notifiers_uninit (dev, dev->nvqs); } -if (dev->vq_index + dev->nvqs != dev->last_index) { +if (dev->vq_index + dev->nvqs != dev->last_vq_index) {return 0 ; }
Signature · 1 line
2.27.0
Re: [PATCH v3 2/2] vhost: Fix last vq queue index of devices with no cvq
In reply to Eugenio PérezQuoted 10 lines · Eugenio Pérez
The -1 assumes that last index counts all vhost device models as having two queues, but they count only the ones that models the data queues.
Because of that, the right change in
last_indexis to actually add the cvq, not to remove the missing one.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_vdpawith host's vhost=on and vhost=off, with ctrl_vq=on and ctrl_vq=off.Fixes 049eb15b5fc9 ("vhost: record the last virtqueue index for thevirtio device")
Signed-off-by Eugenio Pérez <[email protected]>
Re: [PATCH v3 1/2] vhost: Rename last_index to last_vq_index
In reply to Eugenio PérezQuoted 5 lines · Eugenio Pérez
The doc of this field points out that
last_indexis the last vq index. Sincelast_indexcan cause confusion if seen out of context, renaming tolast_vq_index, aligning withvq_index.Signed-off-by Eugenio Pérez <[email protected]>
Re: [PATCH v3 1/2] vhost: Rename last_index to last_vq_index
In reply to Eugenio PérezQuoted 6 lines · Eugenio Pérez
The doc of this field points out that
last_indexis the last vq index. Sincelast_indexcan cause confusion if seen out of context, renaming tolast_vq_index, aligning withvq_index.Signed-off-by Eugenio Pérez <[email protected]>
Quoted 52 lines
--- include/hw/virtio/vhost.h | 2 +- hw/net/vhost_net.c | 4 ++-- hw/virtio/vhost-vdpa.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)include/hw/virtio/vhost.h +1
-1@@ -75,7 +75,7 @@ struct vhost_dev {/* the first virtqueue which would be used by this vhost dev */ int vq_index;/* the last vq index for the virtio device (not vhost) */ -int last_index; +int last_vq_index;/* if non-zero, minimum required value for max_queues */ int num_queues;uint64_t features;hw/net/vhost_net.c +2
-2@@ -232,10 +232,10 @@ fail: }static void vhost_net_set_vq_index (struct vhost_net *net,int vq_index, -int last_index) +int last_vq_index) { net->dev.vq_index = vq_index; - net->dev.last_index = last_index; + net->dev.last_vq_index = last_vq_index; } static int vhost_net_start_one(struct vhost_net *net,hw/virtio/vhost-vdpa.c +1
-2@@ -632,7 +632,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)vhost_vdpa_host_notifiers_uninit (dev, dev->nvqs); } -if (dev->vq_index + dev->nvqs != dev->last_index) { +if (dev->vq_index + dev->nvqs != dev->last_vq_index) {return 0 ; } --2.27.0
Re: [PATCH v3 2/2] vhost: Fix last vq queue index of devices with no cvq
In reply to Eugenio PérezQuoted 25 lines · Eugenio Pérez
The -1 assumes that last index counts all vhost device models as having two queues, but they count only the ones that models the data queues.
Because of that, the right change in
last_indexis to actually add the cvq, not to remove the missing one.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_vdpawith host's vhost=on and vhost=off, with ctrl_vq=on and ctrl_vq=off.Fixes 049eb15b5fc9 ("vhost: record the last virtqueue index for the virtio device")Signed-off-by Eugenio Pérez <[email protected]>--- hw/net/vhost_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/net/vhost_net.c +0
-0
hw/net/vhost_net.c int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, · line 333
Quoted 7 lines
hw/net/vhost_net.c +2
-2@@ -329,8 +329,8 @@ 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 (cvq) { + last_index +=1 ;
Patch looks ok.
Not a native speaker but I guess "last" should be inside the closed interval. If this is true, I still prefer to change the check in vhost_vdpa_dev_start().
Thanks
Quoted 6 lines
hw/net/vhost_net.c +0
-1}if (!k->set_guest_notifiers) { --2.27.0
Re: [PATCH v3 2/2] vhost: Fix last vq queue index of devices with no cvq
Quoted 37 lines · Jason Wang
Quoted 25 lines · Eugenio Pérez
The -1 assumes that last index counts all vhost device models as having two queues, but they count only the ones that models the data queues.
Because of that, the right change in
last_indexis to actually add the cvq, not to remove the missing one.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_vdpawith host's vhost=on and vhost=off, with ctrl_vq=on and ctrl_vq=off.Fixes 049eb15b5fc9 ("vhost: record the last virtqueue index for the virtio device")Signed-off-by Eugenio Pérez <[email protected]>--- hw/net/vhost_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/net/vhost_net.c +0
-0hw/net/vhost_net.c int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, · line 333
Quoted 7 lines
hw/net/vhost_net.c +2
-2@@ -329,8 +329,8 @@ 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 (cvq) { + last_index +=1 ;Patch looks ok.
Quoted 4 lines
Not a native speaker but I guess "last" should be inside the closed interval. If this is true, I still prefer to change the check in
vhost_vdpa_dev_start().
You are right, it's the way we are using it in iova address and there are some other examples. I'll rename to end, similar to other containers.
Thanks!
Quoted 9 lines
Thanks
Quoted 6 lines
hw/net/vhost_net.c +0
-1}if (!k->set_guest_notifiers) { --2.27.0