Skip to contentSkip to conversation

malta: Move PCI interrupt handling from gt64xxx to piix4

PATCH Superseded Bernhard Beschow 5 participants 15 messages Jan 12, 2022 – Feb 10, 2022

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover malta: Move PCI interrupt handling from gt64xxx to piix4

Hi,

first-time contributor here. Inspired by an article in LWN [1] I figured I'd get my hands dirty with QEMU development. According to the article my goal is to eliminate some "accidental complexity".

While studying the code I noticed some (accidental?) differences between piix3 and piix4 where the PCI interrupts are handled. Moreover, I noticed presence of global variables in piix4 which probably constitute a limitation of QOM's idea of configuration-driven machine creation. By applying piix3 concepts, i.e. moving the interrupt handling from gt64xxx to piix4, it's possible to both eliminate the differences and resolve the global variables.

The patch series is structured as follows: Patch 1 eliminates the differences, patch 3 resolves the global variables. Patch 2 is a preparation for patch 3. Some of my further comments regarding the patches are:

Patch 1:
* pci_slot_get_pirq() looks quite malta-specific. Neither gt64xxx nor piix4 seem to be the perfect fit. So I moved it to piix4, analogous to piix3.
* The i8259 property moved from MaltaState to PIIX4State looks quite redundant to the isa property. Could isa be used instead, eliminating i8259?

Patch 2:
* Besides piix4, there were four further cases where the PIC array was passed as the opaque parameter to the pci_map_irq_fn's. AFAICS in all other cases the DeviceState is passed instead. With this patch, consistency is esablished.
* Passing PIIX4State to piix4_set_irq() paves the way for eliminating all global variables left in piix4.c (see patch 3).

Comments welcome.

Cheers
Bernhard

[1] https://lwn.net/Articles/872321/

Bernhard Beschow (3):
malta: Move PCI interrupt handling from gt64xxx to piix4
pci: Always pass own DeviceState to pci_map_irq_fn's isa/piix4: Resolve global variables

 hw/isa/piix4.c                | 62 ++++++++++++++++++++++++++++++++---
 hw/mips/gt64xxx_pci.c         | 62 +++--------------------------------
 hw/mips/malta.c               |  6 +---
 hw/pci-host/sh_pci.c          |  6 ++--
 hw/pci-host/versatile.c       |  6 ++--
 hw/ppc/ppc440_pcix.c          |  6 ++--
 hw/ppc/ppc4xx_pci.c           |  6 ++--
 include/hw/mips/mips.h        |  2 +-
 include/hw/southbridge/piix.h |  2 --
 9 files changed, 77 insertions(+), 81 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 malta: Move PCI interrupt handling from gt64xxx to piix4

Handling PCI interrupts in piix4 increases cohesion and reduces differences between piix4 and piix3.

---
 hw/isa/piix4.c         | 58 +++++++++++++++++++++++++++++++++++++++
 hw/mips/gt64xxx_pci.c  | 62 ++++--------------------------------------
 hw/mips/malta.c        |  6 +---
 include/hw/mips/mips.h |  2 +-
 4 files changed, 65 insertions(+), 63 deletions(-)
