From: "Jan Beulich" Subject: [PATCH] x86/IRQ: fix create_irq() after c/s 24068:6928172f7ded Date: Fri, 04 Nov 2011 11:52:59 +0000 Message-ID: <4EB3E02B020000780005F027@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part4C63BC0B.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" 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. --=__Part4C63BC0B.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline init_one_irq_desc() must be called with interrupts enabled (as it may call functions from the xmalloc() group). Rather than mis-using vector_lock to also protect the finding of an unused IRQ, make this lockless through using cmpxchg(), and obtain the lock only around the actual assignment of the vector. Also fold find_unassigned_irq() into its only caller. It is, btw, questionable whether create_irq() calling __assign_irq_vector() (rather than assign_irq_vector()) is actually correct - desc->affinity appears to not get initialized properly in this case. Signed-off-by: Jan Beulich --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -151,16 +151,6 @@ int __init bind_irq_vector(int irq, int=20 return ret; } =20 -static inline int find_unassigned_irq(void) -{ - int irq; - - for (irq =3D nr_irqs_gsi; irq < nr_irqs; irq++) - if (irq_to_desc(irq)->arch.used =3D=3D IRQ_UNUSED) - return irq; - return -ENOSPC; -} - /* * Dynamic irq allocate and deallocation for MSI */ @@ -170,19 +160,28 @@ int create_irq(void) int irq, ret; struct irq_desc *desc; =20 - spin_lock_irqsave(&vector_lock, flags); + for (irq =3D nr_irqs_gsi; irq < nr_irqs; irq++) + { + desc =3D irq_to_desc(irq); + if (cmpxchg(&desc->arch.used, IRQ_UNUSED, IRQ_RESERVED) =3D=3D = IRQ_UNUSED) + break; + } + + if (irq >=3D nr_irqs) + return -ENOSPC; =20 - irq =3D find_unassigned_irq(); - if (irq < 0) - goto out; - desc =3D irq_to_desc(irq); ret =3D init_one_irq_desc(desc); if (!ret) + { + spin_lock_irqsave(&vector_lock, flags); ret =3D __assign_irq_vector(irq, desc, TARGET_CPUS); + spin_unlock_irqrestore(&vector_lock, flags); + } if (ret < 0) + { + desc->arch.used =3D IRQ_UNUSED; irq =3D ret; -out: - spin_unlock_irqrestore(&vector_lock, flags); + } =20 return irq; } --- a/xen/include/asm-x86/irq.h +++ b/xen/include/asm-x86/irq.h @@ -39,12 +39,13 @@ struct irq_cfg { unsigned move_cleanup_count; vmask_t *used_vectors; u8 move_in_progress : 1; - u8 used: 1; + s8 used; }; =20 /* For use with irq_cfg.used */ #define IRQ_UNUSED (0) #define IRQ_USED (1) +#define IRQ_RESERVED (-1) =20 #define IRQ_VECTOR_UNASSIGNED (-1) =20 --=__Part4C63BC0B.0__= Content-Type: text/plain; name="x86-create-irq-locking.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-create-irq-locking.patch" x86/IRQ: fix create_irq() after c/s 24068:6928172f7ded=0A=0Ainit_one_irq_de= sc() must be called with interrupts enabled (as it may=0Acall functions = from the xmalloc() group). Rather than mis-using=0Avector_lock to also = protect the finding of an unused IRQ, make this=0Alockless through using = cmpxchg(), and obtain the lock only around the=0Aactual assignment of the = vector.=0A=0AAlso fold find_unassigned_irq() into its only caller.=0A=0AIt = is, btw, questionable whether create_irq() calling=0A__assign_irq_vector() = (rather than assign_irq_vector()) is actually=0Acorrect - desc->affinity = appears to not get initialized properly in=0Athis case.=0A=0ASigned-off-by:= Jan Beulich =0A=0A--- a/xen/arch/x86/irq.c=0A+++ = b/xen/arch/x86/irq.c=0A@@ -151,16 +151,6 @@ int __init bind_irq_vector(int = irq, int =0A return ret;=0A }=0A =0A-static inline int find_unassigned_= irq(void)=0A-{=0A- int irq;=0A-=0A- for (irq =3D nr_irqs_gsi; irq < = nr_irqs; irq++)=0A- if (irq_to_desc(irq)->arch.used =3D=3D = IRQ_UNUSED)=0A- return irq;=0A- return -ENOSPC;=0A-}=0A-=0A = /*=0A * Dynamic irq allocate and deallocation for MSI=0A */=0A@@ -170,19 = +160,28 @@ int create_irq(void)=0A int irq, ret;=0A struct = irq_desc *desc;=0A =0A- spin_lock_irqsave(&vector_lock, flags);=0A+ = for (irq =3D nr_irqs_gsi; irq < nr_irqs; irq++)=0A+ {=0A+ desc = =3D irq_to_desc(irq);=0A+ if (cmpxchg(&desc->arch.used, IRQ_UNUSED, = IRQ_RESERVED) =3D=3D IRQ_UNUSED)=0A+ break;=0A+ }=0A+=0A+ = if (irq >=3D nr_irqs)=0A+ return -ENOSPC;=0A =0A- irq =3D = find_unassigned_irq();=0A- if (irq < 0)=0A- goto out;=0A- = desc =3D irq_to_desc(irq);=0A ret =3D init_one_irq_desc(desc);=0A = if (!ret)=0A+ {=0A+ spin_lock_irqsave(&vector_lock, flags);=0A = ret =3D __assign_irq_vector(irq, desc, TARGET_CPUS);=0A+ = spin_unlock_irqrestore(&vector_lock, flags);=0A+ }=0A if (ret < = 0)=0A+ {=0A+ desc->arch.used =3D IRQ_UNUSED;=0A irq =3D = ret;=0A-out:=0A- spin_unlock_irqrestore(&vector_lock, flags);=0A+ = }=0A =0A return irq;=0A }=0A--- a/xen/include/asm-x86/irq.h=0A+++ = b/xen/include/asm-x86/irq.h=0A@@ -39,12 +39,13 @@ struct irq_cfg {=0A = unsigned move_cleanup_count;=0A vmask_t *used_vectors;=0A = u8 move_in_progress : 1;=0A- u8 used: 1;=0A+ s8 used;=0A = };=0A =0A /* For use with irq_cfg.used */=0A #define IRQ_UNUSED = (0)=0A #define IRQ_USED (1)=0A+#define IRQ_RESERVED (-1)=0A =0A = #define IRQ_VECTOR_UNASSIGNED (-1)=0A =0A --=__Part4C63BC0B.0__= 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.xensource.com http://lists.xensource.com/xen-devel --=__Part4C63BC0B.0__=--