From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEgnf-0002WJ-AZ for qemu-devel@nongnu.org; Fri, 23 Jan 2015 11:09:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEgnX-0000PO-U4 for qemu-devel@nongnu.org; Fri, 23 Jan 2015 11:09:35 -0500 Received: from e06smtp10.uk.ibm.com ([195.75.94.106]:57031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEgnX-0000Oi-LX for qemu-devel@nongnu.org; Fri, 23 Jan 2015 11:09:27 -0500 Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 23 Jan 2015 16:09:25 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id ADF69219005E for ; Fri, 23 Jan 2015 16:09:20 +0000 (GMT) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t0NG9Mp354132882 for ; Fri, 23 Jan 2015 16:09:22 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 t0NG9Lqe019850 for ; Fri, 23 Jan 2015 09:09:22 -0700 Date: Fri, 23 Jan 2015 17:09:16 +0100 From: Greg Kurz Message-ID: <20150123170916.202400f1@bahia.local> In-Reply-To: <20150122015409.GH27371@voom.fritz.box> References: <1418304322-7546-1-git-send-email-cornelia.huck@de.ibm.com> <1418304322-7546-7-git-send-email-cornelia.huck@de.ibm.com> <20150122015409.GH27371@voom.fritz.box> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/s02LzjgizBBKfYpgdkUKOod"; protocol="application/pgp-signature" Subject: Re: [Qemu-devel] [PATCH RFC v6 06/20] virtio: endianness checks for virtio 1.0 devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: thuth@linux.vnet.ibm.com, mst@redhat.com, rusty@rustcorp.com.au, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, Cornelia Huck --Sig_/s02LzjgizBBKfYpgdkUKOod Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Thu, 22 Jan 2015 12:54:09 +1100 David Gibson wrote: > On Thu, Dec 11, 2014 at 02:25:08PM +0100, Cornelia Huck wrote: > > Add code that checks for the VERSION_1 feature bit in order to make > > decisions about the device's endianness. This allows us to support > > transitional devices. > >=20 > > Signed-off-by: Cornelia Huck > > --- > > hw/virtio/virtio.c | 6 +++++- > > include/hw/virtio/virtio-access.h | 4 ++++ > > include/hw/virtio/virtio.h | 8 ++++++-- > > 3 files changed, 15 insertions(+), 3 deletions(-) > >=20 > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > > index 7f74ae5..8f69ffa 100644 > > --- a/hw/virtio/virtio.c > > +++ b/hw/virtio/virtio.c > > @@ -881,7 +881,11 @@ static bool virtio_device_endian_needed(void *opaq= ue) > > VirtIODevice *vdev =3D opaque; > > =20 > > assert(vdev->device_endian !=3D VIRTIO_DEVICE_ENDIAN_UNKNOWN); > > - return vdev->device_endian !=3D virtio_default_endian(); > > + if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { > > + return vdev->device_endian !=3D virtio_default_endian(); > > + } > > + /* Devices conforming to VIRTIO 1.0 or later are always LE. */ > > + return vdev->device_endian !=3D VIRTIO_DEVICE_ENDIAN_LITTLE; >=20 > This doesn't seem quite right. Since virtio 1.0 is always LE, this > should just assert that device_endian =3D=3D LE and return false, > right? >=20 The device_endian field is ONLY used by devices when the software is legacy. It is set at device reset time (see virtio_reset()) since we can reasonably assume that when the software changes endianness, it always reset the device before using it again (aka. reboot or kexec). In the case we would have a BE guest, device_endian would be BE, even if the software is virtio 1.0. So, no, we shouldn't assert. I had questioned Cornelia about why we care to migrate device_endian when in virtio 1.0 mode. I got these answers: https://lists.nongnu.org/archive/html/qemu-devel/2014-10/msg03979.html https://lists.nongnu.org/archive/html/qemu-devel/2014-11/msg03888.html My understanding is that a transitional device will necessarily be reset if the software changes from legacy to 1.0 or vice-versa. So, yes, I still think virtio_device_endian_needed() should return false. > > } > > =20 > > static const VMStateDescription vmstate_virtio_device_endian =3D { > > diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virt= io-access.h > > index 46456fd..ee28c21 100644 > > --- a/include/hw/virtio/virtio-access.h > > +++ b/include/hw/virtio/virtio-access.h > > @@ -19,6 +19,10 @@ > > =20 > > static inline bool virtio_access_is_big_endian(VirtIODevice *vdev) > > { > > + if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { > > + /* Devices conforming to VIRTIO 1.0 or later are always LE. */ > > + return false; > > + } > > #if defined(TARGET_IS_BIENDIAN) > > return virtio_is_big_endian(vdev); > > #elif defined(TARGET_WORDS_BIGENDIAN) > > diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h > > index 08141c7..68c40db 100644 > > --- a/include/hw/virtio/virtio.h > > +++ b/include/hw/virtio/virtio.h > > @@ -297,7 +297,11 @@ static inline bool virtio_has_feature(VirtIODevice= *vdev, unsigned int fbit) > > =20 > > static inline bool virtio_is_big_endian(VirtIODevice *vdev) > > { > > - assert(vdev->device_endian !=3D VIRTIO_DEVICE_ENDIAN_UNKNOWN); > > - return vdev->device_endian =3D=3D VIRTIO_DEVICE_ENDIAN_BIG; > > + if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { > > + 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; > > } > > #endif >=20 > AFAICT, the only real difference between virtio_is_big_endian() and > virtio_access_is_big_endian() is that the latter will become > compile-time constant on targets that don't do bi-endian. >=20 > With virtio 1.0 support, that's no longer true, so those two macros > should just be merged, I think. >=20 --Sig_/s02LzjgizBBKfYpgdkUKOod Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlTCciwACgkQAvw66wEB28IvowCgiq9EqUxun7aKkhJh4hUue2De hKQAnRh7QUQnvSCSMAoc1ObvIqxHueZo =Dn8d -----END PGP SIGNATURE----- --Sig_/s02LzjgizBBKfYpgdkUKOod--