Skip to content

Commit d81a91a

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Add is_pkvm_initialized() helper
Add a helper allowing to check when the pkvm static key is enabled to ease the introduction of pkvm hooks in other parts of the code. Signed-off-by: Quentin Perret <qperret@google.com> Signed-off-by: Fuad Tabba <tabba@google.com> Acked-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20240423150538.2103045-18-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 948e1a5 commit d81a91a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

arch/arm64/include/asm/virt.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ bool is_kvm_arm_initialised(void);
8282

8383
DECLARE_STATIC_KEY_FALSE(kvm_protected_mode_initialized);
8484

85+
static inline bool is_pkvm_initialized(void)
86+
{
87+
return IS_ENABLED(CONFIG_KVM) &&
88+
static_branch_likely(&kvm_protected_mode_initialized);
89+
}
90+
8591
/* Reports the availability of HYP mode */
8692
static inline bool is_hyp_mode_available(void)
8793
{
8894
/*
8995
* If KVM protected mode is initialized, all CPUs must have been booted
9096
* in EL2. Avoid checking __boot_cpu_mode as CPUs now come up in EL1.
9197
*/
92-
if (IS_ENABLED(CONFIG_KVM) &&
93-
static_branch_likely(&kvm_protected_mode_initialized))
98+
if (is_pkvm_initialized())
9499
return true;
95100

96101
return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
@@ -104,8 +109,7 @@ static inline bool is_hyp_mode_mismatched(void)
104109
* If KVM protected mode is initialized, all CPUs must have been booted
105110
* in EL2. Avoid checking __boot_cpu_mode as CPUs now come up in EL1.
106111
*/
107-
if (IS_ENABLED(CONFIG_KVM) &&
108-
static_branch_likely(&kvm_protected_mode_initialized))
112+
if (is_pkvm_initialized())
109113
return false;
110114

111115
return __boot_cpu_mode[0] != __boot_cpu_mode[1];

0 commit comments

Comments
 (0)