[PATCH v3 0/6] KVM: VMX: Handle the immediate form of MSR instructions

Sean Christopherson posted 6 patches 2 months ago
arch/x86/include/asm/cpufeatures.h |  1 +
arch/x86/include/asm/kvm_host.h    |  4 ++
arch/x86/include/uapi/asm/vmx.h    |  6 +-
arch/x86/kernel/cpu/scattered.c    |  1 +
arch/x86/kvm/cpuid.c               |  6 +-
arch/x86/kvm/reverse_cpuid.h       |  5 ++
arch/x86/kvm/svm/svm.c             |  8 ++-
arch/x86/kvm/vmx/nested.c          | 13 ++++-
arch/x86/kvm/vmx/vmx.c             | 26 ++++++++-
arch/x86/kvm/vmx/vmx.h             |  5 ++
arch/x86/kvm/x86.c                 | 94 ++++++++++++++++++++++--------
arch/x86/kvm/x86.h                 |  3 +-
12 files changed, 139 insertions(+), 33 deletions(-)
[PATCH v3 0/6] KVM: VMX: Handle the immediate form of MSR instructions
Posted by Sean Christopherson 2 months ago
On behalf of Xin, to avoid having to resolve conflicts when applying.
This applies on the fastpath cleanup series:
https://lore.kernel.org/all/20250805190526.1453366-1-seanjc@google.com

This patch set handles two newly introduced VM exit reasons associated
with the immediate form of MSR instructions to ensure proper
virtualization of these instructions.

The immediate form of MSR access instructions are primarily motivated
by performance, not code size: by having the MSR number in an immediate,
it is available *much* earlier in the pipeline, which allows the
hardware much more leeway about how a particular MSR is handled.

For proper virtualization of the immediate form of MSR instructions,
Intel VMX architecture adds the following changes:

  1) The immediate form of RDMSR uses VM exit reason 84.

  2) The immediate form of WRMSRNS uses VM exit reason 85.

  3) For both VM exit reasons 84 and 85, the exit qualification is set
     to the MSR address causing the VM exit.

  4) Bits 3 ~ 6 of the VM exit instruction information field represent
     the operand register used in the immediate form of MSR instruction.

  5) The VM-exit instruction length field records the size of the
     immediate form of the MSR instruction.

Note: The VMX specification for the immediate form of MSR instructions
was inadvertently omitted from the last published ISE, but it will be
included in the upcoming edition.

Linux bare metal support of the immediate form of MSR instructions is
still under development; however, the KVM support effort is proceeding
independently of the bare metal implementation.

v3:
 - Rebase on the fastpath cleanups.
 - Split patches to better isolate the functional changes.
 - Massage and expand on a changelogs.
 - Make a handful of (mostly) stylistic changes (shouldn't affect
   functionality, key word "should").

v2: https://lore.kernel.org/all/20250802001520.3142577-1-xin@zytor.com
v1: https://lore.kernel.org/lkml/20250730174605.1614792-1-xin@zytor.com

Sean Christopherson (1):
  KVM: x86: Rename local "ecx" variables to "msr" and "pmc" as
    appropriate

Xin Li (5):
  x86/cpufeatures: Add a CPU feature bit for MSR immediate form
    instructions
  KVM: x86: Rename handle_fastpath_set_msr_irqoff() to
    handle_fastpath_wrmsr()
  KVM: x86: Add support for RDMSR/WRMSRNS w/ immediate on Intel
  KVM: VMX: Support the immediate form of WRMSRNS in the VM-Exit
    fastpath
  KVM: x86: Advertise support for the immediate form of MSR instructions

 arch/x86/include/asm/cpufeatures.h |  1 +
 arch/x86/include/asm/kvm_host.h    |  4 ++
 arch/x86/include/uapi/asm/vmx.h    |  6 +-
 arch/x86/kernel/cpu/scattered.c    |  1 +
 arch/x86/kvm/cpuid.c               |  6 +-
 arch/x86/kvm/reverse_cpuid.h       |  5 ++
 arch/x86/kvm/svm/svm.c             |  8 ++-
 arch/x86/kvm/vmx/nested.c          | 13 ++++-
 arch/x86/kvm/vmx/vmx.c             | 26 ++++++++-
 arch/x86/kvm/vmx/vmx.h             |  5 ++
 arch/x86/kvm/x86.c                 | 94 ++++++++++++++++++++++--------
 arch/x86/kvm/x86.h                 |  3 +-
 12 files changed, 139 insertions(+), 33 deletions(-)


base-commit: 53d61a43a7973f812caa08fa922b607574befef4
-- 
2.50.1.565.gc32cd1483b-goog
Re: [PATCH v3 0/6] KVM: VMX: Handle the immediate form of MSR instructions
Posted by Sean Christopherson 1 month, 2 weeks ago
On Tue, 05 Aug 2025 13:22:18 -0700, Sean Christopherson wrote:
> On behalf of Xin, to avoid having to resolve conflicts when applying.
> This applies on the fastpath cleanup series:
> https://lore.kernel.org/all/20250805190526.1453366-1-seanjc@google.com
> 
> This patch set handles two newly introduced VM exit reasons associated
> with the immediate form of MSR instructions to ensure proper
> virtualization of these instructions.
> 
> [...]

Applied to kvm-x86 misc, thanks!

[1/6] x86/cpufeatures: Add a CPU feature bit for MSR immediate form instructions
      https://github.com/kvm-x86/linux/commit/3c7cb8414533
[2/6] KVM: x86: Rename local "ecx" variables to "msr" and "pmc" as appropriate
      https://github.com/kvm-x86/linux/commit/ec400f6c2f27
[3/6] KVM: x86: Rename handle_fastpath_set_msr_irqoff() to handle_fastpath_wrmsr()
      https://github.com/kvm-x86/linux/commit/87a877de367d
[4/6] KVM: x86: Add support for RDMSR/WRMSRNS w/ immediate on Intel
      https://github.com/kvm-x86/linux/commit/885df2d2109a
[5/6] KVM: VMX: Support the immediate form of WRMSRNS in the VM-Exit fastpath
      https://github.com/kvm-x86/linux/commit/ec93675a3251
[6/6] KVM: x86: Advertise support for the immediate form of MSR instructions
      https://github.com/kvm-x86/linux/commit/d90ebf5a06ec

--
https://github.com/kvm-x86/linux/tree/next
Re: [PATCH v3 0/6] KVM: VMX: Handle the immediate form of MSR instructions
Posted by Xin Li 1 month, 4 weeks ago
On 8/5/2025 1:22 PM, Sean Christopherson wrote:
> On behalf of Xin, to avoid having to resolve conflicts when applying.
> This applies on the fastpath cleanup series:
> https://lore.kernel.org/all/20250805190526.1453366-1-seanjc@google.com
>

Thanks for being considerate, and this is a much better use of time :)
> v3:
>   - Rebase on the fastpath cleanups.
>   - Split patches to better isolate the functional changes.
>   - Massage and expand on a changelogs.
>   - Make a handful of (mostly) stylistic changes (shouldn't affect
>     functionality, key word "should").

Tested after applying both patch sets, it works well.