mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 06/10] KVM: arm64: vgic: Pass the enable state of HW SGIs to the ITS
Date: Sun,  6 Dec 2026 13:53:50 +0000	[thread overview]
Message-ID: <20261206135354.1519499-7-justin.he@arm.com> (raw)
In-Reply-To: <20261206135354.1519499-1-justin.he@arm.com>

With direct vSGIs, the ITS holds each SGI's enable state in the vPE's
sgi_config. Guest writes to GICR_ISENABLER0/ICENABLER0 currently use
enable_irq()/disable_irq_nosync() on the host IRQ, while userspace
accessors do not update the ITS at all.

Because vgic_v4_enable_vsgis() only activates the host IRQs, their
descriptors remain disabled and masked. disable_irq_nosync() therefore
only bumps the disable depth and never reaches the ITS, leaving the SGI
enabled in hardware.

Update sgi_config and send a VSGI command for both guest and userspace
enable/disable writes, matching group and priority updates. On failure,
the hardware enable state is unknown, so mark the VM dead and return
-EIO to userspace (a guest vCPU exits on KVM_REQ_VM_DEAD). Group and
priority updates continue to only warn.

Signed-off-by: Jia He <justin.he@arm.com>
---
 arch/arm64/kvm/vgic/vgic-mmio.c | 69 ++++++++++++++++++++++++---------
 1 file changed, 51 insertions(+), 18 deletions(-)

diff --git a/arch/arm64/kvm/vgic/vgic-mmio.c b/arch/arm64/kvm/vgic/vgic-mmio.c
index fddb9da0403d..af84f18d057b 100644
--- a/arch/arm64/kvm/vgic/vgic-mmio.c
+++ b/arch/arm64/kvm/vgic/vgic-mmio.c
@@ -66,6 +66,22 @@ static void vgic_update_vsgi(struct vgic_irq *irq)
 	WARN_ON(its_prop_update_vsgi(irq->host_irq, irq->priority, irq->group));
 }
 
+/*
+ * Must be called with the irq_lock held. On failure, the caller must mark
+ * the VM dead once it has dropped the lock.
+ */
+static int vgic_set_hw_sgi_enable(struct vgic_irq *irq, bool enable)
+{
+	struct its_vpe *vpe = &irq->target_vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
+
+	if (irq->enabled == enable)
+		return 0;
+
+	irq->enabled = enable;
+	vpe->sgi_config[irq->intid].enabled = enable;
+	return its_prop_update_vsgi(irq->host_irq, irq->priority, irq->group);
+}
+
 void vgic_mmio_write_group(struct kvm_vcpu *vcpu, gpa_t addr,
 			   unsigned int len, unsigned long val)
 {
@@ -126,17 +142,14 @@ void vgic_mmio_write_senable(struct kvm_vcpu *vcpu,
 
 		raw_spin_lock_irqsave(&irq->irq_lock, flags);
 		if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
-			if (!irq->enabled) {
-				struct irq_data *data;
-
-				irq->enabled = true;
-				data = &irq_to_desc(irq->host_irq)->irq_data;
-				while (irqd_irq_disabled(data))
-					enable_irq(irq->host_irq);
-			}
+			int ret = vgic_set_hw_sgi_enable(irq, true);
 
 			raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
 			vgic_put_irq(vcpu->kvm, irq);
+			if (ret) {
+				kvm_vm_dead(vcpu->kvm);
+				return;
+			}
 
 			continue;
 		} else if (vgic_irq_is_mapped_level(irq)) {
@@ -167,20 +180,24 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu,
 			     unsigned long val)
 {
 	u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
-	int i;
+	int i, ret = 0;
 	unsigned long flags;
 
 	for_each_set_bit(i, &val, len * 8) {
 		struct vgic_irq *irq = vgic_get_vcpu_irq(vcpu, intid + i);
 
 		raw_spin_lock_irqsave(&irq->irq_lock, flags);
-		if (irq->hw && vgic_irq_is_sgi(irq->intid) && irq->enabled)
-			disable_irq_nosync(irq->host_irq);
-
-		irq->enabled = false;
+		if (irq->hw && vgic_irq_is_sgi(irq->intid))
+			ret = vgic_set_hw_sgi_enable(irq, false);
+		else
+			irq->enabled = false;
 
 		raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
 		vgic_put_irq(vcpu->kvm, irq);
+		if (ret) {
+			kvm_vm_dead(vcpu->kvm);
+			return;
+		}
 	}
 }
 
@@ -189,17 +206,26 @@ int vgic_uaccess_write_senable(struct kvm_vcpu *vcpu,
 			       unsigned long val)
 {
 	u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
-	int i;
+	int i, ret = 0;
 	unsigned long flags;
 
 	for_each_set_bit(i, &val, len * 8) {
 		struct vgic_irq *irq = vgic_get_vcpu_irq(vcpu, intid + i);
 
 		raw_spin_lock_irqsave(&irq->irq_lock, flags);
-		irq->enabled = true;
-		vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
+		if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
+			ret = vgic_set_hw_sgi_enable(irq, true);
+			raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
+		} else {
+			irq->enabled = true;
+			vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
+		}
 
 		vgic_put_irq(vcpu->kvm, irq);
+		if (ret) {
+			kvm_vm_dead(vcpu->kvm);
+			return -EIO;
+		}
 	}
 
 	return 0;
@@ -210,17 +236,24 @@ int vgic_uaccess_write_cenable(struct kvm_vcpu *vcpu,
 			       unsigned long val)
 {
 	u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
-	int i;
+	int i, ret = 0;
 	unsigned long flags;
 
 	for_each_set_bit(i, &val, len * 8) {
 		struct vgic_irq *irq = vgic_get_vcpu_irq(vcpu, intid + i);
 
 		raw_spin_lock_irqsave(&irq->irq_lock, flags);
-		irq->enabled = false;
+		if (irq->hw && vgic_irq_is_sgi(irq->intid))
+			ret = vgic_set_hw_sgi_enable(irq, false);
+		else
+			irq->enabled = false;
 		raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
 
 		vgic_put_irq(vcpu->kvm, irq);
+		if (ret) {
+			kvm_vm_dead(vcpu->kvm);
+			return -EIO;
+		}
 	}
 
 	return 0;
-- 
2.34.1


  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 ` [PATCH 03/10] KVM: arm64: Stop vSGI enablement on state transfer errors Jia He
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 ` Jia He [this message]
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-7-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®