Skip to contentSkip to conversation

xen: fix interrupt routing

PATCH Superseded Stefano Stabellini 5 participants 16 messages May 26, 2011 – Jun 15, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: fix interrupt routing

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts lines to 128;

hw/pc.h +0 -1
index 0dcbee7..6d5730b 100644
@@ -176,7 +176,6 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
-PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -5
index 9a22a8a..ba198de 100644
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size,
     isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
     if (pci_enabled) {
-        if (!xen_enabled()) {
-            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        } else {
-            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        }
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
     } else {
         pci_bus = NULL;
         i440fx_state = NULL;
hw/piix_pci.c +30 -32

110 lines not on this page · raw message

#1 lore raw
Quoted 4 lines · Stefano Stabellini

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

Why not? In which version? Did anything below change? What about compat code? Older hypervisor versions?

Quoted 73 lines

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts lines to 128;

hw/pc.h +0 -1
index 0dcbee7..6d5730b 100644
@@ -176,7 +176,6 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
-PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -5
index 9a22a8a..ba198de 100644
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size,
    isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
    if (pci_enabled) {
-        if (!xen_enabled()) {
-            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        } else {
-            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        }
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
    } else {
        pci_bus = NULL;
        i440fx_state = NULL;
hw/piix_pci.c +3 -7
index 7f1c4cc..3d73a42 100644
@@ -40,6 +40,7 @@ typedef PCIHostState I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 #define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
+#define XEN_PIIX_NUM_PIRQS      128ULL
 #define PIIX_PIRQC              0x60
 
 typedef struct PIIX3State {
@@ -78,6 +79,8 @@ struct PCII440FXState {
 #define I440FX_SMRAM    0x72
 
 static void piix3_set_irq(void *opaque, int pirq, int level);
+static void piix3_write_config_xen(PCIDevice *dev,
+                               uint32_t address, uint32_t val, int len);
 
 /* return the global irq number corresponding to a given device irq
   pin. We could also use the bus number to have a more precise
@@ -173,13 +176,6 @@ static void i440fx_write_config(PCIDevice *dev,
    }
 }
 
-static void i440fx_write_config_xen(PCIDevice *dev,
-                                    uint32_t address, uint32_t val, int len)
-{
-    xen_piix_pci_write_config_client(address, val, len);
-    i440fx_write_config(dev, address, val, len);
-}
-
 static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
 {
    PCII440FXState *d = opaque;

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 270

Quoted 10 lines
hw/piix_pci.c +5 -2
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
    d = pci_create_simple(b, 0, device_name);
    *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

Alex

#2 lore raw
Quoted 9 lines · Alexander Graf
Quoted 4 lines · Stefano Stabellini

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

Why not? In which version? Did anything below change? What about compat code? Older hypervisor versions?

Nothing changed, I think it was a genuine mistake in the original patch
series: the intention was to catch the pci config writes to 0x60-0x63 to reprogram the xen pci link routes accordingly (see xen_piix_pci_write_config_client). If I am not mistaken a similar thing is done by non-Xen Qemu in piix3_update_irq_levels.

Quoted 76 lines
Quoted 76 lines

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts lines to 128;

hw/pc.h +0 -1
index 0dcbee7..6d5730b 100644
@@ -176,7 +176,6 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
-PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -5
index 9a22a8a..ba198de 100644
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size,
    isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
    if (pci_enabled) {
-        if (!xen_enabled()) {
-            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        } else {
-            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        }
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
    } else {
        pci_bus = NULL;
        i440fx_state = NULL;
hw/piix_pci.c +3 -7
index 7f1c4cc..3d73a42 100644
@@ -40,6 +40,7 @@ typedef PCIHostState I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 #define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
+#define XEN_PIIX_NUM_PIRQS      128ULL
 #define PIIX_PIRQC              0x60
 
 typedef struct PIIX3State {
@@ -78,6 +79,8 @@ struct PCII440FXState {
 #define I440FX_SMRAM    0x72
 
 static void piix3_set_irq(void *opaque, int pirq, int level);
+static void piix3_write_config_xen(PCIDevice *dev,
+                               uint32_t address, uint32_t val, int len);
 
 /* return the global irq number corresponding to a given device irq
   pin. We could also use the bus number to have a more precise
@@ -173,13 +176,6 @@ static void i440fx_write_config(PCIDevice *dev,
    }
 }
 
-static void i440fx_write_config_xen(PCIDevice *dev,
-                                    uint32_t address, uint32_t val, int len)
-{
-    xen_piix_pci_write_config_client(address, val, len);
-    i440fx_write_config(dev, address, val, len);
-}
-
 static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
 {
    PCII440FXState *d = opaque;
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
    d = pci_create_simple(b, 0, device_name);
    *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 270

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )

    for ( intx = 0; intx < 4; intx++ ) /* INTA-D */
        printf("Package(){0x%04xffff, %u, 0, %u},\n",
               dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

#3 lore raw
Quoted 112 lines · Stefano Stabellini
Quoted 9 lines · Alexander Graf
Quoted 4 lines · Stefano Stabellini

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

Why not? In which version? Did anything below change? What about compat code? Older hypervisor versions?

Nothing changed, I think it was a genuine mistake in the original patch
series: the intention was to catch the pci config writes to 0x60-0x63 to reprogram the xen pci link routes accordingly (see xen_piix_pci_write_config_client). If I am not mistaken a similar thing is done by non-Xen Qemu in piix3_update_irq_levels.

Quoted 76 lines
Quoted 76 lines

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts lines to 128;

hw/pc.h +0 -1
index 0dcbee7..6d5730b 100644
@@ -176,7 +176,6 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
-PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -5
index 9a22a8a..ba198de 100644
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size,
   isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
   if (pci_enabled) {
-        if (!xen_enabled()) {
-            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        } else {
-            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        }
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
   } else {
       pci_bus = NULL;
       i440fx_state = NULL;
hw/piix_pci.c +3 -7
index 7f1c4cc..3d73a42 100644
@@ -40,6 +40,7 @@ typedef PCIHostState I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 #define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
+#define XEN_PIIX_NUM_PIRQS      128ULL
 #define PIIX_PIRQC              0x60
 
 typedef struct PIIX3State {
@@ -78,6 +79,8 @@ struct PCII440FXState {
 #define I440FX_SMRAM    0x72
 
 static void piix3_set_irq(void *opaque, int pirq, int level);
+static void piix3_write_config_xen(PCIDevice *dev,
+                               uint32_t address, uint32_t val, int len);
 
 /* return the global irq number corresponding to a given device irq
  pin. We could also use the bus number to have a more precise
@@ -173,13 +176,6 @@ static void i440fx_write_config(PCIDevice *dev,
   }
 }
 
-static void i440fx_write_config_xen(PCIDevice *dev,
-                                    uint32_t address, uint32_t val, int len)
-{
-    xen_piix_pci_write_config_client(address, val, len);
-    i440fx_write_config(dev, address, val, len);
-}
-
 static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
 {
   PCII440FXState *d = opaque;
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
   d = pci_create_simple(b, 0, device_name);
   *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 270

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

       printf("Package(){0x%04xffff, %u, 0, %u},\n",
              dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Also, do you really need this? For KVM, we simply share interrupts or use MSI where we need the device separate.

Alex

#4 lore raw
Quoted 123 lines · Alexander Graf
Quoted 112 lines · Stefano Stabellini
Quoted 9 lines · Alexander Graf
Quoted 4 lines · Stefano Stabellini

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

Why not? In which version? Did anything below change? What about compat code? Older hypervisor versions?

Nothing changed, I think it was a genuine mistake in the original patch
series: the intention was to catch the pci config writes to 0x60-0x63 to reprogram the xen pci link routes accordingly (see xen_piix_pci_write_config_client). If I am not mistaken a similar thing is done by non-Xen Qemu in piix3_update_irq_levels.

Quoted 76 lines
Quoted 76 lines

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts lines to 128;

hw/pc.h +0 -1
index 0dcbee7..6d5730b 100644
@@ -176,7 +176,6 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
-PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -5
index 9a22a8a..ba198de 100644
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size,
   isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
   if (pci_enabled) {
-        if (!xen_enabled()) {
-            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        } else {
-            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        }
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
   } else {
       pci_bus = NULL;
       i440fx_state = NULL;
hw/piix_pci.c +3 -7
index 7f1c4cc..3d73a42 100644
@@ -40,6 +40,7 @@ typedef PCIHostState I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 #define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
+#define XEN_PIIX_NUM_PIRQS      128ULL
 #define PIIX_PIRQC              0x60
 
 typedef struct PIIX3State {
@@ -78,6 +79,8 @@ struct PCII440FXState {
 #define I440FX_SMRAM    0x72
 
 static void piix3_set_irq(void *opaque, int pirq, int level);
+static void piix3_write_config_xen(PCIDevice *dev,
+                               uint32_t address, uint32_t val, int len);
 
 /* return the global irq number corresponding to a given device irq
  pin. We could also use the bus number to have a more precise
@@ -173,13 +176,6 @@ static void i440fx_write_config(PCIDevice *dev,
   }
 }
 
-static void i440fx_write_config_xen(PCIDevice *dev,
-                                    uint32_t address, uint32_t val, int len)
-{
-    xen_piix_pci_write_config_client(address, val, len);
-    i440fx_write_config(dev, address, val, len);
-}
-
 static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
 {
   PCII440FXState *d = opaque;
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
   d = pci_create_simple(b, 0, device_name);
   *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 270

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

       printf("Package(){0x%04xffff, %u, 0, %u},\n",
              dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Quoted 4 lines

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Isn't this more a function of the "wires" on the motherboard than the PIIX specifically? i.e. this just encodes the permutation of the wires from the PCI slots into the IO-APIC input pins (bypassing the PIIX, which is only used for legacy ISA IRQs i.e. by non-APIC aware OSes)?

IOW I guess strictly speaking Xen differs from the i440fx rather than from the PIIX?

So XEN_PIIX_NUM_PIRQS is a bit misnamed -- it's more like XEN_I440FX_NUM_PIRQS (or maybe even XEN_IOAPIC_NUM_...?)

Ian.

#5 lore raw

Am 14.06.2011 um 14:17 schrieb Ian Campbell <[email protected]>:

Quoted 129 lines · Alexander Graf
Quoted 123 lines · Stefano Stabellini
Quoted 113 lines · Alexander Graf
Quoted 9 lines · Stefano Stabellini
Quoted 5 lines

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

Why not? In which version? Did anything below change? What about compat code? Older hypervisor versions?

Nothing changed, I think it was a genuine mistake in the original patch
series: the intention was to catch the pci config writes to 0x60-0x63 to reprogram the xen pci link routes accordingly (see xen_piix_pci_write_config_client). If I am not mistaken a similar thing is done by non-Xen Qemu in piix3_update_irq_levels.

Quoted 76 lines
Quoted 76 lines

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts lines to 128;

hw/pc.h +0 -1
index 0dcbee7..6d5730b 100644
@@ -176,7 +176,6 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
-PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -5
index 9a22a8a..ba198de 100644
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size,
  isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
  if (pci_enabled) {
-        if (!xen_enabled()) {
-            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        } else {
-            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        }
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
  } else {
      pci_bus = NULL;
      i440fx_state = NULL;
hw/piix_pci.c +3 -7
index 7f1c4cc..3d73a42 100644
@@ -40,6 +40,7 @@ typedef PCIHostState I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 #define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
+#define XEN_PIIX_NUM_PIRQS      128ULL
 #define PIIX_PIRQC              0x60
 
 typedef struct PIIX3State {
@@ -78,6 +79,8 @@ struct PCII440FXState {
 #define I440FX_SMRAM    0x72
 
 static void piix3_set_irq(void *opaque, int pirq, int level);
+static void piix3_write_config_xen(PCIDevice *dev,
+                               uint32_t address, uint32_t val, int len);
 
 /* return the global irq number corresponding to a given device irq
 pin. We could also use the bus number to have a more precise
@@ -173,13 +176,6 @@ static void i440fx_write_config(PCIDevice *dev,
  }
 }
 
-static void i440fx_write_config_xen(PCIDevice *dev,
-                                    uint32_t address, uint32_t val, int len)
-{
-    xen_piix_pci_write_config_client(address, val, len);
-    i440fx_write_config(dev, address, val, len);
-}
-
 static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
 {
  PCII440FXState *d = opaque;
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
  d = pci_create_simple(b, 0, device_name);
  *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 270

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

      printf("Package(){0x%04xffff, %u, 0, %u},\n",
             dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Quoted 4 lines

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Quoted 4 lines

Isn't this more a function of the "wires" on the motherboard than the PIIX specifically? i.e. this just encodes the permutation of the wires from the PCI slots into the IO-APIC input pins (bypassing the PIIX, which is only used for legacy ISA IRQs i.e. by non-APIC aware OSes)?

Interrupts with PCI work slightly different. PCI devices can map (themselves or by software) to one of 4 interrupt lines: INTA, INTB, INTC, INTD. These get converted using PCI host controller specific logic to 4 interrupt lines which then go into the IO-APIC.

The IO-APIC is a chip with a limited number of pins. IIRC it was 24, could be 26 though.

I haven't seen a single case where PCI devices have a direct link to the IO-APIC. I also have not seen any PCI host controller that exports more than 4 interrupts. Giving each PCI device its own line, on top of that more than ever could be in real hardware, is a plain hack IMHO.

Did this really give you actual performance/latency/scalability gains? I still think for devices that matter, we should go with MSI rather than deriving from real hw.

Alex

Quoted 1 line
#6 lore raw
Quoted 137 lines · Alexander Graf

Am 14.06.2011 um 14:17 schrieb Ian Campbell <[email protected]>:

Quoted 129 lines · Alexander Graf
Quoted 123 lines · Stefano Stabellini
Quoted 113 lines · Alexander Graf
Quoted 9 lines · Stefano Stabellini
Quoted 5 lines

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

Why not? In which version? Did anything below change? What about compat code? Older hypervisor versions?

Nothing changed, I think it was a genuine mistake in the original patch
series: the intention was to catch the pci config writes to 0x60-0x63 to reprogram the xen pci link routes accordingly (see xen_piix_pci_write_config_client). If I am not mistaken a similar thing is done by non-Xen Qemu in piix3_update_irq_levels.

Quoted 76 lines
Quoted 76 lines

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts lines to 128;

hw/pc.h +0 -1
index 0dcbee7..6d5730b 100644
@@ -176,7 +176,6 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
-PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -5
index 9a22a8a..ba198de 100644
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size,
  isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
  if (pci_enabled) {
-        if (!xen_enabled()) {
-            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        } else {
-            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        }
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
  } else {
      pci_bus = NULL;
      i440fx_state = NULL;
hw/piix_pci.c +3 -7
index 7f1c4cc..3d73a42 100644
@@ -40,6 +40,7 @@ typedef PCIHostState I440FXState;
 
 #define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 #define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
+#define XEN_PIIX_NUM_PIRQS      128ULL
 #define PIIX_PIRQC              0x60
 
 typedef struct PIIX3State {
@@ -78,6 +79,8 @@ struct PCII440FXState {
 #define I440FX_SMRAM    0x72
 
 static void piix3_set_irq(void *opaque, int pirq, int level);
+static void piix3_write_config_xen(PCIDevice *dev,
+                               uint32_t address, uint32_t val, int len);
 
 /* return the global irq number corresponding to a given device irq
 pin. We could also use the bus number to have a more precise
@@ -173,13 +176,6 @@ static void i440fx_write_config(PCIDevice *dev,
  }
 }
 
-static void i440fx_write_config_xen(PCIDevice *dev,
-                                    uint32_t address, uint32_t val, int len)
-{
-    xen_piix_pci_write_config_client(address, val, len);
-    i440fx_write_config(dev, address, val, len);
-}
-
 static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
 {
  PCII440FXState *d = opaque;
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
  d = pci_create_simple(b, 0, device_name);
  *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 270

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

      printf("Package(){0x%04xffff, %u, 0, %u},\n",
             dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Quoted 4 lines

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Quoted 4 lines

Isn't this more a function of the "wires" on the motherboard than the PIIX specifically? i.e. this just encodes the permutation of the wires from the PCI slots into the IO-APIC input pins (bypassing the PIIX, which is only used for legacy ISA IRQs i.e. by non-APIC aware OSes)?

Quoted 7 lines

Interrupts with PCI work slightly different. PCI devices can map (themselves or by software) to one of 4 interrupt lines: INTA, INTB, INTC, INTD. These get converted using PCI host controller specific logic to 4 interrupt lines which then go into the IO-APIC.

The IO-APIC is a chip with a limited number of pins. IIRC it was 24, could be 26 though.

I haven't seen a single case where PCI devices have a direct link to the IO-APIC. I also have not seen any PCI host controller that exports more than 4 interrupts. Giving each PCI device its own line, on top of that more than ever could be in real hardware, is a plain hack IMHO.

Did this really give you actual performance/latency/scalability gains? I still think for devices that matter, we should go with MSI rather than deriving from real hw.

I bet the motivation is to have an IRQ route that is independent of QEMU, thus can be discovered inside the Xen kernel and then remains stable - or is simply hard-wired. Device assignment? Direct legacy IRQ injection from the kernel?

KVM (qemu-kvm) has that issue as well and uses a simple hack to get a notification on routing changes. That works as long as there is only one hub (the PIIX3) involved. We need something smarter on the long term, though.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#7 lore raw
Quoted 5 lines · Jan Kiszka

I bet the motivation is to have an IRQ route that is independent of QEMU, thus can be discovered inside the Xen kernel and then remains stable - or is simply hard-wired. Device assignment? Direct legacy IRQ injection from the kernel?

This code predates me, so Keir might have more insights on the original motivation, but you are correct, they are hard-wired and can be used for device-assignment as well.

#8 lore raw
In reply to Alexander Graf
Quoted 39 lines · Alexander Graf
Quoted 39 lines
Quoted 38 lines
Quoted 25 lines
Quoted 7 lines
Quoted 7 lines

static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id) {
PCII440FXState *d = opaque;

(quoted diff) +0 -0
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
  d = pci_create_simple(b, 0, device_name);
  *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

Review static PCIBus *i440fx_common_init(const char *device_name, · line 270

Quoted 7 lines
(quoted diff) +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

      printf("Package(){0x%04xffff, %u, 0, %u},\n",
             dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Quoted 8 lines
Quoted 4 lines

Isn't this more a function of the "wires" on the motherboard than the PIIX specifically? i.e. this just encodes the permutation of the wires from the PCI slots into the IO-APIC input pins (bypassing the PIIX, which is only used for legacy ISA IRQs i.e. by non-APIC aware OSes)?

Interrupts with PCI work slightly different. PCI devices can map (themselves or by software) to one of 4 interrupt lines: INTA, INTB, INTC, INTD. These get converted using PCI host controller specific logic to 4 interrupt lines which then go into the IO-APIC.

The IO-APIC is a chip with a limited number of pins. IIRC it was 24, could be 26 though.

The number of redirection entries in the IOAPIC can be discovered reading from the IOAPICVER register and it is a property of a specific model of IOAPIC. As a matter of fact Xen's emulated IOAPIC supports more pins than the most popular IOAPIC used with PIIX3.

Quoted 1 line

I haven't seen a single case where PCI devices have a direct link to the IO-APIC. I also have not seen any PCI host controller that exports more than 4 interrupts. Giving each PCI device its own line, on top of that more than ever could be in real hardware, is a plain hack IMHO.

Actually this happens quite often: if I am not mistaken all the GSIs higher than 15 are actually the result of a direct connection between an interrupt source and the IOAPIC. I have several on my testboxes. Also give a look at the Intel Multiprocessor Specification, section 3.6.2.3: as you can see from the diagram in "Symmetric I/O Mode" all the interrupts are routed through the IOAPIC directly.

Quoted 2 lines

Did this really give you actual performance/latency/scalability gains? I still think for devices that matter, we should go with MSI rather than deriving from real hw.

Not all the operating systems support MSIs, it is nice to be able to avoid interrupt sharing without recurring to MSIs.
Also this is how Xen has been working for more then 5 years in HVM mode, so this configuration is well tested and supported by most operating systems (at least all the ones we tried so far).

In any case I think it is a good idea to add a comment to better explain what we are doing, see below.

commit 973bb091a967fdec37a1bc8fe30d46a483d2903d

Author: Stefano Stabellini <[email protected]>
Date:   Tue May 17 12:10:36 2011 +0000

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts line to 128;

hw/pc.h +0 -1
index 0dcbee7..6d5730b 100644
@@ -176,7 +176,6 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
-PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -5
index 9a22a8a..ba198de 100644
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size,
     isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
     if (pci_enabled) {
-        if (!xen_enabled()) {
-            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        } else {
-            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
-        }
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
     } else {
         pci_bus = NULL;
         i440fx_state = NULL;
hw/piix_pci.c +34 -32

114 lines not on this page · raw message

#9 lore raw
Quoted 45 lines · Stefano Stabellini
Quoted 44 lines · Alexander Graf
Quoted 43 lines
Quoted 34 lines
Quoted 25 lines
Quoted 7 lines
Quoted 7 lines

static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id) {
PCII440FXState *d = opaque;

hw/piix_pci.c +0 -0
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
  d = pci_create_simple(b, 0, device_name);
  *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 274

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

      printf("Package(){0x%04xffff, %u, 0, %u},\n",
             dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Quoted 4 lines

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Isn't this more a function of the "wires" on the motherboard than the PIIX specifically? i.e. this just encodes the permutation of the wires from the PCI slots into the IO-APIC input pins (bypassing the PIIX, which is only used for legacy ISA IRQs i.e. by non-APIC aware OSes)?

Quoted 8 lines
Quoted 3 lines

Interrupts with PCI work slightly different. PCI devices can map (themselves or by software) to one of 4 interrupt lines: INTA, INTB, INTC, INTD. These get converted using PCI host controller specific logic to 4 interrupt lines which then go into the IO-APIC.

The IO-APIC is a chip with a limited number of pins. IIRC it was 24, could be 26 though.

The number of redirection entries in the IOAPIC can be discovered reading from the IOAPICVER register and it is a property of a specific model of IOAPIC. As a matter of fact Xen's emulated IOAPIC supports more pins than the most popular IOAPIC used with PIIX3.

Do real IOAPICs exist with more than 24 pins? Otherwise there is the risk that OSes aren't well prepared for this oddity - specifically not when the chipset is specified to include a 24-pin IOAPIC.

Quoted 7 lines
Quoted 3 lines

I haven't seen a single case where PCI devices have a direct link to the IO-APIC. I also have not seen any PCI host controller that exports more than 4 interrupts. Giving each PCI device its own line, on top of that more than ever could be in real hardware, is a plain hack IMHO.

Actually this happens quite often: if I am not mistaken all the GSIs higher than 15 are actually the result of a direct connection between an interrupt source and the IOAPIC. I have several on my testboxes.

Except that the interrupt source is the chipset with its PCI bridge, not individual PCI devices.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#10 lore raw
Quoted 50 lines · Jan Kiszka
Quoted 49 lines · Stefano Stabellini
Quoted 47 lines · Alexander Graf
Quoted 39 lines
Quoted 34 lines
Quoted 25 lines
Quoted 7 lines
Quoted 7 lines

static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id) {
PCII440FXState *d = opaque;

hw/piix_pci.c +0 -0
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
  d = pci_create_simple(b, 0, device_name);
  *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 274

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

      printf("Package(){0x%04xffff, %u, 0, %u},\n",
             dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Quoted 4 lines

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Quoted 4 lines

Isn't this more a function of the "wires" on the motherboard than the PIIX specifically? i.e. this just encodes the permutation of the wires from the PCI slots into the IO-APIC input pins (bypassing the PIIX, which is only used for legacy ISA IRQs i.e. by non-APIC aware OSes)?

Interrupts with PCI work slightly different. PCI devices can map (themselves or by software) to one of 4 interrupt lines: INTA, INTB, INTC, INTD. These get converted using PCI host controller specific logic to 4 interrupt lines which then go into the IO-APIC.

The IO-APIC is a chip with a limited number of pins. IIRC it was 24, could be 26 though.

Quoted 8 lines
Quoted 4 lines

The number of redirection entries in the IOAPIC can be discovered reading from the IOAPICVER register and it is a property of a specific model of IOAPIC. As a matter of fact Xen's emulated IOAPIC supports more pins than the most popular IOAPIC used with PIIX3.

Do real IOAPICs exist with more than 24 pins? Otherwise there is the risk that OSes aren't well prepared for this oddity - specifically not when the chipset is specified to include a 24-pin IOAPIC.

Linux supports up to 128 pins and as I wrote before all the other OSes we tested so far seem to react well.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I haven't seen a single case where PCI devices have a direct link to the IO-APIC. I also have not seen any PCI host controller that exports more than 4 interrupts. Giving each PCI device its own line, on top of that more than ever could be in real hardware, is a plain hack IMHO.

Actually this happens quite often: if I am not mistaken all the GSIs higher than 15 are actually the result of a direct connection between an interrupt source and the IOAPIC. I have several on my testboxes.

Except that the interrupt source is the chipset with its PCI bridge, not individual PCI devices.

That is the most common configuration but it is not the only one: I have an ACPI table that has individual PCI devices as source in some test boxes.
In fact there is even an example of it in this good article about interrupt routing from the FreeBSD guys (it is the last figure):

http://people.freebsd.org/~jhb/papers/bsdcan/2007/article/node5.html

"Figure 6 contains a portion of an example _PRT. Specifically, it includes the first entry in the table. This corresponds to the PCI interrupt for PCI bus 3, slot 7"

..ZIP...

"For APIC mode, the interrupt is routed to GSI 66. For this machine, ACPI assigns a base GSI of 64 to the I/O APIC with an APIC ID of 10. Thus, GSI 66 corresponds to pin 2 on that I/O APIC"

Unless I am missing something I don't think that interrupt is going through any PCI bridges...

#11 lore raw
Quoted 85 lines · Stefano Stabellini
Quoted 50 lines · Jan Kiszka
Quoted 49 lines · Stefano Stabellini
Quoted 47 lines · Alexander Graf
Quoted 39 lines
Quoted 34 lines
Quoted 25 lines
Quoted 7 lines
Quoted 7 lines

static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id) {
PCII440FXState *d = opaque;

hw/piix_pci.c +0 -0
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
 d = pci_create_simple(b, 0, device_name);
 *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 274

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

     printf("Package(){0x%04xffff, %u, 0, %u},\n",
            dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Quoted 4 lines

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Quoted 4 lines

Isn't this more a function of the "wires" on the motherboard than the PIIX specifically? i.e. this just encodes the permutation of the wires from the PCI slots into the IO-APIC input pins (bypassing the PIIX, which is only used for legacy ISA IRQs i.e. by non-APIC aware OSes)?

Interrupts with PCI work slightly different. PCI devices can map (themselves or by software) to one of 4 interrupt lines: INTA, INTB, INTC, INTD. These get converted using PCI host controller specific logic to 4 interrupt lines which then go into the IO-APIC.

The IO-APIC is a chip with a limited number of pins. IIRC it was 24, could be 26 though.

Quoted 8 lines
Quoted 4 lines

The number of redirection entries in the IOAPIC can be discovered reading from the IOAPICVER register and it is a property of a specific model of IOAPIC. As a matter of fact Xen's emulated IOAPIC supports more pins than the most popular IOAPIC used with PIIX3.

Do real IOAPICs exist with more than 24 pins? Otherwise there is the risk that OSes aren't well prepared for this oddity - specifically not when the chipset is specified to include a 24-pin IOAPIC.

Linux supports up to 128 pins and as I wrote before all the other OSes we tested so far seem to react well.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I haven't seen a single case where PCI devices have a direct link to the IO-APIC. I also have not seen any PCI host controller that exports more than 4 interrupts. Giving each PCI device its own line, on top of that more than ever could be in real hardware, is a plain hack IMHO.

Actually this happens quite often: if I am not mistaken all the GSIs higher than 15 are actually the result of a direct connection between an interrupt source and the IOAPIC. I have several on my testboxes.

Except that the interrupt source is the chipset with its PCI bridge, not individual PCI devices.

That is the most common configuration but it is not the only one: I have an ACPI table that has individual PCI devices as source in some test boxes.
In fact there is even an example of it in this good article about interrupt routing from the FreeBSD guys (it is the last figure):

http://people.freebsd.org/~jhb/papers/bsdcan/2007/article/node5.html

"Figure 6 contains a portion of an example _PRT. Specifically, it includes the first entry in the table. This corresponds to the PCI interrupt for PCI bus 3, slot 7"

Quoted 8 lines

..ZIP...

"For APIC mode, the interrupt is routed to GSI 66. For this machine, ACPI assigns a base GSI of 64 to the I/O APIC with an APIC ID of 10. Thus, GSI 66 corresponds to pin 2 on that I/O APIC"

Unless I am missing something I don't think that interrupt is going through any PCI bridges...

I'm actually not quite sure what exactly he's describing here. But if it's bypassing the bus logic, it's not a normal PCI device :). Sure, there are special case devices that also expose a PCI interface. But real PCI cards that you plug in onto the PCI bus can't bypass the interrupt logic of the bus, as the only interrupt wires they have go to the bus. And since the PCI adapters we use in PC machines in Qemu are all non-special, guests can possibly choke on this.

But either way, I won't block the patch as I mentioned before.

Alex

#12 lore raw
Quoted 2 lines · Alexander Graf

I'm actually not quite sure what exactly he's describing here. But if it's bypassing the bus logic, it's not a normal PCI device :). Sure, there are special case devices that also expose a PCI interface. But real PCI cards that you plug in onto the PCI bus can't bypass the interrupt logic of the bus, as the only interrupt wires they have go to the bus. And since the PCI adapters we use in PC machines in Qemu are all non-special, guests can possibly choke on this.

There actually is a special device in qemu - acpi power management is configured as a PCI device, but its interrupt is hard-wired to gsi 9 and is edge-triggered (so it can't share the irq line).

I other devices that are special in this regard to also be part of the chipset, not devices you can plug into arbitrary slots.

Signature · 1 line
error compiling committee.c: too many arguments to function
#13 lore raw

Am 15.06.2011 um 18:34 schrieb Avi Kivity <[email protected]>:

Quoted 7 lines · Alexander Graf
Quoted 2 lines

I'm actually not quite sure what exactly he's describing here. But if it's bypassing the bus logic, it's not a normal PCI device :). Sure, there are special case devices that also expose a PCI interface. But real PCI cards that you plug in onto the PCI bus can't bypass the interrupt logic of the bus, as the only interrupt wires they have go to the bus. And since the PCI adapters we use in PC machines in Qemu are all non-special, guests can possibly choke on this.

There actually is a special device in qemu - acpi power management is configured as a PCI device, but its interrupt is hard-wired to gsi 9 and is edge-triggered (so it can't share the irq line).

I other devices that are special in this regard to also be part of the chipset, not devices you can plug into arbitrary slots.

Sure, platform devices can do that. Real PCI cards can not. Have you ever seen an e1000 with direct mapped interrupt lines? :)

I admit though that we also emulate platform devices that happen to expose themselves on the PCI bus. It's not common though and I wouldn't expect every OS/driver to be happy about it.

Alex

Quoted 1 line
#14 lore raw
In reply to Stefano Stabellini
Quoted 45 lines · Stefano Stabellini
Quoted 44 lines · Alexander Graf
Quoted 43 lines
Quoted 34 lines
Quoted 25 lines
Quoted 7 lines
Quoted 7 lines

static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id) {
PCII440FXState *d = opaque;

hw/piix_pci.c +0 -0
@@ -267,8 +263,17 @@ static PCIBus *i440fx_common_init(const char *device_name,
 d = pci_create_simple(b, 0, device_name);
 *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
Quoted 9 lines

hw/piix_pci.c static PCIBus *i440fx_common_init(const char *device_name, · line 274

Quoted 7 lines
hw/piix_pci.c +5 -2
-    piix3 = DO_UPCAST(PIIX3State, dev,
-                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+    if (xen_enabled()) {
+        piix3 = DO_UPCAST(PIIX3State, dev,
+                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                piix3, XEN_PIIX_NUM_PIRQS);

But with XEN_PIIX_NUM_PIRQS it's not a piix3 anymore, no? What's the reason behind this change?

It is still a piix3, but also provides non-legacy interrupt links to the IO-APIC.
The four pins of each PCI device on the bus not only are routed to the normal four pirqs (programmed writing to 0x60-0x63, see above) but also they are connected to the IO-APIC directly.
These additional routes can only be discovered through ACPI, so you need matching ACPI tables. We used to build the old ACPI tables like this:

Quoted 8 lines

/* PRTA: APIC routing table (via non-legacy IOAPIC GSIs). */ printf("Name(PRTA, Package() {\n");
for ( dev = 1; dev < 32; dev++ )
for ( intx = 0; intx < 4; intx++ ) /* INTA-D */

     printf("Package(){0x%04xffff, %u, 0, %u},\n",
            dev, intx, ((dev*4+dev/8+intx)&31)+16);

printf("})\n");

Quoted 4 lines

Interesting concept, but completely non-standard and very much different from real hardware. Please at least add a comment there to show readers that Xen is doing a hack which is not at all related to how the PIIX really works.

Isn't this more a function of the "wires" on the motherboard than the PIIX specifically? i.e. this just encodes the permutation of the wires from the PCI slots into the IO-APIC input pins (bypassing the PIIX, which is only used for legacy ISA IRQs i.e. by non-APIC aware OSes)?

Quoted 8 lines
Quoted 3 lines

Interrupts with PCI work slightly different. PCI devices can map (themselves or by software) to one of 4 interrupt lines: INTA, INTB, INTC, INTD. These get converted using PCI host controller specific logic to 4 interrupt lines which then go into the IO-APIC.

The IO-APIC is a chip with a limited number of pins. IIRC it was 24, could be 26 though.

The number of redirection entries in the IOAPIC can be discovered reading from the IOAPICVER register and it is a property of a specific model of IOAPIC. As a matter of fact Xen's emulated IOAPIC supports more pins than the most popular IOAPIC used with PIIX3.

which means you're emulating hardware that never existed :).

Quoted 7 lines
Quoted 3 lines

I haven't seen a single case where PCI devices have a direct link to the IO-APIC. I also have not seen any PCI host controller that exports more than 4 interrupts. Giving each PCI device its own line, on top of that more than ever could be in real hardware, is a plain hack IMHO.

Actually this happens quite often: if I am not mistaken all the GSIs higher than 15 are actually the result of a direct connection between an interrupt source and the IOAPIC. I have several on my testboxes.

Yes. "Interrupt source" meaning a wire on the board. I haven't seen any situation so far where you get direct IO-APIC connections to PCI _device_ pins. You obviously get plenty connections to PCI _bus_ pins.

Quoted 10 lines

Also give a look at the Intel Multiprocessor Specification, section 3.6.2.3: as you can see from the diagram in "Symmetric I/O Mode" all the interrupts are routed through the IOAPIC directly.

Quoted 2 lines

Did this really give you actual performance/latency/scalability gains? I still think for devices that matter, we should go with MSI rather than deriving from real hw.

Not all the operating systems support MSIs, it is nice to be able to avoid interrupt sharing without recurring to MSIs.

Yes and no. It's a tradeoff. If no interrupt sharing means that we emulate hardware that simply never could have existed the way we model it, I think it's a bad idea.

Quoted 3 lines

Also this is how Xen has been working for more then 5 years in HVM mode, so this configuration is well tested and supported by most operating systems (at least all the ones we tried so far).

I'm fine with Xen breaking its own neck, as long as it doesn't affect non-Xen code paths. Just be aware that I'm not a huge fan of this approach :).

Quoted 11 lines

In any case I think it is a good idea to add a comment to better explain what we are doing, see below.

commit 973bb091a967fdec37a1bc8fe30d46a483d2903d

Author: Stefano Stabellini <[email protected]>
Date:   Tue May 17 12:10:36 2011 +0000

xen: fix interrupt routing

Quoted 8 lines

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

- set the number of PIIX3-xen interrupts line to 128;

I still find it unpretty and I'm pretty sure it's completely different from real hardware, but since Xen code is your call and this doesn't affect non-Xen workloads, I won't block it, unless someone else is very much opposed to it.

Please resend as proper patch.

Alex

#15 lore raw
Quoted 13 lines · Alexander Graf
Quoted 13 lines

commit 973bb091a967fdec37a1bc8fe30d46a483d2903d

Author: Stefano Stabellini <[email protected]>
Date:   Tue May 17 12:10:36 2011 +0000

xen: fix interrupt routing

- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;

- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;

Quoted 6 lines
Quoted 1 line

- set the number of PIIX3-xen interrupts line to 128;

I still find it unpretty and I'm pretty sure it's completely different from real hardware, but since Xen code is your call and this doesn't affect non-Xen workloads, I won't block it, unless someone else is very much opposed to it.

Please resend as proper patch.

Thanks, I'll do that.