[PATCH 05/10] KVM: s390: arm64: Enable host irq

From: Andreas Grapentin

Date: Fri Dec 04 2026 - 07:11:10 EST


From: Sven Schnelle <svens@xxxxxxxxxxxxx>

Register KVM callbacks for host interrupt guest exits. If a host
interrupt happened during guest execution set the MODE to outside guets
mode.

Co-developed-by: Steffen Eiden <seiden@xxxxxxxxxxxxx>
Signed-off-by: Steffen Eiden <seiden@xxxxxxxxxxxxx>
Signed-off-by: Sven Schnelle <svens@xxxxxxxxxxxxx>
Co-developed-by: Andreas Grapentin <gra@xxxxxxxxxxxxx>
Signed-off-by: Andreas Grapentin <gra@xxxxxxxxxxxxx>
---
arch/s390/kvm/arm64/arm.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index 547f77be7e3c..cc8453bd820c 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -6,6 +6,7 @@
#include <linux/kvm.h>
#include <linux/kvm_types.h>
#include <linux/kvm_host.h>
+#include <linux/rcupdate.h>
#include <linux/cleanup.h>
#include <linux/fpu.h>
#include <linux/bitfield.h>
@@ -425,6 +426,13 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
return -EINVAL;
}

+static noinstr void kvm_sae_exit_handler(unsigned long v)
+{
+ struct kvm_vcpu *vcpu = (struct kvm_vcpu *)v;
+
+ WRITE_ONCE(vcpu->mode, OUTSIDE_GUEST_MODE);
+}
+
static noinstr void arm_vcpu_enter_exit(struct kvm_sae_block *sae_block,
struct kvm_vcpu *vcpu)
{
@@ -517,7 +525,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
vcpu->arch.ctxt.elr_el1 = _vcpu_read_sys_reg(vcpu, SYS_ELR_EL1);
vcpu->arch.ctxt.spsr_el1 = _vcpu_read_sys_reg(vcpu, SYS_SPSR_EL1);

- vcpu->mode = OUTSIDE_GUEST_MODE;
+ if (vcpu->mode != OUTSIDE_GUEST_MODE)
+ kvm_sae_exit_handler((unsigned long)vcpu);
vcpu->stat.exits++;

local_irq_enable();
@@ -798,6 +807,13 @@ static bool __init machine_supports_arm64_kvm(void)
return true;
}

+static void unregister_callbacks(void)
+{
+ kvm_s390_arm64_vcpu_exit = NULL;
+ /* wait for all possible users of the callback to quiesce */
+ synchronize_rcu();
+}
+
static int __init kvm_s390_arm64_init(void)
{
int ret;
@@ -813,11 +829,23 @@ static int __init kvm_s390_arm64_init(void)
return ret;
}

- return kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
+ kvm_s390_arm64_vcpu_exit = kvm_sae_exit_handler;
+
+ /*
+ * kvm_init _must_ be the very last thing done, as this exposes
+ * /dev/kvm_arm64 to userspace, i.e. all infrastructure must be setup!
+ */
+ ret = kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
+ if (ret) {
+ unregister_callbacks();
+ return ret;
+ }
+ return 0;
}

static __exit void kvm_s390_arm64_exit(void)
{
+ unregister_callbacks();
kvm_exit();
}


--
2.55.0