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

Configure Feed

Select the types of activity you want to include in your feed.

KVM: Introduce paravirtualization hints and KVM_HINTS_DEDICATED

This patch introduces kvm_para_has_hint() to query for hints about
the configuration of the guests. The first hint KVM_HINTS_DEDICATED,
is set if the guest has dedicated physical CPUs for each vCPU (i.e.
pinning and no over-commitment). This allows optimizing spinlocks
and tells the guest to avoid PV TLB flush.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>

authored by

Wanpeng Li and committed by
Radim Krčmář
a4429e53 d4c67a7a

+55 -4
+13 -2
Documentation/virtual/kvm/cpuid.txt
··· 23 23 24 24 25 25 function: define KVM_CPUID_FEATURES (0x40000001) 26 - returns : ebx, ecx, edx = 0 27 - eax = and OR'ed group of (1 << flag), where each flags is: 26 + returns : ebx, ecx 27 + eax = an OR'ed group of (1 << flag), where each flags is: 28 28 29 29 30 30 flag || value || meaning ··· 66 66 || || per-cpu warps are expected in 67 67 || || kvmclock. 68 68 ------------------------------------------------------------------------------ 69 + 70 + edx = an OR'ed group of (1 << flag), where each flags is: 71 + 72 + 73 + flag || value || meaning 74 + ================================================================================== 75 + KVM_HINTS_DEDICATED || 0 || guest checks this feature bit to 76 + || || determine if there is vCPU pinning 77 + || || and there is no vCPU over-commitment, 78 + || || allowing optimizations 79 + ----------------------------------------------------------------------------------
+5
arch/mips/include/asm/kvm_para.h
··· 94 94 return 0; 95 95 } 96 96 97 + static inline unsigned int kvm_arch_para_hints(void) 98 + { 99 + return 0; 100 + } 101 + 97 102 #ifdef CONFIG_MIPS_PARAVIRT 98 103 static inline bool kvm_para_available(void) 99 104 {
+5
arch/powerpc/include/asm/kvm_para.h
··· 61 61 return r; 62 62 } 63 63 64 + static inline unsigned int kvm_arch_para_hints(void) 65 + { 66 + return 0; 67 + } 68 + 64 69 static inline bool kvm_check_and_clear_guest_paused(void) 65 70 { 66 71 return false;
+5
arch/s390/include/asm/kvm_para.h
··· 193 193 return 0; 194 194 } 195 195 196 + static inline unsigned int kvm_arch_para_hints(void) 197 + { 198 + return 0; 199 + } 200 + 196 201 static inline bool kvm_check_and_clear_guest_paused(void) 197 202 { 198 203 return false;
+6
arch/x86/include/asm/kvm_para.h
··· 88 88 #ifdef CONFIG_KVM_GUEST 89 89 bool kvm_para_available(void); 90 90 unsigned int kvm_arch_para_features(void); 91 + unsigned int kvm_arch_para_hints(void); 91 92 void kvm_async_pf_task_wait(u32 token, int interrupt_kernel); 92 93 void kvm_async_pf_task_wake(u32 token); 93 94 u32 kvm_read_and_reset_pf_reason(void); ··· 112 111 } 113 112 114 113 static inline unsigned int kvm_arch_para_features(void) 114 + { 115 + return 0; 116 + } 117 + 118 + static inline unsigned int kvm_arch_para_hints(void) 115 119 { 116 120 return 0; 117 121 }
+6 -2
arch/x86/include/uapi/asm/kvm_para.h
··· 10 10 */ 11 11 #define KVM_CPUID_SIGNATURE 0x40000000 12 12 13 - /* This CPUID returns a feature bitmap in eax. Before enabling a particular 14 - * paravirtualization, the appropriate feature bit should be checked. 13 + /* This CPUID returns two feature bitmaps in eax, edx. Before enabling 14 + * a particular paravirtualization, the appropriate feature bit should 15 + * be checked in eax. The performance hint feature bit should be checked 16 + * in edx. 15 17 */ 16 18 #define KVM_CPUID_FEATURES 0x40000001 17 19 #define KVM_FEATURE_CLOCKSOURCE 0 ··· 29 27 #define KVM_FEATURE_PV_UNHALT 7 30 28 #define KVM_FEATURE_PV_TLB_FLUSH 9 31 29 #define KVM_FEATURE_ASYNC_PF_VMEXIT 10 30 + 31 + #define KVM_HINTS_DEDICATED 0 32 32 33 33 /* The last 8 bits are used to indicate how to interpret the flags field 34 34 * in pvclock structure. If no bits are set, all flags are ignored.
+5
arch/x86/kernel/kvm.c
··· 605 605 return cpuid_eax(kvm_cpuid_base() | KVM_CPUID_FEATURES); 606 606 } 607 607 608 + unsigned int kvm_arch_para_hints(void) 609 + { 610 + return cpuid_edx(kvm_cpuid_base() | KVM_CPUID_FEATURES); 611 + } 612 + 608 613 static uint32_t __init kvm_detect(void) 609 614 { 610 615 return kvm_cpuid_base();
+5
include/asm-generic/kvm_para.h
··· 19 19 return 0; 20 20 } 21 21 22 + static inline unsigned int kvm_arch_para_hints(void) 23 + { 24 + return 0; 25 + } 26 + 22 27 static inline bool kvm_para_available(void) 23 28 { 24 29 return false;
+5
include/linux/kvm_para.h
··· 9 9 { 10 10 return !!(kvm_arch_para_features() & (1UL << feature)); 11 11 } 12 + 13 + static inline bool kvm_para_has_hint(unsigned int feature) 14 + { 15 + return !!(kvm_arch_para_hints() & (1UL << feature)); 16 + } 12 17 #endif /* __LINUX_KVM_PARA_H */