From nobody Sun May 5 09:28:18 2024 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.zoho.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 1490259761705540.8872127192312; Thu, 23 Mar 2017 02:02:41 -0700 (PDT) Received: from localhost ([::1]:55026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqydk-0006Fo-D7 for importer@patchew.org; Thu, 23 Mar 2017 05:02:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqybv-0004uC-Ie for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqybt-00073q-Ks for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:47 -0400 Received: from [59.151.112.132] (port=34027 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqybt-00070x-9E for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:45 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2017 17:00:42 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id A658647EE1EC; Thu, 23 Mar 2017 17:00:41 +0800 (CST) Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.69) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 23 Mar 2017 17:00:41 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="16901628" From: Cao jin To: Date: Thu, 23 Mar 2017 17:09:21 +0800 Message-ID: <1490260163-6157-2-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1490260163-6157-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1490260163-6157-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.69] X-yoursite-MailScanner-ID: A658647EE1EC.AD3F2 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: caoj.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH v3 1/3] pcie aer: verify if AER functionality is available 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: , Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com, Dou Liyang , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For devices which support AER function, verify it can work or not in the system: 1. AER capable device is a PCIe device, it can't be plugged into PCI bus 2. If root port doesn't support AER, then there is no need to expose the AER capability Signed-off-by: Dou Liyang Signed-off-by: Cao jin --- hw/pci/pcie_aer.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index daf1f65..a2e9818 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -100,6 +100,34 @@ static void aer_log_clear_all_err(PCIEAERLog *aer_log) int pcie_aer_init(PCIDevice *dev, uint8_t cap_ver, uint16_t offset, uint16_t size, Error **errp) { + PCIDevice *parent_dev; + uint8_t type; + uint8_t parent_type; + + /* Topology test: see if there is need to expose AER cap */ + type =3D pcie_cap_get_type(dev); + parent_dev =3D pci_bridge_get_device(dev->bus); + while (parent_dev) { + parent_type =3D pcie_cap_get_type(parent_dev); + + if (type =3D=3D PCI_EXP_TYPE_ENDPOINT && + (parent_type !=3D PCI_EXP_TYPE_ROOT_PORT && + parent_type !=3D PCI_EXP_TYPE_DOWNSTREAM)) { + error_setg(errp, "Parent device is not a PCIe component"); + return -ENOTSUP; + } + =20 + if (parent_type =3D=3D PCI_EXP_TYPE_ROOT_PORT) { + if (!parent_dev->exp.aer_cap) + { + error_setg(errp, "Root port does not support AER"); + return -ENOTSUP; + } + } + + parent_dev =3D pci_bridge_get_device(parent_dev->bus); + } + pcie_add_capability(dev, PCI_EXT_CAP_ID_ERR, cap_ver, offset, size); dev->exp.aer_cap =3D offset; --=20 1.8.3.1 From nobody Sun May 5 09:28:18 2024 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.zoho.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 1490259844640672.2581360241958; Thu, 23 Mar 2017 02:04:04 -0700 (PDT) Received: from localhost ([::1]:55034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqyf5-0007TN-Hi for importer@patchew.org; Thu, 23 Mar 2017 05:04:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqyc0-0004xS-DB for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqybu-00075B-PZ for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:52 -0400 Received: from [59.151.112.132] (port=4330 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqybu-00073g-4x for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:46 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2017 17:00:42 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id E1AAF47EE1FB; Thu, 23 Mar 2017 17:00:43 +0800 (CST) Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.69) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 23 Mar 2017 17:00:44 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="16901630" From: Cao jin To: Date: Thu, 23 Mar 2017 17:09:22 +0800 Message-ID: <1490260163-6157-3-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1490260163-6157-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1490260163-6157-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.69] X-yoursite-MailScanner-ID: E1AAF47EE1FB.AE450 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: caoj.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH v3 2/3] vfio pci: new function to init AER capability 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: , Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com, Dou Liyang , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Dou Liyang Signed-off-by: Cao jin --- hw/vfio/pci.c | 41 ++++++++++++++++++++++++++++++++++++----- hw/vfio/pci.h | 1 + 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 332f41d..3d0d005 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1855,18 +1855,42 @@ out: return 0; } =20 -static void vfio_add_ext_cap(VFIOPCIDevice *vdev) +static int vfio_setup_aer(VFIOPCIDevice *vdev, uint8_t cap_ver, + int pos, uint16_t size, Error **errp) +{ + PCIDevice *pdev =3D &vdev->pdev; + uint32_t errcap; + + errcap =3D vfio_pci_read_config(pdev, pos + PCI_ERR_CAP, 4); + /* + * The ability to record multiple headers is depending on + * the state of the Multiple Header Recording Capable bit and + * enabled by the Multiple Header Recording Enable bit. + */ + if ((errcap & PCI_ERR_CAP_MHRC) && + (errcap & PCI_ERR_CAP_MHRE)) { + pdev->exp.aer_log.log_max =3D PCIE_AER_LOG_MAX_DEFAULT; + } else { + pdev->exp.aer_log.log_max =3D 0; + } + + pcie_cap_deverr_init(pdev); + return pcie_aer_init(pdev, cap_ver, pos, size, errp); +} + +static int vfio_add_ext_cap(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; uint32_t header; uint16_t cap_id, next, size; uint8_t cap_ver; uint8_t *config; + int ret =3D 0; =20 /* Only add extended caps if we have them and the guest can see them */ if (!pci_is_express(pdev) || !pci_bus_is_express(pdev->bus) || !pci_get_long(pdev->config + PCI_CONFIG_SPACE_SIZE)) { - return; + return 0; } =20 /* @@ -1915,6 +1939,9 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) PCI_EXT_CAP_NEXT_MASK); =20 switch (cap_id) { + case PCI_EXT_CAP_ID_ERR: + ret =3D vfio_setup_aer(vdev, cap_ver, next, size, errp); + break; case PCI_EXT_CAP_ID_SRIOV: /* Read-only VF BARs confuse OVMF */ case PCI_EXT_CAP_ID_ARI: /* XXX Needs next function virtualization= */ trace_vfio_add_ext_cap_dropped(vdev->vbasedev.name, cap_id, ne= xt); @@ -1923,6 +1950,9 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) pcie_add_capability(pdev, cap_id, cap_ver, next, size); } =20 + if (ret) { + goto out; + } } =20 /* Cleanup chain head ID if necessary */ @@ -1930,8 +1960,9 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) pci_set_word(pdev->config + PCI_CONFIG_SPACE_SIZE, 0); } =20 +out: g_free(config); - return; + return ret; } =20 static int vfio_add_capabilities(VFIOPCIDevice *vdev, Error **errp) @@ -1949,8 +1980,8 @@ static int vfio_add_capabilities(VFIOPCIDevice *vdev,= Error **errp) return ret; } =20 - vfio_add_ext_cap(vdev); - return 0; + ret =3D vfio_add_ext_cap(vdev, errp); + return ret; } =20 static void vfio_pci_pre_reset(VFIOPCIDevice *vdev) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index a8366bb..34e8b04 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -15,6 +15,7 @@ #include "qemu-common.h" #include "exec/memory.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bridge.h" #include "hw/vfio/vfio-common.h" #include "qemu/event_notifier.h" #include "qemu/queue.h" --=20 1.8.3.1 From nobody Sun May 5 09:28:18 2024 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.zoho.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 1490259764802512.4740333398344; Thu, 23 Mar 2017 02:02:44 -0700 (PDT) Received: from localhost ([::1]:55027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqydn-0006Hf-Gu for importer@patchew.org; Thu, 23 Mar 2017 05:02:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqyc0-0004xY-G7 for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqybz-00076D-8z for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:52 -0400 Received: from [59.151.112.132] (port=23720 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqyby-00075g-BN for qemu-devel@nongnu.org; Thu, 23 Mar 2017 05:00:51 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2017 17:00:48 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id D3E8C47EE1F1; Thu, 23 Mar 2017 17:00:47 +0800 (CST) Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.69) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 23 Mar 2017 17:00:48 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="16901635" From: Cao jin To: Date: Thu, 23 Mar 2017 17:09:23 +0800 Message-ID: <1490260163-6157-4-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1490260163-6157-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1490260163-6157-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.69] X-yoursite-MailScanner-ID: D3E8C47EE1F1.AF859 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: caoj.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH v3 3/3] vfio-pci: process non fatal error of AER 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: , Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com, Dou Liyang , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make use of the non fatal error eventfd that the kernel module provide to process the AER non fatal error. Fatal error still goes into the legacy way which results in VM stop. Register the handler, wait for notification. Construct aer message and pass it to root port on notification. Root port will trigger an interrupt to signal guest, then guest driver will do the recovery. Signed-off-by: Dou Liyang Signed-off-by: Cao jin --- hw/vfio/pci.c | 202 +++++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/pci.h | 2 + linux-headers/linux/vfio.h | 2 + 3 files changed, 206 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 3d0d005..c6786d5 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2432,6 +2432,200 @@ static void vfio_put_device(VFIOPCIDevice *vdev) vfio_put_base_device(&vdev->vbasedev); } =20 +static void vfio_non_fatal_err_notifier_handler(void *opaque) +{ + VFIOPCIDevice *vdev =3D opaque; + PCIDevice *dev =3D &vdev->pdev; + PCIEAERMsg msg =3D { + .severity =3D PCI_ERR_ROOT_CMD_NONFATAL_EN, + .source_id =3D pci_requester_id(dev), + }; + + if (!event_notifier_test_and_clear(&vdev->non_fatal_err_notifier)) { + return; + } + + /* Populate the aer msg and send it to root port */ + if (dev->exp.aer_cap) { + uint8_t *aer_cap =3D dev->config + dev->exp.aer_cap; + uint32_t uncor_status; + bool isfatal; + + uncor_status =3D vfio_pci_read_config(dev, + dev->exp.aer_cap + PCI_ERR_UNCOR_STATUS, 4); + if (!uncor_status) { + return; + } + + isfatal =3D uncor_status & pci_get_long(aer_cap + PCI_ERR_UNCOR_SE= VER); + if (isfatal) { + goto stop; + } + + error_report("%s sending non fatal event to root port. uncor statu= s =3D " + "0x%"PRIx32, vdev->vbasedev.name, uncor_status); + pcie_aer_msg(dev, &msg); + return; + } + +stop: + /* Terminate the guest in case of fatal error */ + error_report("%s: Device detected a fatal error. VM stopped", + vdev->vbasedev.name); + vm_stop(RUN_STATE_INTERNAL_ERROR); +} + +/* + * Register non fatal error notifier for devices supporting error recovery. + * If we encounter a failure in this function, we report an error + * and continue after disabling error recovery support for the device. + */ +static void vfio_register_non_fatal_err_notifier(VFIOPCIDevice *vdev) +{ + int ret; + int argsz; + struct vfio_irq_set *irq_set; + int32_t *pfd; + + if (event_notifier_init(&vdev->non_fatal_err_notifier, 0)) { + error_report("vfio: Unable to init event notifier for non-fatal er= ror detection"); + return; + } + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D VFIO_PCI_NON_FATAL_ERR_IRQ_INDEX; + irq_set->start =3D 0; + irq_set->count =3D 1; + pfd =3D (int32_t *)&irq_set->data; + + *pfd =3D event_notifier_get_fd(&vdev->non_fatal_err_notifier); + qemu_set_fd_handler(*pfd, vfio_non_fatal_err_notifier_handler, NULL, v= dev); + + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); + if (ret) { + error_report("vfio: Failed to set up non-fatal error notification:= %m"); + qemu_set_fd_handler(*pfd, NULL, NULL, vdev); + event_notifier_cleanup(&vdev->non_fatal_err_notifier); + } + g_free(irq_set); +} + +static void vfio_unregister_non_fatal_err_notifier(VFIOPCIDevice *vdev) +{ + int argsz; + struct vfio_irq_set *irq_set; + int32_t *pfd; + int ret; + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D VFIO_PCI_NON_FATAL_ERR_IRQ_INDEX; + irq_set->start =3D 0; + irq_set->count =3D 1; + pfd =3D (int32_t *)&irq_set->data; + *pfd =3D -1; + + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); + if (ret) { + error_report("vfio: Failed to de-assign error fd: %m"); + } + g_free(irq_set); + qemu_set_fd_handler(event_notifier_get_fd(&vdev->non_fatal_err_notifie= r), + NULL, NULL, vdev); + event_notifier_cleanup(&vdev->non_fatal_err_notifier); +} + +static void vfio_passive_reset_notifier_handler(void *opaque) +{ + VFIOPCIDevice *vdev =3D opaque; + + if (!event_notifier_test_and_clear(&vdev->passive_reset_notifier)) { + return; + } + + error_report("%s: Device lost state due to host device reset. VM stopp= ed", + vdev->vbasedev.name); + vm_stop(RUN_STATE_INTERNAL_ERROR); +} + +/* + * Register passive reset notifier, in case of certain function of a + * multifunction device is passthroughed, while other functions are still + * controlled by device driver. + */ +static void vfio_register_passive_reset_notifier(VFIOPCIDevice *vdev) +{ + int ret; + int argsz; + struct vfio_irq_set *irq_set; + int32_t *pfd; + + if (event_notifier_init(&vdev->passive_reset_notifier, 0)) { + error_report("vfio: Unable to init event notifier for passive rese= t"); + return; + } + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D VFIO_PCI_PASSIVE_RESET_IRQ_INDEX; + irq_set->start =3D 0; + irq_set->count =3D 1; + pfd =3D (int32_t *)&irq_set->data; + + *pfd =3D event_notifier_get_fd(&vdev->passive_reset_notifier); + qemu_set_fd_handler(*pfd, vfio_passive_reset_notifier_handler, NULL, v= dev); + + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); + if (ret) { + error_report("vfio: Failed to set up passive reset notification: %= m"); + qemu_set_fd_handler(*pfd, NULL, NULL, vdev); + event_notifier_cleanup(&vdev->passive_reset_notifier); + } + g_free(irq_set); +} + +static void vfio_unregister_passive_reset_notifier(VFIOPCIDevice *vdev) +{ + int argsz; + struct vfio_irq_set *irq_set; + int32_t *pfd; + int ret; + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D VFIO_PCI_PASSIVE_RESET_IRQ_INDEX; + irq_set->start =3D 0; + irq_set->count =3D 1; + pfd =3D (int32_t *)&irq_set->data; + *pfd =3D -1; + + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); + if (ret) { + error_report("vfio: Failed to de-assign error fd: %m"); + } + g_free(irq_set); + qemu_set_fd_handler(event_notifier_get_fd(&vdev->passive_reset_notifie= r), + NULL, NULL, vdev); + event_notifier_cleanup(&vdev->passive_reset_notifier); +} + static void vfio_err_notifier_handler(void *opaque) { VFIOPCIDevice *vdev =3D opaque; @@ -2860,6 +3054,8 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) } } =20 + vfio_register_passive_reset_notifier(vdev); + vfio_register_non_fatal_err_notifier(vdev); vfio_register_err_notifier(vdev); vfio_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); @@ -2900,6 +3096,12 @@ static void vfio_exitfn(PCIDevice *pdev) =20 vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); + if (event_notifier_get_fd(&vdev->non_fatal_err_notifier)) { + vfio_unregister_non_fatal_err_notifier(vdev); + } + if (event_notifier_get_fd(&vdev->passive_reset_notifier)) { + vfio_unregister_passive_reset_notifier(vdev); + } pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); vfio_disable_interrupts(vdev); if (vdev->intx.mmap_timer) { diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 34e8b04..b35c617 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -119,6 +119,8 @@ typedef struct VFIOPCIDevice { void *igd_opregion; PCIHostDeviceAddress host; EventNotifier err_notifier; + EventNotifier non_fatal_err_notifier; + EventNotifier passive_reset_notifier; EventNotifier req_notifier; int (*resetfn)(struct VFIOPCIDevice *); uint32_t vendor_id; diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 759b850..726ddbe 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -433,6 +433,8 @@ enum { VFIO_PCI_MSIX_IRQ_INDEX, VFIO_PCI_ERR_IRQ_INDEX, VFIO_PCI_REQ_IRQ_INDEX, + VFIO_PCI_NON_FATAL_ERR_IRQ_INDEX, + VFIO_PCI_PASSIVE_RESET_IRQ_INDEX, VFIO_PCI_NUM_IRQS }; =20 --=20 1.8.3.1