[PATCHv2 3/3] arm64: cpufeature: upgrade hyp caps to final

Will Deacon will at kernel.org
Fri Oct 30 04:24:01 EDT 2020


On Mon, Oct 26, 2020 at 01:49:31PM +0000, Mark Rutland wrote:
> We finalize caps before initializing kvm hyp code, and any use of
> cpus_have_const_cap() in kvm hyp code generates redundant and
> potentially unsound code to read the cpu_hwcaps array.
> 
> A number of helper functions used in both hyp context and regular kernel
> context use cpus_have_const_cap(), as some regular kernel code runs
> before the capabilities are finalized. It's tedious and error-prone to
> write separate copies of these for hyp and non-hyp code.
> 
> So that we can avoid the redundant code, let's automatically upgrade
> cpus_have_const_cap() to cpus_have_final_cap() when used in hyp context.
> With this change, there's never a reason to access to cpu_hwcaps array
> from hyp code, and we don't need to create an NVHE alias for this.
> 
> This should have no effect on non-hyp code.
> 
> Signed-off-by: Mark Rutland <mark.rutland at arm.com>
> Cc: David Brazdil <dbrazdil at google.com>
> Cc: Marc Zyngier <maz at kernel.org>
> Cc: Will Deacon <will at kernel.org>
> ---
>  arch/arm64/include/asm/cpufeature.h | 26 ++++++++++++++++++++++++--
>  arch/arm64/include/asm/virt.h       | 12 ------------
>  arch/arm64/kernel/image-vars.h      |  1 -
>  3 files changed, 24 insertions(+), 15 deletions(-)

[...]

> diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
> index 61684a5009148..c615b285ff5b3 100644
> --- a/arch/arm64/kernel/image-vars.h
> +++ b/arch/arm64/kernel/image-vars.h
> @@ -87,7 +87,6 @@ KVM_NVHE_ALIAS(__icache_flags);
>  /* Kernel symbols needed for cpus_have_final/const_caps checks. */
>  KVM_NVHE_ALIAS(arm64_const_caps_ready);
>  KVM_NVHE_ALIAS(cpu_hwcap_keys);
> -KVM_NVHE_ALIAS(cpu_hwcaps);

Nice!

Acked-by: Will Deacon <will at kernel.org>

Will



More information about the linux-arm-kernel mailing list