public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/12] x86/msr: Inline rdmsr/wrmsr instructions
@ 2025-09-30  7:03 Juergen Gross
  2025-09-30  7:03 ` [PATCH v2 01/12] coco/tdx: Rename MSR access helpers Juergen Gross
                   ` (12 more replies)
  0 siblings, 13 replies; 43+ messages in thread
From: Juergen Gross @ 2025-09-30  7:03 UTC (permalink / raw)
  To: linux-kernel, x86, linux-coco, kvm, linux-hyperv, virtualization,
	llvm
  Cc: xin, Juergen Gross, Kirill A. Shutemov, Dave Hansen,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	Sean Christopherson, Paolo Bonzini, K. Y. Srinivasan,
	Haiyang Zhang, Wei Liu, Dexuan Cui, Vitaly Kuznetsov,
	Boris Ostrovsky, xen-devel, Ajay Kaher, Alexey Makhalov,
	Broadcom internal kernel review list, Andy Lutomirski,
	Peter Zijlstra, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt

When building a kernel with CONFIG_PARAVIRT_XXL the paravirt
infrastructure will always use functions for reading or writing MSRs,
even when running on bare metal.

Switch to inline RDMSR/WRMSR instructions in this case, reducing the
paravirt overhead.

In order to make this less intrusive, some further reorganization of
the MSR access helpers is done in the first 5 patches.

The next 5 patches are converting the non-paravirt case to use direct
inlining of the MSR access instructions, including the WRMSRNS
instruction and the immediate variants of RDMSR and WRMSR if possible.

Patch 11 removes the PV hooks for MSR accesses and implements the
Xen PV cases via calls depending on X86_FEATURE_XENPV, which results
in runtime patching those calls away for the non-XenPV case.

Patch 12 is a final little cleanup patch.

This series has been tested to work with Xen PV and on bare metal.

This series is inspired by Xin Li, who used a similar approach, but
(in my opinion) with some flaws. Originally I thought it should be
possible to use the paravirt infrastructure, but this turned out to be
rather complicated, especially for the Xen PV case in the *_safe()
variants of the MSR access functions.

Changes since V1:
- Use Xin Li's approach for inlining
- Several new patches

Juergen Gross (9):
  coco/tdx: Rename MSR access helpers
  x86/sev: replace call of native_wrmsr() with native_wrmsrq()
  x86/kvm: Remove the KVM private read_msr() function
  x86/msr: minimize usage of native_*() msr access functions
  x86/msr: Move MSR trace calls one function level up
  x86/msr: Use the alternatives mechanism for WRMSR
  x86/msr: Use the alternatives mechanism for RDMSR
  x86/paravirt: Don't use pv_ops vector for MSR access functions
  x86/msr: Reduce number of low level MSR access helpers

Xin Li (Intel) (3):
  x86/cpufeatures: Add a CPU feature bit for MSR immediate form
    instructions
  x86/opcode: Add immediate form MSR instructions
  x86/extable: Add support for immediate form MSR instructions

 arch/x86/coco/tdx/tdx.c               |   8 +-
 arch/x86/hyperv/ivm.c                 |   2 +-
 arch/x86/include/asm/cpufeatures.h    |   1 +
 arch/x86/include/asm/fred.h           |   2 +-
 arch/x86/include/asm/kvm_host.h       |  10 -
 arch/x86/include/asm/msr.h            | 409 +++++++++++++++++++-------
 arch/x86/include/asm/paravirt.h       |  67 -----
 arch/x86/include/asm/paravirt_types.h |  13 -
 arch/x86/include/asm/sev-internal.h   |   7 +-
 arch/x86/kernel/cpu/scattered.c       |   1 +
 arch/x86/kernel/kvmclock.c            |   2 +-
 arch/x86/kernel/paravirt.c            |   5 -
 arch/x86/kvm/svm/svm.c                |  16 +-
 arch/x86/kvm/vmx/vmx.c                |   4 +-
 arch/x86/lib/x86-opcode-map.txt       |   5 +-
 arch/x86/mm/extable.c                 |  39 ++-
 arch/x86/xen/enlighten_pv.c           |  24 +-
 arch/x86/xen/pmu.c                    |   5 +-
 tools/arch/x86/lib/x86-opcode-map.txt |   5 +-
 19 files changed, 383 insertions(+), 242 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2025-10-07  6:08 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-30  7:03 [PATCH v2 00/12] x86/msr: Inline rdmsr/wrmsr instructions Juergen Gross
