Received: from eggs.gnu.org ([2001:4830:134:3::10]:60824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOktR-0007kZ-Nt for qemu-devel@nongnu.org; Fri, 20 Feb 2015 05:33:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOktN-0007eR-O4 for qemu-devel@nongnu.org; Fri, 20 Feb 2015 05:33:09 -0500 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:60170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOktN-0007eF-Fm for qemu-devel@nongnu.org; Fri, 20 Feb 2015 05:33:05 -0500 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 20 Feb 2015 10:33:03 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6020F2190046 for ; Fri, 20 Feb 2015 10:32:55 +0000 (GMT) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1KAX1Gl2359600 for ; Fri, 20 Feb 2015 10:33:01 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1KAX1jS016055 for ; Fri, 20 Feb 2015 03:33:01 -0700 From: Greg Kurz Date: Fri, 20 Feb 2015 11:32:59 +0100 Message-ID: <20150220103259.22408.58874.stgit@bahia.local> In-Reply-To: <20150220103253.22408.6807.stgit@bahia.local> References: <20150220103253.22408.6807.stgit@bahia.local> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 1/2] vhost: add VHOST_VRING_F_LEGACY_BIG_ENDIAN flag List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Cedric Le Goater , qemu-devel@nongnu.org When the guest and the host have a different endian order, the data being accessed in the vring queues needs to be byteswapped if we run in legacy mode. This patch adds a flag to inform the vhost kernel backend about the endianness to use. This patch is based on previous work by Cédric Le Goater. Cc: Cédric Le Goater Signed-off-by: Greg Kurz --- hw/virtio/vhost.c | 10 +++++++++- include/hw/virtio/vhost.h | 1 + linux-headers/linux/vhost.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 5a12861..bd442f1 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -539,7 +539,13 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, .log_guest_addr = vq->used_phys, .flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0, }; - int r = dev->vhost_ops->vhost_call(dev, VHOST_SET_VRING_ADDR, &addr); + int r; + + if (vq->legacy_big_endian) { + addr.flags |= (1 << VHOST_VRING_F_LEGACY_BIG_ENDIAN); + } + + r = dev->vhost_ops->vhost_call(dev, VHOST_SET_VRING_ADDR, &addr); if (r < 0) { return -errno; } @@ -707,6 +713,8 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, goto fail_alloc_ring; } + vq->legacy_big_endian = virtio_is_big_endian(vdev); + r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled); if (r < 0) { r = -errno; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index d5593d1..991fa20 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -20,6 +20,7 @@ struct vhost_virtqueue { unsigned long long ring_phys; unsigned ring_size; EventNotifier masked_notifier; + bool legacy_big_endian; /* Only used with legacy virtio devices */ }; typedef unsigned long vhost_log_chunk_t; diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h index c656f61..ffbb8ee 100644 --- a/linux-headers/linux/vhost.h +++ b/linux-headers/linux/vhost.h @@ -34,6 +34,8 @@ struct vhost_vring_addr { /* Flag values: */ /* Whether log address is valid. If set enables logging. */ #define VHOST_VRING_F_LOG 0 + /* Whether we have a big-endian legacy virtio device. */ +#define VHOST_VRING_F_LEGACY_BIG_ENDIAN 1 /* Start of array of descriptors (virtually contiguous) */ __u64 desc_user_addr;