Skip to contentSkip to conversation

hw/intc/arm_gic: Allow reset of the running priority

PATCH Applied Petr Pavlu 2 participants 4 messages Jan 13, 2022 – Jan 14, 2022

lore
Share & tools
lore

Petr Pavlu

author
#0 lore raw

v2 cover hw/intc/arm_gic: Allow reset of the running priority

Thank you Peter for review of the first version of the patch. v2 splits the changes into two commits and updates the code as suggested.

author
#1 lore raw

PATCH v2 1/2 hw/intc/arm_gic: Implement read of GICC_IIDR

From: Petr Pavlu <[email protected]>

Implement support for reading GICC_IIDR. This register is used by the Linux kernel to recognize that GICv2 with GICC_APRn is present.

---
 hw/intc/arm_gic.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/intc/arm_gic.c +9 -0
index a994b1f024..0cd9ceca8d 100644
@@ -1662,6 +1662,15 @@ static MemTxResult gic_cpu_read(GICState *s, int cpu, int offset,
         }
         break;
     }
+    case 0xfc:
+        if (s->revision == REV_11MPCORE) {
+            /* Reserved on 11MPCore */
+            *data = 0;
+        } else {
+            /* GICv1 or v2; Arm implementation */
+            *data = (s->revision << 16) | 0x43b;
+        }
+        break;
     default:
         qemu_log_mask(LOG_GUEST_ERROR,
                       "gic_cpu_read: Bad offset %x\n", (int)offset);
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/2 hw/intc/arm_gic: Allow reset of the running priority

In reply to Petr Pavlu

From: Petr Pavlu <[email protected]>

When running Linux on a machine with GICv2, the kernel can crash while processing an interrupt and can subsequently start a kdump kernel from the active interrupt handler. In such a case, the crashed kernel might not gracefully signal the end of interrupt to the GICv2 hardware. The kdump kernel will however try to reset the GIC state on startup to get the controller into a sane state, in particular the kernel writes ones to GICD_ICACTIVERn and wipes out GICC_APRn to make sure that no interrupt is active.

The patch adds a logic to recalculate the running priority when GICC_APRn/GICC_NSAPRn is written which makes sure that the mentioned reset works with the GICv2 emulation in QEMU too and the kdump kernel starts receiving interrupts.

The described scenario can be reproduced on an AArch64 QEMU virt machine with a kdump-enabled Linux system by using the softdog module. The kdump kernel will hang at some point because QEMU still thinks the running priority is that of the timer interrupt and asserts no new interrupts to the system:

$ modprobe softdog soft_margin=10 soft_panic=1
$ cat > /dev/watchdog
[Press Enter to start the watchdog, wait for its timeout and observe
that the kdump kernel hangs on startup.]
---
 hw/intc/arm_gic.c | 2 ++
 1 file changed, 2 insertions(+)
hw/intc/arm_gic.c +2 -0
index 0cd9ceca8d..492b2421ab 100644
@@ -1736,6 +1736,7 @@ static MemTxResult gic_cpu_write(GICState *s, int cpu, int offset,
         } else {
             s->apr[regno][cpu] = value;
         }
+        s->running_priority[cpu] = gic_get_prio_from_apr_bits(s, cpu);
         break;
     }
     case 0xe0: case 0xe4: case 0xe8: case 0xec:
@@ -1752,6 +1753,7 @@ static MemTxResult gic_cpu_write(GICState *s, int cpu, int offset,
             return MEMTX_OK;
         }
         s->nsapr[regno][cpu] = value;
+        s->running_priority[cpu] = gic_get_prio_from_apr_bits(s, cpu);
         break;
     }
     case 0x1000:
Signature · 1 line
2.34.1
#3 lore raw
In reply to Petr Pavlu
Quoted 4 lines · Petr Pavlu

Thank you Peter for review of the first version of the patch. v2 splits the changes into two commits and updates the code as suggested.

Applied to target-arm.next, thanks.

-- PMM