From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Date: Wed, 29 Oct 2014 08:38:42 +0000 Subject: [RFC PATCH 1/4] vhost: add VHOST_VRING_F_BYTESWAP flag Message-Id: <1414571925-16918-2-git-send-email-clg@fr.ibm.com> List-Id: References: <1414571925-16918-1-git-send-email-clg@fr.ibm.com> In-Reply-To: <1414571925-16918-1-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: "Michael S. Tsirkin" Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, agraf@suse.de, paulus@samba.org, gkurz@linux.vnet.ibm.com.patch, aik@ozlabs.ru, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= The VHOST_VRING_F_BYTESWAP flag will be used by the host to byteswap the vring data when the guest and the host have a different endian order. Signed-off-by: C=C3=A9dric Le Goater --- drivers/vhost/vhost.c | 5 ++++- drivers/vhost/vhost.h | 1 + include/uapi/linux/vhost.h | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index c90f4374442a..72c21b790ba3 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -199,6 +199,7 @@ static void vhost_vq_reset(struct vhost_dev *dev, vq->call =3D NULL; vq->log_ctx =3D NULL; vq->memory =3D NULL; + vq->byteswap =3D 0; } =20 static int vhost_worker(void *data) @@ -701,7 +702,8 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, = void __user *argp) r =3D -EFAULT; break; } - if (a.flags & ~(0x1 << VHOST_VRING_F_LOG)) { + if (a.flags & ~(0x1 << VHOST_VRING_F_LOG | + 0x1 << VHOST_VRING_F_BYTESWAP)) { r =3D -EOPNOTSUPP; break; } @@ -747,6 +749,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, = void __user *argp) vq->avail =3D (void __user *)(unsigned long)a.avail_user_addr; vq->log_addr =3D a.log_guest_addr; vq->used =3D (void __user *)(unsigned long)a.used_user_addr; + vq->byteswap =3D !!(a.flags & (0x1 << VHOST_VRING_F_BYTESWAP)); break; case VHOST_SET_VRING_KICK: if (copy_from_user(&f, argp, sizeof f)) { diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 3eda654b8f5a..ab25b7d0720d 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -110,6 +110,7 @@ struct vhost_virtqueue { /* Log write descriptors */ void __user *log_base; struct vhost_log *log; + bool byteswap; }; =20 struct vhost_dev { diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index bb6a5b4cb3c5..6a8c2b325c44 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -34,6 +34,9 @@ struct vhost_vring_addr { /* Flag values: */ /* Whether log address is valid. If set enables logging. */ #define VHOST_VRING_F_LOG 0 + /* Whether vring memory accesses should be byte-swapped. + * required when the guest has a different endianness */ +#define VHOST_VRING_F_BYTESWAP 1 =20 /* Start of array of descriptors (virtually contiguous) */ __u64 desc_user_addr; --=20 1.7.10.4