[PATCH 09/10] KVM: s390: arm64: Enable mcck forwarding
From: Andreas Grapentin
Date: Fri Dec 04 2026 - 07:11:59 EST
From: Steffen Eiden <seiden@xxxxxxxxxxxxx>
Register KVM callback for machine check backup info. On resume,
translate saved machine check conditions into ARM64 SError exceptions
and reinject them into the guest via kvm_inject_serror_esr().
Signed-off-by: Steffen Eiden <seiden@xxxxxxxxxxxxx>
Co-developed-by: Andreas Grapentin <gra@xxxxxxxxxxxxx>
Signed-off-by: Andreas Grapentin <gra@xxxxxxxxxxxxx>
---
arch/s390/include/asm/kvm_host_arm64.h | 3 +++
arch/s390/kvm/arm64/arm.c | 44 ++++++++++++++++++++++++++++++++++
arch/s390/kvm/arm64/reset.c | 3 +++
3 files changed, 50 insertions(+)
diff --git a/arch/s390/include/asm/kvm_host_arm64.h b/arch/s390/include/asm/kvm_host_arm64.h
index a76e1bfc64bb..5d9487f37482 100644
--- a/arch/s390/include/asm/kvm_host_arm64.h
+++ b/arch/s390/include/asm/kvm_host_arm64.h
@@ -116,6 +116,9 @@ struct kvm_vcpu_arch {
struct kvm_s390_mmu_cache *mc;
+ /* Saved machine check info when mcck occurs during SAE execution */
+ struct mcck_volatile_info mcck_info;
+
void *debugfs_state_data;
};
diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index 49e2ffcfdf22..22ed1109f7b8 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -13,8 +13,11 @@
#include <asm/access-regs.h>
#include <asm/aef.h>
+#include <asm/irq.h>
+#include <asm/nmi.h>
#include <arm64/kvm_emulate.h>
+#include <arm64/esr.h>
#include <arm64/sysreg.h>
#include <arm64/sys_regs.h>
@@ -433,6 +436,42 @@ static noinstr void kvm_sae_exit_handler(unsigned long v)
WRITE_ONCE(vcpu->mode, OUTSIDE_GUEST_MODE);
}
+static noinstr void
+kvm_sae_backup_mcck_info(void *v, struct mcck_volatile_info *mcck_info)
+{
+ struct kvm_vcpu *vcpu = v;
+
+ vcpu->arch.mcck_info = *mcck_info;
+}
+
+static u64 mci_to_esr(union mci mci)
+{
+ /* for now, as a reasonable approximation, consider any host
+ * machine check during arm64 guest execution a fatal uncontainable
+ * event for the arm64 guest.
+ */
+ return ESR_ELx_AET_UEU | ESR_ELx_FSC_SERROR;
+}
+
+static void reinject_mcck(struct kvm_vcpu *vcpu)
+{
+ struct mcck_volatile_info *mcck;
+ union mci mci;
+ u64 esr;
+
+ mcck = &vcpu->arch.mcck_info;
+ mci.val = mcck->mcic;
+
+ if (!mcck->mcic)
+ return;
+
+ esr = mci_to_esr(mci);
+
+ memset(mcck, 0, sizeof(*mcck));
+
+ kvm_inject_serror_esr(vcpu, esr);
+}
+
static noinstr void arm_vcpu_enter_exit(struct kvm_sae_block *sae_block,
struct kvm_vcpu *vcpu)
{
@@ -492,6 +531,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
if (ret > 0)
ret = check_vcpu_requests(vcpu);
+ if (ret > 0)
+ reinject_mcck(vcpu);
+
vcpu->arch.sae_block.icptr = 0;
local_irq_disable();
@@ -816,6 +858,7 @@ static bool __init machine_supports_arm64_kvm(void)
static void unregister_callbacks(void)
{
kvm_s390_arm64_vcpu_exit = NULL;
+ kvm_sae_backup_mci = NULL;
/* wait for all possible users of the callback to quiesce */
synchronize_rcu();
}
@@ -836,6 +879,7 @@ static int __init kvm_s390_arm64_init(void)
}
kvm_s390_arm64_vcpu_exit = kvm_sae_exit_handler;
+ kvm_sae_backup_mci = kvm_sae_backup_mcck_info;
/*
* kvm_init _must_ be the very last thing done, as this exposes
diff --git a/arch/s390/kvm/arm64/reset.c b/arch/s390/kvm/arm64/reset.c
index 2ae363f6821a..206f42ba3256 100644
--- a/arch/s390/kvm/arm64/reset.c
+++ b/arch/s390/kvm/arm64/reset.c
@@ -109,6 +109,9 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
vcpu_reset_cnthctl(vcpu);
vcpu_reset_icc(vcpu);
+ /* Discard any pending mcck's */
+ memset(&vcpu->arch.mcck_info, 0, sizeof(vcpu->arch.mcck_info));
+
if (reset_state.reset) {
*vcpu_pc(vcpu) = reset_state.pc;
vcpu_clear_flag(vcpu, PENDING_EXCEPTION);
--
2.55.0