Skip to contentSkip to conversation

hw/intc: Skip reset for KVM irqchip

PATCH Applied Qingwei Hu 2 participants 6 messages Jun 15 – Jun 22 RISC-V

lore
Share & tools
lore

Qingwei Hu

author
#0 lore raw

v2 cover hw/intc: Skip reset for KVM irqchip

This series fixes NULL pointer dereferences in the RISC-V APLIC and IMSIC reset paths when the interrupt controller is handled by the KVM in-kernel irqchip.

Changes in v2:
- Split the APLIC and IMSIC reset fixes into separate patches.
- Carry Nutty Liu's Reviewed-by tag from v1.

Qingwei Hu (2):
hw/intc: riscv_aplic: Skip reset for KVM irqchip hw/intc: riscv_imsic: Skip reset for KVM irqchip

 hw/intc/riscv_aplic.c | 4 ++++
 hw/intc/riscv_imsic.c | 4 ++++
 2 files changed, 8 insertions(+)
Signature · 1 line
2.47.3
author
#1 lore raw

PATCH v2 1/2 hw/intc: riscv_aplic: Skip reset for KVM irqchip

The emulated APLIC state arrays are only allocated when QEMU handles the interrupt controller state itself. With KVM AIA/APLIC-IMSIC, the interrupt controller state is owned by the KVM in-kernel irqchip, so these emulated state arrays are not allocated.

The APLIC reset handler still clears those arrays unconditionally. This makes qemu_system_reset(), which runs during machine creation, dereference NULL pointers with -machine virt,aia=aplic-imsic and KVM.

Skip the emulated APLIC reset path when the interrupt controller is handled by KVM. The emulated path is unchanged for TCG and for configurations that use QEMU emulation.

Fixes 99bfcd329a ("hw/intc: riscv_aplic: Add reset API to APLIC")
---
 hw/intc/riscv_aplic.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/intc/riscv_aplic.c +4 -0
index c2c67c29e6..84606e9f3d 100644
@@ -910,6 +910,10 @@ static void riscv_aplic_reset_enter(Object *obj, ResetType type)
     RISCVAPLICState *aplic = RISCV_APLIC(obj);
     int i;
 
+    if (!riscv_use_emulated_aplic(aplic->msimode)) {
+        return;
+    }
+
     aplic->domaincfg = 0;
     memset(aplic->sourcecfg, 0, sizeof(uint32_t) * aplic->num_irqs);
     memset(aplic->target, 0, sizeof(uint32_t) * aplic->num_irqs);
Signature · 1 line
2.47.3
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] hw/intc: riscv_aplic: Skip reset for KVM irqchip

Quoted 10 lines · Qingwei Hu

The emulated APLIC state arrays are only allocated when QEMU handles the interrupt controller state itself. With KVM AIA/APLIC-IMSIC, the interrupt controller state is owned by the KVM in-kernel irqchip, so these emulated state arrays are not allocated.

The APLIC reset handler still clears those arrays unconditionally. This makes qemu_system_reset(), which runs during machine creation, dereference NULL pointers with -machine virt,aia=aplic-imsic and KVM.

Quoted 7 lines

Skip the emulated APLIC reset path when the interrupt controller is handled by KVM. The emulated path is unchanged for TCG and for configurations that use QEMU emulation.

Fixes 99bfcd329a ("hw/intc: riscv_aplic: Add reset API to APLIC")

Alistair

Quoted 23 lines
---
 hw/intc/riscv_aplic.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/intc/riscv_aplic.c +4 -1
index c2c67c29e6..84606e9f3d 100644
@@ -910,6 +910,10 @@ static void riscv_aplic_reset_enter(Object *obj, ResetType type)
     RISCVAPLICState *aplic = RISCV_APLIC(obj);
     int i;
 
+    if (!riscv_use_emulated_aplic(aplic->msimode)) {
+        return;
+    }
+
     aplic->domaincfg = 0;
     memset(aplic->sourcecfg, 0, sizeof(uint32_t) * aplic->num_irqs);
     memset(aplic->target, 0, sizeof(uint32_t) * aplic->num_irqs);
