VFIO fixes 2017-05-03
The following changes since commit e619b14746e5d8c0e53061661fd0e1da01fd4d60:
Merge remote-tracking branch 'sthibault/tags/samuel-thibault' into staging (2017-05-02 15:16:29 +0100)
are available in the git repository at:
git://github.com/awilliam/qemu-vfio.git tags/vfio-updates-20170503.0
for you to fetch changes up to 6e4e6f0d403b1fb25f9dfdbe17754c643997753d:
vfio/pci: Fix incorrect error message (2017-05-03 14:52:35 -0600)
----------------------------------------------------------------
VFIO fixes 2017-05-03
- Enable 8-byte memory region accesses (Jose Ricardo Ziviani)
- Fix vfio-pci error message (Dong Jia Shi)
----------------------------------------------------------------
Dong Jia Shi (1):
vfio/pci: Fix incorrect error message
Jose Ricardo Ziviani (2):
vfio: Set MemoryRegionOps:max_access_size and min_access_size
vfio: enable 8-byte reads/writes to vfio
hw/vfio/common.c | 14 ++++++++++++++ hw/vfio/pci.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-)
[Qemu-devel] [PULL 1/3] vfio: Set MemoryRegionOps:max_access_size and min_access_size
From: Jose Ricardo Ziviani <[email protected]>
Sets valid.max_access_size and valid.min_access_size to ensure safe 8-byte accesses to vfio. Today, 8-byte accesses are broken into pairs of 4-byte calls that goes unprotected:
qemu_mutex_lock locked mutex 0x10905ad8
vfio_region_write (0001:03:00.0:region1+0xc0, 0x2020c, 4)qemu_mutex_unlock unlocked mutex 0x10905ad8 qemu_mutex_lock locked mutex 0x10905ad8
vfio_region_write (0001:03:00.0:region1+0xc4, 0xa0000, 4)qemu_mutex_unlock unlocked mutex 0x10905ad8
which occasionally leads to:
qemu_mutex_lock locked mutex 0x10905ad8
vfio_region_write (0001:03:00.0:region1+0xc0, 0x2030c, 4)qemu_mutex_unlock unlocked mutex 0x10905ad8 qemu_mutex_lock locked mutex 0x10905ad8
vfio_region_write (0001:03:00.0:region1+0xc0, 0x1000c, 4)qemu_mutex_unlock unlocked mutex 0x10905ad8 qemu_mutex_lock locked mutex 0x10905ad8
vfio_region_write (0001:03:00.0:region1+0xc4, 0xb0000, 4)qemu_mutex_unlock unlocked mutex 0x10905ad8 qemu_mutex_lock locked mutex 0x10905ad8
vfio_region_write (0001:03:00.0:region1+0xc4, 0xa0000, 4)qemu_mutex_unlock unlocked mutex 0x10905ad8
causing strange errors in guest OS. With this patch, such accesses are protected by the same lock guard:
qemu_mutex_lock locked mutex 0x10905ad8 vfio_region_write (0001:03:00.0:region1+0xc0, 0x2000c, 4) vfio_region_write (0001:03:00.0:region1+0xc4, 0xb0000, 4) qemu_mutex_unlock unlocked mutex 0x10905ad8
This happens because the 8-byte write should be broken into 4-byte writes by memory.c:access_with_adjusted_size() in order to be under the same lock. Today, it's done in exec.c:address_space_write_continue() which was able to handle only 4 bytes due to a zero'ed valid.max_access_size (see exec.c:memory_access_size()).
--- hw/vfio/common.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/vfio/common.c +4 -0
@@ -190,6 +190,10 @@ const MemoryRegionOps vfio_region_ops = { .read = vfio_region_read, .write = vfio_region_write, .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 1, + .max_access_size = 8, + }, };/*
[Qemu-devel] [PULL 2/3] vfio: enable 8-byte reads/writes to vfio
In reply to Alex WilliamsonFrom: Jose Ricardo Ziviani <[email protected]>
This patch enables 8-byte writes and reads to VFIO. Such implemention is already done but it's missing the 'case' to handle such accesses in both vfio_region_write and vfio_region_read and the MemoryRegionOps:
impl.max_access_size and impl.min_access_size.
After this patch, 8-byte writes such as:
qemu_mutex_lock locked mutex 0x10905ad8 vfio_region_write (0001:03:00.0:region1+0xc0, 0x4140c, 4) vfio_region_write (0001:03:00.0:region1+0xc4, 0xa0000, 4) qemu_mutex_unlock unlocked mutex 0x10905ad8
goes like this:
qemu_mutex_lock locked mutex 0x10905ad8 vfio_region_write (0001:03:00.0:region1+0xc0, 0xbfd0008, 8) qemu_mutex_unlock unlocked mutex 0x10905ad8
--- hw/vfio/common.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/vfio/common.c +10 -0
@@ -119,6 +119,9 @@ void vfio_region_write(void *opaque, hwaddr addr,case 4 : buf.dword =cpu_to_le32 (data);break ; +case 8 : + buf.qword =cpu_to_le64 (data); +break ;default :hw_error ("vfio: unsupported write size, %d bytes" , size);break ;
@@ -173,6 +176,9 @@ uint64_t vfio_region_read(void *opaque,case 4 : data =le32_to_cpu (buf.dword);break ; +case 8 : + data =le64_to_cpu (buf.qword); +break ;default :hw_error ("vfio: unsupported read size, %d bytes" , size);break ;
@@ -194,6 +200,10 @@ const MemoryRegionOps vfio_region_ops = { .min_access_size = 1, .max_access_size = 8, }, + .impl = { + .min_access_size = 1, + .max_access_size = 8, + }, };/*
[Qemu-devel] [PULL 3/3] vfio/pci: Fix incorrect error message
In reply to Alex WilliamsonFrom: Dong Jia Shi <[email protected]>
When the "No host device provided" error occurs, the hint message that starts with "Use -vfio-pci," makes no sense, since "-vfio-pci" is not a valid command line parameter.
Correct this by replacing "-vfio-pci" with "-device vfio-pci".
--- hw/vfio/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/vfio/pci.c +2 -2
@@ -2625,8 +2625,8 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)if (!(~vdev->host.domain || ~vdev->host.bus || ~vdev->host.slot || ~vdev->host.function)) {error_setg (errp,"No provided host device" ); -error_append_hint (errp,"Use -vfio-pci,host=DDDD:BB:DD.F " -"or -vfio-pci,sysfsdev=PATH_TO_DEVICE\n" ); +error_append_hint (errp,"Use -device vfio-pci,host=DDDD:BB:DD.F " +"or -device vfio-pci,sysfsdev=PATH_TO_DEVICE\n" );return ; } vdev->vbasedev.sysfsdev =
Stefan Hajnoczi
AppliedQuoted 23 lines · Alex Williamson
The following changes since commit
e619b14746e5d8c0e53061661fd0e1da01fd4d60:Merge remote-tracking branch 'sthibault/tags/samuel-thibault' into staging (2017-05-02 15:16:29 +0100)
are available in the git repository at:
git://github.com/awilliam/qemu-vfio.gittags/vfio-updates-20170503.0for you to fetch changes up to
6e4e6f0d403b1fb25f9dfdbe17754c643997753d:vfio/pci: Fix incorrect error message (2017-05-03 14:52:35 -0600)
----------------------------------------------------------------
VFIO fixes 2017-05-03- Enable 8-byte memory region accesses (Jose Ricardo Ziviani)
- Fix vfio-pci error message (Dong Jia Shi)----------------------------------------------------------------
Dong Jia Shi (1):
vfio/pci: Fix incorrect error message
Quoted 8 lines
Jose Ricardo Ziviani (2):
vfio: Set MemoryRegionOps:max_access_size andmin_access_size
vfio: enable 8-byte reads/writes to vfiohw/vfio/common.c | 14 ++++++++++++++ hw/vfio/pci.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-)
Thanks, applied to my staging tree:
https://github.com/stefanha/qemu/commits/staging
Stefan