diff mbox

[03/10] tests/vhost-user-bridge: workaround stale vring base

Message ID 1465231508-30183-4-git-send-email-marcandre.lureau@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Marc-André Lureau June 6, 2016, 4:45 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

This patch is a similar solution to what Yuanhan Liu/Huawei Xie have
suggested for DPDK. When vubr quits (killed or crashed), a restart of
vubr would get stale vring base from QEMU. That would break the kernel
virtio net completely, making it non-work any more, unless a driver
reset is done.

So, instead of getting the stale vring base from QEMU, Huawei suggested
we could get a proper one from used->idx. This works because the queues
packets are processed in order.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 tests/vhost-user-bridge.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Victor Kaplansky June 9, 2016, 10:07 a.m. UTC | #1
On Mon, Jun 06, 2016 at 06:45:01PM +0200, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> This patch is a similar solution to what Yuanhan Liu/Huawei Xie have
> suggested for DPDK. When vubr quits (killed or crashed), a restart of
> vubr would get stale vring base from QEMU. That would break the kernel
> virtio net completely, making it non-work any more, unless a driver
> reset is done.
> 
> So, instead of getting the stale vring base from QEMU, Huawei suggested
> we could get a proper one from used->idx. This works because the queues
> packets are processed in order.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Tested-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> Reviewed-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> ---
>  tests/vhost-user-bridge.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index f907ce7..38963e4 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -946,6 +946,13 @@ vubr_set_vring_addr_exec(VubrDev *dev, VhostUserMsg *vmsg)
>      DPRINT("    vring_avail at %p\n", vq->avail);
>  
>      vq->last_used_index = vq->used->idx;
> +
> +    if (vq->last_avail_index != vq->used->idx) {
> +        DPRINT("Last avail index != used index: %d != %d, resuming",
> +               vq->last_avail_index, vq->used->idx);
> +        vq->last_avail_index = vq->used->idx;
> +    }
> +

What if set_vring_base is called after set_vring_addr?
Maybe it is worth to add the fixup to the set_vring_base as well?

>      return 0;
>  }
>  
> -- 
> 2.7.4
> 
>
Marc-André Lureau June 9, 2016, 10:25 a.m. UTC | #2
Hi

On Thu, Jun 9, 2016 at 12:07 PM, Victor Kaplansky <victork@redhat.com> wrote:
> What if set_vring_base is called after set_vring_addr?
> Maybe it is worth to add the fixup to the set_vring_base as well?

It would need to handle conditions like set_vring_base() being called
while set_vring_addr() is not yet, and thus vq->used isn't set.

Imho it's not necessary, since order is currently fixed in
vhost_virtqueue_start(), but we could specify this in the protocol to
avoid too much possible states.
Michael S. Tsirkin June 13, 2016, 8:45 p.m. UTC | #3
On Thu, Jun 09, 2016 at 12:25:54PM +0200, Marc-André Lureau wrote:
> Hi
> 
> On Thu, Jun 9, 2016 at 12:07 PM, Victor Kaplansky <victork@redhat.com> wrote:
> > What if set_vring_base is called after set_vring_addr?
> > Maybe it is worth to add the fixup to the set_vring_base as well?
> 
> It would need to handle conditions like set_vring_base() being called
> while set_vring_addr() is not yet, and thus vq->used isn't set.
> 
> Imho it's not necessary, since order is currently fixed in
> vhost_virtqueue_start(), but we could specify this in the protocol to
> avoid too much possible states.

I personally think it's better to just get the used idx
from memory before reconnecting.

Will fix old clients automatically.

Whoever wants to support old QEMU, can do this by a work-around
similar to the supplied one. Maybe add code here to make
sure everything is setup - if not it's a new QEMU so
it does not need the work-around.

I think there was a patch like this suggested at some point -
mind digging it up?

> -- 
> Marc-André Lureau
diff mbox

Patch

diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index f907ce7..38963e4 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -946,6 +946,13 @@  vubr_set_vring_addr_exec(VubrDev *dev, VhostUserMsg *vmsg)
     DPRINT("    vring_avail at %p\n", vq->avail);
 
     vq->last_used_index = vq->used->idx;
+
+    if (vq->last_avail_index != vq->used->idx) {
+        DPRINT("Last avail index != used index: %d != %d, resuming",
+               vq->last_avail_index, vq->used->idx);
+        vq->last_avail_index = vq->used->idx;
+    }
+
     return 0;
 }