assign_irq_vector adjustments
PATCH 1/1 assign_irq_vector adjustments
In both i386 and x86-64 Linux, using a static variable (and thus having the potential of missing synchronization there, as I suspect exists in native Linux) is not needed with the hypercall approach. In the hypervisor, the patch adds the needed synchronization.
Jan
linux-2.6-xen-sparse/arch/i386/kernel/io_apic-xen.c +3 -5
@@ -1205,7 +1205,6 @@ u8 irq_vector[NR_IRQ_VECTORS] __read_mosint assign_irq_vector (int irq) { -static int current_vector =FIRST_DEVICE_VECTOR ;physdev_op_t op;BUG_ON (irq >=NR_IRQ_VECTORS );
@@ -1216,13 +1215,12 @@ int assign_irq_vector(int irq) op.u.irq_op.irq = irq;if (HYPERVISOR_physdev_op (&op))return -ENOSPC ; - current_vector = op.u.irq_op.vector; - vector_irq[current_vector] = irq; + vector_irq[op.u.irq_op.vector] = irq;if (irq !=AUTO_ASSIGN ) -IO_APIC_VECTOR (irq) = current_vector; +IO_APIC_VECTOR (irq) = op.u.irq_op.vector; -return current_vector; +return op.u.irq_op.vector; }#ifndef CONFIG_XEN
linux-2.6-xen-sparse/arch/x86_64/kernel/io_apic-xen.c +3 -5
@@ -869,7 +869,6 @@ u8 irq_vector[NR_IRQ_VECTORS] __read_mosint assign_irq_vector (int irq) { -static int current_vector =FIRST_DEVICE_VECTOR ;physdev_op_t op;BUG_ON (irq !=AUTO_ASSIGN && (unsigned )irq >=NR_IRQ_VECTORS );
@@ -880,13 +879,12 @@ int assign_irq_vector(int irq) op.u.irq_op.irq = irq;if (HYPERVISOR_physdev_op (&op))return -ENOSPC ; - current_vector = op.u.irq_op.vector; - vector_irq[current_vector] = irq; + vector_irq[op.u.irq_op.vector] = irq;if (irq !=AUTO_ASSIGN ) -IO_APIC_VECTOR (irq) = current_vector; +IO_APIC_VECTOR (irq) = op.u.irq_op.vector; -return current_vector; +return op.u.irq_op.vector; }extern void (*interrupt[NR_IRQS ])(void );
xen/arch/x86/io_apic.c +14 -5
@@ -48,6 +48,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 skip_ioapic_setup;
@@ -661,11 +662,14 @@ u8 irq_vector[NR_IRQ_VECTORS] __read_mosint assign_irq_vector (int irq) { -static int current_vector =FIRST_DEVICE_VECTOR , offset =0 ; +static unsigned current_vector =FIRST_DEVICE_VECTOR , offset =0 ; +unsigned vector;BUG_ON (irq >=NR_IRQ_VECTORS );if (irq !=AUTO_ASSIGN &&IO_APIC_VECTOR (irq) >0 )return IO_APIC_VECTOR (irq); + +spin_lock (&vector_lock); next: current_vector +=8 ;
@@ -679,16 +683,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; +spin_unlock (&vector_lock); + + vector_irq[vector] = irq;if (irq !=AUTO_ASSIGN ) -IO_APIC_VECTOR (irq) = current_vector; +IO_APIC_VECTOR (irq) = vector; -return current_vector; +return vector; }static struct hw_interrupt_type ioapic_level_type;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Jan Beulich
In both i386 and x86-64 Linux, using a static variable (and thus having the potential of missing synchronization there, as I suspect exists in native Linux) is not needed with the hypercall approach. In the hypervisor, the patch adds the needed synchronization.
1. Should you not assign to irq_vector[] and vector_irq[] in Xen with the lock held? Otherwise you may double-allocate if two requests are made concurrently to assign for the same irq (unlikely, but...)
2. Since that'll need a re-send, please also add a Signed-off-by line.
Thanks,
Keir
Quoted 9 lines
Quoted 5 lines
In both i386 and x86-64 Linux, using a static variable (and thus having the potential of missing synchronization there,
as I suspect exists in native Linux) is not needed with the hypercall approach. In the hypervisor, the patch adds the
needed synchronization.1. Should you not assign to irq_vector[] and vector_irq[] in Xen with the lock held? Otherwise you may double-allocate if two requests are made concurrently to assign for the same irq (unlikely, but...)
Hmm, the vector_irq assignment shouldn't need the lock (which is why I moved the unlock up), but you're right, the IO_APIC_VECTOR() write *and* read should happen with the lock held. I'll update that.
Quoted 1 line
2. Since that'll need a re-send, please also add a Signed-off-by line.
Sure, if you prefer it that way. Should this go into the patch (attachment) or the message?
Jan
Quoted 3 lines · Jan Beulich
Quoted 1 line
2. Since that'll need a re-send, please also add a Signed-off-by line.
Sure, if you prefer it that way. Should this go into the patch (attachment) or the message?
Wherever you put the text that should go in the changeset comment (so that I can cut-and-paste). Apart from that I'm not fussed either way.
-- Keir
PATCH 1/1 assign_irq_vector adjustments
In reply to Keir FraserIn both i386 and x86-64 Linux, using a static variable (and thus having the potential of missing synchronization there,
as I suspect exists in native Linux) is not needed with the hypercall approach. In the hypervisor, the patch adds the
needed synchronization.
linux-2.6-xen-sparse/arch/i386/kernel/io_apic-xen.c +3 -5
@@ -1205,7 +1205,6 @@ u8 irq_vector[NR_IRQ_VECTORS] __read_mosint assign_irq_vector (int irq) { -static int current_vector =FIRST_DEVICE_VECTOR ;physdev_op_t op;BUG_ON (irq >=NR_IRQ_VECTORS );
@@ -1216,13 +1215,12 @@ int assign_irq_vector(int irq) op.u.irq_op.irq = irq;if (HYPERVISOR_physdev_op (&op))return -ENOSPC ; - current_vector = op.u.irq_op.vector; - vector_irq[current_vector] = irq; + vector_irq[op.u.irq_op.vector] = irq;if (irq !=AUTO_ASSIGN ) -IO_APIC_VECTOR (irq) = current_vector; +IO_APIC_VECTOR (irq) = op.u.irq_op.vector; -return current_vector; +return op.u.irq_op.vector; }#ifndef CONFIG_XEN
linux-2.6-xen-sparse/arch/x86_64/kernel/io_apic-xen.c +3 -5
@@ -869,7 +869,6 @@ u8 irq_vector[NR_IRQ_VECTORS] __read_mosint assign_irq_vector (int irq) { -static int current_vector =FIRST_DEVICE_VECTOR ;physdev_op_t op;BUG_ON (irq !=AUTO_ASSIGN && (unsigned )irq >=NR_IRQ_VECTORS );
@@ -880,13 +879,12 @@ int assign_irq_vector(int irq) op.u.irq_op.irq = irq;if (HYPERVISOR_physdev_op (&op))return -ENOSPC ; - current_vector = op.u.irq_op.vector; - vector_irq[current_vector] = irq; + vector_irq[op.u.irq_op.vector] = irq;if (irq !=AUTO_ASSIGN ) -IO_APIC_VECTOR (irq) = current_vector; +IO_APIC_VECTOR (irq) = op.u.irq_op.vector; -return current_vector; +return op.u.irq_op.vector; }extern void (*interrupt[NR_IRQS ])(void );
xen/arch/x86/io_apic.c +18 -6
@@ -48,6 +48,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 skip_ioapic_setup;
@@ -661,11 +662,17 @@ u8 irq_vector[NR_IRQ_VECTORS] __read_mosint assign_irq_vector (int irq) { -static int current_vector =FIRST_DYNAMIC_VECTOR , offset =0 ; +static unsigned current_vector =FIRST_DYNAMIC_VECTOR , offset =0 ; +unsigned vector;BUG_ON (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 ;
@@ -679,16 +686,21 @@ next:if (current_vector >LAST_DYNAMIC_VECTOR ) { offset++; -if (!(offset%8 )) +if (!(offset%8 )) { +spin_unlock (&vector_lock);return -ENOSPC ; + } current_vector =FIRST_DYNAMIC_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;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel