Skip to contentSkip to conversation

VFIO fixes 2017-07-10

GIT PULL Applied Alex Williamson 2 participants 4 messages Jul 10, 2017 – Jul 11, 2017

lore
Share & tools
lore
#0 lore raw

The following changes since commit 6b06e3e49eb8c91cc286c16d6bf3181ac296f33d:

Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2017-07-10-v2'
into staging (2017-07-10 16:12:47 +0100)

are available in the git repository at:

git://github.com/awilliam/qemu-vfio.git tags/vfio-updates-20170710.0

for you to fetch changes up to 47985727e383eee191a39cc007541c17cd8680ee:

vfio/pci: Fixup v0 PCIe capabilities (2017-07-10 10:39:43 -0600)

----------------------------------------------------------------
VFIO fixes 2017-07-10

- Don't iterate over non-realized devices (Alex Williamson)
- Add PCIe capability version fixup (Alex Williamson)

----------------------------------------------------------------
Alex Williamson (2):
vfio: Test realized when using VFIOGroup.device_list iterator vfio/pci: Fixup v0 PCIe capabilities

 hw/vfio/common.c              |  6 ++++--
 hw/vfio/pci.c                 | 19 +++++++++++++++++--
 hw/vfio/platform.c            |  1 +
 include/hw/vfio/vfio-common.h |  1 +
 4 files changed, 23 insertions(+), 4 deletions(-)
#1 lore raw

[Qemu-devel] [PULL 1/2] vfio: Test realized when using VFIOGroup.device_list iterator

VFIOGroup.device_list is effectively our reference tracking mechanism such that we can teardown a group when all of the device references are removed. However, we also use this list from our machine reset handler for processing resets that affect multiple devices. Generally device removals are fully processed (exitfn + finalize) when this reset handler is invoked, however if the removal is triggered via another reset handler (piix4_reset->acpi_pcihp_reset) then the device exitfn may run, but not finalize. In this case we hit asserts when we start trying to access PCI helpers since much of the PCI state of the device is released. To resolve this, add a pointer to the Object DeviceState in our common base-device and skip non-realized devices as we iterate.

---
 hw/vfio/common.c              |    6 ++++--
 hw/vfio/pci.c                 |    7 +++++--
 hw/vfio/platform.c            |    1 +
 include/hw/vfio/vfio-common.h |    1 +
 4 files changed, 11 insertions(+), 4 deletions(-)
