From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Binbin Wu <binbin.wu@linux.intel.com>,
Uros Bizjak <ubizjak@gmail.com>,
"Chang S. Bae" <chang.seok.bae@intel.com>,
Sean Christopherson <seanjc@google.com>
Subject: [PATCH v3 0/8] KVM: VMX/SVM: use the same SPEC_CTRL assembly code
Date: Tue, 28 Apr 2026 07:04:59 -0400 [thread overview]
Message-ID: <20260428110507.11248-1-pbonzini@redhat.com> (raw)
As discussed in the APX thread, this series moves the SPEC_CTRL
handling for VMX entirely to vmenter.S, and while at it improves
the code reuse between SVM and VMX.
The prototype of __vmx_vcpu_run() and __svm_vcpu_run() becomes
the same, with a set of bit flags for the second argument (which
can be augmented with an extra bit for whether to save/restore APX).
The register allocation also becomes very similar, with %edi/%rdi
pointing to the vmx (resp. svm) argument (patches 1-4).
Thanks to this, the code to restore the guest SPEC_CTRL value is the
same up to the register names and can be dropped into vmx/vmenter.S.
On the vmexit side the only change required is support for
X86_FEATURE_KERNEL_IBRS, which is a single ALTERNATIVE macro.
This also introduces vmenter.h, which hosts common code between
vmx/vmenter.S and svm/vmenter.S, and which will be augmented
further by the APX enablement series.
Paolo
v2->v3:
- add extra patch so that it actually works [Chang S. Bae]
- fix incorrect reference to KVM_ENTER_RUN_* in comments
- preserve LFENCE in the eIBRS case [sashiko]
v1->v2:
- fix "Reload @vmx to RAX" comment [Binbin]
- fix polarity of KVM_ENTER_SAVE_SPEC_CTRL in SVM, which would
have caused problems when the macros are reused for VMX
- adjust prototypes of __svm_vcpu_run and __svm_sev_es_vcpu_run
- fix order of ALTERNATIVE arguments for X86_FEATURE_KERNEL_IBRS.
Add comment
- Leave @flags and @vmx on the stack during RESTORE_HOST_SPEC_CTRL_BODY.
[Uros, Binbin]
Paolo Bonzini (8):
KVM: VMX: remove regs argument of __vmx_vcpu_run
KVM: VMX: more cleanups to __vmx_vcpu_run
KVM: SVM: prepare for making SPEC_CTRL switch common with VMX
KVM: SVM: pass struct vcpu_svm to msr_write_intercepted
KVM: SVM: adopt the same VMX_RUN_* flags as VMX
KVM: SVM: extract RESTORE_*_SPEC_CTRL_BODY out of svm/vmenter.S
KVM: VMX: switch to RESTORE_GUEST_SPEC_CTRL_BODY
KVM: VMX: replace vmx_spec_ctrl_restore_host with
RESTORE_HOST_SPEC_CTRL_BODY
arch/x86/kvm/kvm-asm-offsets.c | 1 +
arch/x86/kvm/svm/svm.c | 23 +++--
arch/x86/kvm/svm/svm.h | 4 +-
arch/x86/kvm/svm/vmenter.S | 103 +++++-------------
arch/x86/kvm/vmenter.h | 80 ++++++++++++++
arch/x86/kvm/vmx/run_flags.h | 9 --
arch/x86/kvm/vmx/vmenter.S | 184 +++++++++++++++------------------
arch/x86/kvm/vmx/vmx.c | 39 ++-----
arch/x86/kvm/vmx/vmx.h | 7 +-
9 files changed, 212 insertions(+), 238 deletions(-)
create mode 100644 arch/x86/kvm/vmenter.h
delete mode 100644 arch/x86/kvm/vmx/run_flags.h
--
2.52.0
next reply other threads:[~2026-04-28 11:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 11:04 Paolo Bonzini [this message]
2026-04-28 11:05 ` [PATCH 1/8] KVM: VMX: remove regs argument of __vmx_vcpu_run Paolo Bonzini
2026-04-28 11:05 ` [PATCH 2/8] KVM: VMX: more cleanups to __vmx_vcpu_run Paolo Bonzini
2026-04-28 11:05 ` [PATCH 3/8] KVM: SVM: prepare for making SPEC_CTRL switch common with VMX Paolo Bonzini
2026-04-28 11:05 ` [PATCH 4/8] KVM: SVM: pass struct vcpu_svm to msr_write_intercepted Paolo Bonzini
2026-04-28 11:05 ` [PATCH 5/8] KVM: SVM: adopt the same VMX_RUN_* flags as VMX Paolo Bonzini
2026-04-28 11:05 ` [PATCH 6/8] KVM: SVM: extract RESTORE_*_SPEC_CTRL_BODY out of svm/vmenter.S Paolo Bonzini
2026-04-28 11:05 ` [PATCH 7/8] KVM: VMX: switch to RESTORE_GUEST_SPEC_CTRL_BODY Paolo Bonzini
2026-04-28 11:05 ` [PATCH 8/8] KVM: VMX: replace vmx_spec_ctrl_restore_host with RESTORE_HOST_SPEC_CTRL_BODY Paolo Bonzini
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=20260428110507.11248-1-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=binbin.wu@linux.intel.com \
--cc=chang.seok.bae@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=ubizjak@gmail.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