[PATCH 00/10] KVM: arm64: GICv4.1 vSGI error handling and VGIC state fixes
From: Jia He
Date: Sun Dec 06 2026 - 08:54:17 EST
This series fixes GICv4.1 vSGI error handling and VGIC state
synchronisation bugs.
Patches 1-4 handle ITS and redistributor failures in the vSGI code.
Previously, KVM ignored failed pending queries and only logged command
queue errors, including failures to clear pending state when moving a
vSGI to SW. On failure, KVM now keeps interrupt state consistent and
marks the VM dead.
Patches 5-7 fix missed or unwanted interrupts when enabling the
distributor or switching vSGIs between HW and SW, for both guest writes
and userspace restore:
- Patch 5: interrupts made pending while the distributor is disabled
were not delivered after re-enabling it.
- Patch 6: SGI enable/disable writes from the guest or userspace did
not reach the ITS for direct vSGIs.
- Patch 7: userspace writes to GICD_CTLR did not switch vSGIs between
HW and SW (depends on patch 6 because userspace restores GICD_CTLR
before the SGI enable bits).
Patches 8-10 update the KVM selftests: patch 8 fixes GIC write-one
register helpers in the selftest library, and patches 9 and 10 add
selftests for the fixes above.
Patch 2 touches drivers/irqchip and is needed by the following KVM
patches. I'd suggest taking the whole series through the kvmarm tree,
with an ack from the irqchip side.
Testing (on GIC-700 / GICv4.1):
- Existing and new vgic selftests plus guest boot and vSGI traffic pass.
- vgic_dist_reenable fails without patch 5 (SPI, vtimer PPI, and LPI
are not delivered).
- vgic_sgi_restore fails without patch 6 or 7: without patch 6 the
guest takes a disabled SGI in enable-warm and enable-guest (and in
enable-cold with patch 7 applied). Patch 8 was verified separately.
- Patches 1-4 and patch 6's error paths were tested with local fault
injection failing the Nth pending query, activation, pending
transfer, or VSGI command on a 4-vCPU VM (triggered by userspace
GICD_CTLR write or guest toggle under concurrent SGI traffic).
Without patch 4 or patch 6's error handling, the guest takes an SGI
twice after switching to SW or takes a disabled SGI. With them, the
userspace write or KVM_RUN returns -EIO, the VM is marked dead, and
no warnings or leaked IRQs occur.
Jia He (10):
KVM: arm64: Preserve vSGI state when pending queries fail
irqchip/gic-v3-its: Propagate vSGI command queue failures
KVM: arm64: Stop vSGI enablement on state transfer errors
KVM: arm64: Check clearing the pending state of vSGIs moved to SW
KVM: arm64: vgic: Queue pending interrupts when the distributor is
enabled
KVM: arm64: vgic: Pass the enable state of HW SGIs to the ITS
KVM: arm64: Synchronize vSGI state when restoring GICD_CTLR
KVM: arm64: selftests: Avoid read-modify-write for GIC write-one
registers
KVM: arm64: selftests: Add vgic_dist_reenable test
KVM: arm64: selftests: Check SGI delivery after VGIC restore
arch/arm64/kvm/vgic/vgic-mmio-v2.c | 4 +-
arch/arm64/kvm/vgic/vgic-mmio-v3.c | 36 ++-
arch/arm64/kvm/vgic/vgic-mmio.c | 69 ++--
arch/arm64/kvm/vgic/vgic-v4.c | 71 ++--
arch/arm64/kvm/vgic/vgic.c | 38 +++
arch/arm64/kvm/vgic/vgic.h | 3 +-
drivers/irqchip/irq-gic-v3-its.c | 26 +-
tools/testing/selftests/kvm/Makefile.kvm | 2 +
.../selftests/kvm/arm64/vgic_dist_reenable.c | 228 +++++++++++++
.../selftests/kvm/arm64/vgic_sgi_restore.c | 306 ++++++++++++++++++
.../testing/selftests/kvm/lib/arm64/gic_v3.c | 14 +-
11 files changed, 740 insertions(+), 57 deletions(-)
create mode 100644 tools/testing/selftests/kvm/arm64/vgic_dist_reenable.c
create mode 100644 tools/testing/selftests/kvm/arm64/vgic_sgi_restore.c
base-commit: eedaa7d61f1ec8ae053a9ece0d553785350ac486
--
2.34.1