From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS3Ih-0006eB-3N for qemu-devel@nongnu.org; Thu, 11 Sep 2014 08:16:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XS3IS-00016I-CI for qemu-devel@nongnu.org; Thu, 11 Sep 2014 08:16:35 -0400 Received: from e06smtp14.uk.ibm.com ([195.75.94.110]:49391) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS3IS-00015j-42 for qemu-devel@nongnu.org; Thu, 11 Sep 2014 08:16:20 -0400 Received: from /spool/local by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 11 Sep 2014 13:16:17 +0100 Date: Thu, 11 Sep 2014 14:16:07 +0200 From: Greg Kurz Message-ID: <20140911141607.1f3f6b73@bahia.local> In-Reply-To: <1410262487-24079-2-git-send-email-aik@ozlabs.ru> References: <1410262487-24079-1-git-send-email-aik@ozlabs.ru> <1410262487-24079-2-git-send-email-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH 1/2] Revert "vfio: Make BARs native endian" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: Alex Williamson , qemu-ppc@nongnu.org, qemu-devel@nongnu.org On Tue, 9 Sep 2014 21:34:46 +1000 Alexey Kardashevskiy wrote: > This reverts commit c40708176a6b52b73bec14796b7c71b882ceb102. > > The idea not to swap bytes at all did not work out as MMIO interface > is defined as target host endian and it is always big-endian for PPC64 s/target host endian/target endian/ > so the original part broke PPC64 guests on LE hosts (x86/ppc64le). > What about a simpler description ? The resulting code wrongly assumed target and host endianness are the same. > Signed-off-by: Alexey Kardashevskiy > --- > hw/misc/vfio.c | 41 ++++++++++------------------------------- > 1 file changed, 10 insertions(+), 31 deletions(-) > > diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c > index 40dcaa6..22ebcbd 100644 > --- a/hw/misc/vfio.c > +++ b/hw/misc/vfio.c > @@ -1098,10 +1098,10 @@ static void vfio_bar_write(void *opaque, hwaddr addr, > buf.byte = data; > break; > case 2: > - buf.word = data; > + buf.word = cpu_to_le16(data); > break; > case 4: > - buf.dword = data; > + buf.dword = cpu_to_le32(data); > break; > default: > hw_error("vfio: unsupported write size, %d bytes", size); > @@ -1158,10 +1158,10 @@ static uint64_t vfio_bar_read(void *opaque, > data = buf.byte; > break; > case 2: > - data = buf.word; > + data = le16_to_cpu(buf.word); > break; > case 4: > - data = buf.dword; > + data = le32_to_cpu(buf.dword); > break; > default: > hw_error("vfio: unsupported read size, %d bytes", size); > @@ -1188,7 +1188,7 @@ static uint64_t vfio_bar_read(void *opaque, > static const MemoryRegionOps vfio_bar_ops = { > .read = vfio_bar_read, > .write = vfio_bar_write, > - .endianness = DEVICE_NATIVE_ENDIAN, > + .endianness = DEVICE_LITTLE_ENDIAN, > }; > > static void vfio_pci_load_rom(VFIODevice *vdev) > @@ -1250,42 +1250,21 @@ static void vfio_pci_load_rom(VFIODevice *vdev) > static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size) > { > VFIODevice *vdev = opaque; > - union { > - uint8_t byte; > - uint16_t word; > - uint32_t dword; > - uint64_t qword; > - } buf; > - uint64_t data = 0; > + uint64_t val = ((uint64_t)1 << (size * 8)) - 1; > > /* Load the ROM lazily when the guest tries to read it */ > if (unlikely(!vdev->rom && !vdev->rom_read_failed)) { > vfio_pci_load_rom(vdev); > } > > - memcpy(&buf, vdev->rom + addr, > + memcpy(&val, vdev->rom + addr, > (addr < vdev->rom_size) ? MIN(size, vdev->rom_size - addr) : 0); > > - switch (size) { > - case 1: > - data = buf.byte; > - break; > - case 2: > - data = buf.word; > - break; > - case 4: > - data = buf.dword; > - break; > - default: > - hw_error("vfio: unsupported read size, %d bytes", size); > - break; > - } > - > DPRINTF("%s(%04x:%02x:%02x.%x, 0x%"HWADDR_PRIx", 0x%x) = 0x%"PRIx64"\n", > __func__, vdev->host.domain, vdev->host.bus, vdev->host.slot, > - vdev->host.function, addr, size, data); > + vdev->host.function, addr, size, val); > > - return data; > + return val; > } > > static void vfio_rom_write(void *opaque, hwaddr addr, > @@ -1296,7 +1275,7 @@ static void vfio_rom_write(void *opaque, hwaddr addr, > static const MemoryRegionOps vfio_rom_ops = { > .read = vfio_rom_read, > .write = vfio_rom_write, > - .endianness = DEVICE_NATIVE_ENDIAN, > + .endianness = DEVICE_LITTLE_ENDIAN, > }; > > static bool vfio_blacklist_opt_rom(VFIODevice *vdev) -- Gregory Kurz kurzgreg@fr.ibm.com gkurz@linux.vnet.ibm.com Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)562 165 496 "Anarchy is about taking complete responsibility for yourself." Alan Moore.