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

KVM: VMX: Enable and initialize VMX TSC scaling

This patch exhances kvm-intel module to enable VMX TSC scaling and
collects information of TSC scaling ratio during initialization.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Haozhong Zhang and committed by
Paolo Bonzini
64903d61 27cca94e

+19 -1
+3
arch/x86/include/asm/vmx.h
··· 73 73 #define SECONDARY_EXEC_ENABLE_PML 0x00020000 74 74 #define SECONDARY_EXEC_XSAVES 0x00100000 75 75 #define SECONDARY_EXEC_PCOMMIT 0x00200000 76 + #define SECONDARY_EXEC_TSC_SCALING 0x02000000 76 77 77 78 #define PIN_BASED_EXT_INTR_MASK 0x00000001 78 79 #define PIN_BASED_NMI_EXITING 0x00000008 ··· 168 167 VMWRITE_BITMAP = 0x00002028, 169 168 XSS_EXIT_BITMAP = 0x0000202C, 170 169 XSS_EXIT_BITMAP_HIGH = 0x0000202D, 170 + TSC_MULTIPLIER = 0x00002032, 171 + TSC_MULTIPLIER_HIGH = 0x00002033, 171 172 GUEST_PHYSICAL_ADDRESS = 0x00002400, 172 173 GUEST_PHYSICAL_ADDRESS_HIGH = 0x00002401, 173 174 VMCS_LINK_POINTER = 0x00002800,
+16 -1
arch/x86/kvm/vmx.c
··· 107 107 static bool __read_mostly enable_pml = 1; 108 108 module_param_named(pml, enable_pml, bool, S_IRUGO); 109 109 110 + #define KVM_VMX_TSC_MULTIPLIER_MAX 0xffffffffffffffffULL 111 + 110 112 #define KVM_GUEST_CR0_MASK (X86_CR0_NW | X86_CR0_CD) 111 113 #define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST (X86_CR0_WP | X86_CR0_NE) 112 114 #define KVM_VM_CR0_ALWAYS_ON \ ··· 1172 1170 static inline bool cpu_has_vmx_pml(void) 1173 1171 { 1174 1172 return vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_ENABLE_PML; 1173 + } 1174 + 1175 + static inline bool cpu_has_vmx_tsc_scaling(void) 1176 + { 1177 + return vmcs_config.cpu_based_2nd_exec_ctrl & 1178 + SECONDARY_EXEC_TSC_SCALING; 1175 1179 } 1176 1180 1177 1181 static inline bool report_flexpriority(void) ··· 3141 3133 SECONDARY_EXEC_SHADOW_VMCS | 3142 3134 SECONDARY_EXEC_XSAVES | 3143 3135 SECONDARY_EXEC_ENABLE_PML | 3144 - SECONDARY_EXEC_PCOMMIT; 3136 + SECONDARY_EXEC_PCOMMIT | 3137 + SECONDARY_EXEC_TSC_SCALING; 3145 3138 if (adjust_vmx_controls(min2, opt2, 3146 3139 MSR_IA32_VMX_PROCBASED_CTLS2, 3147 3140 &_cpu_based_2nd_exec_control) < 0) ··· 6186 6177 6187 6178 if (!cpu_has_vmx_apicv()) 6188 6179 enable_apicv = 0; 6180 + 6181 + if (cpu_has_vmx_tsc_scaling()) { 6182 + kvm_has_tsc_control = true; 6183 + kvm_max_tsc_scaling_ratio = KVM_VMX_TSC_MULTIPLIER_MAX; 6184 + kvm_tsc_scaling_ratio_frac_bits = 48; 6185 + } 6189 6186 6190 6187 if (enable_apicv) 6191 6188 kvm_x86_ops->update_cr8_intercept = NULL;