From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDu5z-0001AM-6v for qemu-devel@nongnu.org; Sat, 31 Mar 2012 04:55:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDu5x-0004h4-E1 for qemu-devel@nongnu.org; Sat, 31 Mar 2012 04:55:38 -0400 Received: from fmmailgate05.web.de ([217.72.192.243]:48825) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDu5x-0004gx-4c for qemu-devel@nongnu.org; Sat, 31 Mar 2012 04:55:37 -0400 Received: from moweb002.kundenserver.de (moweb002.kundenserver.de [172.19.20.108]) by fmmailgate05.web.de (Postfix) with ESMTP id 4B0116BDE371 for ; Sat, 31 Mar 2012 10:54:07 +0200 (CEST) Message-ID: <4F76C62A.5040904@web.de> Date: Sat, 31 Mar 2012 10:54:02 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <201203301918.q2UJI63c005908@int-mx02.intmail.prod.int.phx2.redhat.com> In-Reply-To: <201203301918.q2UJI63c005908@int-mx02.intmail.prod.int.phx2.redhat.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigA041FE2DB2DE1D87BA74E95A" Subject: Re: [Qemu-devel] [PATCH] kvm: deassign irqs in reset path List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Baron Cc: alex.williamson@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, mst@redhat.com This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigA041FE2DB2DE1D87BA74E95A Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable On 2012-03-30 21:18, Jason Baron wrote: > diff --git a/hw/device-assignment.c b/hw/device-assignment.c > index 89823f1..31aed17 100644 > --- a/hw/device-assignment.c > +++ b/hw/device-assignment.c > @@ -1609,10 +1609,32 @@ static void reset_assigned_device(DeviceState *= dev) > { > PCIDevice *pci_dev =3D DO_UPCAST(PCIDevice, qdev, dev); > AssignedDevice *adev =3D DO_UPCAST(AssignedDevice, dev, pci_dev); > + struct kvm_assigned_irq assigned_irq_data; > char reset_file[64]; > const char reset[] =3D "1"; > int fd, ret; > =20 > + /* > + * Make sure the irq for the device is set to a consistent state o= f INTx > + * on reset. This also ensures that a subsequent deassign_irq/assi= gn_irq > + * sequence (such as during 'system_reset'), does not touch memory= > + * mapped msi space, since we are about to disallow that access vi= a a > + * 0 write to the command register. In addition, the 'kvm_deassign= _irq()' > + * clears the msi enable bit, thus preventing any unexpected MSIs.= > + */ > + memset(&assigned_irq_data, 0, sizeof assigned_irq_data); > + assigned_irq_data.assigned_dev_id =3D > + calc_assigned_dev_id(adev); > + assigned_irq_data.flags =3D adev->irq_requested_type; > + free_dev_irq_entries(adev); > + ret =3D kvm_deassign_irq(kvm_state, &assigned_irq_data); > + /* -ENXIO means no assigned irq */ > + if (ret && ret !=3D -ENXIO) { > + perror("reset_assigned_device: deassign irq"); > + } > + > + adev->irq_requested_type =3D 0; > + What is actually missing here, independent of the kernel bug you saw, is a proper reset of the MSI[-X] control flags followed by a call to our update handlers. The day we stop open-coding MSI support here, that will be triggered by the MSI layer, but for now we need a if (requested_type =3D=3D MSI) clear_msi_in_shadow_cap update_msi else if (requested_type =3D=3D MSIX) clear_msix_in_shadow_cap update_msix Or, better, fix the update handlers to allow unconditional clear_msi_in_shadow_cap update_msi clear_msix_in_shadow_cap update_msix because that is the pattern we will once get from a refactored version anyway where msi[x]_reset will be invoked automatically. But we also need to calm down the PCI error handling to not get hysteric over untrusted devices. Jan --------------enigA041FE2DB2DE1D87BA74E95A Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk92xiwACgkQitSsb3rl5xT2oACgjNwDbM1nieuMoJ+O6EF9yJhb lGoAnR4jyJTfIkAe2KWzeWbv23yslnz1 =MzoL -----END PGP SIGNATURE----- --------------enigA041FE2DB2DE1D87BA74E95A--