From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhHIk-0002ph-EK for qemu-devel@nongnu.org; Tue, 28 May 2013 06:38:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UhHIV-0003VV-1Z for qemu-devel@nongnu.org; Tue, 28 May 2013 06:38:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26628) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhHIU-0003VL-Oh for qemu-devel@nongnu.org; Tue, 28 May 2013 06:38:30 -0400 Date: Tue, 28 May 2013 13:38:48 +0300 From: "Michael S. Tsirkin" Message-ID: <20130528103847.GC5467@redhat.com> References: <20130528101115.GA29353@redhat.com> <51A483A3.3000703@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51A483A3.3000703@redhat.com> Subject: Re: [Qemu-devel] [PATCH RFC] virtio-pci: fix LE host/BE guest capacity for blk List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Peter Maydell , Anthony Liguori , agraf@suse.de, qemu-devel@nongnu.org, blauwirbel@gmail.com, KONRAD Frederic On Tue, May 28, 2013 at 12:14:59PM +0200, Paolo Bonzini wrote: > Il 28/05/2013 12:11, Michael S. Tsirkin ha scritto: > > When a BE guest reads capacity from an LE host virtio-blk device or vice > > versa, it will get the dwords of the qword field swapped. > > As virtio-blk is the only one with such a quirk, > > and as non-pci transports don't do byte-swaps at all, > > solve this with a bit of device-specific hackery in > > virtio-pci. > > > > Signed-off-by: Michael S. Tsirkin > > --- > > > > I don't seem to be able to boot any big-endian > > guests ATM, so this is only compile-tested - sending > > this out for early feedback/flames. > > Testing reports also wellcome! > > > > hw/virtio/virtio-pci.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > > index 9668b2b..0e9ae4c 100644 > > --- a/hw/virtio/virtio-pci.c > > +++ b/hw/virtio/virtio-pci.c > > @@ -411,6 +411,15 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr, > > } > > break; > > case 4: > > + /* Most devices don't have 64 bit config fields. > > + * Block is an exception: first 8 bytes include > > + * a 64 bit capacity field. > > + */ > > + if (virtio_is_big_endian() != defined(HOST_WORDS_BIGENDIAN) && > > I thought think this is not valid C? > > Paolo Yes, v2 I just sent fixes this. Thanks for paying attention. > > + proxy->vdev->dev_id == VIRTIO_ID_BLOCK && addr < 8) { > > + /* Swap first two words */ > > + addr ^= 0x4; > > + } > > val = virtio_config_readl(proxy->vdev, addr); > > if (virtio_is_big_endian()) { > > val = bswap32(val); > >