[PATCH 18/28] KVM: arm64: Add kvm_has_nv{2,3}() predicates
Joey Gouly
joey.gouly at arm.com
Fri Jul 10 08:30:16 PDT 2026
Question,
On Thu, Jul 02, 2026 at 05:02:38PM +0100, Marc Zyngier wrote:
> Add a new set of predicates indicating whether VM is capable of
> NV2, NV3, and is in a nested NV3 context.
>
> This is going to become useful as we start dealing with a mix of
> behaviours (NV2, NV3, NV2 on NV3...).
>
> Signed-off-by: Marc Zyngier <maz at kernel.org>
> ---
> arch/arm64/include/asm/kvm_emulate.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> index 9831166695186..c562d8171d5e1 100644
> --- a/arch/arm64/include/asm/kvm_emulate.h
> +++ b/arch/arm64/include/asm/kvm_emulate.h
> @@ -266,6 +266,26 @@ static inline bool vserror_state_is_nested(struct kvm_vcpu *vcpu)
> (__vcpu_sys_reg(vcpu, HCRX_EL2) & HCRX_EL2_TMEA);
> }
>
> +static inline bool kvm_has_nv2(struct kvm *kvm)
> +{
> + return (cpus_have_final_cap(ARM64_HAS_NESTED_VIRT) &&
> + kvm_has_feat(kvm, ID_AA64MMFR4_EL1, NV_frac, NV2_ONLY));
Should this also check ID_AA64MMFR2_EL1.NV=0b10? (aka NV2, not just NV2_ONLY)
> +}
> +
> +static inline bool kvm_has_nv3(struct kvm *kvm)
> +{
> + return (cpus_have_final_cap(ARM64_HAS_NESTED_VIRT) &&
> + cpus_have_final_cap(ARM64_HAS_NV3) &&
> + kvm_has_feat(kvm, ID_AA64MMFR4_EL1, NV_frac, NV3));
> +}
> +
> +static inline bool is_nested_nv3_ctxt(struct kvm_vcpu *vcpu)
> +{
> + return (has_vhe() && kvm_has_nv3(vcpu->kvm) && is_nested_ctxt(vcpu) &&
> + (__vcpu_sys_reg(vcpu, HCR_EL2) & HCR_EL2_NV) &&
> + (__vcpu_sys_reg(vcpu, HCRX_EL2) & HCRX_EL2_NVTGE));
> +}
> +
> /*
> * The layout of SPSR for an AArch32 state is different when observed from an
> * AArch64 SPSR_ELx or an AArch32 SPSR_*. This function generates the AArch32
Thanks,
Joey
More information about the linux-arm-kernel
mailing list