Skip to contentSkip to conversation

vmx: use mov instead of lea in __vmx_vcpu_run()

PATCH In review Alexey Dobriyan 2 participants 2 messages Nov 17, 2022 – Nov 18, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmx: use mov instead of lea in __vmx_vcpu_run()

"mov rsi, rsp" is equivalent to "lea rsi, [rsp]" but 1 byte shorter.

---

 arch/x86/kvm/vmx/vmenter.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmenter.S +1 -1
@@ -72,7 +72,7 @@ SYM_FUNC_START(__vmx_vcpu_run)
 	/* Copy @flags to BL, _ASM_ARG3 is volatile. */
 	mov %_ASM_ARG3B, %bl
 
-	lea (%_ASM_SP), %_ASM_ARG2
+	mov %_ASM_SP, %_ASM_ARG2
 	call vmx_update_host_rsp
 
 	ALTERNATIVE "jmp .Lspec_ctrl_done", "", X86_FEATURE_MSR_SPEC_CTRL
#1 lore raw

KVM: VMX: for the shortlog please.

Quoted 1 line · Alexey Dobriyan

"mov rsi, rsp" is equivalent to "lea rsi, [rsp]" but 1 byte shorter.

Eww, Intel syntax ;-)

Quoted 9 lines

---

 arch/x86/kvm/vmx/vmenter.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

arch/x86/kvm/vmx/vmenter.S SYM_FUNC_START(__vmx_vcpu_run) · line 75

Quoted 5 lines
arch/x86/kvm/vmx/vmenter.S +1 -1
@@ -72,7 +72,7 @@ SYM_FUNC_START(__vmx_vcpu_run)
 	/* Copy @flags to BL, _ASM_ARG3 is volatile. */
 	mov %_ASM_ARG3B, %bl
 
-	lea (%_ASM_SP), %_ASM_ARG2
+	mov %_ASM_SP, %_ASM_ARG2

I don't have a strong preference. It's probably worth converting, e.g. move elimination on modern CPUs might shave a whole uop.

I'm pretty sure LEA is a holdover from when this code pre-calculated RSP before a series of pushes.

Quoted 3 lines
arch/x86/kvm/vmx/vmenter.S +0 -0
 	call vmx_update_host_rsp
 
 	ALTERNATIVE "jmp .Lspec_ctrl_done", "", X86_FEATURE_MSR_SPEC_CTRL