Skip to contentSkip to conversation

vhost-user: sync backend

PATCH Superseded Marcel Apfelbaum 2 participants 7 messages Jul 29, 2015 – Jul 30, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover vhost-user: sync backend

To be used on top of:
[PATCH 0/4] vhost-user: protocol updates
https://lists.gnu.org/archive/html/qemu-devel/2015-07/msg03842.html

v1 -> v2:
- Addressed Michael S. Tsirkin's comments:
- Prefer a white-list of supported features
- Add a unit-test to show the problem we are trying to solve (run the unit-test before the patch and it will fail)

Currently the vhost-user supported features are not evaluated. The way I see it, and please correct me, the best way to do this is to:
1. Get the backend features on vhost init.
2. Check them one by one (white-list) against all the currently supported virtio features.
3. All other code should remain the same.

Marcel Apfelbaum (2):
vhost-user: sync backend features tests/vhost-user: check vhost-user feature negotiation

 hw/virtio/vhost-user.c  | 17 +++++++++++++++++
 tests/vhost-user-test.c | 19 ++++++++++++++++---
 2 files changed, 33 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH v2 1/2 vhost-user: sync backend features

Complete vhost-user negotiation by syncing the features supported by the backend.

---
 hw/virtio/vhost-user.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/virtio/vhost-user.c +17 -0
index c4428a1..b522437 100644
@@ -22,6 +22,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <linux/vhost.h>
+#include <linux/virtio_net.h>
 
 #define VHOST_MEMORY_MAX_NREGIONS    8
 
@@ -358,6 +359,22 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
         return err;
     }
 
+    if (__virtio_has_feature(msg.u64, VIRTIO_F_ANY_LAYOUT)) {
+        dev->backend_features |= 1ULL << VIRTIO_F_ANY_LAYOUT;
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_F_VERSION_1)) {
+        dev->backend_features |= 1ULL << VIRTIO_F_VERSION_1;
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_NET_F_MRG_RXBUF)) {
+        dev->backend_features |= 1ULL << VIRTIO_NET_F_MRG_RXBUF;
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_NET_F_MQ)) {
+        dev->backend_features |= 1ULL << VIRTIO_NET_F_MQ;
+    }
+
     if (__virtio_has_feature(msg.u64, VHOST_USER_F_PROTOCOL_FEATURES)) {
         dev->backend_features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
 
Signature · 1 line
2.1.0
#2 lore raw

Re: [Qemu-devel] [PATCH V2 1/2] vhost-user: sync backend features

Quoted 1 line · Marcel Apfelbaum

Complete vhost-user negotiation by syncing

synching.

Quoted 30 lines

the features
supported by the backend.

---
 hw/virtio/vhost-user.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/virtio/vhost-user.c +7 -0
index c4428a1..b522437 100644
@@ -22,6 +22,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <linux/vhost.h>
+#include <linux/virtio_net.h>
 
 #define VHOST_MEMORY_MAX_NREGIONS    8
 
@@ -358,6 +359,22 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
         return err;
     }
 
+    if (__virtio_has_feature(msg.u64, VIRTIO_F_ANY_LAYOUT)) {
+        dev->backend_features |= 1ULL << VIRTIO_F_ANY_LAYOUT;
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_F_VERSION_1)) {
+        dev->backend_features |= 1ULL << VIRTIO_F_VERSION_1;

hw/virtio/vhost-user.c static int vhost_user_init(struct vhost_dev *dev, void *opaque) · line 377

Quoted 10 lines
hw/virtio/vhost-user.c +10 -0
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_NET_F_MRG_RXBUF)) {
+        dev->backend_features |= 1ULL << VIRTIO_NET_F_MRG_RXBUF;
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_NET_F_MQ)) {
+        dev->backend_features |= 1ULL << VIRTIO_NET_F_MQ;
+    }
+

A bit too early for MQ, isn't it?

