Skip to contentSkip to conversation

vhost-user-bridge reconnect regression

PATCH Superseded Marc-André Lureau 3 participants 12 messages Aug 29, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover vhost-user-bridge reconnect regression

Hi,

libvhost-user doesn't support resuming with the same trick vubr had since commit 523b018dde3b7650fe5401d0499b30cf2f117515. The following two patches fix that regression.

Thanks

Marc-André Lureau (2):
libvhost-user: support resuming vq->last_avail_idx based on used_idx
vhost-user-bridge: fix resume regression (since 2.9)

 contrib/libvhost-user/libvhost-user.h |  5 +++++
 contrib/libvhost-user/libvhost-user.c | 13 +++++++++++++
 tests/vhost-user-bridge.c             |  7 +++++++
 3 files changed, 25 insertions(+)
Signature · 1 line
2.14.1.146.gd35faa819
#1 lore raw

PATCH 1/2 libvhost-user: support resuming vq->last_avail_idx based on used_idx

This is the same workaround as commit 523b018dde3b765, which was lost with libvhost-user transition in commit e10e798c85c2331.

---
 contrib/libvhost-user/libvhost-user.h |  5 +++++
 contrib/libvhost-user/libvhost-user.c | 13 +++++++++++++
 2 files changed, 18 insertions(+)
contrib/libvhost-user/libvhost-user.h +5 -0
index 53ef222c0b..aca71717c1 100644
@@ -132,6 +132,7 @@ typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features);
 typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg,
                                   int *do_reply);
 typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool started);
+typedef bool (*vu_queue_resume_to_used_cb) (VuDev *dev, int qidx);
 
 typedef struct VuDevIface {
     /* called by VHOST_USER_GET_FEATURES to get the features bitmask */
@@ -148,6 +149,10 @@ typedef struct VuDevIface {
     vu_process_msg_cb process_msg;
     /* tells when queues can be processed */
     vu_queue_set_started_cb queue_set_started;
+    /* If the queue must be resumed to vring.used->idx. */
+    /* This can help to support resuming on unmanaged exit/crash when
+     * the slave/driver processes elements in order. */
+    vu_queue_resume_to_used_cb queue_resume_to_used;
 } VuDevIface;
 
 typedef void (*vu_queue_handler_cb) (VuDev *dev, int qidx);
contrib/libvhost-user/libvhost-user.c +13 -0
index 35fa0c5e56..36439caed6 100644
@@ -521,6 +521,19 @@ vu_set_vring_addr_exec(VuDev *dev, VhostUserMsg *vmsg)
 
     vq->used_idx = vq->vring.used->idx;
 
+    if (vq->last_avail_idx != vq->used_idx) {
+        bool resume = dev->iface->queue_resume_to_used &&
+            dev->iface->queue_resume_to_used(dev, index);
+
+        DPRINT("Last avail index != used index: %u != %u%s\n",
+               vq->last_avail_idx, vq->used_idx,
+               resume ? ", resuming" : "");
+
+        if (resume) {
+            vq->shadow_avail_idx = vq->last_avail_idx = vq->used_idx;
+        }
+    }
+
     return false;
 }
 
Signature · 1 line
2.14.1.146.gd35faa819
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] libvhost-user: support resuming vq->last_avail_idx based on used_idx

Quoted 22 lines · Marc-André Lureau

This is the same workaround as commit 523b018dde3b765, which was lost with libvhost-user transition in commit e10e798c85c2331.

---
 contrib/libvhost-user/libvhost-user.h |  5 +++++
 contrib/libvhost-user/libvhost-user.c | 13 +++++++++++++
 2 files changed, 18 insertions(+)
contrib/libvhost-user/libvhost-user.h +1 -0
index 53ef222c0b..aca71717c1 100644
@@ -132,6 +132,7 @@ typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features);
 typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg,
                                   int *do_reply);
 typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool started);
