aboutsummaryrefslogtreecommitdiffstats
path: root/xen/arch/x86/io_apic.c
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2011-11-18 09:21:24 +0100
committerJan Beulich <jbeulich@suse.com>2011-11-18 09:21:24 +0100
commit8eca0db0e836a081d873de7e9eefb3763f065780 (patch)
tree3d1de8742a3c35ef7ce3184bb2d1712f49da826f /xen/arch/x86/io_apic.c
parentf0b7583fd5a6ea317637693138e060a263b94a2c (diff)
downloadxen-8eca0db0e836a081d873de7e9eefb3763f065780.tar.gz
xen-8eca0db0e836a081d873de7e9eefb3763f065780.tar.bz2
xen-8eca0db0e836a081d873de7e9eefb3763f065780.zip
x86/IRQ: prevent vector sharing within IO-APICs
Following the prevention of vector sharing for MSIs, this change enforces the same within IO-APICs: Pin based interrupts use the IO-APIC as their identifying device under the AMD IOMMU (and just like for MSIs, only the identifying device is used to remap interrupts here, with no regard to an interrupt's destination). Additionally, LAPIC initiated EOIs (for level triggered interrupts) too use only the vector for identifying which interrupts to end. While this generally causes no significant problem (at worst an interrupt would be re-raised without a new interrupt event actually having occurred), it still seems better to avoid the situation. For this second aspect, a distinction is being made between the traditional and the directed-EOI cases: In the former, vectors should not be shared throughout all IO-APICs in the system, while in the latter case only individual IO-APICs need to be contrained (or, if the firmware indicates so, sub- groups of them having the same GSI appear at multiple pins). Signed-off-by: Jan Beulich <jbeulich@suse.com> Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Diffstat (limited to 'xen/arch/x86/io_apic.c')
-rw-r--r--xen/arch/x86/io_apic.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index ee1d778b7c..752b3f4758 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -69,6 +69,34 @@ int __read_mostly nr_ioapics;
#define ioapic_has_eoi_reg(apic) (mp_ioapics[(apic)].mpc_apicver >= 0x20)
+static int apic_pin_2_gsi_irq(int apic, int pin);
+
+static vmask_t *__read_mostly vector_map[MAX_IO_APICS];
+
+static void share_vector_maps(unsigned int src, unsigned int dst)
+{
+ unsigned int pin;
+
+ if (vector_map[src] == vector_map[dst])
+ return;
+
+ bitmap_or(vector_map[src]->_bits, vector_map[src]->_bits,
+ vector_map[dst]->_bits, NR_VECTORS);
+
+ for (pin = 0; pin < nr_ioapic_entries[dst]; ++pin) {
+ int irq = apic_pin_2_gsi_irq(dst, pin);
+ struct irq_desc *desc;
+
+ if (irq < 0)
+ continue;
+ desc = irq_to_desc(irq);
+ if (desc->arch.used_vectors == vector_map[dst])
+ desc->arch.used_vectors = vector_map[src];
+ }
+
+ vector_map[dst] = vector_map[src];
+}
+
/*
* This is performance-critical, we want to do it O(1)
*
@@ -109,6 +137,7 @@ static void add_pin_to_irq(unsigned int irq, int apic, int pin)
}
entry->apic = apic;
entry->pin = pin;
+ share_vector_maps(irq_2_pin[irq].apic, apic);
}
/*
@@ -124,6 +153,7 @@ static void __init replace_pin_at_irq(unsigned int irq,
if (entry->apic == oldapic && entry->pin == oldpin) {
entry->apic = newapic;
entry->pin = newpin;
+ share_vector_maps(oldapic, newapic);
}
if (!entry->next)
break;
@@ -131,6 +161,16 @@ static void __init replace_pin_at_irq(unsigned int irq,
}
}
+vmask_t *io_apic_get_used_vector_map(unsigned int irq)
+{
+ struct irq_pin_list *entry = irq_2_pin + irq;
+
+ if (entry->pin == -1)
+ return NULL;
+
+ return vector_map[entry->apic];
+}
+
struct IO_APIC_route_entry **alloc_ioapic_entries(void)
{
int apic;
@@ -1190,6 +1230,18 @@ static void __init enable_IO_APIC(void)
for (i = irq_2_pin_free_entry = nr_irqs_gsi; i < PIN_MAP_SIZE; i++)
irq_2_pin[i].next = i + 1;
+ if (directed_eoi_enabled) {
+ for (apic = 0; apic < nr_ioapics; apic++) {
+ vector_map[apic] = xzalloc(vmask_t);
+ BUG_ON(!vector_map[apic]);
+ }
+ } else {
+ vector_map[0] = xzalloc(vmask_t);
+ BUG_ON(!vector_map[0]);
+ for (apic = 1; apic < nr_ioapics; apic++)
+ vector_map[apic] = vector_map[0];
+ }
+
for(apic = 0; apic < nr_ioapics; apic++) {
int pin;
/* See if any of the pins is in ExtINT mode */
@@ -2287,13 +2339,12 @@ int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val)
}
if ( desc->arch.vector <= 0 || desc->arch.vector > LAST_DYNAMIC_VECTOR ) {
+ add_pin_to_irq(irq, apic, pin);
vector = assign_irq_vector(irq);
if ( vector < 0 )
return vector;
printk(XENLOG_INFO "allocated vector %02x for irq %d\n", vector, irq);
-
- add_pin_to_irq(irq, apic, pin);
}
spin_lock(&dom0->event_lock);
ret = map_domain_pirq(dom0, pirq, irq,