Skip to contentSkip to conversation

Small vhost-user fixes and tweaks

PATCH In review Dr. David Alan Gilbert (git) 3 participants 9 messages Oct 2, 2017 – Oct 3, 2017

lore
Share & tools
lore
#0 lore raw

cover Small vhost-user fixes and tweaks

From: "Dr. David Alan Gilbert" <[email protected]>

Hi,
This set has a small set of fixes for vhost-user and also enables the SET_SLAVE_REQ_FD feature in libvhost-user. (Where it just stashes the fd).

Dave

Dr. David Alan Gilbert (4):
libvhost-user: vu_queue_started
vhost-user-bridge: Only process received packets on started queues
libvhost-user: Update and fix feature and request lists
libvhost-user: Support VHOST_USER_SET_SLAVE_REQ_FD

 contrib/libvhost-user/libvhost-user.c | 43 ++++++++++++++++++++++++++++++-----
 contrib/libvhost-user/libvhost-user.h | 19 +++++++++++++++-
 tests/vhost-user-bridge.c             |  1 +
 3 files changed, 56 insertions(+), 7 deletions(-)
Signature · 1 line
2.13.6
#1 lore raw

PATCH 1/4 libvhost-user: vu_queue_started

From: "Dr. David Alan Gilbert" <[email protected]>

Add a vu_queue_started method to complement vu_queue_enabled.

---
 contrib/libvhost-user/libvhost-user.c | 6 ++++++
 contrib/libvhost-user/libvhost-user.h | 9 +++++++++
 2 files changed, 15 insertions(+)
contrib/libvhost-user/libvhost-user.c +6 -0
index d27d6303db..5ee8483a32 100644
@@ -943,6 +943,12 @@ vu_queue_enabled(VuDev *dev, VuVirtq *vq)
     return vq->enable;
 }
 
+bool
+vu_queue_started(const VuDev *dev, const VuVirtq *vq)
+{
+    return vq->started;
+}
+
 static inline uint16_t
 vring_avail_flags(VuVirtq *vq)
 {
contrib/libvhost-user/libvhost-user.h +9 -0
index 4021f1124e..94d7cc8fbd 100644
@@ -335,6 +335,15 @@ void vu_queue_set_notification(VuDev *dev, VuVirtq *vq, int enable);
 bool vu_queue_enabled(VuDev *dev, VuVirtq *vq);
 
 /**
+ * vu_queue_started:
+ * @dev: a VuDev context
+ * @vq: a VuVirtq queue
+ *
+ * Returns: whether the queue is started.
+ */
+bool vu_queue_started(const VuDev *dev, const VuVirtq *vq);
+
+/**
  * vu_queue_empty:
  * @dev: a VuDev context
  * @vq: a VuVirtq queue
Signature · 1 line
2.13.6
#3 lore raw

PATCH 2/4 vhost-user-bridge: Only process received packets on started queues

In reply to Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Only process received packets if the queue has been started.

---
 tests/vhost-user-bridge.c | 1 +
 1 file changed, 1 insertion(+)
tests/vhost-user-bridge.c +1 -0
index f922cc75ae..d820033a72 100644
@@ -277,6 +277,7 @@ vubr_backend_recv_cb(int sock, void *ctx)
     DPRINT("    hdrlen = %d\n", hdrlen);
 
     if (!vu_queue_enabled(dev, vq) ||
+        !vu_queue_started(dev, vq) ||
         !vu_queue_avail_bytes(dev, vq, hdrlen, 0)) {
         DPRINT("Got UDP packet, but no available descriptors on RX virtq.\n");
         return;
Signature · 1 line
2.13.6
#4 lore raw

PATCH 3/4 libvhost-user: Update and fix feature and request lists

In reply to Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Update the ProtocolFeature and UserRequest lists to match hw/virtio/vhost-user.c.
Fix the text labelling in libvhost-user.c to match the list.

---
 contrib/libvhost-user/libvhost-user.c | 10 +++++-----
 contrib/libvhost-user/libvhost-user.h |  9 ++++++++-
 2 files changed, 13 insertions(+), 6 deletions(-)
contrib/libvhost-user/libvhost-user.c +5 -5
index 5ee8483a32..1901311a70 100644
@@ -35,16 +35,13 @@
     } while (0)
 
 static const char *
-vu_request_to_string(int req)
+vu_request_to_string(unsigned int req)
 {
 #define REQ(req) [req] = #req
     static const char *vu_request_str[] = {
         REQ(VHOST_USER_NONE),
         REQ(VHOST_USER_GET_FEATURES),
         REQ(VHOST_USER_SET_FEATURES),
-        REQ(VHOST_USER_NONE),
-        REQ(VHOST_USER_GET_FEATURES),
-        REQ(VHOST_USER_SET_FEATURES),
         REQ(VHOST_USER_SET_OWNER),
         REQ(VHOST_USER_RESET_OWNER),
         REQ(VHOST_USER_SET_MEM_TABLE),
@@ -62,7 +59,10 @@ vu_request_to_string(int req)
         REQ(VHOST_USER_GET_QUEUE_NUM),
         REQ(VHOST_USER_SET_VRING_ENABLE),
         REQ(VHOST_USER_SEND_RARP),
-        REQ(VHOST_USER_INPUT_GET_CONFIG),
+        REQ(VHOST_USER_NET_SET_MTU),
+        REQ(VHOST_USER_SET_SLAVE_REQ_FD),
+        REQ(VHOST_USER_IOTLB_MSG),
+        REQ(VHOST_USER_SET_VRING_ENDIAN),
         REQ(VHOST_USER_MAX),
     };
 #undef REQ
contrib/libvhost-user/libvhost-user.h +8 -1
index 94d7cc8fbd..c2fc6da720 100644
@@ -34,6 +34,10 @@ enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_MQ = 0,
     VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
     VHOST_USER_PROTOCOL_F_RARP = 2,
+    VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
+    VHOST_USER_PROTOCOL_F_NET_MTU = 4,
+    VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5,
+    VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
 
     VHOST_USER_PROTOCOL_F_MAX
 };
@@ -61,7 +65,10 @@ typedef enum VhostUserRequest {
     VHOST_USER_GET_QUEUE_NUM = 17,
     VHOST_USER_SET_VRING_ENABLE = 18,
     VHOST_USER_SEND_RARP = 19,
-    VHOST_USER_INPUT_GET_CONFIG = 20,
+    VHOST_USER_NET_SET_MTU = 20,
+    VHOST_USER_SET_SLAVE_REQ_FD = 21,
+    VHOST_USER_IOTLB_MSG = 22,
+    VHOST_USER_SET_VRING_ENDIAN = 23,
     VHOST_USER_MAX
 } VhostUserRequest;
 
Signature · 1 line
2.13.6
#6 lore raw

PATCH 4/4 libvhost-user: Support VHOST_USER_SET_SLAVE_REQ_FD

In reply to Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Allow the qemu to pass us a slave fd. We don't do anything with it yet.

---
 contrib/libvhost-user/libvhost-user.c | 27 ++++++++++++++++++++++++++-
 contrib/libvhost-user/libvhost-user.h |  1 +
 2 files changed, 27 insertions(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +26 -1
index 1901311a70..756b60c4b3 100644
@@ -703,7 +703,8 @@ vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg)
 static bool
 vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg)
 {
-    uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD;
+    uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD |
+                        1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ;
 
     if (dev->iface->get_protocol_features) {
         features |= dev->iface->get_protocol_features(dev);
@@ -757,6 +758,23 @@ vu_set_vring_enable_exec(VuDev *dev, VhostUserMsg *vmsg)
 }
 
 static bool
+vu_set_slave_req_fd(VuDev *dev, VhostUserMsg *vmsg)
+{
+    if (vmsg->fd_num != 1) {
+        vu_panic(dev, "Invalid slave_req_fd message (%d fd's)", vmsg->fd_num);
+        return false;
+    }
+
+    if (dev->slave_fd != -1) {
+        close(dev->slave_fd);
+    }
+    dev->slave_fd = vmsg->fds[0];
+    DPRINT("Got slave_fd: %d\n", vmsg->fds[0]);
+
+    return false;
+}
+
+static bool
 vu_process_message(VuDev *dev, VhostUserMsg *vmsg)
 {
     int do_reply = 0;
@@ -819,6 +837,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg)
         return vu_get_queue_num_exec(dev, vmsg);
     case VHOST_USER_SET_VRING_ENABLE:
         return vu_set_vring_enable_exec(dev, vmsg);
+    case VHOST_USER_SET_SLAVE_REQ_FD:
+        return vu_set_slave_req_fd(dev, vmsg);
     case VHOST_USER_NONE:
         break;
     default:
@@ -892,6 +912,10 @@ vu_deinit(VuDev *dev)
 
 
     vu_close_log(dev);
+    if (dev->slave_fd != -1) {
+        close(dev->slave_fd);
+        dev->slave_fd = -1;
+    }
 
     if (dev->sock != -1) {
         close(dev->sock);
@@ -922,6 +946,7 @@ vu_init(VuDev *dev,
     dev->remove_watch = remove_watch;
     dev->iface = iface;
     dev->log_call_fd = -1;
+    dev->slave_fd = -1;
     for (i = 0; i < VHOST_MAX_NR_VIRTQUEUE; i++) {
         dev->vq[i] = (VuVirtq) {
             .call_fd = -1, .kick_fd = -1, .err_fd = -1,
contrib/libvhost-user/libvhost-user.h +1 -0
index c2fc6da720..7534e97f92 100644
@@ -226,6 +226,7 @@ struct VuDev {
     VuDevRegion regions[VHOST_MEMORY_MAX_NREGIONS];
     VuVirtq vq[VHOST_MAX_NR_VIRTQUEUE];
     int log_call_fd;
+    int slave_fd;
     uint64_t log_size;
     uint8_t *log_table;
     uint64_t features;
Signature · 1 line
2.13.6
Reviewed-by on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] libvhost-user: vu_queue_started

In reply to Dr. David Alan Gilbert (git)
Quoted 5 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Add a vu_queue_started method to complement vu_queue_enabled.

Quoted 46 lines
---
 contrib/libvhost-user/libvhost-user.c | 6 ++++++
 contrib/libvhost-user/libvhost-user.h | 9 +++++++++
 2 files changed, 15 insertions(+)
contrib/libvhost-user/libvhost-user.c +6 -0
index d27d6303db..5ee8483a32 100644
@@ -943,6 +943,12 @@ vu_queue_enabled(VuDev *dev, VuVirtq *vq)
     return vq->enable;
 }
 
+bool
+vu_queue_started(const VuDev *dev, const VuVirtq *vq)
+{
+    return vq->started;
+}
+
 static inline uint16_t
 vring_avail_flags(VuVirtq *vq)
 {
contrib/libvhost-user/libvhost-user.h +9 -1
index 4021f1124e..94d7cc8fbd 100644
@@ -335,6 +335,15 @@ void vu_queue_set_notification(VuDev *dev, VuVirtq *vq, int enable);
 bool vu_queue_enabled(VuDev *dev, VuVirtq *vq);
 
 /**
+ * vu_queue_started:
+ * @dev: a VuDev context
+ * @vq: a VuVirtq queue
+ *
+ * Returns: whether the queue is started.
+ */
+bool vu_queue_started(const VuDev *dev, const VuVirtq *vq);
+
+/**
  * vu_queue_empty:
  * @dev: a VuDev context
  * @vq: a VuVirtq queue
--

2.13.6

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 4/4
#7 lore raw

Re: [Qemu-devel] [PATCH 4/4] libvhost-user: Support VHOST_USER_SET_SLAVE_REQ_FD

In reply to Dr. David Alan Gilbert (git)
Quoted 6 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Allow the qemu to pass us a slave fd. We don't do anything with it yet.

Quoted 87 lines
---
 contrib/libvhost-user/libvhost-user.c | 27 ++++++++++++++++++++++++++-
 contrib/libvhost-user/libvhost-user.h |  1 +
 2 files changed, 27 insertions(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +26 -1
index 1901311a70..756b60c4b3 100644
@@ -703,7 +703,8 @@ vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg)
 static bool
 vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg)
 {
-    uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD;
+    uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD |
+                        1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ;
 
     if (dev->iface->get_protocol_features) {
         features |= dev->iface->get_protocol_features(dev);
@@ -757,6 +758,23 @@ vu_set_vring_enable_exec(VuDev *dev, VhostUserMsg *vmsg)
 }
 
 static bool
+vu_set_slave_req_fd(VuDev *dev, VhostUserMsg *vmsg)
+{
+    if (vmsg->fd_num != 1) {
+        vu_panic(dev, "Invalid slave_req_fd message (%d fd's)", vmsg->fd_num);
+        return false;
+    }
+
+    if (dev->slave_fd != -1) {
+        close(dev->slave_fd);
+    }
+    dev->slave_fd = vmsg->fds[0];
+    DPRINT("Got slave_fd: %d\n", vmsg->fds[0]);
+
+    return false;
+}
+
+static bool
 vu_process_message(VuDev *dev, VhostUserMsg *vmsg)
 {
     int do_reply = 0;
@@ -819,6 +837,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg)
         return vu_get_queue_num_exec(dev, vmsg);
     case VHOST_USER_SET_VRING_ENABLE:
         return vu_set_vring_enable_exec(dev, vmsg);
+    case VHOST_USER_SET_SLAVE_REQ_FD:
+        return vu_set_slave_req_fd(dev, vmsg);
     case VHOST_USER_NONE:
         break;
     default:
@@ -892,6 +912,10 @@ vu_deinit(VuDev *dev)
 
 
     vu_close_log(dev);
+    if (dev->slave_fd != -1) {
+        close(dev->slave_fd);
+        dev->slave_fd = -1;
+    }
 
     if (dev->sock != -1) {
         close(dev->sock);
@@ -922,6 +946,7 @@ vu_init(VuDev *dev,
     dev->remove_watch = remove_watch;
     dev->iface = iface;
     dev->log_call_fd = -1;
+    dev->slave_fd = -1;
     for (i = 0; i < VHOST_MAX_NR_VIRTQUEUE; i++) {
         dev->vq[i] = (VuVirtq) {
             .call_fd = -1, .kick_fd = -1, .err_fd = -1,
contrib/libvhost-user/libvhost-user.h +1 -1
index c2fc6da720..7534e97f92 100644
@@ -226,6 +226,7 @@ struct VuDev {
     VuDevRegion regions[VHOST_MEMORY_MAX_NREGIONS];
     VuVirtq vq[VHOST_MAX_NR_VIRTQUEUE];
     int log_call_fd;
+    int slave_fd;
     uint64_t log_size;
     uint8_t *log_table;
     uint64_t features;
--

2.13.6

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 3/4
#5 lore raw

Re: [Qemu-devel] [PATCH 3/4] libvhost-user: Update and fix feature and request lists

In reply to Dr. David Alan Gilbert (git)
Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Update the ProtocolFeature and UserRequest lists to match hw/virtio/vhost-user.c.
Fix the text labelling in libvhost-user.c to match the list.

Quoted 70 lines
---
 contrib/libvhost-user/libvhost-user.c | 10 +++++-----
 contrib/libvhost-user/libvhost-user.h |  9 ++++++++-
 2 files changed, 13 insertions(+), 6 deletions(-)
contrib/libvhost-user/libvhost-user.c +5 -5
index 5ee8483a32..1901311a70 100644
@@ -35,16 +35,13 @@
     } while (0)
 
 static const char *
-vu_request_to_string(int req)
+vu_request_to_string(unsigned int req)
 {
 #define REQ(req) [req] = #req
     static const char *vu_request_str[] = {
         REQ(VHOST_USER_NONE),
         REQ(VHOST_USER_GET_FEATURES),
         REQ(VHOST_USER_SET_FEATURES),
-        REQ(VHOST_USER_NONE),
-        REQ(VHOST_USER_GET_FEATURES),
-        REQ(VHOST_USER_SET_FEATURES),
         REQ(VHOST_USER_SET_OWNER),
         REQ(VHOST_USER_RESET_OWNER),
         REQ(VHOST_USER_SET_MEM_TABLE),
@@ -62,7 +59,10 @@ vu_request_to_string(int req)
         REQ(VHOST_USER_GET_QUEUE_NUM),
         REQ(VHOST_USER_SET_VRING_ENABLE),
         REQ(VHOST_USER_SEND_RARP),
-        REQ(VHOST_USER_INPUT_GET_CONFIG),
+        REQ(VHOST_USER_NET_SET_MTU),
+        REQ(VHOST_USER_SET_SLAVE_REQ_FD),
+        REQ(VHOST_USER_IOTLB_MSG),
+        REQ(VHOST_USER_SET_VRING_ENDIAN),
         REQ(VHOST_USER_MAX),
     };
 #undef REQ
contrib/libvhost-user/libvhost-user.h +8 -2
index 94d7cc8fbd..c2fc6da720 100644
@@ -34,6 +34,10 @@ enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_MQ = 0,
     VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
     VHOST_USER_PROTOCOL_F_RARP = 2,
+    VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
+    VHOST_USER_PROTOCOL_F_NET_MTU = 4,
+    VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5,
+    VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
 
     VHOST_USER_PROTOCOL_F_MAX
 };
@@ -61,7 +65,10 @@ typedef enum VhostUserRequest {
     VHOST_USER_GET_QUEUE_NUM = 17,
     VHOST_USER_SET_VRING_ENABLE = 18,
     VHOST_USER_SEND_RARP = 19,
-    VHOST_USER_INPUT_GET_CONFIG = 20,
+    VHOST_USER_NET_SET_MTU = 20,
+    VHOST_USER_SET_SLAVE_REQ_FD = 21,
+    VHOST_USER_IOTLB_MSG = 22,
+    VHOST_USER_SET_VRING_ENDIAN = 23,
     VHOST_USER_MAX
 } VhostUserRequest;
 
--

2.13.6

Signature · 1 line
Marc-André Lureau
Reviewed-by on the v1 series
#8 lore raw
In reply to Dr. David Alan Gilbert (git)

Hi David,

Quoted 15 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Hi,
This set has a small set of fixes for vhost-user and also enables the SET_SLAVE_REQ_FD feature in libvhost-user. (Where it just stashes the fd).

Dave

Dr. David Alan Gilbert (4):
libvhost-user: vu_queue_started
vhost-user-bridge: Only process received packets on started queues
libvhost-user: Update and fix feature and request lists
libvhost-user: Support VHOST_USER_SET_SLAVE_REQ_FD

Quoted 5 lines
  contrib/libvhost-user/libvhost-user.c | 43 ++++++++++++++++++++++++++++++-----
  contrib/libvhost-user/libvhost-user.h | 19 +++++++++++++++-
  tests/vhost-user-bridge.c             |  1 +
  3 files changed, 56 insertions(+), 7 deletions(-)

For the series:

Thanks,
Maxime