public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: seanjc@google.com, chang.seok.bae@intel.com
Subject: Re: [PATCH 7/7] KVM: VMX: replace vmx_spec_ctrl_restore_host with RESTORE_HOST_SPEC_CTRL_BODY
Date: Thu, 9 Apr 2026 19:36:34 +0200	[thread overview]
Message-ID: <57796f12-53f7-426b-be4c-abf0b2ce2061@gmail.com> (raw)
In-Reply-To: <20260408182213.522713-8-pbonzini@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]



On 4/8/26 20:22, Paolo Bonzini wrote:
> Reuse the same assembly as SVM, just with alternatives instead
> of cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS).
> 
> Due to the dearth of registers in 32-bit x86, save/restore %eax
> across the restoring sequence, keeping it simple; the main alternative
> would be to leave vmx and flags on the stack, avoiding the need to read
> flags from %ebx.  It's not really measurable difference.

You don't need to save/restore %eax. Considering that
RESTORE_HOST_SPEC_CTRL_BODY doesn't touch %ebx, and that

testl $KVM_ENTER_SAVE_SPEC_CTRL, \enter_flags

is placed at the beginning of the macro, you can put @flags into %eax:

+ pop %_ASM_AX /* @flags */
+ pop %_ASM_DI /* @vmx */
+
+        /* Clobbers RAX, RCX, RDX, RSI.  */
+ ALTERNATIVE "jmp .Lspec_ctrl_host_done", "", X86_FEATURE_MSR_SPEC_CTRL
+ RESTORE_HOST_SPEC_CTRL_BODY VMX_spec_ctrl(%_ASM_DI), %eax,
.Lspec_ctrl_host_done
+.Lspec_ctrl_host_done:
+
+ CLEAR_BRANCH_HISTORY_VMEXIT

The above macro will clobber %eax via clear_bhb_loop(), so you should leave:

   /* Put return value in AX */
   mov %_ASM_BX, %_ASM_AX

after it, like in the attached (partial) patch.

BR,
Uros.

[-- Attachment #2: vmx.diff.txt --]
[-- Type: text/plain, Size: 755 bytes --]

diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S
index 4426d34811fc..b707ebf6e7a5 100644
--- a/arch/x86/kvm/vmx/vmenter.S
+++ b/arch/x86/kvm/vmx/vmenter.S
@@ -286,10 +286,13 @@ SYM_INNER_LABEL_ALIGN(vmx_vmexit, SYM_L_GLOBAL)
 	FILL_RETURN_BUFFER %_ASM_CX, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT,\
 			   X86_FEATURE_RSB_VMEXIT_LITE
 
-	pop %_ASM_ARG2	/* @flags */
-	pop %_ASM_ARG1	/* @vmx */
+	pop %_ASM_AX	/* @flags */
+	pop %_ASM_DI	/* @vmx */
 
-	call vmx_spec_ctrl_restore_host
+	/* Clobbers RAX, RCX, RDX, RSI.  */
+	ALTERNATIVE "jmp .Lspec_ctrl_host_done", "", X86_FEATURE_MSR_SPEC_CTRL
+	RESTORE_HOST_SPEC_CTRL_BODY VMX_spec_ctrl(%_ASM_DI), %eax, .Lspec_ctrl_host_done
+.Lspec_ctrl_host_done:
 
 	CLEAR_BRANCH_HISTORY_VMEXIT
 

      parent reply	other threads:[~2026-04-09 17:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 18:22 [PATCH 0/7] KVM: VMX/SVM: use the same SPEC_CTRL assembly code Paolo Bonzini
2026-04-08 18:22 ` [PATCH 1/7] KVM: VMX: remove regs argument of __vmx_vcpu_run Paolo Bonzini
2026-04-08 18:22 ` [PATCH 2/7] KVM: VMX: more cleanups to __vmx_vcpu_run Paolo Bonzini
2026-04-09  9:38   ` Binbin Wu
2026-04-08 18:22 ` [PATCH 3/7] KVM: SVM: prepare for making SPEC_CTRL switch common with VMX Paolo Bonzini
2026-04-08 18:22 ` [PATCH 4/7] KVM: SVM: adopt the same VMX_RUN_* flags as VMX Paolo Bonzini
2026-04-08 18:22 ` [PATCH 5/7] KVM: SVM: extract RESTORE_*_SPEC_CTRL_BODY out of svm/vmenter.S Paolo Bonzini
2026-04-08 18:22 ` [PATCH 6/7] KVM: VMX: switch to RESTORE_GUEST_SPEC_CTRL_BODY Paolo Bonzini
2026-04-08 18:22 ` [PATCH 7/7] KVM: VMX: replace vmx_spec_ctrl_restore_host with RESTORE_HOST_SPEC_CTRL_BODY Paolo Bonzini
2026-04-08 21:48   ` Paolo Bonzini
2026-04-09 17:36   ` Uros Bizjak [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57796f12-53f7-426b-be4c-abf0b2ce2061@gmail.com \
    --to=ubizjak@gmail.com \
    --cc=chang.seok.bae@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox