Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <srikar@linux.vnet.ibm.com>
Acked-by: Waiman Long <longman@redhat.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201202050456.164005-4-srikar@linux.vnet.ibm.com

authored by

Srikar Dronamraju and committed by
Michael Ellerman
a21d1bec 16520a85

+13 -1
+10
arch/powerpc/include/asm/kvm_guest.h
··· 7 7 #define _ASM_POWERPC_KVM_GUEST_H_ 8 8 9 9 #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 + 10 19 bool check_kvm_guest(void); 11 20 #else 21 + static inline bool is_kvm_guest(void) { return false; } 12 22 static inline bool check_kvm_guest(void) { return false; } 13 23 #endif 14 24
+1 -1
arch/powerpc/include/asm/kvm_para.h
··· 14 14 15 15 static inline int kvm_para_available(void) 16 16 { 17 - return IS_ENABLED(CONFIG_KVM_GUEST) && check_kvm_guest(); 17 + return IS_ENABLED(CONFIG_KVM_GUEST) && is_kvm_guest(); 18 18 } 19 19 20 20 static inline unsigned int kvm_arch_para_features(void)
+2
arch/powerpc/kernel/firmware.c
··· 22 22 #endif 23 23 24 24 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_KVM_GUEST) 25 + DEFINE_STATIC_KEY_FALSE(kvm_guest); 25 26 bool check_kvm_guest(void) 26 27 { 27 28 struct device_node *hyper_node; ··· 34 33 if (!of_device_is_compatible(hyper_node, "linux,kvm")) 35 34 return false; 36 35 36 + static_branch_enable(&kvm_guest); 37 37 return true; 38 38 } 39 39 #endif