hw/isa/piix4.c +58 -0
index 0fe7b69bc4..5a86308689 100644
@@ -45,6 +45,7 @@ struct PIIX4State {
     PCIDevice dev;
     qemu_irq cpu_intr;
     qemu_irq *isa;
+    qemu_irq i8259[ISA_NUM_IRQS];
 
     RTCState rtc;
     /* Reset Control Register */
@@ -54,6 +55,30 @@ struct PIIX4State {
 
 OBJECT_DECLARE_SIMPLE_TYPE(PIIX4State, PIIX4_PCI_DEVICE)
 
+static int pci_irq_levels[4];
+
+static void piix4_set_irq(void *opaque, int irq_num, int level)
+{
+    int i, pic_irq, pic_level;
+    qemu_irq *pic = opaque;
+
+    pci_irq_levels[irq_num] = level;
+
+    /* now we change the pic irq level according to the piix irq mappings */
+    /* XXX: optimize */
+    pic_irq = piix4_dev->config[PIIX_PIRQCA + irq_num];
+    if (pic_irq < 16) {
+        /* The pic level is the logical OR of all the PCI irqs mapped to it. */
+        pic_level = 0;
+        for (i = 0; i < 4; i++) {
+            if (pic_irq == piix4_dev->config[PIIX_PIRQCA + i]) {
+                pic_level |= pci_irq_levels[i];
+            }
+        }
+        qemu_set_irq(pic[pic_irq], pic_level);
+    }
+}
+
 static void piix4_isa_reset(DeviceState *dev)
 {
     PIIX4State *d = PIIX4_PCI_DEVICE(dev);
@@ -248,8 +273,34 @@ static void piix4_register_types(void)
 
 type_init(piix4_register_types)
 
+static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
+{
+    int slot;
+
+    slot = PCI_SLOT(pci_dev->devfn);
+
+    switch (slot) {
+    /* PIIX4 USB */
+    case 10:
+        return 3;
+    /* AMD 79C973 Ethernet */
+    case 11:
+        return 1;
+    /* Crystal 4281 Sound */
+    case 12:
+        return 2;
+    /* PCI slot 1 to 4 */
+    case 18 ... 21:
+        return ((slot - 18) + irq_num) & 0x03;
+    /* Unknown device, don't do any translation */
+    default:
+        return irq_num;
+    }
+}
+
 DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 {
+    PIIX4State *s;
     PCIDevice *pci;
     DeviceState *dev;
     int devfn = PCI_DEVFN(10, 0);
@@ -257,6 +308,7 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
     pci = pci_create_simple_multifunction(pci_bus, devfn,  true,
                                           TYPE_PIIX4_PCI_DEVICE);
     dev = DEVICE(pci);
+    s = PIIX4_PCI_DEVICE(pci);
     if (isa_bus) {
         *isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
     }
@@ -271,5 +323,11 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
                                NULL, 0, NULL);
     }
 
+    pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s->i8259, 4);
+
+    for (int i = 0; i < ISA_NUM_IRQS; i++) {
+        s->i8259[i] = qdev_get_gpio_in_named(dev, "isa", i);
+    }
+
     return dev;
 }
hw/mips/gt64xxx_pci.c +5 -57

80 lines not on this page · raw message

hw/mips/malta.c +1 -5
index b770b8d367..13254dbc89 100644
@@ -97,7 +97,6 @@ struct MaltaState {
 
     Clock *cpuclk;
     MIPSCPSState cps;
-    qemu_irq i8259[ISA_NUM_IRQS];
 };
 
 static struct _loaderparams {
@@ -1391,7 +1390,7 @@ void mips_malta_init(MachineState *machine)
     stl_p(memory_region_get_ram_ptr(bios_copy) + 0x10, 0x00000420);
 
     /* Northbridge */
-    pci_bus = gt64120_register(s->i8259);
+    pci_bus = gt64120_register();
     /*
      * The whole address space decoded by the GT-64120A doesn't generate
      * exception when accessing invalid memory. Create an empty slot to
@@ -1404,9 +1403,6 @@ void mips_malta_init(MachineState *machine)
 
     /* Interrupt controller */
     qdev_connect_gpio_out_named(dev, "intr", 0, i8259_irq);
-    for (int i = 0; i < ISA_NUM_IRQS; i++) {
-        s->i8259[i] = qdev_get_gpio_in_named(dev, "isa", i);
-    }
 
     /* generate SPD EEPROM data */
     generate_eeprom_spd(&smbus_eeprom_buf[0 * 256], ram_size);
include/hw/mips/mips.h +1 -1
index 6c9c8805f3..ff88942e63 100644
@@ -10,7 +10,7 @@
 #include "exec/memory.h"
 
 /* gt64xxx.c */
-PCIBus *gt64120_register(qemu_irq *pic);
+PCIBus *gt64120_register(void);
 
 /* bonito.c */
 PCIBus *bonito_init(qemu_irq *pic);
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 1/3
#2 lore raw
Quoted 10 lines · Bernhard Beschow

Handling PCI interrupts in piix4 increases cohesion and reduces differences between piix4 and piix3.

---
  hw/isa/piix4.c         | 58 +++++++++++++++++++++++++++++++++++++++
  hw/mips/gt64xxx_pci.c  | 62 ++++--------------------------------------
  hw/mips/malta.c        |  6 +---
  include/hw/mips/mips.h |  2 +-
  4 files changed, 65 insertions(+), 63 deletions(-)

Great!

#3 lore raw

PATCH 2/3 pci: Always pass own DeviceState to pci_map_irq_fn's

In reply to Bernhard Beschow

Passing own DeviceState rather than just the IRQs allows for resolving global variables.

---
 hw/isa/piix4.c          | 6 +++---
 hw/pci-host/sh_pci.c    | 6 +++---
 hw/pci-host/versatile.c | 6 +++---
 hw/ppc/ppc440_pcix.c    | 6 +++---
 hw/ppc/ppc4xx_pci.c     | 6 +++---
 5 files changed, 15 insertions(+), 15 deletions(-)
hw/isa/piix4.c +3 -3
index 5a86308689..a31e9714cf 100644
@@ -60,7 +60,7 @@ static int pci_irq_levels[4];
 static void piix4_set_irq(void *opaque, int irq_num, int level)
 {
     int i, pic_irq, pic_level;
-    qemu_irq *pic = opaque;
+    PIIX4State *s = opaque;
 
     pci_irq_levels[irq_num] = level;
 
@@ -75,7 +75,7 @@ static void piix4_set_irq(void *opaque, int irq_num, int level)
                 pic_level |= pci_irq_levels[i];
             }
         }
-        qemu_set_irq(pic[pic_irq], pic_level);
+        qemu_set_irq(s->i8259[pic_irq], pic_level);
     }
 }
 
@@ -323,7 +323,7 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
                                NULL, 0, NULL);
     }
 
-    pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s->i8259, 4);
+    pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s, 4);
 
     for (int i = 0; i < ISA_NUM_IRQS; i++) {
         s->i8259[i] = qdev_get_gpio_in_named(dev, "isa", i);
hw/pci-host/sh_pci.c +3 -3
index 719d6ca2a6..ae0aa462b3 100644
@@ -111,9 +111,9 @@ static int sh_pci_map_irq(PCIDevice *d, int irq_num)
 
 static void sh_pci_set_irq(void *opaque, int irq_num, int level)
 {
-    qemu_irq *pic = opaque;
+    SHPCIState *s = opaque;
 
-    qemu_set_irq(pic[irq_num], level);
+    qemu_set_irq(s->irq[irq_num], level);
 }
 
 static void sh_pci_device_realize(DeviceState *dev, Error **errp)
@@ -128,7 +128,7 @@ static void sh_pci_device_realize(DeviceState *dev, Error **errp)
     }
     phb->bus = pci_register_root_bus(dev, "pci",
                                      sh_pci_set_irq, sh_pci_map_irq,
-                                     s->irq,
+                                     s,
                                      get_system_memory(),
                                      get_system_io(),
                                      PCI_DEVFN(0, 0), 4, TYPE_PCI_BUS);
hw/pci-host/versatile.c +3 -3
index f66384fa02..5fbcb72d7d 100644
@@ -362,9 +362,9 @@ static int pci_vpb_rv_map_irq(PCIDevice *d, int irq_num)
 
 static void pci_vpb_set_irq(void *opaque, int irq_num, int level)
 {
-    qemu_irq *pic = opaque;
+    PCIVPBState *s = opaque;
 
-    qemu_set_irq(pic[irq_num], level);
+    qemu_set_irq(s->irq[irq_num], level);
 }
 
 static void pci_vpb_reset(DeviceState *d)
@@ -422,7 +422,7 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp)
         mapfn = pci_vpb_map_irq;
     }
 
-    pci_bus_irqs(&s->pci_bus, pci_vpb_set_irq, mapfn, s->irq, 4);
+    pci_bus_irqs(&s->pci_bus, pci_vpb_set_irq, mapfn, s, 4);
 
     /* Our memory regions are:
      * 0 : our control registers
hw/ppc/ppc440_pcix.c +3 -3
index 788d25514a..291c1bfbe7 100644
@@ -431,14 +431,14 @@ static int ppc440_pcix_map_irq(PCIDevice *pci_dev, int irq_num)
 
 static void ppc440_pcix_set_irq(void *opaque, int irq_num, int level)
 {
-    qemu_irq *pci_irq = opaque;
+    PPC440PCIXState *s = opaque;
 
     trace_ppc440_pcix_set_irq(irq_num);
     if (irq_num < 0) {
         error_report("%s: PCI irq %d", __func__, irq_num);
         return;
     }
-    qemu_set_irq(*pci_irq, level);
+    qemu_set_irq(s->irq, level);
 }
 
 static AddressSpace *ppc440_pcix_set_iommu(PCIBus *b, void *opaque, int devfn)
@@ -492,7 +492,7 @@ static void ppc440_pcix_realize(DeviceState *dev, Error **errp)
     sysbus_init_irq(sbd, &s->irq);
     memory_region_init(&s->busmem, OBJECT(dev), "pci bus memory", UINT64_MAX);
     h->bus = pci_register_root_bus(dev, NULL, ppc440_pcix_set_irq,
-                         ppc440_pcix_map_irq, &s->irq, &s->busmem,
+                         ppc440_pcix_map_irq, s, &s->busmem,
                          get_system_io(), PCI_DEVFN(0, 0), 1, TYPE_PCI_BUS);
 
     s->dev = pci_create_simple(h->bus, PCI_DEVFN(0, 0), "ppc4xx-host-bridge");
hw/ppc/ppc4xx_pci.c +3 -3
index 5df97e6d15..f6718746a1 100644
@@ -256,11 +256,11 @@ static int ppc4xx_pci_map_irq(PCIDevice *pci_dev, int irq_num)
 
 static void ppc4xx_pci_set_irq(void *opaque, int irq_num, int level)
 {
-    qemu_irq *pci_irqs = opaque;
+    PPC4xxPCIState *s = opaque;
 
     trace_ppc4xx_pci_set_irq(irq_num);
     assert(irq_num >= 0 && irq_num < PPC4xx_PCI_NUM_DEVS);
-    qemu_set_irq(pci_irqs[irq_num], level);
+    qemu_set_irq(s->irq[irq_num], level);
 }
 
 static const VMStateDescription vmstate_pci_master_map = {
@@ -319,7 +319,7 @@ static void ppc4xx_pcihost_realize(DeviceState *dev, Error **errp)
     }
 
     b = pci_register_root_bus(dev, NULL, ppc4xx_pci_set_irq,
-                              ppc4xx_pci_map_irq, s->irq, get_system_memory(),
+                              ppc4xx_pci_map_irq, s, get_system_memory(),
                               get_system_io(), 0, ARRAY_SIZE(s->irq),
                               TYPE_PCI_BUS);
     h->bus = b;
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 2/3
#5 lore raw

Re: [PATCH 2/3] pci: Always pass own DeviceState to pci_map_irq_fn's

In reply to Bernhard Beschow
Quoted 11 lines · Bernhard Beschow

Passing own DeviceState rather than just the IRQs allows for resolving global variables.

---
  hw/isa/piix4.c          | 6 +++---
  hw/pci-host/sh_pci.c    | 6 +++---
  hw/pci-host/versatile.c | 6 +++---
  hw/ppc/ppc440_pcix.c    | 6 +++---
  hw/ppc/ppc4xx_pci.c     | 6 +++---
  5 files changed, 15 insertions(+), 15 deletions(-)
#6 lore raw

PATCH 3/3 isa/piix4: Resolve global variables

In reply to Bernhard Beschow

Now that piix4_set_irq's opaque parameter references own PIIX4State, piix4_dev becomes redundant and pci_irq_levels can be moved into PIIX4State.

---
 hw/isa/piix4.c                | 22 +++++++++-------------
 include/hw/southbridge/piix.h |  2 --
 2 files changed, 9 insertions(+), 15 deletions(-)
hw/isa/piix4.c +9 -13
index a31e9714cf..964e09cf7f 100644
@@ -39,14 +39,14 @@
 #include "sysemu/runstate.h"
 #include "qom/object.h"
 
-PCIDevice *piix4_dev;
-
 struct PIIX4State {
     PCIDevice dev;
     qemu_irq cpu_intr;
     qemu_irq *isa;
     qemu_irq i8259[ISA_NUM_IRQS];
 
+    int pci_irq_levels[PIIX_NUM_PIRQS];
+
     RTCState rtc;
     /* Reset Control Register */
     MemoryRegion rcr_mem;
@@ -55,24 +55,22 @@ struct PIIX4State {
 
 OBJECT_DECLARE_SIMPLE_TYPE(PIIX4State, PIIX4_PCI_DEVICE)
 
-static int pci_irq_levels[4];
-
 static void piix4_set_irq(void *opaque, int irq_num, int level)
 {
     int i, pic_irq, pic_level;
     PIIX4State *s = opaque;
 
-    pci_irq_levels[irq_num] = level;
+    s->pci_irq_levels[irq_num] = level;
 
     /* now we change the pic irq level according to the piix irq mappings */
     /* XXX: optimize */
-    pic_irq = piix4_dev->config[PIIX_PIRQCA + irq_num];
-    if (pic_irq < 16) {
+    pic_irq = s->dev.config[PIIX_PIRQCA + irq_num];
+    if (pic_irq < ISA_NUM_IRQS) {
         /* The pic level is the logical OR of all the PCI irqs mapped to it. */
         pic_level = 0;
-        for (i = 0; i < 4; i++) {
-            if (pic_irq == piix4_dev->config[PIIX_PIRQCA + i]) {
-                pic_level |= pci_irq_levels[i];
+        for (i = 0; i < PIIX_NUM_PIRQS; i++) {
+            if (pic_irq == s->dev.config[PIIX_PIRQCA + i]) {
+                pic_level |= s->pci_irq_levels[i];
             }
         }
         qemu_set_irq(s->i8259[pic_irq], pic_level);
@@ -223,8 +221,6 @@ static void piix4_realize(PCIDevice *dev, Error **errp)
         return;
     }
     isa_init_irq(ISA_DEVICE(&s->rtc), &s->rtc.irq, RTC_ISA_IRQ);
-
-    piix4_dev = dev;
 }
 
 static void piix4_init(Object *obj)
@@ -323,7 +319,7 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
                                NULL, 0, NULL);
     }
 
-    pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s, 4);
+    pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s, PIIX_NUM_PIRQS);
 
     for (int i = 0; i < ISA_NUM_IRQS; i++) {
         s->i8259[i] = qdev_get_gpio_in_named(dev, "isa", i);
include/hw/southbridge/piix.h +0 -2
index 6387f2b612..f63f83e5c6 100644
@@ -70,8 +70,6 @@ typedef struct PIIXState PIIX3State;
 DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
                          TYPE_PIIX3_PCI_DEVICE)
 
-extern PCIDevice *piix4_dev;
-
 PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus);
 
 DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus);
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH 3/3] isa/piix4: Resolve global variables

Quoted 18 lines · Bernhard Beschow

Now that piix4_set_irq's opaque parameter references own PIIX4State, piix4_dev becomes redundant and pci_irq_levels can be moved into PIIX4State.

---
 hw/isa/piix4.c                | 22 +++++++++-------------
 include/hw/southbridge/piix.h |  2 --
 2 files changed, 9 insertions(+), 15 deletions(-)
hw/isa/piix4.c +0 -0
index a31e9714cf..964e09cf7f 100644
@@ -39,14 +39,14 @@
 #include "sysemu/runstate.h"
 #include "qom/object.h"
 

hw/isa/piix4.c line 49

Quoted 10 lines
hw/isa/piix4.c +2 -2
-PCIDevice *piix4_dev;
-
 struct PIIX4State {
     PCIDevice dev;
     qemu_irq cpu_intr;
     qemu_irq *isa;
     qemu_irq i8259[ISA_NUM_IRQS];
 
+    int pci_irq_levels[PIIX_NUM_PIRQS];
+

I wondered how we were migrating this state, and the answer seems to be that we aren't (and weren't before, when it was a global variable, so this is a pre-existing bug).

Does the malta platform support migration save/load? We should probably add this field to the vmstate struct (which will be a migration compatibility break, which is OK as the malta board isn't versioned.)

-- PMM

#8 lore raw

Re: [PATCH 3/3] isa/piix4: Resolve global variables

Quoted 27 lines · Peter Maydell
Quoted 26 lines · Bernhard Beschow

Now that piix4_set_irq's opaque parameter references own PIIX4State, piix4_dev becomes redundant and pci_irq_levels can be moved into PIIX4State.

---
  hw/isa/piix4.c                | 22 +++++++++-------------
  include/hw/southbridge/piix.h |  2 --
  2 files changed, 9 insertions(+), 15 deletions(-)
hw/isa/piix4.c +0 -2
index a31e9714cf..964e09cf7f 100644
@@ -39,14 +39,14 @@
  #include "sysemu/runstate.h"
  #include "qom/object.h"
 
-PCIDevice *piix4_dev;
-
  struct PIIX4State {
      PCIDevice dev;
      qemu_irq cpu_intr;
      qemu_irq *isa;
      qemu_irq i8259[ISA_NUM_IRQS];
 
Quoted 6 lines

hw/isa/piix4.c line 49

Quoted 2 lines
hw/isa/piix4.c +2 -0
+    int pci_irq_levels[PIIX_NUM_PIRQS];
+

I wondered how we were migrating this state, and the answer seems to be that we aren't (and weren't before, when it was a global variable, so this is a pre-existing bug).

Indeed the migrated VM starts with PCI IRQ levels zeroed.

Quoted 1 line

Does the malta platform support migration save/load?

Maybe a "best effort" support, but not versioned machines.

Quoted 3 lines

We should probably add this field to the vmstate struct (which will be a migration compatibility break, which is OK as the malta board isn't versioned.)

Yeah good catch.

Bernhard, do you mind adding it?

Regards,

Phil.

author
#9 lore raw

Re: [PATCH 3/3] isa/piix4: Resolve global variables

Am 30. Januar 2022 23:53:42 MEZ schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 41 lines · Peter Maydell
Quoted 27 lines · Bernhard Beschow
Quoted 26 lines

Now that piix4_set_irq's opaque parameter references own PIIX4State, piix4_dev becomes redundant and pci_irq_levels can be moved into PIIX4State.

---
  hw/isa/piix4.c                | 22 +++++++++-------------
  include/hw/southbridge/piix.h |  2 --
  2 files changed, 9 insertions(+), 15 deletions(-)
hw/isa/piix4.c +0 -2
index a31e9714cf..964e09cf7f 100644
@@ -39,14 +39,14 @@
  #include "sysemu/runstate.h"
  #include "qom/object.h"
 
-PCIDevice *piix4_dev;
-
  struct PIIX4State {
      PCIDevice dev;
      qemu_irq cpu_intr;
      qemu_irq *isa;
      qemu_irq i8259[ISA_NUM_IRQS];
 
Quoted 6 lines

hw/isa/piix4.c line 49

Quoted 2 lines
hw/isa/piix4.c +2 -0
+    int pci_irq_levels[PIIX_NUM_PIRQS];
+

I wondered how we were migrating this state, and the answer seems to be that we aren't (and weren't before, when it was a global variable, so this is a pre-existing bug).

Indeed the migrated VM starts with PCI IRQ levels zeroed.

Quoted 1 line

Does the malta platform support migration save/load?

Maybe a "best effort" support, but not versioned machines.

Quoted 7 lines
Quoted 3 lines

We should probably add this field to the vmstate struct (which will be a migration compatibility break, which is OK as the malta board isn't versioned.)

Yeah good catch.

Bernhard, do you mind adding it?

Sure, I'll give it a try. Shall I submit a v2 of this patch series then? If so, would it be ok to change the topic of the cover letter or would that be confusing?

Last but not least: How to treat the version_id and the version parameters of the new and existing fields?

Regards,

Bernhard.

#10 lore raw

Re: [PATCH 3/3] isa/piix4: Resolve global variables

Quoted 46 lines · BB

Am 30. Januar 2022 23:53:42 MEZ schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 45 lines · Peter Maydell
Quoted 27 lines · Bernhard Beschow
Quoted 26 lines

Now that piix4_set_irq's opaque parameter references own PIIX4State, piix4_dev becomes redundant and pci_irq_levels can be moved into PIIX4State.

---
  hw/isa/piix4.c                | 22 +++++++++-------------
  include/hw/southbridge/piix.h |  2 --
  2 files changed, 9 insertions(+), 15 deletions(-)
hw/isa/piix4.c +0 -2
index a31e9714cf..964e09cf7f 100644
@@ -39,14 +39,14 @@
  #include "sysemu/runstate.h"
  #include "qom/object.h"
 
-PCIDevice *piix4_dev;
-
  struct PIIX4State {
      PCIDevice dev;
      qemu_irq cpu_intr;
      qemu_irq *isa;
      qemu_irq i8259[ISA_NUM_IRQS];
 
Quoted 6 lines

hw/isa/piix4.c line 49

Quoted 2 lines
hw/isa/piix4.c +2 -0
+    int pci_irq_levels[PIIX_NUM_PIRQS];
+

I wondered how we were migrating this state, and the answer seems to be that we aren't (and weren't before, when it was a global variable, so this is a pre-existing bug).

Indeed the migrated VM starts with PCI IRQ levels zeroed.

Quoted 1 line

Does the malta platform support migration save/load?

Maybe a "best effort" support, but not versioned machines.

Quoted 3 lines

We should probably add this field to the vmstate struct (which will be a migration compatibility break, which is OK as the malta board isn't versioned.)

Quoted 5 lines
Quoted 3 lines

Yeah good catch.

Bernhard, do you mind adding it?

Sure, I'll give it a try. Shall I submit a v2 of this patch series then? If so, would it be ok to change the topic of the cover letter or would that be confusing?

It's ok to change the subject of the cover letter.

Quoted 5 lines

Last but not least: How to treat the version_id and the version parameters of the new and existing fields?

Regards,

Bernhard.

Reviewed-by Philippe Mathieu-Daudé on v1 3/3
#11 lore raw

Re: [PATCH 3/3] isa/piix4: Resolve global variables

In reply to Bernhard Beschow
Quoted 8 lines · Bernhard Beschow

Now that piix4_set_irq's opaque parameter references own PIIX4State, piix4_dev becomes redundant and pci_irq_levels can be moved into PIIX4State.

---
  hw/isa/piix4.c                | 22 +++++++++-------------
  include/hw/southbridge/piix.h |  2 --
  2 files changed, 9 insertions(+), 15 deletions(-)

Finally!

#12 lore raw
In reply to Bernhard Beschow

Hi Bernhard,

Quoted 36 lines · Bernhard Beschow

Hi,

first-time contributor here. Inspired by an article in LWN [1] I figured I'd get my hands dirty with QEMU development. According to the article my goal is to eliminate some "accidental complexity".

While studying the code I noticed some (accidental?) differences between piix3 and piix4 where the PCI interrupts are handled. Moreover, I noticed presence of global variables in piix4 which probably constitute a limitation of QOM's idea of configuration-driven machine creation. By applying piix3 concepts, i.e. moving the interrupt handling from gt64xxx to piix4, it's possible to both eliminate the differences and resolve the global variables.

The patch series is structured as follows: Patch 1 eliminates the differences, patch 3 resolves the global variables. Patch 2 is a preparation for patch 3. Some of my further comments regarding the patches are:

Patch 1:
* pci_slot_get_pirq() looks quite malta-specific. Neither gt64xxx nor piix4 seem to be the perfect fit. So I moved it to piix4, analogous to piix3.
* The i8259 property moved from MaltaState to PIIX4State looks quite redundant to the isa property. Could isa be used instead, eliminating i8259?

Patch 2:
* Besides piix4, there were four further cases where the PIC array was passed as the opaque parameter to the pci_map_irq_fn's. AFAICS in all other cases the DeviceState is passed instead. With this patch, consistency is esablished.
* Passing PIIX4State to piix4_set_irq() paves the way for eliminating all global variables left in piix4.c (see patch 3).

Comments welcome.

Cheers
Bernhard

Quoted 6 lines

[1] https://lwn.net/Articles/872321/

Bernhard Beschow (3):
malta: Move PCI interrupt handling from gt64xxx to piix4
pci: Always pass own DeviceState to pci_map_irq_fn's isa/piix4: Resolve global variables

Did you forget to sent the patches?

#13 lore raw

Hi Philippe,

Quoted 53 lines · Philippe Mathieu-Daudé

Hi Bernhard,

Quoted 3 lines · Bernhard Beschow

Hi,

first-time contributor here. Inspired by an article in LWN [1] I figured

I'd

Quoted 1 line

get my hands dirty with QEMU development. According to the article my

goal is

Quoted 3 lines

to eliminate some "accidental complexity".

While studying the code I noticed some (accidental?) differences between

piix3

Quoted 1 line

and piix4 where the PCI interrupts are handled. Moreover, I noticed

presence of

Quoted 1 line

global variables in piix4 which probably constitute a limitation of

QOM's idea

Quoted 1 line

of configuration-driven machine creation. By applying piix3 concepts,

i.e.

Quoted 1 line

moving the interrupt handling from gt64xxx to piix4, it's possible to

both

Quoted 3 lines

eliminate the differences and resolve the global variables.

The patch series is structured as follows: Patch 1 eliminates the

differences,

Quoted 1 line

patch 3 resolves the global variables. Patch 2 is a preparation for

patch 3.

Quoted 4 lines

Some of my further comments regarding the patches are:

Patch 1:
* pci_slot_get_pirq() looks quite malta-specific. Neither gt64xxx nor

piix4

Quoted 1 line

seem to be the perfect fit. So I moved it to piix4, analogous to

piix3.

Quoted 1 line

* The i8259 property moved from MaltaState to PIIX4State looks quite

redundant

Quoted 4 lines

to the isa property. Could isa be used instead, eliminating i8259?

Patch 2:
* Besides piix4, there were four further cases where the PIC array was

passed

Quoted 1 line

as the opaque parameter to the pci_map_irq_fn's. AFAICS in all other

cases

Quoted 10 lines

the DeviceState is passed instead. With this patch, consistency is esablished.
* Passing PIIX4State to piix4_set_irq() paves the way for eliminating all global variables left in piix4.c (see patch 3).

Comments welcome.

Cheers
Bernhard

Quoted 9 lines
Quoted 6 lines

[1] https://lwn.net/Articles/872321/

Bernhard Beschow (3):
malta: Move PCI interrupt handling from gt64xxx to piix4
pci: Always pass own DeviceState to pci_map_irq_fn's isa/piix4: Resolve global variables

Did you forget to sent the patches?

I can see my patches in-reply-to my cover letter here [1]. Do I miss something?

[1] https://lists.nongnu.org/archive/html/qemu-devel/2022-01/msg02786.html

#14 lore raw
Quoted 9 lines · Bernhard Beschow

Hi Philippe,

On Thu, Jan 13, 2022 at 10:24 AM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

> Bernhard Beschow (3):
>    malta: Move PCI interrupt handling from gt64xxx to piix4 >    pci: Always pass own DeviceState to pci_map_irq_fn's >    isa/piix4: Resolve global variables

Quoted 6 lines

Did you forget to sent the patches?

I can see my patches in-reply-to my cover letter here [1]. Do I miss something?

[1] https://lists.nongnu.org/archive/html/qemu-devel/2022-01/msg02786.html <https://lists.nongnu.org/archive/html/qemu-devel/2022-01/msg02786.html>

I should have checked there first. I found the patches in my SPAM box, apparently due to "SPF=SOFTFAIL" (no clue...):

Authentication-Results: mx.google.com;
dkim=pass [email protected] header.s=20210112 header.b="Sf/DBOt0";
spf=softfail (google.com: domain of transitioning
[email protected] does not designate 172.105.152.211 as permitted sender) [email protected];
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com