Skip to content

Commit a21d1be

Browse files
srikardmpe
authored andcommitted
powerpc: Reintroduce is_kvm_guest() as a fast-path check
Introduce a static branch that would be set during boot if the OS happens to be a KVM guest. Subsequent checks to see if we are on KVM will rely on this static branch. This static branch would be used in vcpu_is_preempted() in a subsequent patch. Signed-off-by: Srikar Dronamraju <[email protected]> Acked-by: Waiman Long <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 16520a8 commit a21d1be

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

arch/powerpc/include/asm/kvm_guest.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77
#define _ASM_POWERPC_KVM_GUEST_H_
88

99
#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_KVM_GUEST)
10+
#include <linux/jump_label.h>
11+
12+
DECLARE_STATIC_KEY_FALSE(kvm_guest);
13+
14+
static inline bool is_kvm_guest(void)
15+
{
16+
return static_branch_unlikely(&kvm_guest);
17+
}
18+
1019
bool check_kvm_guest(void);
1120
#else
21+
static inline bool is_kvm_guest(void) { return false; }
1222
static inline bool check_kvm_guest(void) { return false; }
1323
#endif
1424

arch/powerpc/include/asm/kvm_para.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
static inline int kvm_para_available(void)
1616
{
17-
return IS_ENABLED(CONFIG_KVM_GUEST) && check_kvm_guest();
17+
return IS_ENABLED(CONFIG_KVM_GUEST) && is_kvm_guest();
1818
}
1919

2020
static inline unsigned int kvm_arch_para_features(void)

arch/powerpc/kernel/firmware.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ EXPORT_SYMBOL_GPL(powerpc_firmware_features);
2222
#endif
2323

2424
#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_KVM_GUEST)
25+
DEFINE_STATIC_KEY_FALSE(kvm_guest);
2526
bool check_kvm_guest(void)
2627
{
2728
struct device_node *hyper_node;
@@ -33,6 +34,7 @@ bool check_kvm_guest(void)
3334
if (!of_device_is_compatible(hyper_node, "linux,kvm"))
3435
return false;
3536

37+
static_branch_enable(&kvm_guest);
3638
return true;
3739
}
3840
#endif

0 commit comments

Comments
 (0)