qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Felipe Franciosi <felipe@nutanix.com>, Mike Cui <cui@nutanix.com>
Subject: [Qemu-devel] [PULL 03/10] vhost-user: fix legacy cross-endian configurations
Date: Wed, 2 Aug 2017 00:37:38 +0300	[thread overview]
Message-ID: <1501623438-31419-4-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1501623438-31419-1-git-send-email-mst@redhat.com>

From: Felipe Franciosi <felipe@nutanix.com>

Currently, vhost-user does not implement any means for notifying the
backend about guest endianess. This commit introduces a new message
called VHOST_USER_SET_VRING_ENDIAN which is analogous to the ioctl()
called VHOST_SET_VRING_ENDIAN used for kernel vhost backends. Such
message is necessary for backends supporting legacy (pre-1.0) virtio
devices running in big-endian guests.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
Signed-off-by: Mike Cui <cui@nutanix.com>
---
 docs/interop/vhost-user.txt | 16 ++++++++++++++++
 hw/virtio/vhost-user.c      | 23 +++++++++++++++++++++--
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt
index 481ab56..954771d 100644
--- a/docs/interop/vhost-user.txt
+++ b/docs/interop/vhost-user.txt
@@ -326,6 +326,7 @@ Protocol features
 #define VHOST_USER_PROTOCOL_F_REPLY_ACK      3
 #define VHOST_USER_PROTOCOL_F_MTU            4
 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ      5
+#define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN   6
 
 Master message types
 --------------------
@@ -580,6 +581,21 @@ Master message types
       This request should be send only when VIRTIO_F_IOMMU_PLATFORM feature
       has been successfully negotiated.
 
+ * VHOST_USER_SET_VRING_ENDIAN
+
+      Id: 23
+      Equivalent ioctl: VHOST_SET_VRING_ENDIAN
+      Master payload: vring state description
+
+      Set the endianess of a VQ for legacy devices. Little-endian is indicated
+      with state.num set to 0 and big-endian is indicated with state.num set
+      to 1. Other values are invalid.
+      This request should be sent only when VHOST_USER_PROTOCOL_F_CROSS_ENDIAN
+      has been negotiated.
+      Backends that negotiated this feature should handle both endianesses
+      and expect this message once (per VQ) during device configuration
+      (ie. before the master starts the VQ).
+
 Slave message types
 -------------------
 
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 2203011..093675e 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -33,6 +33,7 @@ enum VhostUserProtocolFeature {
     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
 };
@@ -63,6 +64,7 @@ typedef enum VhostUserRequest {
     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;
 
@@ -367,8 +369,25 @@ static int vhost_user_set_vring_addr(struct vhost_dev *dev,
 static int vhost_user_set_vring_endian(struct vhost_dev *dev,
                                        struct vhost_vring_state *ring)
 {
-    error_report("vhost-user trying to send unhandled ioctl");
-    return -1;
+    bool cross_endian = virtio_has_feature(dev->protocol_features,
+                                           VHOST_USER_PROTOCOL_F_CROSS_ENDIAN);
+    VhostUserMsg msg = {
+        .request = VHOST_USER_SET_VRING_ENDIAN,
+        .flags = VHOST_USER_VERSION,
+        .payload.state = *ring,
+        .size = sizeof(msg.payload.state),
+    };
+
+    if (!cross_endian) {
+        error_report("vhost-user trying to send unhandled ioctl");
+        return -1;
+    }
+
+    if (vhost_user_write(dev, &msg, NULL, 0) < 0) {
+        return -1;
+    }
+
+    return 0;
 }
 
 static int vhost_set_vring(struct vhost_dev *dev,
-- 
MST

  parent reply	other threads:[~2017-08-01 21:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-01 21:37 [Qemu-devel] [PULL 00/10] pc, acpi, virtio: fixes, test speedup for rc1 Michael S. Tsirkin
2017-08-01 21:37 ` [Qemu-devel] [PULL 01/10] tests: switch pxe and vm gen id tests to use kvm Michael S. Tsirkin
2017-08-01 21:37 ` [Qemu-devel] [PULL 02/10] vhost: fix a memory leak Michael S. Tsirkin
2017-08-01 21:37 ` Michael S. Tsirkin [this message]
2017-08-01 21:37 ` [Qemu-devel] [PULL 04/10] intel_iommu: fix iova for pt Michael S. Tsirkin
2017-08-01 21:37 ` [Qemu-devel] [PULL 05/10] intel_iommu: use access_flags for iotlb Michael S. Tsirkin
2017-08-01 21:37 ` [Qemu-devel] [PULL 06/10] accel: cleanup error output Michael S. Tsirkin
2017-08-01 21:42   ` Eric Blake
2017-08-01 21:37 ` [Qemu-devel] [PULL 07/10] tests/bios-tables-test: Compiler warning fix Michael S. Tsirkin
2017-08-01 21:37 ` [Qemu-devel] [PULL 08/10] vhost-user: fix watcher need be removed when vhost-user hotplug Michael S. Tsirkin
2017-08-01 21:37 ` [Qemu-devel] [PULL 09/10] pc: make 'pc.rom' readonly when machine has PCI enabled Michael S. Tsirkin
2017-08-01 21:37 ` [Qemu-devel] [PULL 10/10] pc: acpi: force FADT rev1 for 440fx based machine types Michael S. Tsirkin
2017-08-02 10:09 ` [Qemu-devel] [PULL 00/10] pc, acpi, virtio: fixes, test speedup for rc1 Peter Maydell

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=1501623438-31419-4-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=cui@nutanix.com \
    --cc=felipe@nutanix.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).