From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlLW7-0001Ld-PE for qemu-devel@nongnu.org; Mon, 03 Nov 2014 12:34:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlLVx-0001th-QI for qemu-devel@nongnu.org; Mon, 03 Nov 2014 12:34:11 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:53378) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlLVx-0001tM-IG for qemu-devel@nongnu.org; Mon, 03 Nov 2014 12:34:01 -0500 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 3 Nov 2014 17:33:59 -0000 Date: Mon, 3 Nov 2014 18:33:50 +0100 From: Greg Kurz Message-ID: <20141103183350.70764cb3@bahia.local> In-Reply-To: <20141103162931.4edbed1f.cornelia.huck@de.ibm.com> References: <1414572130-17014-1-git-send-email-clg@fr.ibm.com> <1414572130-17014-2-git-send-email-clg@fr.ibm.com> <20141103162931.4edbed1f.cornelia.huck@de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [Qemu-ppc] [RFC PATCH 1/2] vhost: add VHOST_VRING_F_BYTESWAP flag List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cornelia Huck Cc: paulus@samba.org, =?UTF-8?B?Q8OpZHJpYw==?= Le Goater , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, mst@redhat.com On Mon, 3 Nov 2014 16:29:31 +0100 Cornelia Huck wrote: > On Wed, 29 Oct 2014 09:42:09 +0100 > C=C3=A9dric Le Goater wrote: >=20 > > When the guest and the host have a different endian order, the data=20 > > being accessed in the vring queues needs to be byteswapped. > >=20 > > This patch adds a VHOST_VRING_F_BYTESWAP flag to inform the vhost=20 > > kernel backend to byteswap vring data. > >=20 > > Signed-off-by: C=C3=A9dric Le Goater > > --- > > hw/virtio/vhost.c | 25 ++++++++++++++++++++++++- > > include/hw/virtio/vhost.h | 1 + > > linux-headers/linux/vhost.h | 3 +++ > > 3 files changed, 28 insertions(+), 1 deletion(-) >=20 > > +static bool vhost_virtqueue_needs_byteswap(VirtIODevice *vdev) > > +{ > > +#ifdef TARGET_IS_BIENDIAN > > +#ifdef HOST_WORDS_BIGENDIAN > > + return !virtio_is_big_endian(vdev); > > +#else > > + return virtio_is_big_endian(vdev); > > +#endif > > + > > +#else > > + return false; > > +#endif > > +} >=20 > *thinks aloud* >=20 > We call this function after features have been negotiated, so we should > be able to reuse this interface for virtio-1 by checking for > VIRTIO_F_VERSION_1, right? >=20 >=20 Yes. Moreover, we're not on a hot path, so we could simply ignore TARGET_IS_BIENDIAN and only have: static bool vhost_virtqueue_needs_byteswap(VirtIODevice *vdev) { #ifdef HOST_WORDS_BIGENDIAN return !virtio_is_big_endian(vdev); #else return virtio_is_big_endian(vdev); #endif } in which case, this would work right away with the changes brought by Conny's virtio-1 series: static inline bool virtio_device_is_legacy(VirtIODevice *vdev) { return !(vdev->guest_features[1] & (1 << (VIRTIO_F_VERSION_1 - 32))); } static inline bool virtio_is_big_endian(VirtIODevice *vdev) { if (virtio_device_is_legacy(vdev)) { assert(vdev->device_endian !=3D VIRTIO_DEVICE_ENDIAN_UNKNOWN); return vdev->device_endian =3D=3D VIRTIO_DEVICE_ENDIAN_BIG; } /* Devices conforming to VIRTIO 1.0 or later are always LE. */ return false; } Cheers. -- Greg