From: Steffen Eiden Allow KVM to inject an Serror into its guest. On SAE exit re-sync the SError bit HCR_EL2.VSE bit with the HCR_EL2 value saved on SAE exit, as hardware clears VSE when the guest takes the virtual SError. Signed-off-by: Steffen Eiden Co-developed-by: Andreas Grapentin Signed-off-by: Andreas Grapentin --- arch/s390/kvm/arm64/arm.c | 6 ++++++ arch/s390/kvm/arm64/inject_fault.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c index cc8453bd820c..49e2ffcfdf22 100644 --- a/arch/s390/kvm/arm64/arm.c +++ b/arch/s390/kvm/arm64/arm.c @@ -525,6 +525,12 @@ 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); + /* Cleared by hardware once the guest takes the vSError. */ + if (vcpu->arch.hcr_el2 & HCR_EL2_VSE) { + vcpu->arch.hcr_el2 &= ~HCR_EL2_VSE; + vcpu->arch.hcr_el2 |= vcpu_read_host_sys_reg(vcpu, SYS_HCR_EL2) & HCR_EL2_VSE; + } + if (vcpu->mode != OUTSIDE_GUEST_MODE) kvm_sae_exit_handler((unsigned long)vcpu); vcpu->stat.exits++; diff --git a/arch/s390/kvm/arm64/inject_fault.c b/arch/s390/kvm/arm64/inject_fault.c index 33f40c5188c9..82c924c45a81 100644 --- a/arch/s390/kvm/arm64/inject_fault.c +++ b/arch/s390/kvm/arm64/inject_fault.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include static void pend_sync_exception(struct kvm_vcpu *vcpu) { @@ -80,3 +81,17 @@ void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr) pend_sync_exception(vcpu); vcpu_write_sys_reg(vcpu, esr, ESR_EL1); } + +/** + * kvm_inject_serror_esr() - inject a virtual SError into the guest + * @vcpu: The vCPU in which to inject the SError + * @esr: The ESR ISS value describing the SError + */ +int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr) +{ + lockdep_assert_held(&vcpu->mutex); + + vcpu_write_host_sys_reg(vcpu, esr & ESR_ELx_ISS_MASK, SYS_VSESR_EL2); + vcpu->arch.hcr_el2 |= HCR_EL2_VSE; + return 1; +} -- 2.55.0