Skip to content

Commit 35230be

Browse files
Marc Zyngieroupton
authored andcommitted
arm64: Prevent the use of is_kernel_in_hyp_mode() in hypervisor code
Using is_kernel_in_hyp_mode() in hypervisor code is a pretty bad mistake. This helper only checks for CurrentEL being EL2, which is always true. Make the compilation fail if using the helper in hypervisor context Whilst we're at it, flag the helper as __always_inline, which it really should be. Signed-off-by: Marc Zyngier <maz@kernel.org> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Link: https://lore.kernel.org/r/20230609162200.2024064-3-maz@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent c4b9fd2 commit 35230be

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

arch/arm64/include/asm/virt.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ static inline bool is_hyp_mode_mismatched(void)
110110
return __boot_cpu_mode[0] != __boot_cpu_mode[1];
111111
}
112112

113-
static inline bool is_kernel_in_hyp_mode(void)
113+
static __always_inline bool is_kernel_in_hyp_mode(void)
114114
{
115+
BUILD_BUG_ON(__is_defined(__KVM_NVHE_HYPERVISOR__) ||
116+
__is_defined(__KVM_VHE_HYPERVISOR__));
115117
return read_sysreg(CurrentEL) == CurrentEL_EL2;
116118
}
117119

0 commit comments

Comments
 (0)