--

2.47.3

author
#3 lore raw

PATCH v2 2/2 hw/intc: riscv_imsic: Skip reset for KVM irqchip

In reply to Qingwei Hu

The emulated IMSIC state arrays are only allocated when QEMU handles the interrupt controller state itself. With KVM AIA/APLIC-IMSIC, the interrupt controller state is owned by the KVM in-kernel irqchip, so these emulated state arrays are not allocated.

The IMSIC reset handler still clears those arrays unconditionally. This makes qemu_system_reset(), which runs during machine creation, dereference NULL pointers with -machine virt,aia=aplic-imsic and KVM.

Skip the emulated IMSIC reset path when the interrupt controller is handled by KVM. The emulated path is unchanged for TCG and for configurations that use QEMU emulation.

Fixes 766391483b ("hw/intc: riscv_imsic: Add reset API to IMSIC")
---
 hw/intc/riscv_imsic.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/intc/riscv_imsic.c +4 -0
index ac59496c22..f1f23c3a3e 100644
@@ -347,6 +347,10 @@ static void riscv_imsic_reset_enter(Object *obj, ResetType type)
     RISCVIMSICState *imsic = RISCV_IMSIC(obj);
     int i;
 
+    if (kvm_irqchip_in_kernel()) {
+        return;
+    }
+
     memset(imsic->eidelivery, 0, sizeof(uint32_t) * imsic->num_pages);
     memset(imsic->eithreshold, 0, sizeof(uint32_t) * imsic->num_pages);
 
Signature · 1 line
2.47.3
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] hw/intc: riscv_imsic: Skip reset for KVM irqchip

Quoted 10 lines · Qingwei Hu

The emulated IMSIC state arrays are only allocated when QEMU handles the interrupt controller state itself. With KVM AIA/APLIC-IMSIC, the interrupt controller state is owned by the KVM in-kernel irqchip, so these emulated state arrays are not allocated.

The IMSIC reset handler still clears those arrays unconditionally. This makes qemu_system_reset(), which runs during machine creation, dereference NULL pointers with -machine virt,aia=aplic-imsic and KVM.

Quoted 7 lines

Skip the emulated IMSIC reset path when the interrupt controller is handled by KVM. The emulated path is unchanged for TCG and for configurations that use QEMU emulation.

Fixes 766391483b ("hw/intc: riscv_imsic: Add reset API to IMSIC")

Alistair

Quoted 23 lines
---
 hw/intc/riscv_imsic.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/intc/riscv_imsic.c +4 -1
index ac59496c22..f1f23c3a3e 100644
@@ -347,6 +347,10 @@ static void riscv_imsic_reset_enter(Object *obj, ResetType type)
     RISCVIMSICState *imsic = RISCV_IMSIC(obj);
     int i;
 
+    if (kvm_irqchip_in_kernel()) {
+        return;
+    }
+
     memset(imsic->eidelivery, 0, sizeof(uint32_t) * imsic->num_pages);
     memset(imsic->eithreshold, 0, sizeof(uint32_t) * imsic->num_pages);
 
--

2.47.3

#5 lore raw
In reply to Qingwei Hu
Quoted 5 lines · Qingwei Hu

This series fixes NULL pointer dereferences in the RISC-V APLIC and IMSIC reset paths when the interrupt controller is handled by the KVM in-kernel irqchip.

Quoted 7 lines

Changes in v2:
- Split the APLIC and IMSIC reset fixes into separate patches.
- Carry Nutty Liu's Reviewed-by tag from v1.

Qingwei Hu (2):
hw/intc: riscv_aplic: Skip reset for KVM irqchip hw/intc: riscv_imsic: Skip reset for KVM irqchip

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 9 lines
 hw/intc/riscv_aplic.c | 4 ++++
 hw/intc/riscv_imsic.c | 4 ++++
 2 files changed, 8 insertions(+)

--
2.47.3