[RFC PATCH v7 07/28] KVM: arm64: Add KVM_ARM_VCPU_SPE VCPU feature

Lorenzo Stoakes (ARM) ljs at kernel.org
Fri Oct 16 07:23:57 PDT 2026


On Thu, Sep 03, 2026 at 05:06:02PM +0100, Alexandru Elisei wrote:
> Add a new VCPU feature that enables SPE virtualization when set by
> userspace. KVM_VCPU_MAX_FEATURE will be bumped and the feature will
> become selectable by userspace once SPE support in KVM is implemented.

I guess it's also limited currently at this point in the series by
KVM_CAP_ARM_SPE being unselectable as it stands I think?

Maybe worth mentioning here that you're adding KVM_ARM_VPCU_SPE to the uapi,
updating docs, etc.?

>
> Signed-off-by: Alexandru Elisei <alexandru.elisei at arm.com>

I wonder if there are any dependencies that need expressing in
arch/arm64/kvm/config.c?

In any case all LGTM, with mega-nit below addressed :):

Reviewed-by: Lorenzo Stoakes (ARM) <ljs at kernel.org>

> ---
>  Documentation/virt/kvm/api.rst    | 2 ++
>  arch/arm64/include/asm/kvm_spe.h  | 5 +++++
>  arch/arm64/include/uapi/asm/kvm.h | 1 +
>  arch/arm64/kvm/arm.c              | 7 +++++++
>  4 files changed, 15 insertions(+)
>
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index 1ed5c389c7a4..654736fac78c 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -3591,6 +3591,8 @@ Possible features:
>  	  Depends on KVM_CAP_ARM_EL2_E2H0.
>  	  KVM_ARM_VCPU_HAS_EL2 must also be set.
>
> +        - KVM_ARM_VCPU_SPE: Enable SPE for the CPU. Depends on KVM_CAP_ARM_SPE.

Super nitty, sorry, but it seems other parts of the docs use tabs, whereas this
uses spaces?

> +
>  4.83 KVM_ARM_PREFERRED_TARGET
>  -----------------------------
>
> diff --git a/arch/arm64/include/asm/kvm_spe.h b/arch/arm64/include/asm/kvm_spe.h
> index f05e6d3f5705..e452da82666d 100644
> --- a/arch/arm64/include/asm/kvm_spe.h
> +++ b/arch/arm64/include/asm/kvm_spe.h
> @@ -8,11 +8,16 @@
>
>  #ifdef CONFIG_KVM_ARM_SPE
>  bool kvm_supports_spe(void);
> +
> +#define vcpu_has_spe(vcpu)					\
> +	(vcpu_has_feature(vcpu, KVM_ARM_VCPU_SPE))
>  #else
>  static __always_inline bool kvm_supports_spe(void)
>  {
>  	return false;
>  }
> +
> +#define vcpu_has_spe(vcpu)	false
>  #endif /* CONFIG_KVM_ARM_SPE */
>
>  #endif /* __ARM64_KVM_SPE_H__ */
> diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
> index 019e5e3d892e..f7f751c00e6f 100644
> --- a/arch/arm64/include/uapi/asm/kvm.h
> +++ b/arch/arm64/include/uapi/asm/kvm.h
> @@ -107,6 +107,7 @@ struct kvm_regs {
>  #define KVM_ARM_VCPU_HAS_EL2		7 /* Support nested virtualization */
>  #define KVM_ARM_VCPU_HAS_EL2_E2H0	8 /* Limit NV support to E2H RES0 */
>  #define KVM_ARM_VCPU_PMU_V3_STRICT	9 /* No default PMU creation */
> +#define KVM_ARM_VCPU_SPE		10 /* Support SPE in guest */
>
>  struct kvm_vcpu_init {
>  	__u32 target;
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index eca1184ef9dd..b9cee4cf293d 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -1604,6 +1604,9 @@ static unsigned long system_supported_vcpu_features(void)
>  	if (!cpus_have_final_cap(ARM64_HAS_NESTED_VIRT))
>  		clear_bit(KVM_ARM_VCPU_HAS_EL2, &features);
>
> +	if (!kvm_supports_spe())
> +		clear_bit(KVM_ARM_VCPU_SPE, &features);
> +
>  	return features;
>  }
>
> @@ -1648,6 +1651,10 @@ static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu,
>  	if (test_bit(KVM_ARM_VCPU_HAS_EL2, &features))
>  		return -EINVAL;
>
> +	/* SPE is incompatible with AArch32 */
> +	if (test_bit(KVM_ARM_VCPU_SPE, &features))
> +		return -EINVAL;
> +
>  	return 0;
>  }
>
> --
> 2.43.0
>
>

--
Cheers, Lorenzo



More information about the linux-arm-kernel mailing list