+typedef bool (*vu_queue_resume_to_used_cb) (VuDev *dev, int qidx);
 
 typedef struct VuDevIface {
     /* called by VHOST_USER_GET_FEATURES to get the features bitmask */

contrib/libvhost-user/libvhost-user.h typedef struct VuDevIface { · line 158

Quoted 10 lines
contrib/libvhost-user/libvhost-user.h +4 -0
@@ -148,6 +149,10 @@ typedef struct VuDevIface {
     vu_process_msg_cb process_msg;
     /* tells when queues can be processed */
     vu_queue_set_started_cb queue_set_started;
+    /* If the queue must be resumed to vring.used->idx. */
+    /* This can help to support resuming on unmanaged exit/crash when
+     * the slave/driver processes elements in order. */
+    vu_queue_resume_to_used_cb queue_resume_to_used;
 } VuDevIface;
 
 typedef void (*vu_queue_handler_cb) (VuDev *dev, int qidx);

Let's consider: this is only safe if queue is processed in order. So I think that would be a better name for the field.

Quoted 26 lines
contrib/libvhost-user/libvhost-user.c +13 -0
index 35fa0c5e56..36439caed6 100644
@@ -521,6 +521,19 @@ vu_set_vring_addr_exec(VuDev *dev, VhostUserMsg *vmsg)
 
     vq->used_idx = vq->vring.used->idx;
 
+    if (vq->last_avail_idx != vq->used_idx) {
+        bool resume = dev->iface->queue_resume_to_used &&
+            dev->iface->queue_resume_to_used(dev, index);
+
+        DPRINT("Last avail index != used index: %u != %u%s\n",
+               vq->last_avail_idx, vq->used_idx,
+               resume ? ", resuming" : "");
+
+        if (resume) {
+            vq->shadow_avail_idx = vq->last_avail_idx = vq->used_idx;
+        }
+    }
+
     return false;
 }
 
Signature · 1 line
2.14.1.146.gd35faa819
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] libvhost-user: support resuming vq->last_avail_idx based on used_idx

Hi

Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Marc-André Lureau

This is the same workaround as commit 523b018dde3b765, which was lost with libvhost-user transition in commit e10e798c85c2331.

---
 contrib/libvhost-user/libvhost-user.h |  5 +++++
 contrib/libvhost-user/libvhost-user.c | 13 +++++++++++++
 2 files changed, 18 insertions(+)
contrib/libvhost-user/libvhost-user.h +5 -0
index 53ef222c0b..aca71717c1 100644
@@ -132,6 +132,7 @@ typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features);
 typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg,
                                   int *do_reply);
 typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool started);
+typedef bool (*vu_queue_resume_to_used_cb) (VuDev *dev, int qidx);
 
 typedef struct VuDevIface {
     /* called by VHOST_USER_GET_FEATURES to get the features bitmask */
@@ -148,6 +149,10 @@ typedef struct VuDevIface {
     vu_process_msg_cb process_msg;
     /* tells when queues can be processed */
     vu_queue_set_started_cb queue_set_started;
+    /* If the queue must be resumed to vring.used->idx. */
+    /* This can help to support resuming on unmanaged exit/crash when
+     * the slave/driver processes elements in order. */
+    vu_queue_resume_to_used_cb queue_resume_to_used;
 } VuDevIface;
 
Quoted 5 lines

contrib/libvhost-user/libvhost-user.h typedef struct VuDevIface { · line 158

Quoted 1 line
contrib/libvhost-user/libvhost-user.h +0 -0
 typedef void (*vu_queue_handler_cb) (VuDev *dev, int qidx);

Let's consider: this is only safe if queue is processed in order. So I think that would be a better name for the field.

That's what the comment say already :)

Which name do you suggest? vu_queue_is_processed_in_order? Does that imply it should always resume?

Quoted 28 lines
Quoted 27 lines
contrib/libvhost-user/libvhost-user.c +13 -1
index 35fa0c5e56..36439caed6 100644
@@ -521,6 +521,19 @@ vu_set_vring_addr_exec(VuDev *dev, VhostUserMsg *vmsg)
 
     vq->used_idx = vq->vring.used->idx;
 
+    if (vq->last_avail_idx != vq->used_idx) {
+        bool resume = dev->iface->queue_resume_to_used &&
+            dev->iface->queue_resume_to_used(dev, index);
+
+        DPRINT("Last avail index != used index: %u != %u%s\n",
+               vq->last_avail_idx, vq->used_idx,
+               resume ? ", resuming" : "");
+
+        if (resume) {
+            vq->shadow_avail_idx = vq->last_avail_idx = vq->used_idx;
+        }
+    }
+
     return false;
 }
 
--

2.14.1.146.gd35faa819

Signature · 1 line
Marc-André Lureau
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] libvhost-user: support resuming vq->last_avail_idx based on used_idx

Quoted 35 lines · Marc-André Lureau

Hi

Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Marc-André Lureau

This is the same workaround as commit 523b018dde3b765, which was lost with libvhost-user transition in commit e10e798c85c2331.

---
 contrib/libvhost-user/libvhost-user.h |  5 +++++
 contrib/libvhost-user/libvhost-user.c | 13 +++++++++++++
 2 files changed, 18 insertions(+)
