Skip to content

Commit e9a33ca

Browse files
mrutland-armMarc Zyngier
authored andcommitted
KVM: arm64: Factor out is_{vhe,nvhe}_hyp_code()
Currently has_vhe() detects whether it is being compiled for VHE/NVHE hyp code based on preprocessor definitions, and uses this knowledge to avoid redundant runtime checks. There are other cases where we'd like to use this knowledge, so let's factor the preprocessor checks out into separate helpers. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Acked-by: Will Deacon <will@kernel.org> Cc: David Brazdil <dbrazdil@google.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20201026134931.28246-2-mark.rutland@arm.com
1 parent 91a2c34 commit e9a33ca

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

arch/arm64/include/asm/virt.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,27 @@ static inline bool is_kernel_in_hyp_mode(void)
8383
return read_sysreg(CurrentEL) == CurrentEL_EL2;
8484
}
8585

86+
static __always_inline bool is_vhe_hyp_code(void)
87+
{
88+
/* Only defined for code run in VHE hyp context */
89+
return __is_defined(__KVM_VHE_HYPERVISOR__);
90+
}
91+
92+
static __always_inline bool is_nvhe_hyp_code(void)
93+
{
94+
/* Only defined for code run in NVHE hyp context */
95+
return __is_defined(__KVM_NVHE_HYPERVISOR__);
96+
}
97+
8698
static __always_inline bool has_vhe(void)
8799
{
88100
/*
89-
* The following macros are defined for code specic to VHE/nVHE.
90-
* If has_vhe() is inlined into those compilation units, it can
91-
* be determined statically. Otherwise fall back to caps.
101+
* Code only run in VHE/NVHE hyp context can assume VHE is present or
102+
* absent. Otherwise fall back to caps.
92103
*/
93-
if (__is_defined(__KVM_VHE_HYPERVISOR__))
104+
if (is_vhe_hyp_code())
94105
return true;
95-
else if (__is_defined(__KVM_NVHE_HYPERVISOR__))
106+
else if (is_nvhe_hyp_code())
96107
return false;
97108
else
98109
return cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN);

0 commit comments

Comments
 (0)