Skip to content

Commit 64903d6

Browse files
Haozhong Zhangbonzini
authored andcommitted
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>
1 parent 27cca94 commit 64903d6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

arch/x86/include/asm/vmx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#define SECONDARY_EXEC_ENABLE_PML 0x00020000
7474
#define SECONDARY_EXEC_XSAVES 0x00100000
7575
#define SECONDARY_EXEC_PCOMMIT 0x00200000
76+
#define SECONDARY_EXEC_TSC_SCALING 0x02000000
7677

7778
#define PIN_BASED_EXT_INTR_MASK 0x00000001
7879
#define PIN_BASED_NMI_EXITING 0x00000008
@@ -167,6 +168,8 @@ enum vmcs_field {
167168
VMWRITE_BITMAP = 0x00002028,
168169
XSS_EXIT_BITMAP = 0x0000202C,
169170
XSS_EXIT_BITMAP_HIGH = 0x0000202D,
171+
TSC_MULTIPLIER = 0x00002032,
172+
TSC_MULTIPLIER_HIGH = 0x00002033,
170173
GUEST_PHYSICAL_ADDRESS = 0x00002400,
171174
GUEST_PHYSICAL_ADDRESS_HIGH = 0x00002401,
172175
VMCS_LINK_POINTER = 0x00002800,

arch/x86/kvm/vmx.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ static u64 __read_mostly host_xss;
107107
static bool __read_mostly enable_pml = 1;
108108
module_param_named(pml, enable_pml, bool, S_IRUGO);
109109

110+
#define KVM_VMX_TSC_MULTIPLIER_MAX 0xffffffffffffffffULL
111+
110112
#define KVM_GUEST_CR0_MASK (X86_CR0_NW | X86_CR0_CD)
111113
#define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST (X86_CR0_WP | X86_CR0_NE)
112114
#define KVM_VM_CR0_ALWAYS_ON \
@@ -1172,6 +1174,12 @@ static inline bool cpu_has_vmx_pml(void)
11721174
return vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_ENABLE_PML;
11731175
}
11741176

1177+
static inline bool cpu_has_vmx_tsc_scaling(void)
1178+
{
1179+
return vmcs_config.cpu_based_2nd_exec_ctrl &
1180+
SECONDARY_EXEC_TSC_SCALING;
1181+
}
1182+
11751183
static inline bool report_flexpriority(void)
11761184
{
11771185
return flexpriority_enabled;
@@ -3133,7 +3141,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
31333141
SECONDARY_EXEC_SHADOW_VMCS |
31343142
SECONDARY_EXEC_XSAVES |
31353143
SECONDARY_EXEC_ENABLE_PML |
3136-
SECONDARY_EXEC_PCOMMIT;
3144+
SECONDARY_EXEC_PCOMMIT |
3145+
SECONDARY_EXEC_TSC_SCALING;
31373146
if (adjust_vmx_controls(min2, opt2,
31383147
MSR_IA32_VMX_PROCBASED_CTLS2,
31393148
&_cpu_based_2nd_exec_control) < 0)
@@ -6178,6 +6187,12 @@ static __init int hardware_setup(void)
61786187
if (!cpu_has_vmx_apicv())
61796188
enable_apicv = 0;
61806189

6190+
if (cpu_has_vmx_tsc_scaling()) {
6191+
kvm_has_tsc_control = true;
6192+
kvm_max_tsc_scaling_ratio = KVM_VMX_TSC_MULTIPLIER_MAX;
6193+
kvm_tsc_scaling_ratio_frac_bits = 48;
6194+
}
6195+
61816196
if (enable_apicv)
61826197
kvm_x86_ops->update_cr8_intercept = NULL;
61836198
else {

0 commit comments

Comments
 (0)