From: "Jan Beulich" Subject: [PATCH] x86/MSI: fix guest unmasking when handling IRQ via event channel Date: Wed, 08 Jul 2015 09:56:30 +0100 Message-ID: <559D01DE020000780008E03C@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartEADE2EAE.3__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZCl9e-0004LA-33 for xen-devel@lists.xenproject.org; Wed, 08 Jul 2015 08:56:34 +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: Keir Fraser , Stefano Stabellini , Andrew Cooper , Ian Jackson , Tim Deegan , Ian Campbell , Sander Eikelenboom 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. --=__PartEADE2EAE.3__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Rather than assuming only PV guests need special treatment (and dealing with that directly when an IRQ gets set up), keep all guest MSI IRQs masked until either the (HVM) guest unmasks them via vMSI or the (PV, PVHVM, or PVH) guest sets up an event channel for it. To not further clutter the common evtchn_bind_pirq() with x86-specific code, introduce an arch_evtchn_bind_pirq() hook instead. Reported-by: Sander Eikelenboom Signed-off-by: Jan Beulich Tested-by: Sander Eikelenboom --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -2502,6 +2502,25 @@ int unmap_domain_pirq_emuirq(struct doma return ret; } =20 +void arch_evtchn_bind_pirq(struct domain *d, int pirq) +{ + int irq =3D domain_pirq_to_irq(d, pirq); + struct irq_desc *desc; + unsigned long flags; + + if ( irq <=3D 0 ) + return; + + if ( is_hvm_domain(d) ) + map_domain_emuirq_pirq(d, pirq, IRQ_PT); + + desc =3D irq_to_desc(irq); + spin_lock_irqsave(&desc->lock, flags); + if ( desc->msi_desc ) + guest_mask_msi_irq(desc, 0); + spin_unlock_irqrestore(&desc->lock, flags); +} + bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq = *pirq) { return is_hvm_domain(d) && pirq && --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -422,10 +422,7 @@ void guest_mask_msi_irq(struct irq_desc=20 =20 static unsigned int startup_msi_irq(struct irq_desc *desc) { - bool_t guest_masked =3D (desc->status & IRQ_GUEST) && - is_hvm_domain(desc->msi_desc->dev->domain); - - msi_set_mask_bit(desc, 0, guest_masked); + msi_set_mask_bit(desc, 0, !!(desc->status & IRQ_GUEST)); return 0; } =20 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -502,10 +502,7 @@ static long evtchn_bind_pirq(evtchn_bind =20 bind->port =3D port; =20 -#ifdef CONFIG_X86 - if ( is_hvm_domain(d) && domain_pirq_to_irq(d, pirq) > 0 ) - map_domain_emuirq_pirq(d, pirq, IRQ_PT); -#endif + arch_evtchn_bind_pirq(d, pirq); =20 out: spin_unlock(&d->event_lock); --- a/xen/include/asm-arm/irq.h +++ b/xen/include/asm-arm/irq.h @@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d,=20 =20 void arch_move_irqs(struct vcpu *v); =20 +#define arch_evtchn_bind_pirq(d, pirq) ((void)((d) + (pirq))) + /* Set IRQ type for an SPI */ int irq_set_spi_type(unsigned int spi, unsigned int type); =20 --- a/xen/include/xen/irq.h +++ b/xen/include/xen/irq.h @@ -172,4 +172,8 @@ unsigned int set_desc_affinity(struct ir unsigned int arch_hwdom_irqs(domid_t); #endif =20 +#ifndef arch_evtchn_bind_pirq +void arch_evtchn_bind_pirq(struct domain *, int pirq); +#endif + #endif /* __XEN_IRQ_H__ */ --=__PartEADE2EAE.3__= Content-Type: text/plain; name="x86-MSI-pv-unmask.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-MSI-pv-unmask.patch" x86/MSI: fix guest unmasking when handling IRQ via event channel=0A=0ARathe= r than assuming only PV guests need special treatment (and=0Adealing with = that directly when an IRQ gets set up), keep all guest MSI=0AIRQs masked = until either the (HVM) guest unmasks them via vMSI or the=0A(PV, PVHVM, or = PVH) guest sets up an event channel for it.=0A=0ATo not further clutter = the common evtchn_bind_pirq() with x86-specific=0Acode, introduce an = arch_evtchn_bind_pirq() hook instead.=0A=0AReported-by: Sander Eikelenboom = =0ASigned-off-by: Jan Beulich =0AT= ested-by: Sander Eikelenboom =0A=0A--- a/xen/arch/x86= /irq.c=0A+++ b/xen/arch/x86/irq.c=0A@@ -2502,6 +2502,25 @@ int unmap_domain= _pirq_emuirq(struct doma=0A return ret;=0A }=0A =0A+void arch_evtchn_bi= nd_pirq(struct domain *d, int pirq)=0A+{=0A+ int irq =3D domain_pirq_to_= irq(d, pirq);=0A+ struct irq_desc *desc;=0A+ unsigned long flags;=0A+= =0A+ if ( irq <=3D 0 )=0A+ return;=0A+=0A+ if ( is_hvm_domain(= d) )=0A+ map_domain_emuirq_pirq(d, pirq, IRQ_PT);=0A+=0A+ desc = =3D irq_to_desc(irq);=0A+ spin_lock_irqsave(&desc->lock, flags);=0A+ = if ( desc->msi_desc )=0A+ guest_mask_msi_irq(desc, 0);=0A+ = spin_unlock_irqrestore(&desc->lock, flags);=0A+}=0A+=0A bool_t hvm_domain_u= se_pirq(const struct domain *d, const struct pirq *pirq)=0A {=0A = return is_hvm_domain(d) && pirq &&=0A--- a/xen/arch/x86/msi.c=0A+++ = b/xen/arch/x86/msi.c=0A@@ -422,10 +422,7 @@ void guest_mask_msi_irq(struct = irq_desc =0A =0A static unsigned int startup_msi_irq(struct irq_desc = *desc)=0A {=0A- bool_t guest_masked =3D (desc->status & IRQ_GUEST) = &&=0A- is_hvm_domain(desc->msi_desc->dev->domain);= =0A-=0A- msi_set_mask_bit(desc, 0, guest_masked);=0A+ msi_set_mask_bi= t(desc, 0, !!(desc->status & IRQ_GUEST));=0A return 0;=0A }=0A =0A--- = a/xen/common/event_channel.c=0A+++ b/xen/common/event_channel.c=0A@@ = -502,10 +502,7 @@ static long evtchn_bind_pirq(evtchn_bind=0A =0A = bind->port =3D port;=0A =0A-#ifdef CONFIG_X86=0A- if ( is_hvm_domain(d) = && domain_pirq_to_irq(d, pirq) > 0 )=0A- map_domain_emuirq_pirq(d, = pirq, IRQ_PT);=0A-#endif=0A+ arch_evtchn_bind_pirq(d, pirq);=0A =0A = out:=0A spin_unlock(&d->event_lock);=0A--- a/xen/include/asm-arm/irq.h= =0A+++ b/xen/include/asm-arm/irq.h=0A@@ -47,6 +47,8 @@ int release_guest_ir= q(struct domain *d, =0A =0A void arch_move_irqs(struct vcpu *v);=0A = =0A+#define arch_evtchn_bind_pirq(d, pirq) ((void)((d) + (pirq)))=0A+=0A = /* Set IRQ type for an SPI */=0A int irq_set_spi_type(unsigned int spi, = unsigned int type);=0A =0A--- a/xen/include/xen/irq.h=0A+++ b/xen/include/x= en/irq.h=0A@@ -172,4 +172,8 @@ unsigned int set_desc_affinity(struct ir=0A = unsigned int arch_hwdom_irqs(domid_t);=0A #endif=0A =0A+#ifndef arch_evtchn= _bind_pirq=0A+void arch_evtchn_bind_pirq(struct domain *, int pirq);=0A+#en= dif=0A+=0A #endif /* __XEN_IRQ_H__ */=0A --=__PartEADE2EAE.3__= 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 --=__PartEADE2EAE.3__=--