qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ouyang Changchun <changchun.ouyang@intel.com>
To: qemu-devel@nongnu.org, mst@redhat.com
Cc: snabb-devel@googlegroups.com, thibaut.collet@6wind.com,
	n.nikolaev@virtualopensystems.com, luke@snabb.co,
	thomas.long@intel.com, changchun.ouyang@intel.com
Subject: [Qemu-devel] [PATCH v6 2/2] vhost-user: new protocol feature for multi queue
Date: Wed, 12 Aug 2015 14:25:42 +0800	[thread overview]
Message-ID: <1439360742-2186-3-git-send-email-changchun.ouyang@intel.com> (raw)
In-Reply-To: <1439360742-2186-1-git-send-email-changchun.ouyang@intel.com>

This patch is based on top of "vhost-user: protocol updates" series
proposed earlier by Michael S. Tsirkin.

Use new message VHOST_USER_SET_VRING_FLAG to enable and disable an
actual virt queue, which is similar to attach/detach queue for tap device.
virtio driver on guest doesn't have to use max virt queue pair, it could
enable any number of virt queue ranging from 1 to max virt queue pair.

It requires that VHOST_USER_F_PROTOCOL_FEATURES is present.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
This is added since v5

 docs/specs/vhost-user.txt         | 17 +++++++++++++++++
 hw/net/vhost_net.c                | 18 ++++++++++++++++++
 hw/net/virtio-net.c               |  2 ++
 hw/virtio/vhost-user.c            | 35 +++++++++++++++++++++++++++++++++--
 include/hw/virtio/vhost-backend.h |  2 ++
 include/net/vhost_net.h           |  1 +
 6 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 9390f89..cca3e5b 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -135,6 +135,10 @@ As older slaves don't support negotiating protocol features,
 a feature bit was dedicated for this purpose:
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
 
+The Slave uses vring flag to notify the vhost-user whether one virtq is enabled
+or not. This request doesn't require replies:
+#define VHOST_USER_PROTOCOL_F_VRING_FLAG 2
+
 Multi queue support
 -------------------
 The protocol supports multiple queues by setting all index fields in the sent
@@ -306,3 +310,16 @@ Message types
       Bits (0-7) of the payload contain the vring index. Bit 8 is the
       invalid FD flag. This flag is set when there is no file descriptor
       in the ancillary data.
+
+ * VHOST_USER_SET_VRING_FLAG
+
+      Id: 18
+      Equivalent ioctl: N/A
+      Master payload: vring state description
+
+      Set the flag(enable or disable) in the vring, the vhost user backend
+      enable or disable the vring according to state.num. Olny legal if feature
+      bit VHOST_USER_F_PROTOCOL_FEATURES is present in VHOST_USER_GET_FEATURE
+      and feature bit VHOST_USER_PROTOCOL_F_VRING_FLAG is present in
+      VHOST_USER_GET_PROTOCOL_FEATURES. The vring is enabled when state.num is
+      1, otherwise, the vring is disabled.
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 9cd6c05..5fa341c 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -405,6 +405,19 @@ VHostNetState *get_vhost_net(NetClientState *nc)
 
     return vhost_net;
 }
+
+int vhost_set_vring_flag(NetClientState *nc, unsigned int enable)
+{
+    if (nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
+        struct vhost_net *net = get_vhost_net(nc);
+        const VhostOps *vhost_ops = net->dev.vhost_ops;
+        if (vhost_ops->vhost_backend_mq_set_vring_flag)
+            return vhost_ops->vhost_backend_mq_set_vring_flag(&net->dev, enable);
+    }
+
+    return 0;
+}
+
 #else
 struct vhost_net *vhost_net_init(VhostNetOptions *options)
 {
@@ -455,4 +468,9 @@ VHostNetState *get_vhost_net(NetClientState *nc)
 {
     return 0;
 }
+
+int vhost_set_vring_flag(NetClientState *nc, unsigned int enable)
+{
+    return 0;
+}
 #endif
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 3af6faf..272b77d 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -396,6 +396,7 @@ static int peer_attach(VirtIONet *n, int index)
     }
 
     if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
+        vhost_set_vring_flag(nc->peer, 1);
         return 0;
     }
 
@@ -411,6 +412,7 @@ static int peer_detach(VirtIONet *n, int index)
     }
 
     if (nc->peer->info->type !=  NET_CLIENT_OPTIONS_KIND_TAP) {
+        vhost_set_vring_flag(nc->peer, 0);
         return 0;
     }
 
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index fb11d4c..d806ce2 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -25,7 +25,8 @@
 
 #define VHOST_MEMORY_MAX_NREGIONS    8
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
-#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x0ULL
+#define VHOST_USER_PROTOCOL_F_VRING_FLAG 2
+#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x7ULL
 
 typedef enum VhostUserRequest {
     VHOST_USER_NONE = 0,
@@ -45,6 +46,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_SET_VRING_ERR = 14,
     VHOST_USER_GET_PROTOCOL_FEATURES = 15,
     VHOST_USER_SET_PROTOCOL_FEATURES = 16,
+    VHOST_USER_SET_VRING_FLAG = 18,
     VHOST_USER_MAX
 } VhostUserRequest;
 
@@ -399,6 +401,34 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
     return 0;
 }
 