Quoted 5 lines
hw/virtio/vhost-user.c +0 -0
     if (__virtio_has_feature(msg.u64, VHOST_USER_F_PROTOCOL_FEATURES)) {
         dev->backend_features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
 
Signature · 1 line
2.1.0
#3 lore raw

Re: [Qemu-devel] [PATCH V2 1/2] vhost-user: sync backend features

Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · Marcel Apfelbaum

Complete vhost-user negotiation by syncing

synching.

OK, thanks

Quoted 35 lines
Quoted 35 lines

the features
supported by the backend.

---
  hw/virtio/vhost-user.c | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
hw/virtio/vhost-user.c +11 -0
index c4428a1..b522437 100644
@@ -22,6 +22,7 @@
  #include <sys/socket.h>
  #include <sys/un.h>
  #include <linux/vhost.h>
+#include <linux/virtio_net.h>
 
  #define VHOST_MEMORY_MAX_NREGIONS    8
 
@@ -358,6 +359,22 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
          return err;
      }
 
+    if (__virtio_has_feature(msg.u64, VIRTIO_F_ANY_LAYOUT)) {
+        dev->backend_features |= 1ULL << VIRTIO_F_ANY_LAYOUT;
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_F_VERSION_1)) {
+        dev->backend_features |= 1ULL << VIRTIO_F_VERSION_1;
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_NET_F_MRG_RXBUF)) {
+        dev->backend_features |= 1ULL << VIRTIO_NET_F_MRG_RXBUF;
Quoted 8 lines

hw/virtio/vhost-user.c static int vhost_user_init(struct vhost_dev *dev, void *opaque) · line 377

Quoted 6 lines
hw/virtio/vhost-user.c +6 -0
+    }
+
+    if (__virtio_has_feature(msg.u64, VIRTIO_NET_F_MQ)) {
+        dev->backend_features |= 1ULL << VIRTIO_NET_F_MQ;
+    }
+

A bit too early for MQ, isn't it?

For a complete solution, until we have it in protocol features

Quoted 6 lines
Quoted 6 lines
hw/virtio/vhost-user.c +0 -1
      if (__virtio_has_feature(msg.u64, VHOST_USER_F_PROTOCOL_FEATURES)) {
          dev->backend_features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
 
--

2.1.0

#4 lore raw

PATCH v2 2/2 tests/vhost-user: check vhost-user feature negotiation

In reply to Marcel Apfelbaum

Check the backend receives all declared virtio features that are also supported by QEMU virtio.

---
 tests/vhost-user-test.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
tests/vhost-user-test.c +16 -3
index 228acb6..019b880 100644
@@ -17,6 +17,7 @@
 #include "sysemu/sysemu.h"
 
 #include <linux/vhost.h>
+#include <linux/virtio_net.h>
 #include <sys/mman.h>
 #include <sys/vfs.h>
 #include <qemu/sockets.h>
@@ -297,14 +298,26 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
         /* send back features to qemu */
         msg.flags |= VHOST_USER_REPLY_MASK;
         msg.size = sizeof(m.u64);
-        msg.u64 = 0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
+        msg.u64 = (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES) |
+                  (0x1ULL << VIRTIO_F_ANY_LAYOUT) |
+                  (0x1ULL << VIRTIO_F_VERSION_1)  |
+                  (0x1ULL << VIRTIO_NET_F_MRG_RXBUF) |
+                  (0x1ULL << VIRTIO_NET_F_MQ);
         p = (uint8_t *) &msg;
         qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
         break;
 
     case VHOST_USER_SET_FEATURES:
-	g_assert_cmpint(msg.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
-			!=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_F_ANY_LAYOUT),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_F_VERSION_1),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_NET_F_MRG_RXBUF),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_NET_F_MQ),
+            !=, 0ULL);
         break;
 
     case VHOST_USER_GET_PROTOCOL_FEATURES:
Signature · 1 line
2.1.0
#5 lore raw

Re: [Qemu-devel] [PATCH V2 2/2] tests/vhost-user: check vhost-user feature negotiation

Quoted 24 lines · Marcel Apfelbaum

Check the backend receives all declared virtio features that are also supported by QEMU virtio.

---
 tests/vhost-user-test.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
