Skip to content

KVM: nVMX: VMX MSR quirk+fixes, CR4 fixes

Sean Christopherson kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v5 Latest15 patches 15 repliesIn review

Changes in v5 from the cover letter

- Rebase (see above).
- Fix "CR4 valid for nVMX" bugs.
- Modify PERF_GLOBAL_CTRL bits iff the MSR exists.
- Fix a bug where KVM doesn't allow userspace to restore VMX MSRs to _KVM's_ allowed values.
- Fix the UMIP emulation goof.
- Extend the quirk to CR0/4_FIXED1 MSRs.
- Add a helper to identify if the vCPU has a vPMU.
- Rewrote the selftests to more exhaustively test combos, and to test the aforementioned bugs fixed in v5.

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15KVM: x86: Split kvm_is_valid_cr4() and export only the non-vendor bitsarch/x86/kvm/svm/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c +1 more+14 -70 replies
2/15KVM: nVMX: Account for KVM reserved CR4 bits in consistency checksarch/x86/kvm/vmx/nested.h+2 -10 replies
3/15KVM: nVMX: Inject #UD if VMXON is attempted with incompatible CR0/CR4arch/x86/kvm/vmx/nested.c+14 -90 replies
4/15KVM: nVMX: Rename handle_vm{on,off}() to handle_vmx{on,off}()arch/x86/kvm/vmx/nested.c+4 -40 replies
5/15KVM: nVMX: Let userspace set nVMX MSR to any _host_ supported valuearch/x86/kvm/vmx/nested.c+52 -4812 replies
6/15KVM: nVMX: Keep KVM updates to BNDCFGS ctrl bits across MSR writearch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+12 -11 reply
7/15KVM: VMX: Add helper to check if the guest PMU has PERF_GLOBAL_CTRLarch/x86/kvm/vmx/pmu_intel.c arch/x86/kvm/vmx/vmx.h+14 -20 replies
8/15KVM: nVMX: Keep KVM updates to PERF_GLOBAL_CTRL ctrl bits across MSR writearch/x86/kvm/vmx/vmx.c+14 -00 replies
9/15KVM: nVMX: Drop nested_vmx_pmu_refresh()arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/nested.h arch/x86/kvm/vmx/pmu_intel.c+0 -270 replies
10/15KVM: nVMX: Add a quirk for KVM tweaks to VMX MSRsDocumentation/virt/kvm/api.rst arch/x86/include/asm/kvm_host.h arch/x86/include/uapi/asm/kvm.h +2 more+29 -40 replies
11/15KVM: nVMX: Set UMIP bit CR4_FIXED1 MSR when emulating UMIParch/x86/kvm/vmx/nested.c+3 -01 reply
12/15KVM: nVMX: Extend VMX MSRs quirk to CR0/4 fixed1 bitsDocumentation/virt/kvm/api.rst arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c+41 -61 reply
13/15KVM: selftests: Add test to verify KVM's VMX MSRs quirk for controlstools/testing/selftests/kvm/.gitignore tools/testing/selftests/kvm/Makefile tools/testing/selftests/kvm/include/x86_64/processor.h +2 more+166 -00 replies
14/15KVM: selftests: Extend VMX MSRs test to cover CR4_FIXED1 (and its quirks)tools/testing/selftests/kvm/include/x86_64/processor.h tools/testing/selftests/kvm/x86_64/vmx_msrs_test.c+72 -00 replies
15/15KVM: selftests: Verify VMX MSRs can be restored to KVM-supported valuestools/testing/selftests/kvm/x86_64/vmx_msrs_test.c+61 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 00/15] KVM: nVMX: VMX MSR quirk+fixes, CR4 fixes

Resurrecting Oliver's series to quirk nVMX's manipulation of the VMX MSRs.

KVM has a quirk where nVMX overwrites select VMX MSR bits in response to CPUID updates. Specifically, KVM forces CR{0,4}_FIXED1 bits and the VM-Entry/VM-Exit control bits for BNDCFGS and PERF_GLOBAL_CTRL to align with the guest vCPU model. Add a quirk to (a) allow userspace to opt out of the existing behavior and (b) make it clear the the existing behavior should not be propagated to new features.

Patches 0-4 are tangentially related fixes for correctly handling CR4 checks on nested VMXON and VM-Enter. They are included here because there is a subtle dependency created by the fix in patch 02, as it changes the resulting behavior of patch 10, "Extend VMX MSRs quirk to CR0/4 fixed1 bits".

Patch 05 fixes a bug where KVM forces incoming VMX MSR values to be a subset of _current_ value, not of KVM's support valu. E.g. if userspace clears an allowed-1 bit, it can never set that bit back to the original value.

