From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aftpu-0001iY-Sb for qemu-devel@nongnu.org; Tue, 15 Mar 2016 14:36:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aftpq-0003Ec-7U for qemu-devel@nongnu.org; Tue, 15 Mar 2016 14:36:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aftpq-0003EO-2Z for qemu-devel@nongnu.org; Tue, 15 Mar 2016 14:36:50 -0400 Date: Tue, 15 Mar 2016 12:36:45 -0600 From: Alex Williamson Message-ID: <20160315123645.22625ce7@t450s.home> In-Reply-To: <1458005749-4878-7-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1458005749-4878-1-git-send-email-caoj.fnst@cn.fujitsu.com> <1458005749-4878-7-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [patch v3 6/9] vfio: add check aer functionality for hotplug device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cao jin Cc: chen.fan.fnst@cn.fujitsu.com, izumi.taku@jp.fujitsu.com, qemu-devel@nongnu.org, mst@redhat.com On Tue, 15 Mar 2016 09:35:46 +0800 Cao jin wrote: > From: Chen Fan > > because we make the vfio functions are combined > in the same way as on the host for aer, so we can > do the aer check when the function 0 was hotplugged. > > Signed-off-by: Chen Fan > --- > hw/vfio/pci.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 50 insertions(+) > > diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c > index 9670271..223c0ee 100644 > --- a/hw/vfio/pci.c > +++ b/hw/vfio/pci.c > @@ -2029,6 +2029,40 @@ out: > return; > } > > +static void vfio_bus_check_aer_functions(PCIDevice *pdev, Error **errp) > +{ > + PCIBus *bus = pdev->bus; > + VFIOPCIDevice *vdev; > + PCIDevice *dev; > + Error *local_err = NULL; > + int devfn; > + > + for (devfn = 0; devfn < ARRAY_SIZE(bus->devices); devfn++) { > + dev = bus->devices[devfn]; > + if (!dev) { > + continue; > + } > + > + if (pci_get_function_0(dev) != pdev) { > + return; > + } It seems like there are much easier ways to walk all functions on a slot, rather than all devices on the bus, and not access PCIBus private data: for (fn = 0; fn < 8; fn++) { dev = pci_find_device(pdev->bus, pci_bus_num(pdev->bus), PCI_DEVFN(PCI_SLOT(pdev->devfn), fn)); if (!dev) { continue; } ... > + > + if (!object_dynamic_cast(OBJECT(dev), "vfio-pci")) { > + continue; > + } > + vdev = DO_UPCAST(VFIOPCIDevice, pdev, dev); > + if (vdev->features & VFIO_FEATURE_ENABLE_AER) { > + vfio_check_hot_bus_reset(vdev, &local_err); > + if (local_err) { > + error_propagate(errp, local_err); > + return; > + } > + } > + } > + > + return; > +} > + > static void vfio_aer_check_host_bus_reset(Error **errp) > { > VFIOGroup *group; > @@ -2962,6 +2996,22 @@ static int vfio_initfn(PCIDevice *pdev) > } > } > > + /* > + * If this function is func 0, indicate the closure of the slot. > + * we get the chance to check aer-enabled devices whether support > + * hot bus reset. > + */ > + if (DEVICE(pdev)->hotplugged && > + pdev == pci_get_function_0(pdev)) { > + Error *local_err = NULL; > + > + vfio_bus_check_aer_functions(pdev, &local_err); > + if (local_err) { > + error_report_err(local_err); > + goto out_teardown; > + } > + } > + > vfio_register_err_notifier(vdev); > vfio_register_req_notifier(vdev); > vfio_setup_resetfn_quirk(vdev);