[PATCH v3 00/15] KVM: x86: Add "governed" X86_FEATURE framework

Sean Christopherson posted 15 patches 2 years ago
arch/x86/include/asm/kvm_host.h  | 20 ++++++++-
arch/x86/include/asm/vmx.h       |  2 +-
arch/x86/kvm/cpuid.c             | 34 ++++++++++++++++
arch/x86/kvm/cpuid.h             | 46 +++++++++++++++++++++
arch/x86/kvm/governed_features.h | 21 ++++++++++
arch/x86/kvm/mmu/mmu.c           | 20 ++-------
arch/x86/kvm/svm/nested.c        | 46 ++++++++++++---------
arch/x86/kvm/svm/svm.c           | 59 +++++++++++++++------------
arch/x86/kvm/svm/svm.h           | 16 ++------
arch/x86/kvm/vmx/capabilities.h  |  2 +-
arch/x86/kvm/vmx/hyperv.c        |  2 +-
arch/x86/kvm/vmx/nested.c        | 13 +++---
arch/x86/kvm/vmx/nested.h        |  2 +-
arch/x86/kvm/vmx/vmx.c           | 69 ++++++++++++++------------------
arch/x86/kvm/vmx/vmx.h           |  3 +-
arch/x86/kvm/x86.c               |  4 +-
16 files changed, 232 insertions(+), 127 deletions(-)
create mode 100644 arch/x86/kvm/governed_features.h
[PATCH v3 00/15] KVM: x86: Add "governed" X86_FEATURE framework
Posted by Sean Christopherson 2 years ago
Third and hopefully final version of the framework to manage and cache
KVM-governed features, i.e. CPUID based features that require explicit
KVM enabling and/or need to be queried semi-frequently by KVM.

This version is just the governed features patches, as I kept the TSC
scaling patches in kvm-x86/misc but blasted away the goverend features
with a forced push.

My plan is again to apply this quite quickly so that it can be used as
a base for other series.

v3:
 - "Drop" TSC scaling patches (already applied).
 - Remove dead xsave_enabled code (snuck into v2 by a bad conflict
   resolution). [Zeng]
 - Make kvm_is_governed_feature() return a bool. [Zeng]
 - Collect a review. [Yuan]

v2:
 - https://lore.kernel.org/all/20230729011608.1065019-1-seanjc@google.com
 - Add patches to clean up TSC scaling.
 - Add a comment explaining the virtual VMLOAD/VMLAVE vs. SYSENTER on
   Intel madness.
 - Use a governed feature for X86_FEATURE_VMX.
 - Incorporate KVM capabilities into the main check-and-set helper. [Chao]

v1: https://lore.kernel.org/all/20230217231022.816138-1-seanjc@google.com

Sean Christopherson (15):
  KVM: x86: Add a framework for enabling KVM-governed x86 features
  KVM: x86/mmu: Use KVM-governed feature framework to track "GBPAGES
    enabled"
  KVM: VMX: Recompute "XSAVES enabled" only after CPUID update
  KVM: VMX: Check KVM CPU caps, not just VMX MSR support, for XSAVE
    enabling
  KVM: VMX: Rename XSAVES control to follow KVM's preferred "ENABLE_XYZ"
  KVM: x86: Use KVM-governed feature framework to track "XSAVES enabled"
  KVM: nVMX: Use KVM-governed feature framework to track "nested VMX
    enabled"
  KVM: nSVM: Use KVM-governed feature framework to track "NRIPS enabled"
  KVM: nSVM: Use KVM-governed feature framework to track "TSC scaling
    enabled"
  KVM: nSVM: Use KVM-governed feature framework to track "vVM{SAVE,LOAD}
    enabled"
  KVM: nSVM: Use KVM-governed feature framework to track "LBRv enabled"
  KVM: nSVM: Use KVM-governed feature framework to track "Pause Filter
    enabled"
  KVM: nSVM: Use KVM-governed feature framework to track "vGIF enabled"
  KVM: nSVM: Use KVM-governed feature framework to track "vNMI enabled"
  KVM: x86: Disallow guest CPUID lookups when IRQs are disabled

 arch/x86/include/asm/kvm_host.h  | 20 ++++++++-
 arch/x86/include/asm/vmx.h       |  2 +-
 arch/x86/kvm/cpuid.c             | 34 ++++++++++++++++
 arch/x86/kvm/cpuid.h             | 46 +++++++++++++++++++++
 arch/x86/kvm/governed_features.h | 21 ++++++++++
 arch/x86/kvm/mmu/mmu.c           | 20 ++-------
 arch/x86/kvm/svm/nested.c        | 46 ++++++++++++---------
 arch/x86/kvm/svm/svm.c           | 59 +++++++++++++++------------
 arch/x86/kvm/svm/svm.h           | 16 ++------
 arch/x86/kvm/vmx/capabilities.h  |  2 +-
 arch/x86/kvm/vmx/hyperv.c        |  2 +-
 arch/x86/kvm/vmx/nested.c        | 13 +++---
 arch/x86/kvm/vmx/nested.h        |  2 +-
 arch/x86/kvm/vmx/vmx.c           | 69 ++++++++++++++------------------
 arch/x86/kvm/vmx/vmx.h           |  3 +-
 arch/x86/kvm/x86.c               |  4 +-
 16 files changed, 232 insertions(+), 127 deletions(-)
 create mode 100644 arch/x86/kvm/governed_features.h


