qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: thibaut.collet@6wind.com, jasowang@redhat.com, mst@redhat.com,
	haifeng.lin@huawei.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v4 02/22] vhost-user: add protocol feature negotiation
Date: Sat, 19 Sep 2015 12:11:53 +0200	[thread overview]
Message-ID: <1442657533-13030-3-git-send-email-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <1442657533-13030-1-git-send-email-marcandre.lureau@redhat.com>

From: "Michael S. Tsirkin" <mst@redhat.com>

Support a separate bitmask for vhost-user protocol features,
and messages to get/set protocol features.

Invoke them at init.

No features are defined yet.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 docs/specs/vhost-user.txt | 37 +++++++++++++++++++++++++++++++++
 hw/net/vhost_net.c        |  2 ++
 hw/virtio/vhost-user.c    | 52 +++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/virtio/vhost.h |  1 +
 4 files changed, 92 insertions(+)

diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 650bb18..0062baa 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -113,6 +113,7 @@ message replies. Most of the requests don't require replies. Here is a list of
 the ones that do:
 
  * VHOST_GET_FEATURES
+ * VHOST_GET_PROTOCOL_FEATURES
  * VHOST_GET_VRING_BASE
 
 There are several messages that the master sends with file descriptors passed
@@ -127,6 +128,13 @@ in the ancillary data:
 If Master is unable to send the full message or receives a wrong reply it will
 close the connection. An optional reconnection mechanism can be implemented.
 
+Any protocol extensions are gated by protocol feature bits,
+which allows full backwards compatibility on both master
+and slave.
+As older slaves don't support negotiating protocol features,
+a feature bit was dedicated for this purpose:
+#define VHOST_USER_F_PROTOCOL_FEATURES 30
+
 Message types
 -------------
 
@@ -138,6 +146,8 @@ Message types
       Slave payload: u64
 
       Get from the underlying vhost implementation the features bitmask.
+      Feature bit VHOST_USER_F_PROTOCOL_FEATURES signals slave support for
+      VHOST_USER_GET_PROTOCOL_FEATURES and VHOST_USER_SET_PROTOCOL_FEATURES.
 
  * VHOST_USER_SET_FEATURES
 
@@ -146,6 +156,33 @@ Message types
       Master payload: u64
 
       Enable features in the underlying vhost implementation using a bitmask.
+      Feature bit VHOST_USER_F_PROTOCOL_FEATURES signals master support for
+      VHOST_USER_GET_PROTOCOL_FEATURES and VHOST_USER_SET_PROTOCOL_FEATURES.
+
+ * VHOST_USER_GET_PROTOCOL_FEATURES
+
+      Id: 15
+      Equivalent ioctl: VHOST_GET_FEATURES
+      Master payload: N/A
+      Slave payload: u64
+
+      Get the protocol feature bitmask from the underlying vhost implementation.
+      Only legal if feature bit VHOST_USER_F_PROTOCOL_FEATURES is present in
+      VHOST_USER_GET_FEATURES.
+      Note: slave that reported VHOST_USER_F_PROTOCOL_FEATURES must support
+      this message even before VHOST_USER_SET_FEATURES was called.
+
+ * VHOST_USER_SET_PROTOCOL_FEATURES
+
+      Id: 16
+      Ioctl: VHOST_SET_FEATURES
+      Master payload: u64
+
+      Enable protocol features in the underlying vhost implementation.
+      Only legal if feature bit VHOST_USER_F_PROTOCOL_FEATURES is present in
+      VHOST_USER_GET_FEATURES.
+      Note: slave that reported VHOST_USER_F_PROTOCOL_FEATURES must support
+      this message even before VHOST_USER_SET_FEATURES was called.
 
  * VHOST_USER_SET_OWNER
 
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 1d76b94..9d32d76 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -152,8 +152,10 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
         net->dev.backend_features = qemu_has_vnet_hdr(options->net_backend)
             ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_HDR);
         net->backend = r;
+        net->dev.protocol_features = 0;
     } else {
         net->dev.backend_features = 0;
+        net->dev.protocol_features = 0;
         net->backend = -1;
     }
     net->nc = options->net_backend;
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 5a83d00..de87562 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -25,6 +25,9 @@
 
 #define VHOST_MEMORY_MAX_NREGIONS    8
 
