* [PATCH] serialize assign_irq_vector() use of static variables
@ 2006-04-26 14:07 Jan Beulich
2006-04-26 14:14 ` Andi Kleen
2006-04-26 15:53 ` Randy.Dunlap
0 siblings, 2 replies; 3+ messages in thread
From: Jan Beulich @ 2006-04-26 14:07 UTC (permalink / raw)
To: Andreas Kleen, linux-kernel; +Cc: discuss
Since assign_irq_vector() can be called at runtime, its access of static
variables should be protected by a lock.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
diff -Npru /home/jbeulich/tmp/linux-2.6.17-rc2/arch/i386/kernel/io_apic.c
2.6.17-rc2-x86-assign_irq_vector-lock/arch/i386/kernel/io_apic.c
--- /home/jbeulich/tmp/linux-2.6.17-rc2/arch/i386/kernel/io_apic.c 2006-04-26 10:55:11.000000000 +0200
+++ 2.6.17-rc2-x86-assign_irq_vector-lock/arch/i386/kernel/io_apic.c 2006-04-25 15:38:32.000000000 +0200
@@ -50,6 +50,7 @@ atomic_t irq_mis_count;
static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
static DEFINE_SPINLOCK(ioapic_lock);
+static DEFINE_SPINLOCK(vector_lock);
int timer_over_8254 __initdata = 1;
@@ -1152,10 +1153,16 @@ u8 irq_vector[NR_IRQ_VECTORS] __read_mos
int assign_irq_vector(int irq)
{
static int current_vector = FIRST_DEVICE_VECTOR, offset = 0;
+ int vector;
+
+ BUG_ON(irq != AUTO_ASSIGN && (unsigned)irq >= NR_IRQ_VECTORS);
+
+ spin_lock(&vector_lock);
- BUG_ON(irq >= NR_IRQ_VECTORS);
- if (irq != AUTO_ASSIGN && IO_APIC_VECTOR(irq) > 0)
+ if (irq != AUTO_ASSIGN && IO_APIC_VECTOR(irq) > 0) {
+ spin_unlock(&vector_lock);
return IO_APIC_VECTOR(irq);
+ }
next:
current_vector += 8;
if (current_vector == SYSCALL_VECTOR)
@@ -1163,16 +1170,21 @@ next:
if (current_vector >= FIRST_SYSTEM_VECTOR) {
offset++;
- if (!(offset%8))
+ if (!(offset%8)) {
+ spin_unlock(&vector_lock);
return -ENOSPC;
+ }
current_vector = FIRST_DEVICE_VECTOR + offset;
}
- vector_irq[current_vector] = irq;
+ vector = current_vector;
+ vector_irq[vector] = irq;
if (irq != AUTO_ASSIGN)
- IO_APIC_VECTOR(irq) = current_vector;
+ IO_APIC_VECTOR(irq) = vector;
+
+ spin_unlock(&vector_lock);
- return current_vector;
+ return vector;
}
static struct hw_interrupt_type ioapic_level_type;
diff -Npru /home/jbeulich/tmp/linux-2.6.17-rc2/arch/x86_64/kernel/io_apic.c
2.6.17-rc2-x86-assign_irq_vector-lock/arch/x86_64/kernel/io_apic.c
--- /home/jbeulich/tmp/linux-2.6.17-rc2/arch/x86_64/kernel/io_apic.c 2006-04-26 10:55:24.000000000 +0200
+++ 2.6.17-rc2-x86-assign_irq_vector-lock/arch/x86_64/kernel/io_apic.c 2006-04-25 15:38:32.000000000 +0200
@@ -56,6 +56,7 @@ int timer_over_8254 __initdata = 0;
static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
static DEFINE_SPINLOCK(ioapic_lock);
+static DEFINE_SPINLOCK(vector_lock);
/*
* # of IRQ routing registers
@@ -814,10 +815,16 @@ u8 irq_vector[NR_IRQ_VECTORS] __read_mos
int assign_irq_vector(int irq)
{
static int current_vector = FIRST_DEVICE_VECTOR, offset = 0;
+ int vector;
BUG_ON(irq != AUTO_ASSIGN && (unsigned)irq >= NR_IRQ_VECTORS);
- if (irq != AUTO_ASSIGN && IO_APIC_VECTOR(irq) > 0)
+
+ spin_lock(&vector_lock);
+
+ if (irq != AUTO_ASSIGN && IO_APIC_VECTOR(irq) > 0) {
+ spin_unlock(&vector_lock);
return IO_APIC_VECTOR(irq);
+ }
next:
current_vector += 8;
if (current_vector == IA32_SYSCALL_VECTOR)
@@ -829,11 +836,14 @@ next:
current_vector = FIRST_DEVICE_VECTOR + offset;
}
- vector_irq[current_vector] = irq;
+ vector = current_vector;
+ vector_irq[vector] = irq;
if (irq != AUTO_ASSIGN)
- IO_APIC_VECTOR(irq) = current_vector;
+ IO_APIC_VECTOR(irq) = vector;
+
+ spin_unlock(&vector_lock);
- return current_vector;
+ return vector;
}
extern void (*interrupt[NR_IRQS])(void);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] serialize assign_irq_vector() use of static variables
2006-04-26 14:07 [PATCH] serialize assign_irq_vector() use of static variables Jan Beulich
@ 2006-04-26 14:14 ` Andi Kleen
2006-04-26 15:53 ` Randy.Dunlap
1 sibling, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2006-04-26 14:14 UTC (permalink / raw)
To: Jan Beulich; +Cc: linux-kernel, discuss
On Wednesday 26 April 2006 16:07, Jan Beulich wrote:
> Since assign_irq_vector() can be called at runtime, its access of static
> variables should be protected by a lock.
Applied thanks.
-Andi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] serialize assign_irq_vector() use of static variables
2006-04-26 14:07 [PATCH] serialize assign_irq_vector() use of static variables Jan Beulich
2006-04-26 14:14 ` Andi Kleen
@ 2006-04-26 15:53 ` Randy.Dunlap
1 sibling, 0 replies; 3+ messages in thread
From: Randy.Dunlap @ 2006-04-26 15:53 UTC (permalink / raw)
To: Jan Beulich; +Cc: ak, linux-kernel, discuss
On Wed, 26 Apr 2006 16:07:53 +0200 Jan Beulich wrote:
> Since assign_irq_vector() can be called at runtime, its access of static
> variables should be protected by a lock.
>
> Signed-off-by: Jan Beulich <jbeulich@novell.com>
Hi,
Would you include diffstat output also, as mentioned (optional)
in Documentation/SubmittingPatches? I'd really like to see a list
of patched files without having to scan the entire patch.
Thanks.
Oh, the diff filenames should begin at the linux-2.x.y level so
that they can be applied with patch -p1.
Lots of tools know how to do this.
> diff -Npru /home/jbeulich/tmp/linux-2.6.17-rc2/arch/i386/kernel/io_apic.c
> 2.6.17-rc2-x86-assign_irq_vector-lock/arch/i386/kernel/io_apic.c
> --- /home/jbeulich/tmp/linux-2.6.17-rc2/arch/i386/kernel/io_apic.c 2006-04-26 10:55:11.000000000 +0200
> +++ 2.6.17-rc2-x86-assign_irq_vector-lock/arch/i386/kernel/io_apic.c 2006-04-25 15:38:32.000000000 +0200
> @@ -1163,16 +1170,21 @@ next:
>
> if (current_vector >= FIRST_SYSTEM_VECTOR) {
> offset++;
> - if (!(offset%8))
> + if (!(offset%8)) {
Use better spacing here: (offset % 8)
> + spin_unlock(&vector_lock);
> return -ENOSPC;
> + }
> current_vector = FIRST_DEVICE_VECTOR + offset;
> }
>
---
~Randy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-04-26 15:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-26 14:07 [PATCH] serialize assign_irq_vector() use of static variables Jan Beulich
2006-04-26 14:14 ` Andi Kleen
2006-04-26 15:53 ` Randy.Dunlap
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.