[PATCH 1/2] KVM: arm64: Track physical CPU number at EL2

Marc Zyngier maz at kernel.org
Mon Oct 19 03:34:23 PDT 2026


On Wed, 14 Oct 2026 13:55:09 +0100,
Fuad Tabba <fuad.tabba at linux.dev> wrote:
> 
> The nVHE hypervisor has no equivalent of smp_processor_id(), so EL2 code
> has no index for the CPU it runs on.
> 
> Add a hyp per-CPU hyp_cpu_number, which the host writes in
> cpu_prepare_hyp_mode() before it's deprivileged, and a
> hyp_smp_processor_id() accessor to read it. The next patch uses it to
> index per-CPU state in a hyp VM.
> 
> Signed-off-by: Fuad Tabba <fuad.tabba at linux.dev>
> ---
>  arch/arm64/include/asm/kvm_hyp.h  | 3 +++
>  arch/arm64/kvm/arm.c              | 3 +++
>  arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 2 ++
>  3 files changed, 8 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
> index b0e42be3d9eef..6c4169a14b73e 100644
> --- a/arch/arm64/include/asm/kvm_hyp.h
> +++ b/arch/arm64/include/asm/kvm_hyp.h
> @@ -16,6 +16,9 @@
>  DECLARE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt);
>  DECLARE_PER_CPU(unsigned long, kvm_hyp_vector);
>  DECLARE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
> +DECLARE_PER_CPU(int, hyp_cpu_number);
> +
> +#define hyp_smp_processor_id() (__this_cpu_read(hyp_cpu_number))
>

Do we really need this? I was hoping that TPIDR_EL2 would give us a
way to compute the CPU number more or less directly, without having to
maintain per-CPU variable (which is pretty backward, when you think
about it...).

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list