[PATCH] x86: sparse_irq needs spin_lock in allocations

From: Yinghai Lu
Date: Wed Aug 20 2008 - 23:46:25 EST


Suresh Siddha noticed that we should have a spinlock around it.

Signed-off-by: Yinghai Lu <yhlu.kernel@xxxxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxx>
---
arch/x86/kernel/io_apic.c | 10 ++++++++++
kernel/irq/handle.c | 10 ++++++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/io_apic.c b/arch/x86/kernel/io_apic.c
index 34c74cf..d1370ce 100644
--- a/arch/x86/kernel/io_apic.c
+++ b/arch/x86/kernel/io_apic.c
@@ -146,6 +146,12 @@ static void init_one_irq_cfg(struct irq_cfg *cfg)
}

static struct irq_cfg *irq_cfgx;
+
+/*
+ * Protect the irq_cfgx_free freelist:
+ */
+static DEFINE_SPINLOCK(irq_cfg_lock);
+
#ifdef CONFIG_HAVE_SPARSE_IRQ
static struct irq_cfg *irq_cfgx_free;
#endif
@@ -226,6 +232,7 @@ static struct irq_cfg *irq_cfg_alloc(unsigned int irq)
count++;
}

+ spin_lock(&irq_cfg_lock);
if (!irq_cfgx_free) {
unsigned long phys;
unsigned long total_bytes;
@@ -263,6 +270,9 @@ static struct irq_cfg *irq_cfg_alloc(unsigned int irq)
else
irq_cfgx = cfg;
cfg->irq = irq;
+
+ spin_unlock(&irq_cfg_lock);
+
printk(KERN_DEBUG "found new irq_cfg for irq %d\n", cfg->irq);
#ifdef CONFIG_HAVE_SPARSE_IRQ_DEBUG
{
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c
index 24c83a3..2f02e14 100644
--- a/kernel/irq/handle.c
+++ b/kernel/irq/handle.c
@@ -107,6 +107,11 @@ static void init_kstat_irqs(struct irq_desc *desc, int nr_desc, int nr)
}
}

+/*
+ * Protect the sparse_irqs_free freelist:
+ */
+static DEFINE_SPINLOCK(sparse_irq_lock);
+
#ifdef CONFIG_HAVE_SPARSE_IRQ
static struct irq_desc *sparse_irqs_free;
struct irq_desc *sparse_irqs;
@@ -166,6 +171,7 @@ struct irq_desc *irq_to_desc(unsigned int irq)
}
return NULL;
}
+
struct irq_desc *irq_to_desc_alloc(unsigned int irq)
{
struct irq_desc *desc, *desc_pri;
@@ -182,6 +188,7 @@ struct irq_desc *irq_to_desc_alloc(unsigned int irq)
count++;
}

+ spin_lock(&sparse_irq_lock);
/*
* we run out of pre-allocate ones, allocate more
*/
@@ -223,6 +230,9 @@ struct irq_desc *irq_to_desc_alloc(unsigned int irq)
else
sparse_irqs = desc;
desc->irq = irq;
+
+ spin_unlock(&sparse_irq_lock);
+
printk(KERN_DEBUG "found new irq_desc for irq %d\n", desc->irq);
#ifdef CONFIG_HAVE_SPARSE_IRQ_DEBUG
{
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/