From nobody Wed Nov 5 06:37:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499713932735173.9099212371956; Mon, 10 Jul 2017 12:12:12 -0700 (PDT) Received: from localhost ([::1]:42579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUe6L-0005GT-Bc for importer@patchew.org; Mon, 10 Jul 2017 15:12:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39164) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUe4r-0004MA-Rx for qemu-devel@nongnu.org; Mon, 10 Jul 2017 15:10:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUe4o-0001p4-CI for qemu-devel@nongnu.org; Mon, 10 Jul 2017 15:10:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51372) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUe4o-0001oJ-2V for qemu-devel@nongnu.org; Mon, 10 Jul 2017 15:10:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0798A369BD for ; Mon, 10 Jul 2017 19:10:33 +0000 (UTC) Received: from gimli.home (ovpn-116-254.phx2.redhat.com [10.3.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA12117ABC; Mon, 10 Jul 2017 19:10:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0798A369BD Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=alex.williamson@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0798A369BD From: Alex Williamson To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 13:10:30 -0600 Message-ID: <20170710191023.32728.20684.stgit@gimli.home> In-Reply-To: <20170710190904.32728.74078.stgit@gimli.home> References: <20170710190904.32728.74078.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 10 Jul 2017 19:10:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/2] vfio: Test realized when using VFIOGroup.device_list iterator X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 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. Signed-off-by: Alex Williamson --- 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(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index b9abe77f5a7b..29923e499012 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -858,13 +858,15 @@ void vfio_reset_handler(void *opaque) =20 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); + } } } =20 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); } } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 8de8272e964d..ccdb6e1d632a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2116,7 +2116,8 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bo= ol single) =20 /* Prep dependent devices for reset and clear our marker. */ QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { - if (vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { + if (!vbasedev_iter->dev->realized || + vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { continue; } tmp =3D container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); @@ -2197,7 +2198,8 @@ out: } =20 QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { - if (vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { + if (!vbasedev_iter->dev->realized || + vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { continue; } tmp =3D container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); @@ -2647,6 +2649,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) vdev->vbasedev.name =3D g_strdup(basename(vdev->vbasedev.sysfsdev)); vdev->vbasedev.ops =3D &vfio_pci_ops; vdev->vbasedev.type =3D VFIO_DEVICE_TYPE_PCI; + vdev->vbasedev.dev =3D &vdev->pdev.qdev; =20 tmp =3D g_strdup_printf("%s/iommu_group", vdev->vbasedev.sysfsdev); len =3D readlink(tmp, group_path, sizeof(group_path)); diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index a4663c918ea2..7c09deda6143 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -640,6 +640,7 @@ static void vfio_platform_realize(DeviceState *dev, Err= or **errp) int i, ret; =20 vbasedev->type =3D VFIO_DEVICE_TYPE_PLATFORM; + vbasedev->dev =3D dev; vbasedev->ops =3D &vfio_platform_ops; =20 trace_vfio_platform_realize(vbasedev->sysfsdev ? diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 9521013d52b3..0b475a3596fc 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -115,6 +115,7 @@ typedef struct VFIODevice { struct VFIOGroup *group; char *sysfsdev; char *name; + DeviceState *dev; int fd; int type; bool reset_works; From nobody Wed Nov 5 06:37:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499713945520271.82018002822247; Mon, 10 Jul 2017 12:12:25 -0700 (PDT) Received: from localhost ([::1]:42580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUe6W-0005OJ-7Z for importer@patchew.org; Mon, 10 Jul 2017 15:12:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUe51-0004RA-CA for qemu-devel@nongnu.org; Mon, 10 Jul 2017 15:10:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUe4y-0001rx-7n for qemu-devel@nongnu.org; Mon, 10 Jul 2017 15:10:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52789) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUe4x-0001rl-Ts for qemu-devel@nongnu.org; Mon, 10 Jul 2017 15:10:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDBD64E4CA for ; Mon, 10 Jul 2017 19:10:42 +0000 (UTC) Received: from gimli.home (ovpn-116-254.phx2.redhat.com [10.3.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE04B60DD7; Mon, 10 Jul 2017 19:10:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EDBD64E4CA Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=alex.williamson@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EDBD64E4CA From: Alex Williamson To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 13:10:42 -0600 Message-ID: <20170710191038.32728.34984.stgit@gimli.home> In-Reply-To: <20170710190904.32728.74078.stgit@gimli.home> References: <20170710190904.32728.74078.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Jul 2017 19:10:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/2] vfio/pci: Fixup v0 PCIe capabilities X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 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. Signed-off-by: Alex Williamson --- hw/vfio/pci.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index ccdb6e1d632a..d4051cb9513d 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -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); } =20 + /* + * 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) =3D=3D 0) { + vfio_add_emulated_word(vdev, pos + PCI_CAP_FLAGS, + 1, PCI_EXP_FLAGS_VERS); + } + pos =3D pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size, errp); if (pos < 0) {