[PATCH 01/10] KVM: arm64: Preserve vSGI state when pending queries fail

From: Jia He

Date: Sun Dec 06 2026 - 08:54:25 EST


vgic_v4_disable_vsgis() clears irq->hw before reading the pending state
from the GIC. On failure, an uninitialised 'pending' is copied into
pending_latch and the SGI is deactivated anyway.

Switch the SGI to SW only after reading its pending state. On failure,
leave the SGI in HW, drop the lock and reference, and abort the switch.
Because rolling back already-switched SGIs would rely on the same
failing ITS/redistributor operations, mark the VM dead before resuming
the guest.

Signed-off-by: Jia He <justin.he@xxxxxxx>
---
arch/arm64/kvm/vgic/vgic-v4.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/kvm/vgic/vgic-v4.c b/arch/arm64/kvm/vgic/vgic-v4.c
index ed236f083f0d..b4f8e5653bf9 100644
--- a/arch/arm64/kvm/vgic/vgic-v4.c
+++ b/arch/arm64/kvm/vgic/vgic-v4.c
@@ -155,28 +155,28 @@ static void vgic_v4_enable_vsgis(struct kvm_vcpu *vcpu)
}
}

-static void vgic_v4_disable_vsgis(struct kvm_vcpu *vcpu)
+static int vgic_v4_disable_vsgis(struct kvm_vcpu *vcpu)
{
- int i;
+ int i, ret = 0;

for (i = 0; i < VGIC_NR_SGIS; i++) {
struct vgic_irq *irq = vgic_get_vcpu_irq(vcpu, i);
struct irq_desc *desc;
unsigned long flags;
bool pending;
- int ret;

raw_spin_lock_irqsave(&irq->irq_lock, flags);

if (!irq->hw)
goto unlock;

- irq->hw = false;
ret = irq_get_irqchip_state(irq->host_irq,
IRQCHIP_STATE_PENDING,
&pending);
- WARN_ON(ret);
+ if (ret)
+ goto unlock;

+ irq->hw = false;
irq->pending_latch = pending;

desc = irq_to_desc(irq->host_irq);
@@ -184,7 +184,11 @@ static void vgic_v4_disable_vsgis(struct kvm_vcpu *vcpu)
unlock:
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
vgic_put_irq(vcpu->kvm, irq);
+ if (ret)
+ return ret;
}
+
+ return 0;
}

void vgic_v4_configure_vsgis(struct kvm *kvm)
@@ -200,8 +204,11 @@ void vgic_v4_configure_vsgis(struct kvm *kvm)
kvm_for_each_vcpu(i, vcpu, kvm) {
if (dist->nassgireq)
vgic_v4_enable_vsgis(vcpu);
- else
- vgic_v4_disable_vsgis(vcpu);
+ else if (vgic_v4_disable_vsgis(vcpu)) {
+ /* There is no way back from a partial switch */
+ kvm_vm_dead(kvm);
+ break;
+ }
}

kvm_arm_resume_guest(kvm);
--
2.34.1