From: "Jan Beulich" Subject: [PATCH] x86/MSI: fix error handling Date: Wed, 25 Mar 2015 16:23:59 +0000 Message-ID: <5512EF2F020000780006D8F3@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC1F58B0F.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yao66-0004CR-Rw for xen-devel@lists.xenproject.org; Wed, 25 Mar 2015 16:24:03 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartC1F58B0F.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline __setup_msi_irq() needs to undo what it did before calling write_msi_msg() in case that returned an error. map_domain_pirq() needs to get rid of the MSI descriptor it (implicitly) allocated. The case of a setup_msi_irq() failure on a non-initial multi-vector-MSI interrupt needs special handling: While the initial IRQ will get freed by the caller (who also passed it to us), we need to undo the effect setup_msi_irq() had on it. (As a benefit from the added call to msi_free_irq() we no longer need to explicitly call destroy_irq() on the non-initial slots.) Signed-off-by: Jan Beulich --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -1974,6 +1974,8 @@ int map_domain_pirq( dprintk(XENLOG_G_ERR, "dom%d: irq %d in use\n", d->domain_id, irq); pci_disable_msi(msi_desc); + msi_desc->irq =3D -1; + msi_free_irq(msi_desc); ret =3D -EBUSY; goto done; } @@ -2028,22 +2030,29 @@ int map_domain_pirq( if ( ret ) { spin_unlock_irqrestore(&desc->lock, flags); + pci_disable_msi(msi_desc); + if ( nr ) + { + ASSERT(msi_desc->irq >=3D 0); + desc =3D irq_to_desc(msi_desc->irq); + spin_lock_irqsave(&desc->lock, flags); + desc->handler =3D &no_irq_type; + desc->msi_desc =3D NULL; + spin_unlock_irqrestore(&desc->lock, flags); + } while ( nr-- ) { - if ( irq >=3D 0 ) - { - if ( irq_deny_access(d, irq) ) - printk(XENLOG_G_ERR - "dom%d: could not revoke access to IRQ%d = (pirq %d)\n", - d->domain_id, irq, pirq); - destroy_irq(irq); - } + if ( irq >=3D 0 && irq_deny_access(d, irq) ) + printk(XENLOG_G_ERR + "dom%d: could not revoke access to IRQ%d (pirq = %d)\n", + d->domain_id, irq, pirq); if ( info ) cleanup_domain_irq_pirq(d, irq, info); info =3D pirq_info(d, pirq + nr); irq =3D info->arch.irq; } - pci_disable_msi(msi_desc); + msi_desc->irq =3D -1; + msi_free_irq(msi_desc); goto done; } =20 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -561,6 +561,7 @@ static struct msi_desc *alloc_msi_entry( while ( nr-- ) { entry[nr].dev =3D NULL; + entry[nr].irq =3D -1; entry[nr].remap_index =3D -1; } =20 @@ -578,11 +579,19 @@ int __setup_msi_irq(struct irq_desc *des hw_irq_controller *handler) { struct msi_msg msg; + int ret; =20 desc->msi_desc =3D msidesc; desc->handler =3D handler; msi_compose_msg(desc->arch.vector, desc->arch.cpu_mask, &msg); - return write_msi_msg(msidesc, &msg); + ret =3D write_msi_msg(msidesc, &msg); + if ( unlikely(ret) ) + { + desc->handler =3D &no_irq_type; + desc->msi_desc =3D NULL; + } + + return ret; } =20 int msi_free_irq(struct msi_desc *entry) @@ -592,7 +601,8 @@ int msi_free_irq(struct msi_desc *entry) =20 while ( nr-- ) { - destroy_irq(entry[nr].irq); + if ( entry[nr].irq >=3D 0 ) + destroy_irq(entry[nr].irq); =20 /* Free the unused IRTE if intr remap enabled */ if ( iommu_intremap ) --=__PartC1F58B0F.1__= Content-Type: text/plain; name="x86-MSI-error-paths.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-MSI-error-paths.patch" x86/MSI: fix error handling=0A=0A__setup_msi_irq() needs to undo what it = did before calling=0Awrite_msi_msg() in case that returned an error.=0A=0Am= ap_domain_pirq() needs to get rid of the MSI descriptor it=0A(implicitly) = allocated. The case of a setup_msi_irq() failure on a=0Anon-initial = multi-vector-MSI interrupt needs special handling: While=0Athe initial IRQ = will get freed by the caller (who also passed it to=0Aus), we need to undo = the effect setup_msi_irq() had on it. (As a=0Abenefit from the added call = to msi_free_irq() we no longer need to=0Aexplicitly call destroy_irq() on = the non-initial slots.)=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/irq.c=0A+++ b/xen/arch/x86/irq.c=0A@@ -1974,6 = +1974,8 @@ int map_domain_pirq(=0A dprintk(XENLOG_G_ERR, = "dom%d: irq %d in use\n",=0A d->domain_id, irq);=0A = pci_disable_msi(msi_desc);=0A+ msi_desc->irq =3D = -1;=0A+ msi_free_irq(msi_desc);=0A ret =3D = -EBUSY;=0A goto done;=0A }=0A@@ -2028,22 +2030,29 @@ = int map_domain_pirq(=0A if ( ret )=0A {=0A = spin_unlock_irqrestore(&desc->lock, flags);=0A+ pci_disable_msi(= msi_desc);=0A+ if ( nr )=0A+ {=0A+ = ASSERT(msi_desc->irq >=3D 0);=0A+ desc =3D irq_to_desc(msi_d= esc->irq);=0A+ spin_lock_irqsave(&desc->lock, flags);=0A+ = desc->handler =3D &no_irq_type;=0A+ desc->msi_d= esc =3D NULL;=0A+ spin_unlock_irqrestore(&desc->lock, = flags);=0A+ }=0A while ( nr-- )=0A = {=0A- if ( irq >=3D 0 )=0A- {=0A- = if ( irq_deny_access(d, irq) )=0A- = printk(XENLOG_G_ERR=0A- "dom%d: could not = revoke access to IRQ%d (pirq %d)\n",=0A- = d->domain_id, irq, pirq);=0A- destroy_irq(irq);=0A- = }=0A+ if ( irq >=3D 0 && irq_deny_access(d, irq) = )=0A+ printk(XENLOG_G_ERR=0A+ = "dom%d: could not revoke access to IRQ%d (pirq %d)\n",=0A+ = d->domain_id, irq, pirq);=0A if ( info )=0A = cleanup_domain_irq_pirq(d, irq, info);=0A = info =3D pirq_info(d, pirq + nr);=0A irq =3D info->arch.irq= ;=0A }=0A- pci_disable_msi(msi_desc);=0A+ = msi_desc->irq =3D -1;=0A+ msi_free_irq(msi_desc);=0A = goto done;=0A }=0A =0A--- a/xen/arch/x86/msi.c=0A+++ b/xen/arch/x= 86/msi.c=0A@@ -561,6 +561,7 @@ static struct msi_desc *alloc_msi_entry(=0A = while ( nr-- )=0A {=0A entry[nr].dev =3D NULL;=0A+ = entry[nr].irq =3D -1;=0A entry[nr].remap_index =3D -1;=0A }=0A = =0A@@ -578,11 +579,19 @@ int __setup_msi_irq(struct irq_desc *des=0A = hw_irq_controller *handler)=0A {=0A struct msi_msg = msg;=0A+ int ret;=0A =0A desc->msi_desc =3D msidesc;=0A = desc->handler =3D handler;=0A msi_compose_msg(desc->arch.vector, = desc->arch.cpu_mask, &msg);=0A- return write_msi_msg(msidesc, &msg);=0A+= ret =3D write_msi_msg(msidesc, &msg);=0A+ if ( unlikely(ret) )=0A+ = {=0A+ desc->handler =3D &no_irq_type;=0A+ desc->msi_desc = =3D NULL;=0A+ }=0A+=0A+ return ret;=0A }=0A =0A int msi_free_irq(stru= ct msi_desc *entry)=0A@@ -592,7 +601,8 @@ int msi_free_irq(struct msi_desc = *entry)=0A =0A while ( nr-- )=0A {=0A- destroy_irq(entry[nr]= .irq);=0A+ if ( entry[nr].irq >=3D 0 )=0A+ destroy_irq(en= try[nr].irq);=0A =0A /* Free the unused IRTE if intr remap enabled = */=0A if ( iommu_intremap )=0A --=__PartC1F58B0F.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartC1F58B0F.1__=--