From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYq2p-0000vs-IU for qemu-devel@nongnu.org; Fri, 20 Mar 2015 02:04:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYq2j-0007sB-98 for qemu-devel@nongnu.org; Fri, 20 Mar 2015 02:04:31 -0400 Date: Fri, 20 Mar 2015 17:04:01 +1100 From: David Gibson Message-ID: <20150320060401.GY5741@voom.redhat.com> References: <1426523486-9794-1-git-send-email-gwshan@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="z8OPzjJiggy3JOV2" Content-Disposition: inline In-Reply-To: <1426523486-9794-1-git-send-email-gwshan@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v2 1/3] VFIO: Clear stale MSIx table during EEH reset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gavin Shan Cc: aik@ozlabs.ru, qemu-devel@nongnu.org, agraf@suse.de, alex.williamson@redhat.com, qemu-ppc@nongnu.org --z8OPzjJiggy3JOV2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 17, 2015 at 03:31:24AM +1100, Gavin Shan wrote: > The PCI device MSIx table is cleaned out in hardware after EEH PE > reset. However, we still hold the stale MSIx entries in QEMU, which > should be cleared accordingly. Otherwise, we will run into another > (recursive) EEH error and the PCI devices contained in the PE have > to be offlined exceptionally. >=20 > The patch clears stale MSIx table before EEH PE reset so that MSIx > table could be restored properly after EEH PE reset. >=20 > Signed-off-by: Gavin Shan > --- > v2: vfio_container_eeh_event() stub for !CONFIG_PCI and separate > error message for this function. Dropped vfio_put_group() > on NULL group > --- > hw/vfio/Makefile.objs | 6 +++++- > hw/vfio/common.c | 7 +++++++ > hw/vfio/pci-stub.c | 17 +++++++++++++++++ > hw/vfio/pci.c | 38 ++++++++++++++++++++++++++++++++++++++ > include/hw/vfio/vfio.h | 2 ++ > 5 files changed, 69 insertions(+), 1 deletion(-) > create mode 100644 hw/vfio/pci-stub.c >=20 > diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs > index e31f30e..1b8a065 100644 > --- a/hw/vfio/Makefile.objs > +++ b/hw/vfio/Makefile.objs > @@ -1,4 +1,8 @@ > ifeq ($(CONFIG_LINUX), y) > obj-$(CONFIG_SOFTMMU) +=3D common.o > -obj-$(CONFIG_PCI) +=3D pci.o > +ifeq ($(CONFIG_PCI), y) > +obj-y +=3D pci.o > +else > +obj-y +=3D pci-stub.o > +endif > endif > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > index 148eb53..ed07814 100644 > --- a/hw/vfio/common.c > +++ b/hw/vfio/common.c > @@ -949,7 +949,14 @@ int vfio_container_ioctl(AddressSpace *as, int32_t g= roupid, > switch (req) { > case VFIO_CHECK_EXTENSION: > case VFIO_IOMMU_SPAPR_TCE_GET_INFO: > + break; > case VFIO_EEH_PE_OP: > + if (vfio_container_eeh_event(as, groupid, param) !=3D 0) { I really dislike the idea of having an arbitrarily complex side effect =66rom a function whose name suggest's it's just a trivial wrapper around the ioctl(). > + error_report("vfio: cannot handle EEH event on group %d\n", > + groupid); > + return -1; > + } > + > break; > default: > /* Return an error on unknown requests */ > diff --git a/hw/vfio/pci-stub.c b/hw/vfio/pci-stub.c > new file mode 100644 > index 0000000..7726a7a > --- /dev/null > +++ b/hw/vfio/pci-stub.c > @@ -0,0 +1,17 @@ > +/* > + * To include the file on !CONFIG_PCI > + * > + * This work is licensed under the terms of the GNU GPL, version 2. See > + * the COPYING file in the top-level directory. > + */ > + > +#include > + > +#include "exec/memory.h" > +#include "hw/vfio/vfio.h" > + > +int vfio_container_eeh_event(AddressSpace *as, int32_t groupid, > + struct vfio_eeh_pe_op *op) > +{ > + return -1; > +} > diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c > index 6b80539..fca1edc 100644 > --- a/hw/vfio/pci.c > +++ b/hw/vfio/pci.c > @@ -3319,6 +3319,44 @@ static void vfio_unregister_req_notifier(VFIOPCIDe= vice *vdev) > vdev->req_enabled =3D false; > } > =20 > +int vfio_container_eeh_event(AddressSpace *as, int32_t groupid, > + struct vfio_eeh_pe_op *op) > +{ > + VFIOGroup *group; > + VFIODevice *vbasedev; > + VFIOPCIDevice *vdev; > + > + group =3D vfio_get_group(groupid, as); > + if (!group) { > + error_report("vfio: group %d not found\n", groupid); > + return -1; > + } > + > + switch (op->op) { > + case VFIO_EEH_PE_RESET_HOT: > + case VFIO_EEH_PE_RESET_FUNDAMENTAL: > + /* > + * The MSIx table will be cleaned out by reset. We need > + * disable it so that it can be reenabled properly. Also, > + * the cached MSIx table should be cleared as it's not > + * reflecting the contents in hardware. > + */ > + QLIST_FOREACH(vbasedev, &group->device_list, next) { > + vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev); > + if (msix_enabled(&vdev->pdev)) { > + vfio_disable_msix(vdev); > + } > + > + msix_reset(&vdev->pdev); > + } > + > + break; > + } > + > + vfio_put_group(group); > + return 0; > +} > + > static int vfio_initfn(PCIDevice *pdev) > { > VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); > diff --git a/include/hw/vfio/vfio.h b/include/hw/vfio/vfio.h > index 0b26cd8..e9a3abb 100644 > --- a/include/hw/vfio/vfio.h > +++ b/include/hw/vfio/vfio.h > @@ -5,5 +5,7 @@ > =20 > extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid, > int req, void *param); > +extern int vfio_container_eeh_event(AddressSpace *as, int32_t groupid, > + struct vfio_eeh_pe_op *op); > =20 > #endif --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --z8OPzjJiggy3JOV2 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVC7hRAAoJEGw4ysog2bOSUwgP/1tWEqXhUuDQNy+qJYHV+aVU K0+7uWPeRKDrZPdON8XRYEkx21QqNGnx35C0xue5DLWXID6yd5cPK0qUKzHPrrNL DDi9REVq6Aqh8tL9mtB8AH1+8swucqdG2E/e8sSPhoU/7+2fYCChZPWyXN6sD0KN rqV6SVHmmXATOKKzPmwbhrVF1GbTV4EiXn4MlEG7NvdGINmeiZl0wbwKEizX0Ae8 69KX+CKNgJD479nY9qffrmbBCHxcYuJ9lXNJrByi8tkseDLrWHqMoklnGOmzfDPo wTPyTa/3r1gbUtbX/Ih6+MhagNu6/DjlsjwEPG8+18pgMrI3VxEe8m7BRWAeSUt1 7dI/a6c0cBiRzHBhSAKJuD32Ks3nqNOOFgaDVxuZ+xwu0D+BuhfcSqeZaWqUA+3x dOBJMYtkIcPALUwbXkEy2Sxl0yZ2wXWQWov/xTK2D8HobOdCy+F923HVr8RkGn/A UULvwitDGKIzVfDdmjZ54OmZGgmlOe33vJvwB4vj1Iw990PRlP/1EEloKoZ2t9Dc FulfHY11OIVc0CveIGwFHDzqB3a1KE++doNYr7eyBCBF0v1SSJXUlzQ+0ErVWH3F GbTiQtkTnvAQuNa+Q0SbKNlp1aEdpRUkFlRP4IU2YFsjs0CE18v0XPEy89qCVd37 cZwO00thj5XSRhrcmkiU =AP/k -----END PGP SIGNATURE----- --z8OPzjJiggy3JOV2--