contrib/libvhost-user/libvhost-user.h +5 -0
index 53ef222c0b..aca71717c1 100644
@@ -132,6 +132,7 @@ typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features);
 typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg,
                                   int *do_reply);
 typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool started);
+typedef bool (*vu_queue_resume_to_used_cb) (VuDev *dev, int qidx);
 
 typedef struct VuDevIface {
     /* called by VHOST_USER_GET_FEATURES to get the features bitmask */
@@ -148,6 +149,10 @@ typedef struct VuDevIface {
     vu_process_msg_cb process_msg;
     /* tells when queues can be processed */
     vu_queue_set_started_cb queue_set_started;
+    /* If the queue must be resumed to vring.used->idx. */
+    /* This can help to support resuming on unmanaged exit/crash when
+     * the slave/driver processes elements in order. */
+    vu_queue_resume_to_used_cb queue_resume_to_used;
 } VuDevIface;
 
Quoted 8 lines
Quoted 5 lines

contrib/libvhost-user/libvhost-user.h typedef struct VuDevIface { · line 158

Quoted 1 line
contrib/libvhost-user/libvhost-user.h +0 -0
 typedef void (*vu_queue_handler_cb) (VuDev *dev, int qidx);

Let's consider: this is only safe if queue is processed in order. So I think that would be a better name for the field.

That's what the comment say already :)

Which name do you suggest? vu_queue_is_processed_in_order?

Something like this.

Quoted 2 lines

Does that
imply it should always resume?

Not sure I understand the question.

Quoted 33 lines
Quoted 28 lines
Quoted 27 lines
contrib/libvhost-user/libvhost-user.c +13 -1
index 35fa0c5e56..36439caed6 100644
@@ -521,6 +521,19 @@ vu_set_vring_addr_exec(VuDev *dev, VhostUserMsg *vmsg)
 
     vq->used_idx = vq->vring.used->idx;
 
+    if (vq->last_avail_idx != vq->used_idx) {
+        bool resume = dev->iface->queue_resume_to_used &&
+            dev->iface->queue_resume_to_used(dev, index);
+
+        DPRINT("Last avail index != used index: %u != %u%s\n",
+               vq->last_avail_idx, vq->used_idx,
+               resume ? ", resuming" : "");
+
+        if (resume) {
+            vq->shadow_avail_idx = vq->last_avail_idx = vq->used_idx;
+        }
+    }
+
     return false;
 }
 
--

2.14.1.146.gd35faa819

Signature · 1 line
Marc-André Lureau
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] libvhost-user: support resuming vq->last_avail_idx based on used_idx

Hi

Quoted 43 lines · Michael S. Tsirkin
Quoted 42 lines · Marc-André Lureau

Hi

Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Marc-André Lureau

This is the same workaround as commit 523b018dde3b765, which was lost with libvhost-user transition in commit e10e798c85c2331.

---
 contrib/libvhost-user/libvhost-user.h |  5 +++++
 contrib/libvhost-user/libvhost-user.c | 13 +++++++++++++
 2 files changed, 18 insertions(+)
contrib/libvhost-user/libvhost-user.h +5 -0
index 53ef222c0b..aca71717c1 100644
@@ -132,6 +132,7 @@ typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features);
 typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg,
                                   int *do_reply);
 typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool started);
