[PATCH] KVM: arm64: Add missing hyp_enter when trapping sysreg
Fuad Tabba
tabba at google.com
Wed Jun 17 03:28:11 PDT 2026
On Wed, 17 Jun 2026 at 10:55, Vincent Donnefort <vdonnefort at google.com> wrote:
>
> Add a missing hypervisor event call for hyp_enter on sysreg trapping,
> causing an unbalanced hyp_enter/hyp_exit.
>
> The enum hyp_enter_exit_reason is not ABI, so we can keep the ERET
> reasons at the end for clarity.
>
> Fixes: 696dfec22b8e ("KVM: arm64: Add hyp_enter/hyp_exit events to nVHE/pKVM hyp")
> Signed-off-by: Vincent Donnefort <vdonnefort at google.com>
One thing that caught my eye (as Sashiko would say: pre-existing, not
introduced here), __hyp_enter_exit_reason_str() relies on positional
correspondence between strs[] and enum hyp_enter_exit_reason, with no
compile-time check. Inserting a new value in the middle of the enum
(as you do here) silently shifts all the strings after it if the table
isn't updated in lockstep.
A BUILD_BUG_ON(ARRAY_SIZE(strs)...) would at least catch size
mismatches; catching ordering bugs is harder without per-entry
initialisers like [HYP_REASON_SYS] = "sys".
Something for a future patch, for now:
Reviewed-by: Fuad Tabba <tabba at google.com>
Tested-by: Fuad Tabba <tabba at google.com>
Cheers,
/fuad
>
> diff --git a/arch/arm64/include/asm/kvm_hypevents.h b/arch/arm64/include/asm/kvm_hypevents.h
> index 743c49bd878f..5f6e6789d121 100644
> --- a/arch/arm64/include/asm/kvm_hypevents.h
> +++ b/arch/arm64/include/asm/kvm_hypevents.h
> @@ -12,6 +12,7 @@
> enum hyp_enter_exit_reason {
> HYP_REASON_SMC,
> HYP_REASON_HVC,
> + HYP_REASON_SYS,
> HYP_REASON_PSCI,
> HYP_REASON_HOST_ABORT,
> HYP_REASON_GUEST_EXIT,
> diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> index 06db299c37a8..45a4abb9619d 100644
> --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> @@ -913,6 +913,7 @@ void handle_trap(struct kvm_cpu_context *host_ctxt)
> handle_host_mem_abort(host_ctxt);
> break;
> case ESR_ELx_EC_SYS64:
> + trace_hyp_enter(host_ctxt, HYP_REASON_SYS);
> if (handle_host_mte(esr))
> break;
> fallthrough;
> diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c
> index c4b3ee552131..c84434e2349a 100644
> --- a/arch/arm64/kvm/hyp_trace.c
> +++ b/arch/arm64/kvm/hyp_trace.c
> @@ -398,6 +398,7 @@ static const char *__hyp_enter_exit_reason_str(u8 reason)
> static const char strs[][12] = {
> "smc",
> "hvc",
> + "sys",
> "psci",
> "host_abort",
> "guest_exit",
>
> base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
> --
> 2.54.0.1136.gdb2ca164c4-goog
>
More information about the linux-arm-kernel
mailing list