[PATCH 17/43] KVM: arm64: gic-v5: Enable VPE DBs on VPE reset and disable on teardown

Sascha Bischoff Sascha.Bischoff at arm.com
Mon Apr 27 09:11:50 PDT 2026


Ensure that each VPE doorbell is enabled on the host prior to running
the guest by enabling it as part of vgic_v5_reset(). Add a function to
disable it again as part of VM teardown, vgic_v5_disable_vcpu(), which
also frees the IRQ again.

Signed-off-by: Sascha Bischoff <sascha.bischoff at arm.com>
---
 arch/arm64/kvm/vgic/vgic-v5.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/arch/arm64/kvm/vgic/vgic-v5.c b/arch/arm64/kvm/vgic/vgic-v5.c
index 9347bc6895223..48ffcb2494db3 100644
--- a/arch/arm64/kvm/vgic/vgic-v5.c
+++ b/arch/arm64/kvm/vgic/vgic-v5.c
@@ -736,6 +736,31 @@ void vgic_v5_reset(struct kvm_vcpu *vcpu)
 		kvm_vm_dead(vcpu->kvm);
 		return;
 	}
+
+	enable_irq(vgic_v5_vpe_db(vcpu));
+}
+
+static void vgic_v5_disable_vcpu(struct kvm_vcpu *vcpu)
+{
+	int virq = vgic_v5_vpe_db(vcpu);
+
+	if (!vcpu->kvm->arch.vgic.gicv5_vm.domain)
+		return;
+
+	if (!virq)
+		return;
+
+	/*
+	 * We are called in the vgic_v5_teardown path. We no longer need the
+	 * doorbell virqs.
+	 */
+	disable_irq(virq);
+
+	/* Free the doorbell irq (counter-part to request_irq)*/
+	free_irq(virq, vcpu);
+
+	/* Remove the irq from the domain too */
+	irq_domain_free_irqs(virq, 1);
 }
 
 int vgic_v5_map_resources(struct kvm *kvm)
@@ -875,6 +900,10 @@ void vgic_v5_teardown(struct kvm *kvm)
 			kvm_err("Failed to release VM 0x%x\n", dist->gicv5_vm.vm_id);
 	}
 
+	/* Goodbye doorbells */
+	kvm_for_each_vcpu(i, vcpu, kvm)
+		vgic_v5_disable_vcpu(vcpu);
+
 	vgic_v5_teardown_per_vm_domain(&kvm->arch.vgic.gicv5_vm);
 
 	vgic_v5_release_vm_id(kvm);
-- 
2.34.1



More information about the linux-arm-kernel mailing list