VFIO endian updates
The following changes since commit 07e2863d0271ac6c05206d8ce9e4f4c39b25d3ea:
exec.c: fix setting 1-byte-long watchpoints (2014-09-19 17:42:16 +0100)
are available in the git repository at:
git://github.com/awilliam/qemu-vfio.git tags/vfio-pci-for-qemu-20140923.0
for you to fetch changes up to 75bd0c7253f384e868b638db5c6350796cf584f7:
vfio: make rom read endian sensitive (2014-09-22 15:27:43 -0600)
----------------------------------------------------------------
Endian updates to re-fix cross endian host and guest and enable the same for ROM loading (Alexey)
----------------------------------------------------------------
Alexey Kardashevskiy (1):
Revert "vfio: Make BARs native endian"
Nikunj A Dadhania (1):
vfio: make rom read endian sensitive
hw/misc/vfio.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
[Qemu-devel] [PULL 1/2] Revert "vfio: Make BARs native endian"
From: Alexey Kardashevskiy <[email protected]>
This reverts commit c40708176a6b52b73bec14796b7c71b882ceb102.
The resulting code wrongly assumed target and host endianness are the same which is not always the case for PPC64.
[aw: or potentially any host supporting VFIO and TCG]
--- hw/misc/vfio.c | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-)
hw/misc/vfio.c +10 -31
@@ -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)
David Gibson
Reviewed-byRe: [Qemu-devel] [PULL 1/2] Revert "vfio: Make BARs native endian"
Quoted 11 lines · Alex Williamson
From: Alexey Kardashevskiy <[email protected]>
This reverts commit
c40708176a6b52b73bec14796b7c71b882ceb102.The resulting code wrongly assumed target and host endianness are the same which is not always the case for PPC64.
[aw: or potentially any host supporting VFIO and TCG]
Signed-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by Alex Williamson <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
[Qemu-devel] [PULL 2/2] vfio: make rom read endian sensitive
In reply to Alex WilliamsonFrom: Nikunj A Dadhania <[email protected]>
All memory regions used by VFIO are LITTLE_ENDIAN and they already take care of endiannes when accessing real device BARs except ROM - it was broken on BE hosts.
This fixes endiannes for ROM BARs the same way as it is done for other BARs.
This has been tested on PPC64 BE/LE host/guest in all possible combinations including TCG.
--- hw/misc/vfio.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
hw/misc/vfio.c +24 -3
@@ -1250,7 +1250,13 @@ static void vfio_pci_load_rom(VFIODevice *vdev)static uint64_t vfio_rom_read (void *opaque,hwaddr addr,unsigned size) {VFIODevice *vdev = opaque; -uint64_t val = ((uint64_t )1 << (size *8 )) -1 ; +union { +uint8_t byte; +uint16_t word; +uint32_t dword; +uint64_t qword; + } val; +uint64_t data =0 ;/* Load the ROM lazily when the guest tries to read it */ if (unlikely (!vdev->rom && !vdev->rom_read_failed)) {
@@ -1260,11 +1266,26 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)memcpy (&val, vdev->rom + addr, (addr < vdev->rom_size) ?MIN (size, vdev->rom_size - addr) :0 ); +switch (size) { +case 1 : + data = val.byte; +break ; +case 2 : + data =le16_to_cpu (val.word); +break ; +case 4 : + data =le32_to_cpu (val.dword); +break ; +default : +hw_error ("vfio: unsupported read size, %d bytes\n" , 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, val); + vdev->host.function, addr, size, data); -return val; +return data; } static void vfio_rom_write(void *opaque, hwaddr addr,
David Gibson
Reviewed-byRe: [Qemu-devel] [PULL 2/2] vfio: make rom read endian sensitive
Quoted 9 lines · Alex Williamson
From: Nikunj A Dadhania <[email protected]>
All memory regions used by VFIO are
LITTLE_ENDIANand they already take care of endiannes when accessing real device BARs except ROM - it was broken on BE hosts.This fixes endiannes for ROM BARs the same way as it is done for other BARs.
Quoted 7 lines
This has been tested on PPC64 BE/LE host/guest in all possible combinations including TCG.
Signed-off-by Nikunj A Dadhania <[email protected]>[aik: added commit log]Signed-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by Alex Williamson <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Peter Maydell
AppliedQuoted 20 lines · Alex Williamson
The following changes since commit
07e2863d0271ac6c05206d8ce9e4f4c39b25d3ea:
exec.c: fix setting 1-byte-long watchpoints (2014-09-19 17:42:16 +0100)are available in the git repository at:
git://github.com/awilliam/qemu-vfio.gittags/vfio-pci-for-qemu-20140923.0for you to fetch changes up to
75bd0c7253f384e868b638db5c6350796cf584f7:vfio: make rom read endian sensitive (2014-09-22 15:27:43 -0600)
----------------------------------------------------------------
Endian updates to re-fix cross endian host and guest and enable the same for ROM loading (Alexey)----------------------------------------------------------------
Alexey Kardashevskiy (1):
Revert "vfio: Make BARs native endian"
Quoted 5 lines
Nikunj A Dadhania (1):
vfio: make rom read endian sensitivehw/misc/vfio.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Applied, thanks.
-- PMM