qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 RFC] virtio-pci: fix LE host/BE guest capacity for blk
@ 2013-05-28 10:18 Michael S. Tsirkin
  2013-06-14  0:55 ` Alexander Graf
  0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2013-05-28 10:18 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Anthony Liguori, agraf, blauwirbel, Paolo Bonzini,
	KONRAD Frederic

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 <mst@redhat.com>
---

Changes from v1:
fixed some obvious bugs.

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!


diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 9668b2b..e7971cc 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -98,6 +98,12 @@
 /* HACK for virtio to determine if it's running a big endian guest */
 bool virtio_is_big_endian(void);
 
+#ifdef HOST_WORDS_BIGENDIAN
+#define VIRTIO_HOST_IS_BIG_ENDIAN true
+#else
+#define VIRTIO_HOST_IS_BIG_ENDIAN false
+#endif
+
 static void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);
 
 /* virtio device */
@@ -411,6 +417,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() != VIRTIO_HOST_IS_BIG_ENDIAN &&
+            proxy->vdev->device_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);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH v2 RFC] virtio-pci: fix LE host/BE guest capacity for blk
  2013-05-28 10:18 [Qemu-devel] [PATCH v2 RFC] virtio-pci: fix LE host/BE guest capacity for blk Michael S. Tsirkin
@ 2013-06-14  0:55 ` Alexander Graf
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Graf @ 2013-06-14  0:55 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Peter Maydell, Anthony Liguori, qemu-devel, blauwirbel,
	Paolo Bonzini, KONRAD Frederic


On 28.05.2013, at 12:18, Michael S. Tsirkin wrote:

> 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 <mst@redhat.com>
> ---
> 
> Changes from v1:
> fixed some obvious bugs.
> 
> I don't seem to be able to boot any big-endian
> guests ATM, so this is only compile-tested - sending

Huh? Why not? Qemu-system-ppc64 -M pseries -m 1G should be in good enough shape to boot your favorite Linux distro's installation DVD.

> this out for early feedback/flames.
> Testing reports also wellcome!

While the hack looks like a hack, I can't really think of anything better either.


Alex

> 
> 
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 9668b2b..e7971cc 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -98,6 +98,12 @@
> /* HACK for virtio to determine if it's running a big endian guest */
> bool virtio_is_big_endian(void);
> 
> +#ifdef HOST_WORDS_BIGENDIAN
> +#define VIRTIO_HOST_IS_BIG_ENDIAN true
> +#else
> +#define VIRTIO_HOST_IS_BIG_ENDIAN false
> +#endif
> +
> static void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);
> 
> /* virtio device */
> @@ -411,6 +417,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() != VIRTIO_HOST_IS_BIG_ENDIAN &&
> +            proxy->vdev->device_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);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-14  0:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-28 10:18 [Qemu-devel] [PATCH v2 RFC] virtio-pci: fix LE host/BE guest capacity for blk Michael S. Tsirkin
2013-06-14  0:55 ` Alexander Graf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).