+typedef bool (*vu_queue_resume_to_used_cb) (VuDev *dev, int qidx);
 
 typedef struct VuDevIface {
     /* called by VHOST_USER_GET_FEATURES to get the features bitmask */
@@ -148,6 +149,10 @@ typedef struct VuDevIface {
     vu_process_msg_cb process_msg;
     /* tells when queues can be processed */
     vu_queue_set_started_cb queue_set_started;
+    /* If the queue must be resumed to vring.used->idx. */
+    /* This can help to support resuming on unmanaged exit/crash when
+     * the slave/driver processes elements in order. */
+    vu_queue_resume_to_used_cb queue_resume_to_used;
 } VuDevIface;
 
Quoted 5 lines

contrib/libvhost-user/libvhost-user.h typedef struct VuDevIface { · line 158

Quoted 1 line
contrib/libvhost-user/libvhost-user.h +0 -0
 typedef void (*vu_queue_handler_cb) (VuDev *dev, int qidx);

Let's consider: this is only safe if queue is processed in order. So I think that would be a better name for the field.

That's what the comment say already :)

Quoted 8 lines
Quoted 1 line

Which name do you suggest? vu_queue_is_processed_in_order?

Something like this.

Quoted 2 lines

Does that
imply it should always resume?

Not sure I understand the question.

If a "queue_is_processed_in_order", does that imply libvhost-user should always resume it based on used_idx? I think it does, but the correlation is less obvious than explicitly saying "resume_to_used".

Signature · 1 line
Marc-André Lureau
#6 lore raw

Re: [Qemu-devel] [PATCH 1/2] libvhost-user: support resuming vq->last_avail_idx based on used_idx

Quoted 50 lines · Marc-André Lureau

Hi

Quoted 47 lines · Michael S. Tsirkin
Quoted 35 lines · Marc-André Lureau

Hi

Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Marc-André Lureau

This is the same workaround as commit 523b018dde3b765, which was lost with libvhost-user transition in commit e10e798c85c2331.

---
 contrib/libvhost-user/libvhost-user.h |  5 +++++
 contrib/libvhost-user/libvhost-user.c | 13 +++++++++++++
 2 files changed, 18 insertions(+)
contrib/libvhost-user/libvhost-user.h +5 -0
index 53ef222c0b..aca71717c1 100644
@@ -132,6 +132,7 @@ typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features);
 typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg,
                                   int *do_reply);
 typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool started);
+typedef bool (*vu_queue_resume_to_used_cb) (VuDev *dev, int qidx);
 
 typedef struct VuDevIface {
     /* called by VHOST_USER_GET_FEATURES to get the features bitmask */
@@ -148,6 +149,10 @@ typedef struct VuDevIface {
     vu_process_msg_cb process_msg;
     /* tells when queues can be processed */
     vu_queue_set_started_cb queue_set_started;
+    /* If the queue must be resumed to vring.used->idx. */
+    /* This can help to support resuming on unmanaged exit/crash when
+     * the slave/driver processes elements in order. */
+    vu_queue_resume_to_used_cb queue_resume_to_used;
 } VuDevIface;
 
Quoted 8 lines
Quoted 5 lines

contrib/libvhost-user/libvhost-user.h typedef struct VuDevIface { · line 158

Quoted 1 line
contrib/libvhost-user/libvhost-user.h +0 -0
 typedef void (*vu_queue_handler_cb) (VuDev *dev, int qidx);

Let's consider: this is only safe if queue is processed in order. So I think that would be a better name for the field.

That's what the comment say already :)

Which name do you suggest? vu_queue_is_processed_in_order?

Something like this.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Does that
imply it should always resume?

Not sure I understand the question.

If a "queue_is_processed_in_order", does that imply libvhost-user should always resume it based on used_idx? I think it does, but the correlation is less obvious than explicitly saying "resume_to_used".

Just add a comment then. You do not want low level details like used index in all backends.

Quoted 3 lines
Signature · 2 lines
-- 
Marc-André Lureau
#7 lore raw

PATCH 2/2 vhost-user-bridge: fix resume regression (since 2.9)

In reply to Marc-André Lureau

Commit e10e798c85c2331 switched to libvhost-user which lacked support for resuming the avail_idx based on used_idx.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1485867

---
 tests/vhost-user-bridge.c | 7 +++++++
 1 file changed, 7 insertions(+)
tests/vhost-user-bridge.c +7 -0
index 1e5b5ca3da..dca48512ba 100644
@@ -466,11 +466,18 @@ vubr_panic(VuDev *dev, const char *msg)
     vubr->quit = 1;
 }
 
+static bool
+vubr_queue_resume_to_used(VuDev *dev, int qidx)
+{
+    return true;
+}
+
 static const VuDevIface vuiface = {
     .get_features = vubr_get_features,
     .set_features = vubr_set_features,
     .process_msg = vubr_process_msg,
     .queue_set_started = vubr_queue_set_started,
+    .queue_resume_to_used = vubr_queue_resume_to_used,
 };
 
 static void
Signature · 1 line
2.14.1.146.gd35faa819
#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] vhost-user-bridge: fix resume regression (since 2.9)

Quoted 7 lines · Marc-André Lureau

Commit e10e798c85c2331 switched to libvhost-user which lacked support for resuming the avail_idx based on used_idx.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1485867

Can we add a test for reconnect to catch the regression?

Quoted 29 lines
---
 tests/vhost-user-bridge.c | 7 +++++++
 1 file changed, 7 insertions(+)
tests/vhost-user-bridge.c +7 -0
index 1e5b5ca3da..dca48512ba 100644
@@ -466,11 +466,18 @@ vubr_panic(VuDev *dev, const char *msg)
     vubr->quit = 1;
 }
 
