Skip to content

KVM: x86: Purge kvm_x86_ops->*_supported()

Sean Christopherson kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest26 patches 14 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/26KVM: x86: Remove superfluous brackets from case statementarch/x86/kvm/x86.c+2 -22 replies
2/26KVM: x86: Take an unsigned 32-bit int for has_emulated_msr()'s indexarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c+3 -31 reply
3/26KVM: x86: Snapshot MSR index in a local variable when processing listsarch/x86/kvm/x86.c+13 -91 reply
4/26KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR supportarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c +1 more+15 -07 replies
5/26KVM: x86: Move MSR_TSC_AUX existence checks into vendor codearch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+14 -41 reply
6/26KVM: x86: Move MSR_IA32_BNDCFGS existence checks into vendor codearch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+4 -41 reply
7/26KVM: VMX: Add helpers to query Intel PT modearch/x86/kvm/vmx/capabilities.h arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c +1 more+34 -160 replies
8/26KVM: x86: Move RTIT (Intel PT) MSR existence checks into vendor codearch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+22 -230 replies
9/26KVM: x86: Calculate the supported xcr0 mask at load timearch/x86/kvm/cpuid.c arch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c +2 more+20 -220 replies
10/26KVM: x86: Use supported_xcr0 to detect MPX supportarch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/svm.c +2 more+4 -120 replies
11/26KVM: x86: Make kvm_mpx_supported() an inline functionarch/x86/kvm/cpuid.c arch/x86/kvm/cpuid.h arch/x86/kvm/x86.h+5 -70 replies
12/26KVM: x86: Drop explicit @func param from ->set_supported_cpuid()arch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/svm.c +1 more+6 -60 replies
13/26KVM: x86: Use u32 for holding CPUID register value in helpersarch/x86/kvm/cpuid.h+3 -30 replies
14/26KVM: x86: Introduce cpuid_entry_{get,has}() accessorsarch/x86/kvm/cpuid.c arch/x86/kvm/cpuid.h+42 -130 replies
15/26KVM: x86: Introduce cpuid_entry_{change,set,clear}() mutatorsarch/x86/kvm/cpuid.c arch/x86/kvm/cpuid.h arch/x86/kvm/svm.c+62 -420 replies
16/26KVM: x86: Add Kconfig-controlled auditing of reverse CPUID lookupsarch/x86/kvm/Kconfig arch/x86/kvm/cpuid.h+15 -00 replies
17/26KVM: x86: Handle MPX CPUID adjustment in vendor codearch/x86/kvm/cpuid.c arch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c+16 -40 replies
18/26KVM: x86: Handle INVPCID CPUID adjustment in vendor codearch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/svm.c +1 more+5 -160 replies
19/26KVM: x86: Handle UMIP emulation CPUID adjustment in VMX codearch/x86/kvm/cpuid.c arch/x86/kvm/vmx/vmx.c+3 -20 replies
20/26KVM: x86: Handle PKU CPUID adjustment in SVM codearch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/svm.c +2 more+2 -160 replies
21/26KVM: x86: Handle RDTSCP CPUID adjustment in VMX codearch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/svm.c +1 more+5 -110 replies
22/26KVM: x86: Handle XSAVES CPUID adjustment in VMX codearch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/svm.c +1 more+15 -100 replies
23/26KVM: x86: Handle Intel PT CPUID adjustment in vendor codearch/x86/kvm/cpuid.c arch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c+4 -20 replies
24/26KVM: x86: Clear output regs for CPUID 0x14 if PT isn't exposed to guestarch/x86/kvm/cpuid.c+3 -10 replies
25/26KVM: x86: Handle main Intel PT CPUID leaf in vendor codearch/x86/kvm/cpuid.c arch/x86/kvm/svm.c arch/x86/kvm/vmx/vmx.c+23 -161 reply
26/26KVM: VMX: Directly query Intel PT mode when refreshing PMUsarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm.c arch/x86/kvm/vmx/pmu_intel.c +2 more+4 -180 replies

Reviews trailers per patch

6 of 26 patches have a Reviewed-by or Acked-by.

PatchVitaly Kuznetsov
1/26R-b
2/26R-b
3/26R-b
4/26R-b
5/26R-b
6/26R-b
7/26
8/26
9/26
10/26
11/26
12/26
13/26
14/26
15/26
16/26
17/26
18/26
19/26
20/26
21/26
22/26
23/26
24/26
25/26
26/26

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 00/26] KVM: x86: Purge kvm_x86_ops->*_supported()

