All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/1] vhost: Fix last queue index of devices with no cvq
@ 2021-11-02 11:40 Eugenio Pérez
  2021-11-02 11:40 ` [PATCH v2 1/1] " Eugenio Pérez
  0 siblings, 1 reply; 5+ messages in thread
From: Eugenio Pérez @ 2021-11-02 11:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jason Wang, Michael S. Tsirkin, Juan Quintela

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(-)

-- 
2.27.0




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/1] vhost: Fix last queue index of devices with no cvq
  2021-11-02 11:40 [PATCH v2 0/1] vhost: Fix last queue index of devices with no cvq Eugenio Pérez
@ 2021-11-02 11:40 ` Eugenio Pérez
  2021-11-02 14:09   ` Juan Quintela
  2021-11-03  2:50   ` Jason Wang
  0 siblings, 2 replies; 5+ messages in thread
From: Eugenio Pérez @ 2021-11-02 11:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jason Wang, Michael S. Tsirkin, Juan Quintela

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")
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/net/vhost_net.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 0d888f29a6..a859cc943d 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -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;
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] vhost: Fix last queue index of devices with no cvq
  2021-11-02 11:40 ` [PATCH v2 1/1] " Eugenio Pérez
@ 2021-11-02 14:09   ` Juan Quintela
  2021-11-03  2:50   ` Jason Wang
  1 sibling, 0 replies; 5+ messages in thread
From: Juan Quintela @ 2021-11-02 14:09 UTC (permalink / raw)
  To: Eugenio Pérez; +Cc: Jason Wang, qemu-devel, Michael S. Tsirkin

Eugenio Pérez <eperezma@redhat.com> wrote:
Y> 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")
> Reviewed-by: Juan Quintela <quintela@redhat.com>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>

Much clearer, thanks.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] vhost: Fix last queue index of devices with no cvq
  2021-11-02 11:40 ` [PATCH v2 1/1] " Eugenio Pérez
  2021-11-02 14:09   ` Juan Quintela
@ 2021-11-03  2:50   ` Jason Wang
  2021-11-03  7:39     ` Eugenio Perez Martin
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Wang @ 2021-11-03  2:50 UTC (permalink / raw)
  To: Eugenio Pérez; +Cc: Michael S. Tsirkin, qemu-devel, Juan Quintela

On Tue, Nov 2, 2021 at 7:41 PM Eugenio Pérez <eperezma@redhat.com> wrote:
>
> 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")
> Reviewed-by: Juan Quintela <quintela@redhat.com>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>  hw/net/vhost_net.c | 4 ----
>  1 file changed, 4 deletions(-)
>
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index 0d888f29a6..a859cc943d 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -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

>      if (!k->set_guest_notifiers) {
>          error_report("binding does not support guest notifiers");
>          return -ENOSYS;
> --
> 2.27.0
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] vhost: Fix last queue index of devices with no cvq
  2021-11-03  2:50   ` Jason Wang
@ 2021-11-03  7:39     ` Eugenio Perez Martin
  0 siblings, 0 replies; 5+ messages in thread
From: Eugenio Perez Martin @ 2021-11-03  7:39 UTC (permalink / raw)
  To: Jason Wang; +Cc: Michael S. Tsirkin, qemu-devel, Juan Quintela

On Wed, Nov 3, 2021 at 3:50 AM Jason Wang <jasowang@redhat.com> wrote:
>
> On Tue, Nov 2, 2021 at 7:41 PM Eugenio Pérez <eperezma@redhat.com> wrote:
> >
> > 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")
> > Reviewed-by: Juan Quintela <quintela@redhat.com>
> > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > ---
> >  hw/net/vhost_net.c | 4 ----
> >  1 file changed, 4 deletions(-)
> >
> > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > index 0d888f29a6..a859cc943d 100644
> > --- a/hw/net/vhost_net.c
> > +++ b/hw/net/vhost_net.c
> > @@ -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.
>

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.

> 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!

> Thanks
>
> >      if (!k->set_guest_notifiers) {
> >          error_report("binding does not support guest notifiers");
> >          return -ENOSYS;
> > --
> > 2.27.0
> >
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-03  7:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 11:40 [PATCH v2 0/1] vhost: Fix last queue index of devices with no cvq Eugenio Pérez
2021-11-02 11:40 ` [PATCH v2 1/1] " Eugenio Pérez
2021-11-02 14:09   ` Juan Quintela
2021-11-03  2:50   ` Jason Wang
2021-11-03  7:39     ` Eugenio Perez Martin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.