hw/intc/arm_gicv3: active Non-Secure Group 1 NMI overrides higher-priority Secure interrupts under DS=0

Host environment

  • Operating system: Ubuntu 24.04.3 LTS
  • Architecture: x86_64
  • QEMU flavor: qemu-system-aarch64
  • QEMU version: QEMU 11.1.2 and QEMU 11.1.92 (commit fae886567b48c672977acde6b775dd7e2d2121c1)
  • QEMU command line:
    qemu-system-aarch64 -M virt,secure=on,virtualization=on,gic-version=3 \
      -cpu max -smp 2 -m 256M -nodefaults -nographic -serial stdio \
      -semihosting-config enable=on,target=native \
      -device loader,file=guest.elf \
      -device loader,addr=0x40200000,cpu-num=0 \
      -device loader,addr=0x40200000,cpu-num=1

Emulated/Virtualized environment

  • Operating system: None (bare-metal test image)
  • Architecture: AArch64 (-cpu max, GICv3 with secure=on and FEAT_GICv3_NMI, 2 PEs)

Description of problem

Per the Arm Generic Interrupt Controller Architecture Specification, GIC architecture version 3 and version 4 (Arm IHI 0069H.b, §4.8.1 / §4.8.5 "Interrupt prioritization" (including Non-maskable interrupts), §12.2.9 "ICC_EOIR0_EL1", §12.2.10 "ICC_EOIR1_EL1", and §12.2.20 "ICC_RPR_EL1"), when Two Security States are enabled (GICD_CTLR.DS == 0), a Non-Secure Group 1 NMI has effective priority 0x80, which is strictly lower priority than Secure Group 0 and Secure Group 1 interrupts in 0x00..0x7F; ICC_RPR_EL1 must report the highest-priority active interrupt across all groups, and Secure ICC_EOIR0_EL1 / ICC_EOIR1_EL1 writes must drop that highest-priority active Secure interrupt while preserving ICC_AP1R0_EL1_NS.NMI. When a priority-0x20 Secure SGI preempts an active Non-Secure Group 1 NMI (0x80), QEMU's icc_highest_active_prio() and icc_highest_active_group() return early upon detecting ICC_AP1R_EL1_NMI in GICV3_G1NS, causing three architectural violations:

  1. ICC_RPR_EL1 reports running priority 0x80 (0x4000000000000080) instead of 0x20 (0x4000000000000020).
  2. On Secure Group 0 preemption (SGI 0), ICC_EOIR0_EL1 is discarded, leaving ICC_AP0R0_EL1 (0x10) and GICR_ISACTIVER0 (0x40000001) set and blocking delivery of the second priority-0x20 Secure Group 0 SGI (fiq_cnt=1 vs. 2).
  3. On Secure Group 1 preemption (SGI 1), Secure ICC_EOIR1_EL1 at EL3 drops GICV3_G1NS instead of GICV3_G1, clearing ICC_AP1R0_EL1_NS.NMI (ns_ap1r_a=0) while leaving Secure ICC_AP1R0_EL1_S set (apr_a=0x10) and blocking delivery of the second priority-0x20 Secure Group 1 SGI (fiq_cnt=1 vs. 2).

The 2-PE reproducer directly tests priority-0x20 Secure Group 0 (SGI 0) and Secure Group 1 (SGI 1) preemption of an active Non-Secure Group 1 NMI (PPI 30) on PE0. Preemption by lower-priority Secure interrupts (0x40..0x7F) due to inverted running priority, higher-priority (< 0x20) interrupts, recovery after Non-Secure NMI completion, and single-PE triggers follow from the same CPU-interface helpers in source and were not separately executed.

