Skip to contentSkip to conversation

vfio: allow to disable MMAP per device with -x-mmap=off option

PATCH In review Samuel Pitoiset 3 participants 4 messages Feb 24, 2015 – Feb 25, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio: allow to disable MMAP per device with -x-mmap=off option

Disabling MMAP support uses the slower read/write accesses but allows to trace all MMIO accesses, which is not good for performance, but very useful for reverse engineering PCI drivers. This option allows to disable MMAP per device without a compile-time change.

---
 hw/vfio/common.c              | 2 +-
 hw/vfio/pci.c                 | 1 +
 include/hw/vfio/vfio-common.h | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)
hw/vfio/common.c +1 -1
index c5d1551..bb87974 100644
@@ -493,7 +493,7 @@ int vfio_mmap_region(Object *obj, VFIORegion *region,
     int ret = 0;
     VFIODevice *vbasedev = region->vbasedev;
 
-    if (VFIO_ALLOW_MMAP && size && region->flags &
+    if (vbasedev->allow_mmap && size && region->flags &
         VFIO_REGION_INFO_FLAG_MMAP) {
         int prot = 0;
 
hw/vfio/pci.c +1 -0
index 84e9d99..3c71de3 100644
@@ -3456,6 +3456,7 @@ static Property vfio_pci_dev_properties[] = {
     DEFINE_PROP_BIT("x-vga", VFIOPCIDevice, features,
                     VFIO_FEATURE_ENABLE_VGA_BIT, false),
     DEFINE_PROP_INT32("bootindex", VFIOPCIDevice, bootindex, -1),
+    DEFINE_PROP_BOOL("x-mmap", VFIOPCIDevice, vbasedev.allow_mmap, true),
     /*
      * TODO - support passed fds... is this necessary?
      * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name),
include/hw/vfio/vfio-common.h +1 -1
index 5f3679b..be860ca 100644
@@ -36,7 +36,6 @@
 #endif
 
 /* Extra debugging, trap acceleration paths for more logging */
-#define VFIO_ALLOW_MMAP 1
 #define VFIO_ALLOW_KVM_INTX 1
 #define VFIO_ALLOW_KVM_MSI 1
 #define VFIO_ALLOW_KVM_MSIX 1
@@ -102,6 +101,7 @@ typedef struct VFIODevice {
     int type;
     bool reset_works;
     bool needs_reset;
+    bool allow_mmap;
     VFIODeviceOps *ops;
     unsigned int num_irqs;
     unsigned int num_regions;
Signature · 1 line
2.3.0
#1 lore raw
Quoted 14 lines · Samuel Pitoiset

Disabling MMAP support uses the slower read/write accesses but allows to trace all MMIO accesses, which is not good for performance, but very useful for reverse engineering PCI drivers. This option allows to disable MMAP per device without a compile-time change.

---
 hw/vfio/common.c              | 2 +-
 hw/vfio/pci.c                 | 1 +
 include/hw/vfio/vfio-common.h | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

+++ b/hw/vfio/pci.c

hw/vfio/pci.c static Property vfio_pci_dev_properties[] = { · line 3459

Quoted 4 lines
hw/vfio/pci.c +1 -0
@@ -3456,6 +3456,7 @@ static Property vfio_pci_dev_properties[] = {
     DEFINE_PROP_BIT("x-vga", VFIOPCIDevice, features,
                     VFIO_FEATURE_ENABLE_VGA_BIT, false),
     DEFINE_PROP_INT32("bootindex", VFIOPCIDevice, bootindex, -1),
+    DEFINE_PROP_BOOL("x-mmap", VFIOPCIDevice, vbasedev.allow_mmap, true),

Naming it 'x-mmap' implies it is experimental and may be removed someday. Is there any reason why you are not proposing it as a permanent knob?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 13 lines · Eric Blake
Quoted 11 lines · Samuel Pitoiset

Disabling MMAP support uses the slower read/write accesses but allows to trace all MMIO accesses, which is not good for performance, but very useful for reverse engineering PCI drivers. This option allows to disable MMAP per device without a compile-time change.

---
 hw/vfio/common.c              | 2 +-
 hw/vfio/pci.c                 | 1 +
 include/hw/vfio/vfio-common.h | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)
Quoted 10 lines

hw/vfio/pci.c static Property vfio_pci_dev_properties[] = { · line 3459

Quoted 6 lines

+++ b/hw/vfio/pci.c

hw/vfio/pci.c +1 -0
@@ -3456,6 +3456,7 @@ static Property vfio_pci_dev_properties[] = {
     DEFINE_PROP_BIT("x-vga", VFIOPCIDevice, features,
                     VFIO_FEATURE_ENABLE_VGA_BIT, false),
     DEFINE_PROP_INT32("bootindex", VFIOPCIDevice, bootindex, -1),
+    DEFINE_PROP_BOOL("x-mmap", VFIOPCIDevice, vbasedev.allow_mmap, true),

Naming it 'x-mmap' implies it is experimental and may be removed someday. Is there any reason why you are not proposing it as a permanent knob?

I actually suggested the x- prefix to Samuel because I don't think this is a mode that we want to officially support. It's useful for enabling tracing, but it's possible that doing this will break timing sensitive devices. I therefore don't really want to put it at the fingertips of the average user. If we have a reason to call it supported at some point later, we can always change it. Thanks,

Alex

#3 lore raw
Quoted 10 lines · Alex Williamson
Quoted 4 lines

Naming it 'x-mmap' implies it is experimental and may be removed someday. Is there any reason why you are not proposing it as a permanent knob?

I actually suggested the x- prefix to Samuel because I don't think this is a mode that we want to officially support. It's useful for enabling tracing, but it's possible that doing this will break timing sensitive devices. I therefore don't really want to put it at the fingertips of the average user.

Works for me :)

Quoted 2 lines

If we have a reason to call it supported at some
point later, we can always change it. Thanks,

Yep, that's always an option. Easier to make something stable later when it proved worthwhile, than it is to regret making it stable now.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org