+#define VHOST_USER_F_PROTOCOL_FEATURES 30
+#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x0ULL
+
 typedef enum VhostUserRequest {
     VHOST_USER_NONE = 0,
     VHOST_USER_GET_FEATURES = 1,
@@ -41,6 +44,8 @@ typedef enum VhostUserRequest {
     VHOST_USER_SET_VRING_KICK = 12,
     VHOST_USER_SET_VRING_CALL = 13,
     VHOST_USER_SET_VRING_ERR = 14,
+    VHOST_USER_GET_PROTOCOL_FEATURES = 15,
+    VHOST_USER_SET_PROTOCOL_FEATURES = 16,
     VHOST_USER_MAX
 } VhostUserRequest;
 
@@ -332,10 +337,57 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
 
 static int vhost_user_init(struct vhost_dev *dev, void *opaque)
 {
+    VhostUserMsg msg = { 0 };
+    int err;
+
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
 
     dev->opaque = opaque;
 
+    msg.request = VHOST_USER_GET_FEATURES;
+    msg.flags = VHOST_USER_VERSION;
+    msg.size = 0;
+
+    err = vhost_user_write(dev, &msg, NULL, 0);
+    if (err < 0) {
+        return err;
+    }
+
+    err = vhost_user_read(dev, &msg);
+    if (err < 0) {
+        return err;
+    }
+
+    if (virtio_has_feature(msg.u64, VHOST_USER_F_PROTOCOL_FEATURES)) {
+        dev->backend_features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
+
+        msg.request = VHOST_USER_GET_PROTOCOL_FEATURES;
+        msg.flags = VHOST_USER_VERSION;
+        msg.size = 0;
+
+        err = vhost_user_write(dev, &msg, NULL, 0);
+        if (err < 0) {
+            return err;
+        }
+
+        err = vhost_user_read(dev, &msg);
+        if (err < 0) {
+            return err;
+        }
+
+        dev->protocol_features = msg.u64 & VHOST_USER_PROTOCOL_FEATURE_MASK;
+
+        msg.request = VHOST_USER_SET_PROTOCOL_FEATURES;
+        msg.flags = VHOST_USER_VERSION;
+        msg.u64 = dev->protocol_features;
+        msg.size = sizeof msg.u64;
+
+        err = vhost_user_write(dev, &msg, NULL, 0);
+        if (err < 0) {
+            return err;
+        }
+    }
+
     return 0;
 }
 
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index dd51050..6467c73 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -47,6 +47,7 @@ struct vhost_dev {
     unsigned long long features;
     unsigned long long acked_features;
     unsigned long long backend_features;
+    unsigned long long protocol_features;
     bool started;
     bool log_enabled;
     unsigned long long log_size;
-- 
2.4.3

  parent reply	other threads:[~2015-09-19 10:12 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-19 10:11 [Qemu-devel] [PATCH v4 00/22] vhost-user: add migration support marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 01/22] vhost-user: refactor ioctl translation marcandre.lureau
2015-09-19 10:11 ` marcandre.lureau [this message]
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 03/22] vhost-user: unit test for new messages marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 04/22] configure: probe for memfd marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 05/22] util: add linux-only memfd fallback marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 06/22] util: add memfd helpers marcandre.lureau
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 07/22] vhost: alloc shareable log marcandre.lureau
2015-09-21  8:44   ` Michael S. Tsirkin
2015-09-21 14:02     ` Marc-André Lureau
2015-09-21 19:29       ` Michael S. Tsirkin
2015-09-21 21:44         ` Marc-André Lureau
2015-09-22 10:12           ` Michael S. Tsirkin
2015-09-22 11:01             ` Marc-André Lureau
2015-09-22 11:41               ` Michael S. Tsirkin
2015-09-22 11:50                 ` Marc-André Lureau
2015-09-22 11:54                   ` Michael S. Tsirkin
2015-09-19 10:11 ` [Qemu-devel] [PATCH v4 08/22] vhost: document log resizing marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 09/22] vhost: use a function for each call marcandre.lureau
2015-09-21  7:33   ` Thibaut Collet
2015-09-21  8:56     ` Michael S. Tsirkin
2015-09-21  8:58   ` Michael S. Tsirkin
2015-09-21 14:05     ` Marc-André Lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 10/22] vhost-user: remove vhost_user_request_translate() marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 11/22] vhost-user: send log shm fd along with log_base marcandre.lureau
2015-09-21  8:49   ` Michael S. Tsirkin
2015-09-21 14:05     ` Marc-André Lureau
2015-09-21 19:30       ` Michael S. Tsirkin
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 12/22] vhost: only use shared log if in use by backend marcandre.lureau
2015-09-21  8:46   ` Michael S. Tsirkin
2015-09-21 14:03     ` Marc-André Lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 13/22] vhost-user: document migration log marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 14/22] net: add trace_vhost_user_event marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 15/22] vhost user: add support of live migration marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 16/22] vhost user: add rarp sending after live migration for legacy guest marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 17/22] vhost-user-test: move wait_for_fds() out marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 18/22] vhost-user-test: remove useless static check marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 19/22] vhost-user-test: wrap server in TestServer struct marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 20/22] vhost-user-test: learn to tweak various qemu arguments marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 21/22] vhost-user-test: add live-migration test marcandre.lureau
2015-09-19 10:12 ` [Qemu-devel] [PATCH v4 22/22] vhost-user-test: check ownership during migration marcandre.lureau

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=1442657533-13030-3-git-send-email-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=haifeng.lin@huawei.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thibaut.collet@6wind.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).