arm64: kvm: hyp: use cpus_have_final_cap()
authorMark Rutland <mark.rutland@arm.com>
Fri, 21 Feb 2020 14:50:22 +0000 (14:50 +0000)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 13 Mar 2020 17:34:28 +0000 (17:34 +0000)
commitb5475d8caedb71476f999a858ea3f8c24c5f9e50
tree7a46098e055c0f1a206ff4e5bea0632943ca9e7c
parent1db5cdeccd813330aaab19b3fccab15e1d07fe12
arm64: kvm: hyp: use cpus_have_final_cap()

The KVM hyp code is only run after system capabilities have been
finalized, and thus all const cap checks have been patched. This is
noted in in __cpu_init_hyp_mode(), where we BUG() if called too early:

| /*
|  * Call initialization code, and switch to the full blown HYP code.
|  * If the cpucaps haven't been finalized yet, something has gone very
|  * wrong, and hyp will crash and burn when it uses any
|  * cpus_have_const_cap() wrapper.
|  */

Given this, the hyp code can use cpus_have_final_cap() and avoid
generating code to check the cpu_hwcaps array, which would be unsafe to
run in hyp context.

This patch migrate the KVM hyp code to cpus_have_final_cap(), avoiding
this redundant code generation, and making it possible to detect if we
accidentally invoke this code too early. In the latter case, the BUG()
in cpus_have_final_cap() will cause a hyp panic.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Cc: James Morse <james.morse@arm.com>
Cc: Julien Thierry <julien.thierry.kdev@gmail.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/kvm/hyp/switch.c
arch/arm64/kvm/hyp/sysreg-sr.c
arch/arm64/kvm/hyp/tlb.c