Skip to content

Commit 6ab8a40

Browse files
Lai Jiangshanbonzini
Lai Jiangshan
authored andcommitted
KVM: VMX: Avoid to rdmsrl(MSR_IA32_SYSENTER_ESP)
The value of host MSR_IA32_SYSENTER_ESP is known to be constant for each CPU: (cpu_entry_stack(cpu) + 1) when 32 bit syscall is enabled or NULL is 32 bit syscall is not enabled. So rdmsrl() can be avoided for the first case and both rdmsrl() and vmcs_writel() can be avoided for the second case. Signed-off-by: Lai Jiangshan <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 24cd19a commit 6ab8a40

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

arch/x86/kvm/vmx/vmx.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,6 @@ void vmx_vcpu_load_vmcs(struct kvm_vcpu *vcpu, int cpu,
12711271

12721272
if (!already_loaded) {
12731273
void *gdt = get_current_gdt_ro();
1274-
unsigned long sysenter_esp;
12751274

12761275
/*
12771276
* Flush all EPTP/VPID contexts, the new pCPU may have stale
@@ -1287,8 +1286,11 @@ void vmx_vcpu_load_vmcs(struct kvm_vcpu *vcpu, int cpu,
12871286
(unsigned long)&get_cpu_entry_area(cpu)->tss.x86_tss);
12881287
vmcs_writel(HOST_GDTR_BASE, (unsigned long)gdt); /* 22.2.4 */
12891288

1290-
rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
1291-
vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
1289+
if (IS_ENABLED(CONFIG_IA32_EMULATION) || IS_ENABLED(CONFIG_X86_32)) {
1290+
/* 22.2.3 */
1291+
vmcs_writel(HOST_IA32_SYSENTER_ESP,
1292+
(unsigned long)(cpu_entry_stack(cpu) + 1));
1293+
}
12921294

12931295
vmx->loaded_vmcs->cpu = cpu;
12941296
}
@@ -4026,6 +4028,12 @@ void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
40264028

40274029
rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
40284030
vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
4031+
4032+
/*
4033+
* If 32-bit syscall is enabled, vmx_vcpu_load_vcms rewrites
4034+
* HOST_IA32_SYSENTER_ESP.
4035+
*/
4036+
vmcs_writel(HOST_IA32_SYSENTER_ESP, 0);
40294037
rdmsrl(MSR_IA32_SYSENTER_EIP, tmpl);
40304038
vmcs_writel(HOST_IA32_SYSENTER_EIP, tmpl); /* 22.2.3 */
40314039

0 commit comments

Comments
 (0)