tests/vhost-user-test.c +1 -0
index 228acb6..019b880 100644
@@ -17,6 +17,7 @@
 #include "sysemu/sysemu.h"
 
 #include <linux/vhost.h>
+#include <linux/virtio_net.h>
 #include <sys/mman.h>
 #include <sys/vfs.h>
 #include <qemu/sockets.h>
@@ -297,14 +298,26 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
         /* send back features to qemu */
         msg.flags |= VHOST_USER_REPLY_MASK;
         msg.size = sizeof(m.u64);

tests/vhost-user-test.c static void chr_read(void *opaque, const uint8_t *buf, int size) · line 309

Quoted 10 lines
tests/vhost-user-test.c +5 -1
-        msg.u64 = 0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
+        msg.u64 = (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES) |
+                  (0x1ULL << VIRTIO_F_ANY_LAYOUT) |
+                  (0x1ULL << VIRTIO_F_VERSION_1)  |
+                  (0x1ULL << VIRTIO_NET_F_MRG_RXBUF) |
+                  (0x1ULL << VIRTIO_NET_F_MQ);
         p = (uint8_t *) &msg;
         qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
         break;
 

No, this mixes protocol features and virtio features. It's not what was intended.

Quoted 18 lines
tests/vhost-user-test.c +10 -2
     case VHOST_USER_SET_FEATURES:
-	g_assert_cmpint(msg.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
-			!=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_F_ANY_LAYOUT),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_F_VERSION_1),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_NET_F_MRG_RXBUF),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_NET_F_MQ),
+            !=, 0ULL);
         break;
 
     case VHOST_USER_GET_PROTOCOL_FEATURES:
Signature · 1 line
2.1.0
#6 lore raw

Re: [Qemu-devel] [PATCH V2 2/2] tests/vhost-user: check vhost-user feature negotiation

Quoted 30 lines · Michael S. Tsirkin
Quoted 29 lines · Marcel Apfelbaum

Check the backend receives all declared virtio features that are also supported by QEMU virtio.

---
  tests/vhost-user-test.c | 19 ++++++++++++++++---
  1 file changed, 16 insertions(+), 3 deletions(-)
tests/vhost-user-test.c +5 -1
index 228acb6..019b880 100644
@@ -17,6 +17,7 @@
  #include "sysemu/sysemu.h"
 
  #include <linux/vhost.h>
+#include <linux/virtio_net.h>
  #include <sys/mman.h>
  #include <sys/vfs.h>
  #include <qemu/sockets.h>
@@ -297,14 +298,26 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
          /* send back features to qemu */
          msg.flags |= VHOST_USER_REPLY_MASK;
          msg.size = sizeof(m.u64);
-        msg.u64 = 0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
+        msg.u64 = (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES) |
+                  (0x1ULL << VIRTIO_F_ANY_LAYOUT) |
+                  (0x1ULL << VIRTIO_F_VERSION_1)  |
+                  (0x1ULL << VIRTIO_NET_F_MRG_RXBUF) |
Quoted 8 lines

tests/vhost-user-test.c static void chr_read(void *opaque, const uint8_t *buf, int size) · line 309

Quoted 5 lines
tests/vhost-user-test.c +1 -0
+                  (0x1ULL << VIRTIO_NET_F_MQ);
          p = (uint8_t *) &msg;
          qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
          break;
 

No, this mixes protocol features and virtio features. It's not what was intended.

You asked for a test that shows the problem, here it is.

We can change it as you wish, if you have a better idea, just say, "no" doesn't help.

Thanks,
Marcel

Quoted 19 lines
Quoted 19 lines
tests/vhost-user-test.c +10 -3
      case VHOST_USER_SET_FEATURES:
-	g_assert_cmpint(msg.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
-			!=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_F_ANY_LAYOUT),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_F_VERSION_1),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_NET_F_MRG_RXBUF),
+            !=, 0ULL);
+        g_assert_cmpint(msg.u64 & (0x1ULL << VIRTIO_NET_F_MQ),
+            !=, 0ULL);
          break;
 
      case VHOST_USER_GET_PROTOCOL_FEATURES:
--

2.1.0