Patch 06, "Keep KVM updates to BNDCFGS ctrl bits across MSR write", fixes a related bug where KVM's original quirky behavior kept the VMX MSRs up-to-date (almost) all the time.

This series is technically based on my selftests overhaul[*], but practically speaking that only affects the selftests. The KVM should apply cleanly on kvm/queue, 55371f1d0c01 ("KVM: x86/pmu: Update global ...")

I have a KUT test for patch 3 (VMXON fixes) that I'l post separately (yet more cleanup involved, ugh). I spot tested patch 2 by fudging PKU in guest CPUID, but I'm not planning on submitting an official test anywhere (though it could be done without too much pain in selftests).

v5:
- Rebase (see above).
- Fix "CR4 valid for nVMX" bugs.
- Modify PERF_GLOBAL_CTRL bits iff the MSR exists.
- Fix a bug where KVM doesn't allow userspace to restore VMX MSRs to _KVM's_ allowed values.
- Fix the UMIP emulation goof.
- Extend the quirk to CR0/4_FIXED1 MSRs.
- Add a helper to identify if the vCPU has a vPMU.
- Rewrote the selftests to more exhaustively test combos, and to test the aforementioned bugs fixed in v5.

v4:
- https://lore.kernel.org/all/[email protected]
- Rebased to kvm/queue. Avoids conflicts with new CAPs and commit 0bcd556e15f9 ("KVM: nVMX: Refactor PMU refresh to avoid referencing kvm_x86_ops.pmu_ops") on kvm/queue.
- Grabbed KVM_CAP_DISABLE_QUIRKS2 patch, since this series also introduces a quirk.
- Fix typo in KVM_CAP_DISABLE_QUIRKS2 documentation (Sean)
- Eliminated the need to refresh 'load IA32_PGC' bits from PMU refresh.
- Use consistent formatting to make test cases more easily readable (David Dunn)
- Use correct 'Fixes: ' tag and correct a typo in Patch 2 changelog.

Oliver Upton (4):
KVM: nVMX: Keep KVM updates to BNDCFGS ctrl bits across MSR write
KVM: nVMX: Keep KVM updates to PERF_GLOBAL_CTRL ctrl bits across MSR
write
KVM: nVMX: Drop nested_vmx_pmu_refresh()
KVM: nVMX: Add a quirk for KVM tweaks to VMX MSRs

Sean Christopherson (11):
KVM: x86: Split kvm_is_valid_cr4() and export only the non-vendor bits
KVM: nVMX: Account for KVM reserved CR4 bits in consistency checks
KVM: nVMX: Inject #UD if VMXON is attempted with incompatible CR0/CR4
KVM: nVMX: Rename handle_vm{on,off}() to handle_vmx{on,off}()
KVM: nVMX: Let userspace set nVMX MSR to any _host_ supported value
KVM: VMX: Add helper to check if the guest PMU has PERF_GLOBAL_CTRL
KVM: nVMX: Set UMIP bit CR4_FIXED1 MSR when emulating UMIP
KVM: nVMX: Extend VMX MSRs quirk to CR0/4 fixed1 bits
KVM: selftests: Add test to verify KVM's VMX MSRs quirk for controls
KVM: selftests: Extend VMX MSRs test to cover CR4_FIXED1 (and its
quirks)
KVM: selftests: Verify VMX MSRs can be restored to KVM-supported
values

 Documentation/virt/kvm/api.rst                |  29 ++
 arch/x86/include/asm/kvm_host.h               |   3 +-
 arch/x86/include/uapi/asm/kvm.h               |   1 +
 arch/x86/kvm/svm/nested.c                     |   3 +-
 arch/x86/kvm/vmx/nested.c                     | 199 ++++++------
 arch/x86/kvm/vmx/nested.h                     |   5 +-
 arch/x86/kvm/vmx/pmu_intel.c                  |   7 +-
 arch/x86/kvm/vmx/vmx.c                        |  23 +-
 arch/x86/kvm/vmx/vmx.h                        |  14 +
 arch/x86/kvm/x86.c                            |  12 +-
 arch/x86/kvm/x86.h                            |   2 +-
 tools/testing/selftests/kvm/.gitignore        |   1 +
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/include/x86_64/processor.h  |   8 +
 .../selftests/kvm/include/x86_64/vmx.h        |   2 +
 .../selftests/kvm/x86_64/vmx_msrs_test.c      | 287 ++++++++++++++++++
 16 files changed, 493 insertions(+), 104 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86_64/vmx_msrs_test.c

base-commit: 081ad4bbae8d503c79fae45f463766d28b2f3241

Signature · 1 line
2.36.1.255.ge46751e96f-goog