Our benevolent dictator decreed that "all *_supported() should be removed, and the code moved from __do_cpuid_func() to set_supported_cpuid"[*].

To make that happen, move CPUID and MSR checks from x86 into SVM/VMX via the existing ->set_supported_cpuid() and a ->new has_virtualized_msr() ops respectively.

As usual, there's a fair amount of cleanup in between the mechanical changes. Most notable is the introduction of cpuid entry accessors and mutators to replace all of the code to manipulate individual feature bits in cpuid entries, which is error prone and annoying. MPX (*sigh*) also gets a healthly dose of cleanup.

I don't love every patch in this series. Specifically, adding an extra call to ->set_supported_cpuid() to handle XSAVES is ugly. But, I do like that it purges all ->*_supported() hooks. And practically speaking, odds are good that CPUID 0xD.1 will get more feature bits, i.e. keeping ->xsaves_supported() would likely lead to another ->*_supported() hook.

Paolo also expressed a dislike for clearing bits in set_supported_cpuid(). I don't have a strong opinion regarding clearing bits, but the alternative approach, i.e. leave the bits clear and then set them in vendor code, gets quite kludgy because the vendor code (mostly VMX) would need to manually recheck boot_cpu_data to ensure it wasn't advertising a feature that the user/kernel expressly disabled. IMO, forcing manual checks is more likely to introduce errors and provides less insight into why VMX needs to adjust the advertised CPUID values (VMCS != CPUID).

Tested on Intel by verifying the output of KVM_GET_SUPPORTED_CPUID is identical before and after (on almost every patch) on a Haswell and Coffee Lake. The big untested pieces are PKU and PT on Intel, and everything AMD.

[*] https://lkml.kernel.org/r/[email protected]

Sean Christopherson (26):
KVM: x86: Remove superfluous brackets from case statement
KVM: x86: Take an unsigned 32-bit int for has_emulated_msr()'s index
KVM: x86: Snapshot MSR index in a local variable when processing lists
KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
KVM: x86: Move MSR_TSC_AUX existence checks into vendor code
KVM: x86: Move MSR_IA32_BNDCFGS existence checks into vendor code
KVM: VMX: Add helpers to query Intel PT mode
KVM: x86: Move RTIT (Intel PT) MSR existence checks into vendor code
KVM: x86: Calculate the supported xcr0 mask at load time
KVM: x86: Use supported_xcr0 to detect MPX support
KVM: x86: Make kvm_mpx_supported() an inline function
KVM: x86: Drop explicit @func param from ->set_supported_cpuid()
KVM: x86: Use u32 for holding CPUID register value in helpers
KVM: x86: Introduce cpuid_entry_{get,has}() accessors
KVM: x86: Introduce cpuid_entry_{change,set,clear}() mutators
KVM: x86: Add Kconfig-controlled auditing of reverse CPUID lookups
KVM: x86: Handle MPX CPUID adjustment in vendor code
KVM: x86: Handle INVPCID CPUID adjustment in vendor code
KVM: x86: Handle UMIP emulation CPUID adjustment in VMX code
KVM: x86: Handle PKU CPUID adjustment in SVM code
KVM: x86: Handle RDTSCP CPUID adjustment in VMX code
KVM: x86: Handle XSAVES CPUID adjustment in VMX code
KVM: x86: Handle Intel PT CPUID adjustment in vendor code
KVM: x86: Clear output regs for CPUID 0x14 if PT isn't exposed to
guest
KVM: x86: Handle main Intel PT CPUID leaf in vendor code
KVM: VMX: Directly query Intel PT mode when refreshing PMUs

 arch/x86/include/asm/kvm_host.h |  12 +--
 arch/x86/kvm/Kconfig            |  10 +++
 arch/x86/kvm/cpuid.c            | 147 +++++++++++++-------------------
 arch/x86/kvm/cpuid.h            |  85 +++++++++++++++---
 arch/x86/kvm/svm.c              |  88 ++++++++++---------
 arch/x86/kvm/vmx/capabilities.h |  25 ++++--
 arch/x86/kvm/vmx/nested.c       |   2 +-
 arch/x86/kvm/vmx/pmu_intel.c    |   2 +-
 arch/x86/kvm/vmx/vmx.c          | 119 ++++++++++++++++++--------
 arch/x86/kvm/vmx/vmx.h          |   4 +-
 arch/x86/kvm/x86.c              |  76 +++++++----------
 arch/x86/kvm/x86.h              |  10 +--
 12 files changed, 331 insertions(+), 249 deletions(-)
Signature · 1 line
2.24.1