+static int vhost_user_set_vring_flag(struct vhost_dev *dev, unsigned int enable)
+{
+    VhostUserMsg msg = { 0 };
+    int err;
+
+    assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
+
+    if ((dev->backend_features & ( 1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) == 0)
+        return -1;
+
+    if ((dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_VRING_FLAG)) == 0)
+        return -1;
+
+    msg.request = VHOST_USER_SET_VRING_FLAG;
+    msg.flags = VHOST_USER_VERSION;
+    /* Set the virt queue pair index */
+    msg.state.index = dev->vq_index / 2;
+    msg.state.num = enable;
+    msg.size = sizeof msg.state;
+
+    err = vhost_user_write(dev, &msg, NULL, 0);
+    if (err < 0) {
+        return err;
+    }
+
+    return 0;
+}
+
 static int vhost_user_cleanup(struct vhost_dev *dev)
 {
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
@@ -412,5 +442,6 @@ const VhostOps user_ops = {
         .backend_type = VHOST_BACKEND_TYPE_USER,
         .vhost_call = vhost_user_call,
         .vhost_backend_init = vhost_user_init,
-        .vhost_backend_cleanup = vhost_user_cleanup
+        .vhost_backend_cleanup = vhost_user_cleanup,
+        .vhost_backend_mq_set_vring_flag = vhost_user_set_vring_flag,
         };
diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
index e472f29..c394147 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -24,12 +24,14 @@ typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long int request,
              void *arg);
 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);
 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
+typedef int (*vhost_backend_mq_set_vring_flag)(struct vhost_dev *dev, unsigned int enable);
 
 typedef struct VhostOps {
     VhostBackendType backend_type;
     vhost_call vhost_call;
     vhost_backend_init vhost_backend_init;
     vhost_backend_cleanup vhost_backend_cleanup;
+    vhost_backend_mq_set_vring_flag vhost_backend_mq_set_vring_flag;
 } VhostOps;
 
 extern const VhostOps user_ops;
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index b1c18a3..9b76548 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -29,4 +29,5 @@ bool vhost_net_virtqueue_pending(VHostNetState *net, int n);
 void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
                               int idx, bool mask);
 VHostNetState *get_vhost_net(NetClientState *nc);
+int vhost_set_vring_flag(NetClientState * nc, unsigned int enable);
 #endif
-- 
1.8.4.2

  parent reply	other threads:[~2015-08-12  6:55 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-28  1:23 [Qemu-devel] [PATCH v5] vhost-user: add multi queue support Ouyang Changchun
2015-07-08 14:29 ` Michael S. Tsirkin
2015-07-08 22:00   ` Maxime Leroy
2015-07-09  1:29     ` [Qemu-devel] [snabb-devel] " Ouyang, Changchun
2015-07-09  7:31       ` Michael S. Tsirkin
2015-07-09  7:06     ` [Qemu-devel] " Michael S. Tsirkin
2015-07-09 12:00       ` Martin Kletzander
2015-07-09 12:24         ` Maxime Leroy
2015-07-09 12:33           ` Martin Kletzander
2015-07-09 12:54           ` Michael S. Tsirkin
2015-08-12  6:25 ` [Qemu-devel] [PATCH v6 0/2] vhost-user " Ouyang Changchun
2015-08-12  6:25   ` [Qemu-devel] [PATCH v6 1/2] vhost-user: add " Ouyang Changchun
2015-08-13  9:18     ` Michael S. Tsirkin
2015-08-13 10:24       ` Maxime Leroy
2015-08-13 10:55         ` Michael S. Tsirkin
2015-08-25  3:25       ` [Qemu-devel] [snabb-devel] " Ouyang, Changchun
2015-08-27 13:05         ` Michael S. Tsirkin
2015-08-28  1:53           ` Ouyang, Changchun
2015-08-30  6:16             ` Michael S. Tsirkin
2015-08-31  8:29               ` Ouyang, Changchun
2015-08-31 11:30                 ` Michael S. Tsirkin
2015-08-31 15:04                   ` Eric Blake
2015-09-01  9:20                   ` Yuanhan Liu
2015-09-01  9:41                     ` Michael S. Tsirkin
2015-09-01 12:16                       ` Yuanhan Liu
2015-09-01  9:13       ` [Qemu-devel] " Yuanhan Liu
2015-09-01 10:07         ` Michael S. Tsirkin
2015-09-01 12:15           ` Yuanhan Liu
2015-09-01 14:10             ` Michael S. Tsirkin
2015-09-02  5:45               ` Ouyang, Changchun
2015-09-02 12:10                 ` Michael S. Tsirkin
2015-09-07 11:07       ` Marcel Apfelbaum
2015-09-07 12:26         ` Michael S. Tsirkin
2015-09-07 13:08           ` Marcel Apfelbaum
2015-08-12  6:25   ` Ouyang Changchun [this message]
2015-08-13  9:22     ` [Qemu-devel] [PATCH v6 2/2] vhost-user: new protocol feature for multi queue Michael S. Tsirkin
2015-08-24  1:50       ` [Qemu-devel] [snabb-devel] " Ouyang, Changchun
2015-09-01  9:16       ` [Qemu-devel] " Yuanhan Liu
2015-09-01 10:09         ` Michael S. Tsirkin
2015-09-01 11:42           ` Yuanhan Liu
2015-08-30 15:28 ` [Qemu-devel] [PATCH v5] vhost-user: add multi queue support Marcel Apfelbaum
2015-08-31  5:28   ` Ouyang, Changchun
2015-08-31  5:42     ` Xu, Qian Q
2015-08-31  8:55       ` Marcel Apfelbaum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439360742-2186-3-git-send-email-changchun.ouyang@intel.com \
    --to=changchun.ouyang@intel.com \
    --cc=luke@snabb.co \
    --cc=mst@redhat.com \
    --cc=n.nikolaev@virtualopensystems.com \
    --cc=qemu-devel@nongnu.org \
    --cc=snabb-devel@googlegroups.com \
    --cc=thibaut.collet@6wind.com \
    --cc=thomas.long@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).