base-commit: aaf44a3a699309c77537d0abf49411f9dc7dc523
-- 
2.41.0.694.ge786442a9b-goog
Re: [PATCH v3 00/15] KVM: x86: Add "governed" X86_FEATURE framework
Posted by Sean Christopherson 2 years ago
On Tue, 15 Aug 2023 13:36:38 -0700, Sean Christopherson wrote:
> Third and hopefully final version of the framework to manage and cache
> KVM-governed features, i.e. CPUID based features that require explicit
> KVM enabling and/or need to be queried semi-frequently by KVM.
> 
> This version is just the governed features patches, as I kept the TSC
> scaling patches in kvm-x86/misc but blasted away the goverend features
> with a forced push.
> 
> [...]

Applied to kvm-x86 misc, with a blurb added to the nVMX changelog to explain
how "nested" is factored in.

[01/15] KVM: x86: Add a framework for enabling KVM-governed x86 features
        https://github.com/kvm-x86/linux/commit/42764413d195
[02/15] KVM: x86/mmu: Use KVM-governed feature framework to track "GBPAGES enabled"
        https://github.com/kvm-x86/linux/commit/ccf31d6e6cc5
[03/15] KVM: VMX: Recompute "XSAVES enabled" only after CPUID update
        https://github.com/kvm-x86/linux/commit/1143c0b85c07
[04/15] KVM: VMX: Check KVM CPU caps, not just VMX MSR support, for XSAVE enabling
        https://github.com/kvm-x86/linux/commit/0497d2ac9b26
[05/15] KVM: VMX: Rename XSAVES control to follow KVM's preferred "ENABLE_XYZ"
        https://github.com/kvm-x86/linux/commit/662f6815786e
[06/15] KVM: x86: Use KVM-governed feature framework to track "XSAVES enabled"
        https://github.com/kvm-x86/linux/commit/fe60e8f65f79
[07/15] KVM: nVMX: Use KVM-governed feature framework to track "nested VMX enabled"
        https://github.com/kvm-x86/linux/commit/1c18efdaa314
[08/15] KVM: nSVM: Use KVM-governed feature framework to track "NRIPS enabled"
        https://github.com/kvm-x86/linux/commit/7a6a6a3bf5d8
[09/15] KVM: nSVM: Use KVM-governed feature framework to track "TSC scaling enabled"
        https://github.com/kvm-x86/linux/commit/4365a45571c7
[10/15] KVM: nSVM: Use KVM-governed feature framework to track "vVM{SAVE,LOAD} enabled"
        https://github.com/kvm-x86/linux/commit/4d2a1560ffc2
[11/15] KVM: nSVM: Use KVM-governed feature framework to track "LBRv enabled"
        https://github.com/kvm-x86/linux/commit/e183d17ac362
[12/15] KVM: nSVM: Use KVM-governed feature framework to track "Pause Filter enabled"
        https://github.com/kvm-x86/linux/commit/59d67fc1f0db
[13/15] KVM: nSVM: Use KVM-governed feature framework to track "vGIF enabled"
        https://github.com/kvm-x86/linux/commit/b89456aee78d
[14/15] KVM: nSVM: Use KVM-governed feature framework to track "vNMI enabled"
        https://github.com/kvm-x86/linux/commit/ee785c870d6f
[15/15] KVM: x86: Disallow guest CPUID lookups when IRQs are disabled
        https://github.com/kvm-x86/linux/commit/9717efbe5ba3

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes