Skip to contentSkip to conversation

hw/pci-host: PowerNV PCIe Device On Small PHB Seg Faults

PATCH In review Glenn Miles 3 participants 5 messages Jul 16, 2025 – Aug 8, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/pci-host: PowerNV PCIe Device On Small PHB Seg Faults

The PowerNV PCI Host Bridge (PHB) supports a large and small configuration where the small configuration supports only half the number of interrupts supported by the large configuration.

Since the PCIe LSIs are allocated at the end of the PHB IRQ list, when calculating the LSI IRQ number, the code must take into consideration the number of IRQ's supported by the PHB. This was not happening and was resulting in a QEMU segmentation fault when a PCI device was added to a PHB with the small configuration.

---
 hw/pci-host/pnv_phb4.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-host/pnv_phb4.c +2 -0
index 18992054e8..aeb2a45b4b 100644
@@ -1167,6 +1167,7 @@ static int pnv_phb4_map_irq(PCIDevice *pci_dev, int irq_num)
 static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
 {
     PnvPHB4 *phb = PNV_PHB4(opaque);
+    XiveSource *xsrc = &phb->xsrc;
     uint32_t lsi_base;
 
     /* LSI only ... */
@@ -1175,6 +1176,7 @@ static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
     }
     lsi_base = GETFIELD(PHB_LSI_SRC_ID, phb->regs[PHB_LSI_SOURCE_ID >> 3]);
     lsi_base <<= 3;
+    lsi_base &= xsrc->nr_irqs - 1;
     qemu_set_irq(phb->qirqs[lsi_base + irq_num], level);
 }
 
Signature · 1 line
2.43.5
#1 lore raw

[email protected]

Quoted 35 lines · Glenn Miles

The PowerNV PCI Host Bridge (PHB) supports a large and small configuration where the small configuration supports only half the number of interrupts supported by the large configuration.

Since the PCIe LSIs are allocated at the end of the PHB IRQ list, when calculating the LSI IRQ number, the code must take into consideration the number of IRQ's supported by the PHB. This was not happening and was resulting in a QEMU segmentation fault when a PCI device was added to a PHB with the small configuration.

---
 hw/pci-host/pnv_phb4.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-host/pnv_phb4.c +2 -0
index 18992054e8..aeb2a45b4b 100644
@@ -1167,6 +1167,7 @@ static int pnv_phb4_map_irq(PCIDevice *pci_dev, int irq_num)
 static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
 {
     PnvPHB4 *phb = PNV_PHB4(opaque);
+    XiveSource *xsrc = &phb->xsrc;
     uint32_t lsi_base;
 
     /* LSI only ... */
@@ -1175,6 +1176,7 @@ static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
     }
     lsi_base = GETFIELD(PHB_LSI_SRC_ID, phb->regs[PHB_LSI_SOURCE_ID >> 3]);
     lsi_base <<= 3;
+    lsi_base &= xsrc->nr_irqs - 1;
     qemu_set_irq(phb->qirqs[lsi_base + irq_num], level);
 }
 
#2 lore raw

+harsh

Quoted 38 lines · Miles Glenn

[email protected]

Quoted 35 lines · Glenn Miles

The PowerNV PCI Host Bridge (PHB) supports a large and small configuration where the small configuration supports only half the number of interrupts supported by the large configuration.

Since the PCIe LSIs are allocated at the end of the PHB IRQ list, when calculating the LSI IRQ number, the code must take into consideration the number of IRQ's supported by the PHB. This was not happening and was resulting in a QEMU segmentation fault when a PCI device was added to a PHB with the small configuration.

---
 hw/pci-host/pnv_phb4.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-host/pnv_phb4.c +2 -0
