From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9fDX-0004lE-DE for qemu-devel@nongnu.org; Thu, 17 Dec 2015 15:32:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9fDV-0007UH-Fq for qemu-devel@nongnu.org; Thu, 17 Dec 2015 15:32:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54797) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9fDV-0007UB-6K for qemu-devel@nongnu.org; Thu, 17 Dec 2015 15:32:01 -0500 Message-ID: <1450384320.2674.111.camel@redhat.com> From: Alex Williamson Date: Thu, 17 Dec 2015 13:32:00 -0700 In-Reply-To: <4decbb79f80779a15ebabb43e22b71cd7388159a.1447748073.git.chen.fan.fnst@cn.fujitsu.com> References: <4decbb79f80779a15ebabb43e22b71cd7388159a.1447748073.git.chen.fan.fnst@cn.fujitsu.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v14 Resend 09/13] add check reset mechanism when hotplug vfio device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cao jin , qemu-devel@nongnu.org Cc: chen.fan.fnst@cn.fujitsu.com, mst@redhat.com On Thu, 2015-12-17 at 09:41 +0800, Cao jin wrote: > From: Chen Fan >=20 > Since we support multi-function hotplug. the function 0 indicate > the closure of the slot, so we have the chance to do the check. >=20 > Signed-off-by: Chen Fan > --- > =C2=A0hw/pci/pci.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0| 29 +++++++++++++++++++++++++++++ > =C2=A0hw/vfio/pci.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0| 19 +++++++++++++++++++ > =C2=A0hw/vfio/pci.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0|=C2=A0=C2=A02 ++ > =C2=A0include/hw/pci/pci_bus.h |=C2=A0=C2=A05 +++++ > =C2=A04 files changed, 55 insertions(+) MST, can I get a review/ack for this one? =C2=A0Thanks, Alex > diff --git a/hw/pci/pci.c b/hw/pci/pci.c > index 168b9cc..f6ca6ef 100644 > --- a/hw/pci/pci.c > +++ b/hw/pci/pci.c > @@ -81,6 +81,7 @@ static void pci_bus_realize(BusState *qbus, Error > **errp) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0PCIBus *bus =3D PCI_BUS(qbus); > =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0vmstate_register(NULL, -1, &vmstate_pcibu= s, bus); > +=C2=A0=C2=A0=C2=A0=C2=A0notifier_with_return_list_init(&bus->hotplug_n= otifiers); > =C2=A0} > =C2=A0 > =C2=A0static void pci_bus_unrealize(BusState *qbus, Error **errp) > @@ -1835,6 +1836,22 @@ PCIDevice *pci_find_device(PCIBus *bus, int > bus_num, uint8_t devfn) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return bus->devices[devfn]; > =C2=A0} > =C2=A0 > +void pci_bus_add_hotplug_notifier(PCIBus *bus, NotifierWithReturn > *notify) > +{ > +=C2=A0=C2=A0=C2=A0=C2=A0notifier_with_return_list_add(&bus->hotplug_no= tifiers, notify); > +} > + > +void pci_bus_remove_hotplug_notifier(NotifierWithReturn *notifier) > +{ > +=C2=A0=C2=A0=C2=A0=C2=A0notifier_with_return_remove(notifier); > +} > + > +static int pci_bus_hotplug_notifier(PCIBus *bus, void *opaque) > +{ > +=C2=A0=C2=A0=C2=A0=C2=A0return notifier_with_return_list_notify(&bus->= hotplug_notifiers, > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0opaque); > +} > + > =C2=A0static void pci_qdev_realize(DeviceState *qdev, Error **errp) > =C2=A0{ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0PCIDevice *pci_dev =3D (PCIDevice *)qdev; > @@ -1877,6 +1894,18 @@ static void pci_qdev_realize(DeviceState > *qdev, Error **errp) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pci_qdev_unrealiz= e(DEVICE(pci_dev), NULL); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} > + > +=C2=A0=C2=A0=C2=A0=C2=A0/* > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*=C2=A0=C2=A0If the function is func 0, = indicate the closure of the slot. > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*=C2=A0=C2=A0signal the callback. > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*/ > +=C2=A0=C2=A0=C2=A0=C2=A0if (DEVICE(pci_dev)->hotplugged && > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pci_get_function_0(pci= _dev) =3D=3D pci_dev && > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pci_bus_hotplug_notifi= er(bus, pci_dev)) { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0error_setg(errp, "fail= ed to hotplug function 0"); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pci_qdev_unrealize(DEV= ICE(pci_dev), NULL); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return; > +=C2=A0=C2=A0=C2=A0=C2=A0} > =C2=A0} > =C2=A0 > =C2=A0static void pci_default_realize(PCIDevice *dev, Error **errp) > diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c > index 6926dcc..e17dc89 100644 > --- a/hw/vfio/pci.c > +++ b/hw/vfio/pci.c > @@ -2016,6 +2016,19 @@ static int > vfio_check_devices_host_bus_reset(void) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return 0; > =C2=A0} > =C2=A0 > +static int vfio_check_bus_reset(NotifierWithReturn *n, void *opaque) > +{ > +=C2=A0=C2=A0=C2=A0=C2=A0VFIOPCIDevice *vdev =3D container_of(n, VFIOPC= IDevice, > hotplug_notifier); > +=C2=A0=C2=A0=C2=A0=C2=A0PCIDevice *pci_dev =3D PCI_DEVICE(vdev); > +=C2=A0=C2=A0=C2=A0=C2=A0PCIDevice *pci_func0 =3D opaque; > + > +=C2=A0=C2=A0=C2=A0=C2=A0if (pci_get_function_0(pci_dev) !=3D pci_func0= ) { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return 0; > +=C2=A0=C2=A0=C2=A0=C2=A0} > + > +=C2=A0=C2=A0=C2=A0=C2=A0return vfio_check_host_bus_reset(vdev); > +} > + > =C2=A0static int vfio_setup_aer(VFIOPCIDevice *vdev, uint8_t cap_ver, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0int pos, uint16_t size) > =C2=A0{ > @@ -2063,6 +2076,9 @@ static int vfio_setup_aer(VFIOPCIDevice *vdev, > uint8_t cap_ver, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pdev->exp.aer_log= .log_max =3D 0; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} > =C2=A0 > +=C2=A0=C2=A0=C2=A0=C2=A0vdev->hotplug_notifier.notify =3D vfio_check_b= us_reset; > +=C2=A0=C2=A0=C2=A0=C2=A0pci_bus_add_hotplug_notifier(pdev->bus, &vdev- > >hotplug_notifier); > + > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pcie_cap_deverr_init(pdev); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return pcie_aer_init(pdev, pos, size); > =C2=A0 > @@ -2944,6 +2960,9 @@ static void vfio_exitfn(PCIDevice *pdev) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0vfio_unregister_req_notifier(vdev); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0vfio_unregister_err_notifier(vdev); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pci_device_set_intx_routing_notifier(&vde= v->pdev, NULL); > +=C2=A0=C2=A0=C2=A0=C2=A0if (vdev->features & VFIO_FEATURE_ENABLE_AER) = { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pci_bus_remove_hotplug= _notifier(&vdev->hotplug_notifier); > +=C2=A0=C2=A0=C2=A0=C2=A0} > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0vfio_disable_interrupts(vdev); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (vdev->intx.mmap_timer) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0timer_free(vdev->= intx.mmap_timer); > diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h > index 59ae194..b385f07 100644 > --- a/hw/vfio/pci.h > +++ b/hw/vfio/pci.h > @@ -142,6 +142,8 @@ typedef struct VFIOPCIDevice { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0bool no_kvm_intx; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0bool no_kvm_msi; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0bool no_kvm_msix; > + > +=C2=A0=C2=A0=C2=A0=C2=A0NotifierWithReturn hotplug_notifier; > =C2=A0} VFIOPCIDevice; > =C2=A0 > =C2=A0uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int > len); > diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h > index 403fec6..7812fa9 100644 > --- a/include/hw/pci/pci_bus.h > +++ b/include/hw/pci/pci_bus.h > @@ -39,8 +39,13 @@ struct PCIBus { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Keep a count of the num= ber of devices with raised IRQs.=C2=A0=C2=A0*/ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0int nirq; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0int *irq_count; > + > +=C2=A0=C2=A0=C2=A0=C2=A0NotifierWithReturnList hotplug_notifiers; > =C2=A0}; > =C2=A0 > +void pci_bus_add_hotplug_notifier(PCIBus *bus, NotifierWithReturn > *notify); > +void pci_bus_remove_hotplug_notifier(NotifierWithReturn *notify); > + > =C2=A0typedef struct PCIBridgeWindows PCIBridgeWindows; > =C2=A0 > =C2=A0/*