[PATCH v2 3/5] KVM: arm64: Add a generic synchronous exception injection primitive
Yao Yuan
yaoyuan at linux.alibaba.com
Wed Nov 26 21:57:24 PST 2025
On Wed, Nov 26, 2025 at 03:59:49PM +0800, Marc Zyngier wrote:
> Maybe in a surprising way, we don't currently have a generic way
> to inject a synchronous exception at the EL the vcpu is currently
> running at.
Hi Marc,
Thanks for bring this in generic way.
Reviewed-by: Yuan Yao <yaoyuan at linux.alibaba.com>
>
> Extract such primitive from the UNDEF injection code.
>
> Signed-off-by: Marc Zyngier <maz at kernel.org>
> ---
> arch/arm64/include/asm/kvm_emulate.h | 1 +
> arch/arm64/kvm/inject_fault.c | 10 +++++++---
> 2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> index c9eab316398e2..df20d47f0d256 100644
> --- a/arch/arm64/include/asm/kvm_emulate.h
> +++ b/arch/arm64/include/asm/kvm_emulate.h
> @@ -45,6 +45,7 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);
> void kvm_skip_instr32(struct kvm_vcpu *vcpu);
>
> void kvm_inject_undefined(struct kvm_vcpu *vcpu);
> +void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);
> int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
> int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr);
> void kvm_inject_size_fault(struct kvm_vcpu *vcpu);
> diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c
> index dfcd66c655179..7102424a3fa5e 100644
> --- a/arch/arm64/kvm/inject_fault.c
> +++ b/arch/arm64/kvm/inject_fault.c
> @@ -162,12 +162,16 @@ static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr
> vcpu_write_sys_reg(vcpu, esr, exception_esr_elx(vcpu));
> }
>
> +void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr)
> +{
> + pend_sync_exception(vcpu);
> + vcpu_write_sys_reg(vcpu, esr, exception_esr_elx(vcpu));
> +}
> +
> static void inject_undef64(struct kvm_vcpu *vcpu)
> {
> u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
>
> - pend_sync_exception(vcpu);
> -
> /*
> * Build an unknown exception, depending on the instruction
> * set.
> @@ -175,7 +179,7 @@ static void inject_undef64(struct kvm_vcpu *vcpu)
> if (kvm_vcpu_trap_il_is32bit(vcpu))
> esr |= ESR_ELx_IL;
>
> - vcpu_write_sys_reg(vcpu, esr, exception_esr_elx(vcpu));
> + kvm_inject_sync(vcpu, esr);
> }
>
> #define DFSR_FSC_EXTABT_LPAE 0x10
> --
> 2.47.3
>
More information about the linux-arm-kernel
mailing list