vgic_v4_disable_vsgis() copies each vSGI's pending state into pending_latch and then calls irq_domain_deactivate_irq(). Deactivation sends two VSGI commands (disable and clear pending) and cannot return an error. If both fail, the SGI stays enabled and pending in the ITS while also pending in SW, so the guest takes it twice once the vPE becomes resident again. Clear the pending state of a pending SGI with irq_set_irqchip_state() before deactivating it. On failure, leave the SGI in HW and return the error so the VM is marked dead. All vCPUs are halted during the switch, so the SGI cannot become pending again in between. Signed-off-by: Jia He --- arch/arm64/kvm/vgic/vgic-v4.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm64/kvm/vgic/vgic-v4.c b/arch/arm64/kvm/vgic/vgic-v4.c index fd0e7b2521c8..b2fd23366aff 100644 --- a/arch/arm64/kvm/vgic/vgic-v4.c +++ b/arch/arm64/kvm/vgic/vgic-v4.c @@ -180,6 +180,17 @@ static int vgic_v4_disable_vsgis(struct kvm_vcpu *vcpu) if (ret) goto unlock; + /* + * Deactivation can't report a failure to clear the pending + * state, so clear it first. + */ + if (pending) { + ret = irq_set_irqchip_state(irq->host_irq, + IRQCHIP_STATE_PENDING, false); + if (ret) + goto unlock; + } + irq->hw = false; irq->pending_latch = pending; -- 2.34.1