index 18992054e8..aeb2a45b4b 100644
@@ -1167,6 +1167,7 @@ static int pnv_phb4_map_irq(PCIDevice *pci_dev, int irq_num)
 static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
 {
     PnvPHB4 *phb = PNV_PHB4(opaque);
+    XiveSource *xsrc = &phb->xsrc;
     uint32_t lsi_base;
 
     /* LSI only ... */
@@ -1175,6 +1176,7 @@ static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
     }
     lsi_base = GETFIELD(PHB_LSI_SRC_ID, phb->regs[PHB_LSI_SOURCE_ID >> 3]);
     lsi_base <<= 3;
+    lsi_base &= xsrc->nr_irqs - 1;
     qemu_set_irq(phb->qirqs[lsi_base + irq_num], level);
 }
 
#3 lore raw

+ adding folks working in this area to help with review.

Quoted 42 lines · Miles Glenn

+harsh

Quoted 38 lines · Miles Glenn

[email protected]

Quoted 35 lines · Glenn Miles

The PowerNV PCI Host Bridge (PHB) supports a large and small configuration where the small configuration supports only half the number of interrupts supported by the large configuration.

Since the PCIe LSIs are allocated at the end of the PHB IRQ list, when calculating the LSI IRQ number, the code must take into consideration the number of IRQ's supported by the PHB. This was not happening and was resulting in a QEMU segmentation fault when a PCI device was added to a PHB with the small configuration.

---
  hw/pci-host/pnv_phb4.c | 2 ++
  1 file changed, 2 insertions(+)
hw/pci-host/pnv_phb4.c +2 -0
index 18992054e8..aeb2a45b4b 100644
@@ -1167,6 +1167,7 @@ static int pnv_phb4_map_irq(PCIDevice *pci_dev, int irq_num)
  static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
  {
      PnvPHB4 *phb = PNV_PHB4(opaque);
+    XiveSource *xsrc = &phb->xsrc;
      uint32_t lsi_base;
 
      /* LSI only ... */
@@ -1175,6 +1176,7 @@ static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
      }
      lsi_base = GETFIELD(PHB_LSI_SRC_ID, phb->regs[PHB_LSI_SOURCE_ID >> 3]);
      lsi_base <<= 3;
+    lsi_base &= xsrc->nr_irqs - 1;
      qemu_set_irq(phb->qirqs[lsi_base + irq_num], level);
  }
 
Reviewed-by on v1 1/1
#4 lore raw
In reply to Glenn Miles
Quoted 28 lines · Glenn Miles

The PowerNV PCI Host Bridge (PHB) supports a large and small configuration where the small configuration supports only half the number of interrupts supported by the large configuration.

Since the PCIe LSIs are allocated at the end of the PHB IRQ list, when calculating the LSI IRQ number, the code must take into consideration the number of IRQ's supported by the PHB. This was not happening and was resulting in a QEMU segmentation fault when a PCI device was added to a PHB with the small configuration.

---
 hw/pci-host/pnv_phb4.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-host/pnv_phb4.c +1 -0
index 18992054e8..aeb2a45b4b 100644
@@ -1167,6 +1167,7 @@ static int pnv_phb4_map_irq(PCIDevice *pci_dev, int irq_num)
 static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
 {
     PnvPHB4 *phb = PNV_PHB4(opaque);
+    XiveSource *xsrc = &phb->xsrc;
     uint32_t lsi_base;
 
     /* LSI only ... */

hw/pci-host/pnv_phb4.c static void pnv_phb4_set_irq(void *opaque, int irq_num, int level) · line 1181

Quoted 6 lines
hw/pci-host/pnv_phb4.c +1 -0
@@ -1175,6 +1176,7 @@ static void pnv_phb4_set_irq(void *opaque, int irq_num, int level)
     }
     lsi_base = GETFIELD(PHB_LSI_SRC_ID, phb->regs[PHB_LSI_SOURCE_ID >> 3]);
     lsi_base <<= 3;
+    lsi_base &= xsrc->nr_irqs - 1;
     qemu_set_irq(phb->qirqs[lsi_base + irq_num], level);
 }

Looks good to me. And passes all powernv functional tests, hence:

Thanks,
- Aditya G