Skip to contentSkip to conversation

x86: Properly synchronise updates to pirq-to-vector mapping.

Xen-changelog Cui, Dexuan 3 participants 3 messages Sep 26, 2008 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

@@ -491,16 +512,15 @@ int pirq_guest_bind(struct vcpu *v, int

     int                 rc = 0;
     cpumask_t           cpumask = CPU_MASK_NONE;

+ WARN_ON(!spin_is_locked(&v->domain->evtchn_lock));

I find this WARN_ON() is triggered harmlessly when I assign device to HVM guest. The call trace is XEN_DOMCTL_bind_pt_irq -> pt_irq_create_bind_vtd() -> pirq_guest_bind(). Should we remove the WARN_ON here?

Thanks,
-- Dexuan

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Xen patchbot-unstable
Sent: 2008年9月26日 11:20
To: [email protected]
Subject: [Xen-changelog] [xen-unstable] x86: Properly synchronise updates to pirq-to-vector mapping.

# HG changeset patch
# User Keir Fraser <[email protected]>
# Date 1222256215 -3600
# Node ID 31f09a5e24cf8eb8a9d73acc6c23262fe9d463d7 # Parent 7750906b06b3ebbba529e6d1042d7a2a2712623c
x86: Properly synchronise updates to pirq-to-vector mapping.

Per-domain irq mappings are now protected by d->evtchn_lock and by the per-vector irq_desc lock.

---
 xen/arch/ia64/xen/irq.c      |   16 ++++--
 xen/arch/x86/domain.c        |    2
 xen/arch/x86/io_apic.c       |   11 ----
 xen/arch/x86/irq.c           |  112 ++++++++++++++++++++++++++++---------------
 xen/arch/x86/msi.c           |    1
 xen/arch/x86/physdev.c       |   96 +++++++++++++++++++-----------------
 xen/common/event_channel.c   |    3 -
 xen/include/asm-x86/domain.h |    2
 xen/include/asm-x86/irq.h    |    5 +
 xen/include/asm-x86/msi.h    |    2
 xen/include/xen/irq.h        |    3 -
 11 files changed, 142 insertions(+), 111 deletions(-)
xen/arch/ia64/xen/irq.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/arch/ia64/xen/irq.c Wed Sep 24 10:23:51 2008 +0100 +11 -5
diff -r 7750906b06b3 -r 31f09a5e24cf xen/arch/ia64/xen/irq.c
@@ -459,20 +459,24 @@ int pirq_guest_bind(struct vcpu *v, int
     return rc;
 }
 
-void pirq_guest_unbind(struct domain *d, int irq)
+int pirq_guest_unbind(struct domain *d, int irq)
 {
     irq_desc_t         *desc = &irq_desc[irq];
     irq_guest_action_t *action;
     unsigned long       flags;
-    int                 i;
+    int                 i, rc = 0;
 
     spin_lock_irqsave(&desc->lock, flags);
 
     action = (irq_guest_action_t *)desc->action;
 
-    i = 0;
-    while ( action->guest[i] && (action->guest[i] != d) )
-        i++;
+    for ( i = 0; (i < action->nr_guests) && (action->guest[i] != d); i++ )
+        continue;
+    if ( i == action->nr_guests )
+    {
+        rc = -EINVAL;
+        goto out;
+    }
     memmove(&action->guest[i], &action->guest[i+1], IRQ_MAX_GUESTS-i-1);
     action->nr_guests--;
 
@@ -492,7 +496,9 @@ void pirq_guest_unbind(struct domain *d,
         desc->handler->shutdown(irq);
     }
 
+ out:
     spin_unlock_irqrestore(&desc->lock, flags);
+    return rc;
 }
 
 void
xen/arch/x86/domain.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/arch/x86/domain.c Wed Sep 24 10:23:51 2008 +0100 +0 -2
diff -r 7750906b06b3 -r 31f09a5e24cf xen/arch/x86/domain.c
@@ -414,8 +414,6 @@ int arch_domain_create(struct domain *d,
             goto fail;
     }
 
-    spin_lock_init(&d->arch.irq_lock);
-
     if ( is_hvm_domain(d) )
     {
         if ( (rc = hvm_domain_initialise(d)) != 0 )
xen/arch/x86/io_apic.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/arch/x86/io_apic.c Wed Sep 24 10:23:51 2008 +0100 +0 -11
diff -r 7750906b06b3 -r 31f09a5e24cf xen/arch/x86/io_apic.c
@@ -45,16 +45,6 @@ int (*ioapic_renumber_irq)(int ioapic, i
 int (*ioapic_renumber_irq)(int ioapic, int irq);
 atomic_t irq_mis_count;
 
-int domain_irq_to_vector(struct domain *d, int irq)
-{
-    return d->arch.pirq_vector[irq];
-}
-
-int domain_vector_to_irq(struct domain *d, int vector)
-{
-    return d->arch.vector_pirq[vector];
-}
-
 /* Where if anywhere is the i8259 connect in external int mode */
 static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
 
@@ -721,7 +711,6 @@ next:
 
 static struct hw_interrupt_type ioapic_level_type;
 static struct hw_interrupt_type ioapic_edge_type;
-struct hw_interrupt_type pci_msi_type;
 
 #define IOAPIC_AUTO    -1
 #define IOAPIC_EDGE    0
xen/arch/x86/irq.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/arch/x86/irq.c Wed Sep 24 10:23:51 2008 +0100 +73 -39

180 lines not on this page · raw message

xen/arch/x86/msi.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/arch/x86/msi.c Wed Sep 24 10:23:51 2008 +0100 +0 -1
diff -r 7750906b06b3 -r 31f09a5e24cf xen/arch/x86/msi.c
@@ -727,7 +727,6 @@ void pci_disable_msi(int vector)
         __pci_disable_msix(vector);
 }
 
-extern struct hw_interrupt_type pci_msi_type;
 static void msi_free_vectors(struct pci_dev* dev)
 {
     struct msi_desc *entry, *tmp;
xen/arch/x86/physdev.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/arch/x86/physdev.c Wed Sep 24 10:23:51 2008 +0100 +50 -46

215 lines not on this page · raw message

xen/common/event_channel.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/common/event_channel.c Wed Sep 24 10:23:51 2008 +0100 +2 -1
diff -r 7750906b06b3 -r 31f09a5e24cf xen/common/event_channel.c
@@ -387,7 +387,8 @@ static long __evtchn_close(struct domain
         break;
 
     case ECS_PIRQ:
-        pirq_guest_unbind(d1, chn1->u.pirq);
+        if ( pirq_guest_unbind(d1, chn1->u.pirq) != 0 )
+            BUG();
         d1->pirq_to_evtchn[chn1->u.pirq] = 0;
         break;
 
xen/include/asm-x86/domain.h Wed Sep 24 12:36:55 2008 +0100 renamed from xen/include/asm-x86/domain.h Wed Sep 24 10:23:51 2008 +0100 +1 -1
diff -r 7750906b06b3 -r 31f09a5e24cf xen/include/asm-x86/domain.h
@@ -235,7 +235,7 @@ struct arch_domain
     /* Shadow translated domain: P2M mapping */
     pagetable_t phys_table;
 
-    spinlock_t irq_lock;
+    /* NB. protected by d->evtchn_lock and by irq_desc[vector].lock */
     int vector_pirq[NR_VECTORS];
     int pirq_vector[NR_PIRQS];
 
xen/include/asm-x86/irq.h Wed Sep 24 12:36:55 2008 +0100 renamed from xen/include/asm-x86/irq.h Wed Sep 24 10:23:51 2008 +0100 +3 -2
diff -r 7750906b06b3 -r 31f09a5e24cf xen/include/asm-x86/irq.h
@@ -52,6 +52,7 @@ int pirq_acktype(struct domain *d, int i
 int pirq_acktype(struct domain *d, int irq);
 int pirq_shared(struct domain *d , int irq);
 
-extern int domain_irq_to_vector(struct domain *d, int irq);
-extern int domain_vector_to_irq(struct domain *d, int vector);
+#define domain_irq_to_vector(d, irq) ((d)->arch.pirq_vector[(irq)])
+#define domain_vector_to_irq(d, vec) ((d)->arch.vector_pirq[(vec)])
+
 #endif /* _ASM_HW_IRQ_H */
xen/include/asm-x86/msi.h Wed Sep 24 12:36:55 2008 +0100 renamed from xen/include/asm-x86/msi.h Wed Sep 24 10:23:51 2008 +0100 +1 -1
diff -r 7750906b06b3 -r 31f09a5e24cf xen/include/asm-x86/msi.h
@@ -106,7 +106,7 @@ struct msi_desc {
  */
 #define NR_HP_RESERVED_VECTORS         20
 
-extern int vector_irq[NR_VECTORS];
+extern struct hw_interrupt_type pci_msi_type;
 
 /*
  * MSI-X Address Register
xen/include/xen/irq.h Wed Sep 24 12:36:55 2008 +0100 renamed from xen/include/xen/irq.h Wed Sep 24 10:23:51 2008 +0100 +1 -2
diff -r 7750906b06b3 -r 31f09a5e24cf xen/include/xen/irq.h
@@ -22,7 +22,6 @@ struct irqaction
 #define IRQ_PENDING    4       /* IRQ pending - replay on enable */
 #define IRQ_REPLAY     8       /* IRQ has been replayed but not acked yet */
 #define IRQ_GUEST       16      /* IRQ is handled by guest OS(es) */
-#define IRQ_LEVEL       64      /* IRQ level triggered */
 #define IRQ_PER_CPU     256     /* IRQ is per CPU */
 
 /*
@@ -78,7 +77,7 @@ extern int pirq_guest_eoi(struct domain
 extern int pirq_guest_eoi(struct domain *d, int irq);
 extern int pirq_guest_unmask(struct domain *d);
 extern int pirq_guest_bind(struct vcpu *v, int irq, int will_share);
-extern void pirq_guest_unbind(struct domain *d, int irq);
+extern int pirq_guest_unbind(struct domain *d, int irq);
 
 static inline void set_native_irq_info(int irq, cpumask_t mask)
 {

_______________________________________________
Xen-changelog mailing list
[email protected]
http://lists.xensource.com/xen-changelog

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

#2 lore raw
Quoted 11 lines · Dexuan
xen/arch/x86/irq.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/arch/x86/irq.c Wed Sep 24 10:23:51 2008 +0100 +1 -0
@@ -491,16 +512,15 @@ int pirq_guest_bind(struct vcpu *v, int
     int                 rc = 0;
     cpumask_t           cpumask = CPU_MASK_NONE;
 
+    WARN_ON(!spin_is_locked(&v->domain->evtchn_lock));
 

I find this WARN_ON() is triggered harmlessly when I assign device to HVM guest.
The call trace is XEN_DOMCTL_bind_pt_irq -> pt_irq_create_bind_vtd() -> pirq_guest_bind().
Should we remove the WARN_ON here?

I put in that WARN_ON() deliberately, because I think HVM pt_irq locking needs some work. Yunhong Jiang is looking into it I believe (cc'ed). Obviously the current situation is temporary -- either the locking in the passthrough code will be fixed as I envisage, or we'll agree some other fix and the WARN_ON() will be removed or changed. Appended is a relevant section of en email I sent a couple of days ago.

-- Keir

------------------

* I decided to WARN_ON(!spin_is_locked(&d->evtchn_lock)) in
pirq_guest_[un]bind(). The reason is that in any case those functions do not expect to be re-entered -- they really want to be per-domain serialised. Furthermore I am pretty certain that the HVM passthrough code is not synchronising properly with changes to the pirq-to-vector mapping (it uses domain_irq_to_vector() in many places with no care for locking) nor is it synchronised with other users of pirq_guest_bind() --- a reasonable semantics here would be that a domain pirq can be bound to once, either via an event channel, or through a virtual PIC in HVM emulation context. I therefore think that careful locking is required -- it may suffice to get rid of (or at least make less use of) the hvm_domain.irq_lock and replace its use with evtchn_lock (only consideration is that the latter is not IRQ-safe). The WARN_ON() is a nice reminder of work to be done here.

#3 lore raw

Yes, I'm trying to fix this issue.

Yunhong Jiang

Quoted 47 lines · Keir Fraser
Quoted 10 lines · Dexuan
xen/arch/x86/irq.c Wed Sep 24 12:36:55 2008 +0100 renamed from xen/arch/x86/irq.c Wed Sep 24 10:23:51 2008 +0100 +1 -0
@@ -491,16 +512,15 @@ int pirq_guest_bind(struct vcpu *v, int
     int                 rc = 0;
     cpumask_t           cpumask = CPU_MASK_NONE;
 
+    WARN_ON(!spin_is_locked(&v->domain->evtchn_lock));
 

I find this WARN_ON() is triggered harmlessly when I assign device to HVM guest. The call trace is XEN_DOMCTL_bind_pt_irq -> pt_irq_create_bind_vtd() -> pirq_guest_bind(). Should we remove the WARN_ON here?

I put in that WARN_ON() deliberately, because I think HVM pt_irq locking
needs some work. Yunhong Jiang is looking into it I believe (cc'ed). Obviously the current situation is temporary -- either the locking in the
passthrough code will be fixed as I envisage, or we'll agree some other fix
and the WARN_ON() will be removed or changed. Appended is a relevant section
of en email I sent a couple of days ago.

-- Keir

------------------

* I decided to WARN_ON(!spin_is_locked(&d->evtchn_lock)) in pirq_guest_[un]bind(). The reason is that in any case those functions do not
expect to be re-entered -- they really want to be per-domain serialised. Furthermore I am pretty certain that the HVM passthrough code is not synchronising properly with changes to the pirq-to-vector mapping (it uses
domain_irq_to_vector() in many places with no care for locking) nor is it
synchronised with other users of pirq_guest_bind() --- a reasonable semantics here would be that a domain pirq can be bound to once, either via
an event channel, or through a virtual PIC in HVM emulation context. I therefore think that careful locking is required -- it may suffice to get
rid of (or at least make less use of) the hvm_domain.irq_lock and replace
its use with evtchn_lock (only consideration is that the latter is not IRQ-safe). The WARN_ON() is a nice reminder of work to be done here.