2025-09-30  7:03 ` [PATCH v2 01/12] coco/tdx: Rename MSR access helpers Juergen Gross
2025-09-30  9:07   ` Kiryl Shutsemau
2025-09-30  7:03 ` [PATCH v2 02/12] x86/sev: Replace call of native_wrmsr() with native_wrmsrq() Juergen Gross
2025-10-07  6:08   ` Nikunj A Dadhania
2025-09-30  7:03 ` [PATCH v2 03/12] x86/kvm: Remove the KVM private read_msr() function Juergen Gross
2025-09-30 16:04   ` Sean Christopherson
2025-10-01  9:14     ` Jürgen Groß
2025-09-30  7:03 ` [PATCH v2 04/12] x86/msr: Minimize usage of native_*() msr access functions Juergen Gross
2025-09-30  7:03 ` [PATCH v2 05/12] x86/msr: Move MSR trace calls one function level up Juergen Gross
2025-09-30  7:03 ` [PATCH v2 06/12] x86/cpufeatures: Add a CPU feature bit for MSR immediate form instructions Juergen Gross
2025-09-30  7:03 ` [PATCH v2 07/12] x86/opcode: Add immediate form MSR instructions Juergen Gross
2025-09-30  7:03 ` [PATCH v2 08/12] x86/extable: Add support for " Juergen Gross
2025-09-30  8:14   ` Peter Zijlstra
2025-09-30  8:31     ` Jürgen Groß
2025-09-30  7:03 ` [PATCH v2 09/12] x86/msr: Use the alternatives mechanism for WRMSR Juergen Gross
2025-09-30  8:31   ` Peter Zijlstra
2025-09-30  8:46     ` Jürgen Groß
2025-09-30  8:50       ` Peter Zijlstra
2025-09-30 12:51         ` Peter Zijlstra
2025-09-30 15:42           ` Jürgen Groß
2025-10-01  6:43             ` Peter Zijlstra
2025-10-01  7:23               ` Peter Zijlstra
2025-10-03 14:23                 ` Dave Hansen
2025-10-03 16:53                   ` H. Peter Anvin
2025-10-01  8:49       ` Juergen Gross
2025-10-01 10:50         ` Peter Zijlstra
2025-10-01 11:16           ` Jürgen Groß
2025-09-30 16:00   ` Sean Christopherson
2025-10-01  9:13     ` Jürgen Groß
2025-09-30  7:03 ` [PATCH v2 10/12] x86/msr: Use the alternatives mechanism for RDMSR Juergen Gross
2025-09-30  7:03 ` [PATCH v2 11/12] x86/paravirt: Don't use pv_ops vector for MSR access functions Juergen Gross
2025-09-30  8:38   ` Peter Zijlstra
2025-09-30  9:02     ` Jürgen Groß
2025-09-30 10:04       ` Peter Zijlstra
2025-09-30 10:43         ` Jürgen Groß
2025-09-30 19:49           ` H. Peter Anvin
2025-09-30 19:59             ` H. Peter Anvin
2025-10-01  6:45             ` Peter Zijlstra
2025-09-30 21:27   ` kernel test robot
2025-10-01  5:48     ` Jürgen Groß
2025-09-30  7:03 ` [PATCH v2 12/12] x86/msr: Reduce number of low level MSR access helpers Juergen Gross
2025-09-30 19:19 ` [PATCH v2 00/12] x86/msr: Inline rdmsr/wrmsr instructions H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox