Skip to contentSkip to conversation

x86/MSI: fix guest unmasking when handling IRQ via event channel

PATCH In review Jan Beulich 5 participants 10 messages Jul 8, 2015 – Jul 10, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/MSI: fix guest unmasking when handling IRQ via event channel

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.

xen/arch/x86/irq.c +19 -0
@@ -2502,6 +2502,25 @@ int unmap_domain_pirq_emuirq(struct doma
     return ret;
 }
 
+void arch_evtchn_bind_pirq(struct domain *d, int pirq)
+{
+    int irq = domain_pirq_to_irq(d, pirq);
+    struct irq_desc *desc;
+    unsigned long flags;
+
+    if ( irq <= 0 )
+        return;
+
+    if ( is_hvm_domain(d) )
+        map_domain_emuirq_pirq(d, pirq, IRQ_PT);
+
+    desc = 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 &&
xen/arch/x86/msi.c +1 -4
@@ -422,10 +422,7 @@ void guest_mask_msi_irq(struct irq_desc 
 
 static unsigned int startup_msi_irq(struct irq_desc *desc)
 {
-    bool_t guest_masked = (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;
 }
 
xen/common/event_channel.c +1 -4
@@ -502,10 +502,7 @@ static long evtchn_bind_pirq(evtchn_bind
 
     bind->port = port;
 
-#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);
 
  out:
     spin_unlock(&d->event_lock);
xen/include/asm-arm/irq.h +2 -0
@@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d, 
 
 void arch_move_irqs(struct vcpu *v);
 
+#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);
 
xen/include/xen/irq.h +4 -0
@@ -172,4 +172,8 @@ unsigned int set_desc_affinity(struct ir
 unsigned int arch_hwdom_irqs(domid_t);
 #endif
 
+#ifndef arch_evtchn_bind_pirq
+void arch_evtchn_bind_pirq(struct domain *, int pirq);
+#endif
+
 #endif /* __XEN_IRQ_H__ */

x86/MSI: fix guest unmasking when handling IRQ via event channel

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.

xen/arch/x86/irq.c +19 -0
@@ -2502,6 +2502,25 @@ int unmap_domain_pirq_emuirq(struct doma
     return ret;
 }
 
+void arch_evtchn_bind_pirq(struct domain *d, int pirq)
+{
+    int irq = domain_pirq_to_irq(d, pirq);
+    struct irq_desc *desc;
+    unsigned long flags;
+
+    if ( irq <= 0 )
+        return;
+
+    if ( is_hvm_domain(d) )
+        map_domain_emuirq_pirq(d, pirq, IRQ_PT);
+
+    desc = 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 &&
xen/arch/x86/msi.c +1 -4
@@ -422,10 +422,7 @@ void guest_mask_msi_irq(struct irq_desc 
 
 static unsigned int startup_msi_irq(struct irq_desc *desc)
 {
-    bool_t guest_masked = (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;
 }
 
xen/common/event_channel.c +1 -4
@@ -502,10 +502,7 @@ static long evtchn_bind_pirq(evtchn_bind
 
     bind->port = port;
 
-#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);
 
  out:
     spin_unlock(&d->event_lock);
xen/include/asm-arm/irq.h +2 -0
@@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d, 
 
 void arch_move_irqs(struct vcpu *v);
 
+#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);
 
xen/include/xen/irq.h +4 -0
@@ -172,4 +172,8 @@ unsigned int set_desc_affinity(struct ir
 unsigned int arch_hwdom_irqs(domid_t);
 #endif
 
+#ifndef arch_evtchn_bind_pirq
+void arch_evtchn_bind_pirq(struct domain *, int pirq);
+#endif
+
 #endif /* __XEN_IRQ_H__ */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jan Beulich

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.

#2 lore raw
In reply to Jan Beulich

Hi,

xen/include/asm-arm/irq.h int release_guest_irq(struct domain *d, · line 51

Quoted 8 lines · Jan Beulich
xen/include/asm-arm/irq.h +2 -0
@@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d,
 
  void arch_move_irqs(struct vcpu *v);
 
+#define arch_evtchn_bind_pirq(d, pirq) ((void)((d) + (pirq)))
+

This addition is here in order to ensure that d and pirq are evaluated, right?

If so, I didn't find it obvious to understand. Why didn't you use a static inline? Or maybe add a comment explicitly say this is not implemented.

Regards,

Signature · 1 line
Julien Grall
#3 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 08.07.15 at 11:07, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/include/asm-arm/irq.h +0 -0
@@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d,
 
Quoted 7 lines

xen/include/asm-arm/irq.h int release_guest_irq(struct domain *d, · line 51

Quoted 4 lines
xen/include/asm-arm/irq.h +2 -0
  void arch_move_irqs(struct vcpu *v);
 
+#define arch_evtchn_bind_pirq(d, pirq) ((void)((d) + (pirq)))
+

This addition is here in order to ensure that d and pirq are evaluated, right?

Sure.

Quoted 3 lines

If so, I didn't find it obvious to understand. Why didn't you use a static inline? Or maybe add a comment explicitly say this is not implemented.

A static inline could be used in this case, yes. But I see no significant advantages. As to the comment - it is implemented, it's just a no-op. And stating that it is a no-op would be redundant with it obviously being so by looking at it.

Jan

#4 lore raw
Quoted 16 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 08.07.15 at 11:07, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/include/asm-arm/irq.h +0 -0
@@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d,
 
Quoted 7 lines

xen/include/asm-arm/irq.h int release_guest_irq(struct domain *d, · line 51

Quoted 4 lines
xen/include/asm-arm/irq.h +2 -0
   void arch_move_irqs(struct vcpu *v);
 
+#define arch_evtchn_bind_pirq(d, pirq) ((void)((d) + (pirq)))
+

This addition is here in order to ensure that d and pirq are evaluated, right?

Sure.

Quoted 8 lines
Quoted 3 lines

If so, I didn't find it obvious to understand. Why didn't you use a static inline? Or maybe add a comment explicitly say this is not implemented.

A static inline could be used in this case, yes. But I see no significant advantages. As to the comment - it is implemented, it's just a no-op. And stating that it is a no-op would be redundant with it obviously being so by looking at it.

It's not so obvious as I asked about it.

The first thing I saw was (d) + (pirq) and I though : "Why do we want to add a domain with a pirq?". I only see after the (void) and it just because I remembered we talked about similar case a year ago.

Having a comment doesn't hurt and help the comprehension.

Signature · 1 line
Julien Grall
#5 lore raw
In reply to Jan Beulich
Quoted 7 lines · Jan Beulich

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.

Can you describe the symptoms of the bug being fixed here?

xen/include/asm-arm/irq.h int release_guest_irq(struct domain *d, · line 50

Quoted 7 lines
xen/include/asm-arm/irq.h +1 -0
@@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d, 
 
 void arch_move_irqs(struct vcpu *v);
 
+#define arch_evtchn_bind_pirq(d, pirq) ((void)((d) + (pirq)))

Would this be better as a inline function?

xen/include/xen/irq.h unsigned int set_desc_affinity(struct ir · line 176

Quoted 12 lines
xen/include/asm-arm/irq.h +1 -0
+
 /* Set IRQ type for an SPI */
 int irq_set_spi_type(unsigned int spi, unsigned int type);
 
xen/include/xen/irq.h +2 -0
@@ -172,4 +172,8 @@ unsigned int set_desc_affinity(struct ir
 unsigned int arch_hwdom_irqs(domid_t);
 #endif
 
+#ifndef arch_evtchn_bind_pirq
+void arch_evtchn_bind_pirq(struct domain *, int pirq);

... moving this into xen/include/asm-x86/irq.h

David

#6 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 08.07.15 at 11:39, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich

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.

Can you describe the symptoms of the bug being fixed here?

Interrupts simply didn't get unmasked for PVHVM Linux guests.

Quoted 20 lines

xen/include/asm-arm/irq.h int release_guest_irq(struct domain *d, · line 50

Quoted 7 lines
xen/include/asm-arm/irq.h +1 -0
@@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d, 
 
 void arch_move_irqs(struct vcpu *v);
 
+#define arch_evtchn_bind_pirq(d, pirq) ((void)((d) + (pirq)))

Would this be better as a inline function?

Quoted 10 lines
xen/include/asm-arm/irq.h +1 -0
+
 /* Set IRQ type for an SPI */
 int irq_set_spi_type(unsigned int spi, unsigned int type);
 
xen/include/xen/irq.h +0 -0
@@ -172,4 +172,8 @@ unsigned int set_desc_affinity(struct ir
 unsigned int arch_hwdom_irqs(domid_t);
 #endif
 
Quoted 4 lines

xen/include/xen/irq.h unsigned int set_desc_affinity(struct ir · line 176

Quoted 2 lines
xen/include/xen/irq.h +2 -0
+#ifndef arch_evtchn_bind_pirq
+void arch_evtchn_bind_pirq(struct domain *, int pirq);

... moving this into xen/include/asm-x86/irq.h

Oh, right, (also to Julien) - this is exactly the reason I do not want it to be an inline function for ARM: I want the declaration here, not replicated in every interested arch's header.

Jan

#7 lore raw
Quoted 34 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 08.07.15 at 11:39, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich

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.

Can you describe the symptoms of the bug being fixed here?

Interrupts simply didn't get unmasked for PVHVM Linux guests.

Quoted 20 lines

xen/include/asm-arm/irq.h int release_guest_irq(struct domain *d, · line 50

Quoted 7 lines
xen/include/asm-arm/irq.h +1 -0
@@ -47,6 +47,8 @@ int release_guest_irq(struct domain *d, 
 
 void arch_move_irqs(struct vcpu *v);
 
+#define arch_evtchn_bind_pirq(d, pirq) ((void)((d) + (pirq)))

Would this be better as a inline function?

Quoted 10 lines
xen/include/asm-arm/irq.h +1 -0
+
 /* Set IRQ type for an SPI */
 int irq_set_spi_type(unsigned int spi, unsigned int type);
 
xen/include/xen/irq.h +0 -0
@@ -172,4 +172,8 @@ unsigned int set_desc_affinity(struct ir
 unsigned int arch_hwdom_irqs(domid_t);
 #endif
 
Quoted 8 lines
Quoted 4 lines

xen/include/xen/irq.h unsigned int set_desc_affinity(struct ir · line 176

Quoted 2 lines
xen/include/xen/irq.h +2 -0
+#ifndef arch_evtchn_bind_pirq
+void arch_evtchn_bind_pirq(struct domain *, int pirq);

... moving this into xen/include/asm-x86/irq.h

Oh, right, (also to Julien) - this is exactly the reason I do not want it to be an inline function for ARM: I want the declaration here, not replicated in every interested arch's header.

Ok.

FWIW, with this requirement I would (instead of the macros) add a weak arch_evtchn_bind_pirq() that's a no-op.

David

#8 lore raw
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 08.07.15 at 13:14, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 08.07.15 at 11:39, <[email protected]> wrote:

xen/include/xen/irq.h unsigned int set_desc_affinity(struct ir · line 176

Quoted 12 lines · Jan Beulich
xen/include/asm-arm/irq.h +1 -0
+
 /* Set IRQ type for an SPI */
 int irq_set_spi_type(unsigned int spi, unsigned int type);
xen/include/xen/irq.h +2 -0
@@ -172,4 +172,8 @@ unsigned int set_desc_affinity(struct ir
 unsigned int arch_hwdom_irqs(domid_t);
 #endif
 
+#ifndef arch_evtchn_bind_pirq
+void arch_evtchn_bind_pirq(struct domain *, int pirq);

... moving this into xen/include/asm-x86/irq.h

Quoted 8 lines
Quoted 3 lines

Oh, right, (also to Julien) - this is exactly the reason I do not want it to be an inline function for ARM: I want the declaration here, not replicated in every interested arch's header.

Ok.

FWIW, with this requirement I would (instead of the macros) add a weak arch_evtchn_bind_pirq() that's a no-op.

Yeah, that's how Linux likes to do it. But we learned the hard way that weak conflicts with our making symbols hidden by default, so no, weak is not an option either I'm afraid.

Jan

#9 lore raw
In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

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.

For the ARM impact; Acked-by: Ian Campbell <[email protected]>