From: Jia He <justin.he@arm.com>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
Thomas Gleixner <tglx@kernel.org>
Cc: nd@arm.com, Jia He <justin.he@arm.com>,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
Steffen Eiden <seiden@linux.ibm.com>,
Radu Rendec <radu@rendec.net>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Shuah Khan <shuah@kernel.org>,
Ricardo Koller <ricarkol@google.com>,
Andrew Jones <andrew.jones@linux.dev>,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 03/10] KVM: arm64: Stop vSGI enablement on state transfer errors
Date: Sun, 6 Dec 2026 13:53:47 +0000 [thread overview]
Message-ID: <20261206135354.1519499-4-justin.he@arm.com> (raw)
In-Reply-To: <20261206135354.1519499-1-justin.he@arm.com>
vgic_v4_enable_vsgis() sets irq->hw before activating the SGI and
clears pending_latch even if transferring the pending state fails,
leaving the guest with partially switched SGIs.
Set irq->hw only after activation succeeds, and clear pending_latch
only after the pending transfer succeeds. On error, drop the lock and
reference and return it so the caller marks the VM dead before resuming
the guest.
After a failed activation, irq->hw stays clear to match the IRQ core.
If the pending transfer fails after activation, irq->hw stays set and
pending_latch is kept; only clearing pending can fail (setting it is a
write to GITS_SGIR), so a late CLEAR cannot cause a duplicate SGI.
Fixes: bacf2c60548b ("KVM: arm64: GICv4.1: Allow SGIs to switch between HW and SW interrupts")
Signed-off-by: Jia He <justin.he@arm.com>
---
arch/arm64/kvm/vgic/vgic-v4.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/arch/arm64/kvm/vgic/vgic-v4.c b/arch/arm64/kvm/vgic/vgic-v4.c
index b4f8e5653bf9..fd0e7b2521c8 100644
--- a/arch/arm64/kvm/vgic/vgic-v4.c
+++ b/arch/arm64/kvm/vgic/vgic-v4.c
@@ -112,10 +112,10 @@ static void vgic_v4_sync_sgi_config(struct its_vpe *vpe, struct vgic_irq *irq)
vpe->sgi_config[irq->intid].priority = irq->priority;
}
-static void vgic_v4_enable_vsgis(struct kvm_vcpu *vcpu)
+static int vgic_v4_enable_vsgis(struct kvm_vcpu *vcpu)
{
struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
- int i;
+ int i, ret = 0;
/*
* With GICv4.1, every virtual SGI can be directly injected. So
@@ -126,14 +126,12 @@ static void vgic_v4_enable_vsgis(struct kvm_vcpu *vcpu)
struct vgic_irq *irq = vgic_get_vcpu_irq(vcpu, i);
struct irq_desc *desc;
unsigned long flags;
- int ret;
raw_spin_lock_irqsave(&irq->irq_lock, flags);
if (irq->hw)
goto unlock;
- irq->hw = true;
irq->host_irq = irq_find_mapping(vpe->sgi_domain, i);
/* Transfer the full irq state to the vPE */
@@ -141,18 +139,24 @@ static void vgic_v4_enable_vsgis(struct kvm_vcpu *vcpu)
desc = irq_to_desc(irq->host_irq);
ret = irq_domain_activate_irq(irq_desc_get_irq_data(desc),
false);
- if (!WARN_ON(ret)) {
- /* Transfer pending state */
- ret = irq_set_irqchip_state(irq->host_irq,
- IRQCHIP_STATE_PENDING,
- irq->pending_latch);
- WARN_ON(ret);
+ if (ret)
+ goto unlock;
+
+ irq->hw = true;
+ /* Transfer the pending state, keep the latch if that fails */
+ ret = irq_set_irqchip_state(irq->host_irq,
+ IRQCHIP_STATE_PENDING,
+ irq->pending_latch);
+ if (!ret)
irq->pending_latch = false;
- }
unlock:
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
vgic_put_irq(vcpu->kvm, irq);
+ if (ret)
+ return ret;
}
+
+ return 0;
}
static int vgic_v4_disable_vsgis(struct kvm_vcpu *vcpu)
@@ -196,6 +200,7 @@ void vgic_v4_configure_vsgis(struct kvm *kvm)
struct vgic_dist *dist = &kvm->arch.vgic;
struct kvm_vcpu *vcpu;
unsigned long i;
+ int ret;
lockdep_assert_held(&kvm->arch.config_lock);
@@ -203,8 +208,10 @@ void vgic_v4_configure_vsgis(struct kvm *kvm)
kvm_for_each_vcpu(i, vcpu, kvm) {
if (dist->nassgireq)
- vgic_v4_enable_vsgis(vcpu);
- else if (vgic_v4_disable_vsgis(vcpu)) {
+ ret = vgic_v4_enable_vsgis(vcpu);
+ else
+ ret = vgic_v4_disable_vsgis(vcpu);
+ if (ret) {
/* There is no way back from a partial switch */
kvm_vm_dead(kvm);
break;
--
2.34.1
next prev parent reply other threads:[~2026-12-06 13:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 13:53 [PATCH 00/10] KVM: arm64: GICv4.1 vSGI error handling and VGIC state fixes Jia He
2026-12-06 13:53 ` [PATCH 01/10] KVM: arm64: Preserve vSGI state when pending queries fail Jia He
2026-12-06 13:53 ` [PATCH 02/10] irqchip/gic-v3-its: Propagate vSGI command queue failures Jia He
2026-12-06 13:53 ` Jia He [this message]
2026-12-06 13:53 ` [PATCH 04/10] KVM: arm64: Check clearing the pending state of vSGIs moved to SW Jia He
2026-12-06 13:53 ` [PATCH 05/10] KVM: arm64: vgic: Queue pending interrupts when the distributor is enabled Jia He
2026-12-06 13:53 ` [PATCH 06/10] KVM: arm64: vgic: Pass the enable state of HW SGIs to the ITS Jia He
2026-12-06 13:53 ` [PATCH 07/10] KVM: arm64: Synchronize vSGI state when restoring GICD_CTLR Jia He
2026-12-06 13:53 ` [PATCH 08/10] KVM: arm64: selftests: Avoid read-modify-write for GIC write-one registers Jia He
2026-12-06 13:53 ` [PATCH 09/10] KVM: arm64: selftests: Add vgic_dist_reenable test Jia He
2026-12-06 13:53 ` [PATCH 10/10] KVM: arm64: selftests: Check SGI delivery after VGIC restore Jia He
2026-12-06 16:51 ` [PATCH 00/10] KVM: arm64: GICv4.1 vSGI error handling and VGIC state fixes Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261206135354.1519499-4-justin.he@arm.com \
--to=justin.he@arm.com \
--cc=andrew.jones@linux.dev \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maz@kernel.org \
--cc=nd@arm.com \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=radu@rendec.net \
--cc=ricarkol@google.com \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=tglx@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®