KVM: arm64: Use build-time defines in has_vhe()
authorDavid Brazdil <dbrazdil@google.com>
Thu, 25 Jun 2020 13:14:09 +0000 (14:14 +0100)
committerMarc Zyngier <maz@kernel.org>
Sun, 5 Jul 2020 17:38:01 +0000 (18:38 +0100)
Build system compiles hyp code with macros specifying if the code belongs
to VHE or nVHE. Use these macros to evaluate has_vhe() at compile time.

Signed-off-by: David Brazdil <dbrazdil@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20200625131420.71444-5-dbrazdil@google.com
arch/arm64/include/asm/virt.h

index 5051b388c6548596827fc3d33b1b8c25a0d579bf..09977acc007d1562c53ad74c6d0da3d32558a1cd 100644 (file)
@@ -85,10 +85,17 @@ static inline bool is_kernel_in_hyp_mode(void)
 
 static __always_inline bool has_vhe(void)
 {
-       if (cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN))
+       /*
+        * The following macros are defined for code specic to VHE/nVHE.
+        * If has_vhe() is inlined into those compilation units, it can
+        * be determined statically. Otherwise fall back to caps.
+        */
+       if (__is_defined(__KVM_VHE_HYPERVISOR__))
                return true;
-
-       return false;
+       else if (__is_defined(__KVM_NVHE_HYPERVISOR__))
+               return false;
+       else
+               return cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN);
 }
 
 #endif /* __ASSEMBLY__ */