Steps to reproduce

  1. Build the 2-PE bare-metal image (start.S, main.c, link.ld) for TEST_CASE=0..2 (0: non-NMI NS PPI 30 control, 1: NS Group 1 NMI preempted by Secure Group 0 SGI 0, 2: NS Group 1 NMI preempted by Secure Group 1 SGI 1).
  2. Configure GICv3 with DS=0, enable NS Group 1 PPI 30 (priority 0x80, NMI enabled for cases 1 and 2), Secure Group 0 SGI 0 (priority 0x20), and Secure Group 1 SGI 1 (priority 0x20), routing Secure FIQs to EL3.
  3. On PE0 (NS-EL1), pend and acknowledge PPI 30 (ICC_NMIAR1_EL1 for cases 1/2, ICC_IAR1_EL1 for control) so ICC_AP1R0_EL1_NS.NMI is set, then signal PE1.
  4. On PE1 (EL3), inject two priority-0x20 Secure SGIs to PE0; inside PE0's first EL3 FIQ handler, acknowledge via ICC_IAR0/1_EL1, sample ICC_RPR_EL1, write ICC_EOIR0/1_EL1, record post-EOI APR/active state, and signal PE1 to send the second SGI.

Observed output:

[qemu][cand_ns_nmi_g0_preempt][run 1] rc=0 uart="TC=0x0000000000000001 ns_iar=0x000000000000001e ns_ap1r_b=0x8000000000000000 sec_iar=0x0000000000000000 rpr=0x4000000000000080 apr_b=0x0000000000000010 apr_a=0x0000000000000010 ns_ap1r_a=0x8000000000000000 act_b=0x0000000040000001 act_a=0x0000000040000001 fiq_cnt=0x0000000000000001 VERDICT=FAIL"
[qemu][cand_ns_nmi_g1s_preempt][run 1] rc=0 uart="TC=0x0000000000000002 ns_iar=0x000000000000001e ns_ap1r_b=0x8000000000000000 sec_iar=0x0000000000000001 rpr=0x4000000000000080 apr_b=0x0000000000000010 apr_a=0x0000000000000010 ns_ap1r_a=0x0000000000000000 act_b=0x0000000040000002 act_a=0x0000000040000000 fiq_cnt=0x0000000000000001 VERDICT=FAIL"

Expected behavior: In both NMI cases, ICC_RPR_EL1 must report 0x4000000000000020, Secure EOI must clear the Secure APR (apr_a=0) and deactivate the Secure SGI (act_a=0x40000000) while preserving ICC_AP1R0_EL1_NS.NMI (ns_ap1r_a=0x8000000000000000), and the second Secure SGI must be delivered (fiq_cnt=2, VERDICT=PASS).

A standalone bare-metal reproducer (start.S, main.c, link.ld, run.sh) is available to attach.

Additional information

Root cause

At commit fae886567b48c672977acde6b775dd7e2d2121c1 in hw/intc/arm_gicv3_cpuif.c:

  • icc_highest_active_prio() (lines 927–933) returns 0x80 immediately when cs->icc_apr[GICV3_G1NS][0] & ICC_AP1R_EL1_NMI is set under DS=0, before scanning icc_apr[GICV3_G0] and icc_apr[GICV3_G1] for higher-priority Secure active bits (0x00..0x7F).
  • icc_highest_active_group() (lines 1407–1414) returns GICV3_G1NS unconditionally when cs->icc_apr[GICV3_G1NS][0] & ICC_AP1R_EL1_NMI is set. In icc_eoir_write() (lines 1677–1715), this causes ICC_EOIR0_EL1 to return early without dropping priority and causes Secure ICC_EOIR1_EL1 at EL3 to call icc_drop_prio(cs, GICV3_G1NS).

Paired control / Reference

The paired control (regular non-NMI NS PPI 30 at priority 0x80 preempted by Secure Group 0 SGI 0 at priority 0x20) passes 3/3 on unpatched QEMU (rpr=0x20, apr_a=0, ns_ap1r_a=0x10000, act_a=0x40000000, fiq_cnt=2, VERDICT=PASS). Official Arm Fast Models FVP_Base_RevC-2xAEMvA 11.30.27 passes 9/9 across the control and both NMI candidates.

Reproducer

Standalone bare-metal reproducer: https://gist.github.com/canxin121/c1b8138346c9562c311912e85544bb34