hw/vfio/common.c +4 -2
index b9abe77f5a7b..29923e499012 100644
@@ -858,13 +858,15 @@ void vfio_reset_handler(void *opaque)
 
     QLIST_FOREACH(group, &vfio_group_list, next) {
         QLIST_FOREACH(vbasedev, &group->device_list, next) {
-            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
+            if (vbasedev->dev->realized) {
+                vbasedev->ops->vfio_compute_needs_reset(vbasedev);
+            }
         }
     }
 
     QLIST_FOREACH(group, &vfio_group_list, next) {
         QLIST_FOREACH(vbasedev, &group->device_list, next) {
-            if (vbasedev->needs_reset) {
+            if (vbasedev->dev->realized && vbasedev->needs_reset) {
                 vbasedev->ops->vfio_hot_reset_multi(vbasedev);
             }
         }
hw/vfio/pci.c +5 -2
index 8de8272e964d..ccdb6e1d632a 100644
@@ -2116,7 +2116,8 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
 
         /* Prep dependent devices for reset and clear our marker. */
         QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
-            if (vbasedev_iter->type != VFIO_DEVICE_TYPE_PCI) {
+            if (!vbasedev_iter->dev->realized ||
+                vbasedev_iter->type != VFIO_DEVICE_TYPE_PCI) {
                 continue;
             }
             tmp = container_of(vbasedev_iter, VFIOPCIDevice, vbasedev);
@@ -2197,7 +2198,8 @@ out:
         }
 
         QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
-            if (vbasedev_iter->type != VFIO_DEVICE_TYPE_PCI) {
+            if (!vbasedev_iter->dev->realized ||
+                vbasedev_iter->type != VFIO_DEVICE_TYPE_PCI) {
                 continue;
             }
             tmp = container_of(vbasedev_iter, VFIOPCIDevice, vbasedev);
@@ -2647,6 +2649,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
     vdev->vbasedev.name = g_strdup(basename(vdev->vbasedev.sysfsdev));
     vdev->vbasedev.ops = &vfio_pci_ops;
     vdev->vbasedev.type = VFIO_DEVICE_TYPE_PCI;
+    vdev->vbasedev.dev = &vdev->pdev.qdev;
 
     tmp = g_strdup_printf("%s/iommu_group", vdev->vbasedev.sysfsdev);
     len = readlink(tmp, group_path, sizeof(group_path));
hw/vfio/platform.c +1 -0
index a4663c918ea2..7c09deda6143 100644
@@ -640,6 +640,7 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp)
     int i, ret;
 
     vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
+    vbasedev->dev = dev;
     vbasedev->ops = &vfio_platform_ops;
 
     trace_vfio_platform_realize(vbasedev->sysfsdev ?
include/hw/vfio/vfio-common.h +1 -0
index 9521013d52b3..0b475a3596fc 100644
@@ -115,6 +115,7 @@ typedef struct VFIODevice {
     struct VFIOGroup *group;
     char *sysfsdev;
     char *name;
+    DeviceState *dev;
     int fd;
     int type;
     bool reset_works;
#2 lore raw

[Qemu-devel] [PULL 2/2] vfio/pci: Fixup v0 PCIe capabilities

In reply to Alex Williamson

Intel 82599 VFs report a PCIe capability version of 0, which is invalid. The earliest version of the PCIe spec used version 1. This causes Windows to fail startup on the device and it will be disabled with error code 10. Our choices are either to drop the PCIe cap on such devices, which has the side effect of likely preventing the guest from discovering any extended capabilities, or performing a fixup to update the capability to the earliest valid version. This implements the latter.

---
 hw/vfio/pci.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/vfio/pci.c +12 -0
index ccdb6e1d632a..d4051cb9513d 100644
@@ -1743,6 +1743,18 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
                                PCI_EXP_LNKCAP_MLW | PCI_EXP_LNKCAP_SLS);
     }
 
+    /*
+     * Intel 82599 SR-IOV VFs report an invalid PCIe capability version 0
+     * (Niantic errate #35) causing Windows to error with a Code 10 for the
+     * device on Q35.  Fixup any such devices to report version 1.  If we
+     * were to remove the capability entirely the guest would lose extended
+     * config space.
+     */
+    if ((flags & PCI_EXP_FLAGS_VERS) == 0) {
+        vfio_add_emulated_word(vdev, pos + PCI_CAP_FLAGS,
+                               1, PCI_EXP_FLAGS_VERS);
+    }
+
     pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size,
                              errp);
     if (pos < 0) {
#3 lore raw
In reply to Alex Williamson
Quoted 12 lines · Alex Williamson

The following changes since commit 6b06e3e49eb8c91cc286c16d6bf3181ac296f33d:

Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2017-07-10-v2'
into staging (2017-07-10 16:12:47 +0100)

are available in the git repository at:

git://github.com/awilliam/qemu-vfio.git tags/vfio-updates-20170710.0

for you to fetch changes up to 47985727e383eee191a39cc007541c17cd8680ee:

Quoted 8 lines

vfio/pci: Fixup v0 PCIe capabilities (2017-07-10 10:39:43 -0600)

----------------------------------------------------------------
VFIO fixes 2017-07-10

- Don't iterate over non-realized devices (Alex Williamson)
- Add PCIe capability version fixup (Alex Williamson)

Applied, thanks.

-- PMM