xcp-1.6-updates/xen-4.1.hg

changeset 23262:7c0d02aa4742

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>
xen-unstable changeset: 24156:f29b5bd6e25f
xen-unstable date: Fri Nov 18 09:21:24 2011 +0100
author Jan Beulich <jbeulich@suse.com>
date Thu Mar 08 10:04:22 2012 +0000 (2012-03-08)
parents 0bbaff574126
children b01091775dd9
files xen/arch/x86/io_apic.c xen/arch/x86/irq.c xen/include/asm-x86/irq.h
line diff
     1.1 --- a/xen/arch/x86/io_apic.c	Thu Mar 08 10:03:35 2012 +0000
     1.2 +++ b/xen/arch/x86/io_apic.c	Thu Mar 08 10:04:22 2012 +0000
     1.3 @@ -70,6 +70,34 @@ int __read_mostly nr_ioapics;
     1.4  
     1.5  #define ioapic_has_eoi_reg(apic) (mp_ioapics[(apic)].mpc_apicver >= 0x20)
     1.6  
     1.7 +static int apic_pin_2_gsi_irq(int apic, int pin);
     1.8 +
     1.9 +static vmask_t *__read_mostly vector_map[MAX_IO_APICS];
    1.10 +
    1.11 +static void share_vector_maps(unsigned int src, unsigned int dst)
    1.12 +{
    1.13 +    unsigned int pin;
    1.14 +
    1.15 +    if (vector_map[src] == vector_map[dst])
    1.16 +        return;
    1.17 +
    1.18 +    bitmap_or(vector_map[src]->_bits, vector_map[src]->_bits,
    1.19 +              vector_map[dst]->_bits, NR_VECTORS);
    1.20 +
    1.21 +    for (pin = 0; pin < nr_ioapic_registers[dst]; ++pin) {
    1.22 +        int irq = apic_pin_2_gsi_irq(dst, pin);
    1.23 +        struct irq_cfg *cfg;
    1.24 +
    1.25 +        if (irq < 0)
    1.26 +            continue;
    1.27 +        cfg = irq_cfg(irq);
    1.28 +        if (cfg->used_vectors == vector_map[dst])
    1.29 +            cfg->used_vectors = vector_map[src];
    1.30 +    }
    1.31 +
    1.32 +    vector_map[dst] = vector_map[src];
    1.33 +}
    1.34 +
    1.35  /*
    1.36   * This is performance-critical, we want to do it O(1)
    1.37   *
    1.38 @@ -110,6 +138,7 @@ static void add_pin_to_irq(unsigned int 
    1.39      }
    1.40      entry->apic = apic;
    1.41      entry->pin = pin;
    1.42 +    share_vector_maps(irq_2_pin[irq].apic, apic);
    1.43  }
    1.44  
    1.45  /*
    1.46 @@ -125,6 +154,7 @@ static void __init replace_pin_at_irq(un
    1.47          if (entry->apic == oldapic && entry->pin == oldpin) {
    1.48              entry->apic = newapic;
    1.49              entry->pin = newpin;
    1.50 +            share_vector_maps(oldapic, newapic);
    1.51          }
    1.52          if (!entry->next)
    1.53              break;
    1.54 @@ -132,6 +162,16 @@ static void __init replace_pin_at_irq(un
    1.55      }
    1.56  }
    1.57  
    1.58 +vmask_t *io_apic_get_used_vector_map(unsigned int irq)
    1.59 +{
    1.60 +    struct irq_pin_list *entry = irq_2_pin + irq;
    1.61 +
    1.62 +    if (entry->pin == -1)
    1.63 +        return NULL;
    1.64 +
    1.65 +    return vector_map[entry->apic];
    1.66 +}
    1.67 +
    1.68  struct IO_APIC_route_entry **alloc_ioapic_entries(void)
    1.69  {
    1.70      int apic;
    1.71 @@ -1294,6 +1334,18 @@ static void __init enable_IO_APIC(void)
    1.72      for (i = irq_2_pin_free_entry = nr_irqs_gsi; i < PIN_MAP_SIZE; i++)
    1.73          irq_2_pin[i].next = i + 1;
    1.74  
    1.75 +    if (directed_eoi_enabled) {
    1.76 +        for (apic = 0; apic < nr_ioapics; apic++) {
    1.77 +            vector_map[apic] = xzalloc(vmask_t);
    1.78 +            BUG_ON(!vector_map[apic]);
    1.79 +        }
    1.80 +    } else {
    1.81 +        vector_map[0] = xzalloc(vmask_t);
    1.82 +        BUG_ON(!vector_map[0]);
    1.83 +        for (apic = 1; apic < nr_ioapics; apic++)
    1.84 +            vector_map[apic] = vector_map[0];
    1.85 +    }
    1.86 +
    1.87      for(apic = 0; apic < nr_ioapics; apic++) {
    1.88          int pin;
    1.89          /* See if any of the pins is in ExtINT mode */
    1.90 @@ -2465,13 +2517,12 @@ int ioapic_guest_write(unsigned long phy
    1.91      }
    1.92  
    1.93      if ( cfg->vector <= 0 || cfg->vector > LAST_DYNAMIC_VECTOR ) {
    1.94 +        add_pin_to_irq(irq, apic, pin);
    1.95          vector = assign_irq_vector(irq);
    1.96          if ( vector < 0 )
    1.97              return vector;
    1.98  
    1.99          printk(XENLOG_INFO "allocated vector %02x for irq %d\n", vector, irq);
   1.100 -
   1.101 -        add_pin_to_irq(irq, apic, pin);
   1.102      }
   1.103      spin_lock(&pcidevs_lock);
   1.104      spin_lock(&dom0->event_lock);
     2.1 --- a/xen/arch/x86/irq.c	Thu Mar 08 10:03:35 2012 +0000
     2.2 +++ b/xen/arch/x86/irq.c	Thu Mar 08 10:04:22 2012 +0000
     2.3 @@ -403,6 +403,11 @@ static vmask_t *irq_get_used_vector_mask
     2.4              }
     2.5          }
     2.6      }
     2.7 +    else if ( IO_APIC_IRQ(irq) &&
     2.8 +              opt_irq_vector_map != OPT_IRQ_VECTOR_MAP_NONE )
     2.9 +    {
    2.10 +        ret = io_apic_get_used_vector_map(irq);
    2.11 +    }
    2.12  
    2.13      return ret;
    2.14  }
     3.1 --- a/xen/include/asm-x86/irq.h	Thu Mar 08 10:03:35 2012 +0000
     3.2 +++ b/xen/include/asm-x86/irq.h	Thu Mar 08 10:04:22 2012 +0000
     3.3 @@ -113,6 +113,7 @@ void setup_IO_APIC(void);
     3.4  void disable_IO_APIC(void);
     3.5  void print_IO_APIC(void);
     3.6  void setup_ioapic_dest(void);
     3.7 +vmask_t *io_apic_get_used_vector_map(unsigned int irq);
     3.8  
     3.9  extern unsigned long io_apic_irqs;
    3.10