+static bool
+vubr_queue_resume_to_used(VuDev *dev, int qidx)
+{
+    return true;
+}
+
 static const VuDevIface vuiface = {
     .get_features = vubr_get_features,
     .set_features = vubr_set_features,
     .process_msg = vubr_process_msg,
     .queue_set_started = vubr_queue_set_started,
+    .queue_resume_to_used = vubr_queue_resume_to_used,
 };
 
 static void
Signature · 1 line
2.14.1.146.gd35faa819
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] vhost-user-bridge: fix resume regression (since 2.9)

Hi

Quoted 10 lines · Michael S. Tsirkin
Quoted 7 lines · Marc-André Lureau

Commit e10e798c85c2331 switched to libvhost-user which lacked support for resuming the avail_idx based on used_idx.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1485867

Can we add a test for reconnect to catch the regression?

There is no automated tests for vhost-user-bridge yet. We could probably make one based on "[PATCH v2 0/5] tests/pxe-test: add testcase using vhost-user-bridge" series.

We could also add seperate libvhost-user tests, that's not existent yet, partly because libvhost-user was born as a test itself ;).

Quoted 31 lines
Quoted 30 lines
---
 tests/vhost-user-bridge.c | 7 +++++++
 1 file changed, 7 insertions(+)
tests/vhost-user-bridge.c +7 -1
index 1e5b5ca3da..dca48512ba 100644
@@ -466,11 +466,18 @@ vubr_panic(VuDev *dev, const char *msg)
     vubr->quit = 1;
 }
 
+static bool
+vubr_queue_resume_to_used(VuDev *dev, int qidx)
+{
+    return true;
+}
+
 static const VuDevIface vuiface = {
     .get_features = vubr_get_features,
     .set_features = vubr_set_features,
     .process_msg = vubr_process_msg,
     .queue_set_started = vubr_queue_set_started,
+    .queue_resume_to_used = vubr_queue_resume_to_used,
 };
 
 static void
--

2.14.1.146.gd35faa819

Signature · 1 line
Marc-André Lureau
#10 lore raw

Re: [Qemu-devel] [PATCH 2/2] vhost-user-bridge: fix resume regression (since 2.9)

Quoted 10 lines · Marc-André Lureau

Hi

Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Marc-André Lureau

Commit e10e798c85c2331 switched to libvhost-user which lacked support for resuming the avail_idx based on used_idx.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1485867

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Can we add a test for reconnect to catch the regression?

There is no automated tests for vhost-user-bridge yet. We could probably make one based on "[PATCH v2 0/5] tests/pxe-test: add testcase using vhost-user-bridge" series.

Exactly.

Quoted 39 lines

We could also add seperate libvhost-user tests, that's not existent yet, partly because libvhost-user was born as a test itself ;).

Quoted 31 lines
Quoted 30 lines
---
 tests/vhost-user-bridge.c | 7 +++++++
 1 file changed, 7 insertions(+)
tests/vhost-user-bridge.c +7 -1
index 1e5b5ca3da..dca48512ba 100644
@@ -466,11 +466,18 @@ vubr_panic(VuDev *dev, const char *msg)
     vubr->quit = 1;
 }
 
+static bool
+vubr_queue_resume_to_used(VuDev *dev, int qidx)
+{
+    return true;
+}
+
 static const VuDevIface vuiface = {
     .get_features = vubr_get_features,
     .set_features = vubr_set_features,
     .process_msg = vubr_process_msg,
     .queue_set_started = vubr_queue_set_started,
+    .queue_resume_to_used = vubr_queue_resume_to_used,
 };
 
 static void
--

2.14.1.146.gd35faa819

Signature · 1 line
Marc-André Lureau
#11 lore raw
In reply to Marc-André Lureau
Quoted 7 lines · Marc-André Lureau

Hi,

libvhost-user doesn't support resuming with the same trick vubr had since commit 523b018dde3b7650fe5401d0499b30cf2f117515. The following two patches fix that regression.

Thanks

Copy stable maybe?

Quoted 11 lines

Marc-André Lureau (2):
libvhost-user: support resuming vq->last_avail_idx based on used_idx
vhost-user-bridge: fix resume regression (since 2.9)

 contrib/libvhost-user/libvhost-user.h |  5 +++++
 contrib/libvhost-user/libvhost-user.c | 13 +++++++++++++
 tests/vhost-user-bridge.c             |  7 +++++++
 3 files changed, 25 insertions(+)
Signature · 1 line
2.14.1.146.gd35faa819