Skip to content

KVM: x86: Disallow writes to feature MSRs post-KVM_RUN

Sean Christopherson kvm lkml 3 versions – Applied

Status from this message: Applied to kvm-x86 pmu, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest21 patches 1 replyApplied
  2. v221 patches 17 repliesSuperseded
  3. v1 RFC3 patches 6 repliesSuperseded

Changes in v3 from the cover letter

- Collect reviews. [Xiaoyao]
- Fix the PMU selftests _before_ introducing the breaking KVM change. [Like]
- Actually use kvm_vcpu_has_run()... [Yu]

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/21KVM: x86: Rename kvm_init_msr_list() to clarify it inits multiple listsarch/x86/kvm/x86.c+2 -20 replies
2/21KVM: x86: Add a helper to query whether or not a vCPU has ever runarch/x86/kvm/cpuid.c arch/x86/kvm/mmu/mmu.c arch/x86/kvm/x86.h+7 -20 replies
3/21KVM: x86: Add macros to track first...last VMX feature MSRsarch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.h+13 -50 replies
4/21KVM: x86: Generate set of VMX feature MSRs using first/last definitionsarch/x86/kvm/x86.c+22 -310 replies
5/21KVM: selftests: Split PMU caps sub-tests to avoid writing MSR after KVM_RUNtools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+31 -200 replies
6/21KVM: x86: Disallow writes to immutable feature MSRs after KVM_RUNarch/x86/kvm/x86.c+35 -00 replies
7/21KVM: x86/pmu: WARN and bug the VM if PMU is refreshed after vCPU has runarch/x86/kvm/pmu.c arch/x86/kvm/x86.c+12 -10 replies
8/21KVM: x86/pmu: Zero out LBR capabilities during PMU refresharch/x86/kvm/vmx/pmu_intel.c+10 -00 replies
9/21KVM: selftests: Move 0/initial value PERF_CAPS checks to dedicated sub-testtools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+19 -60 replies
10/21KVM: selftests: Assert that full-width PMC writes are supported if PDCM=1tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+3 -00 replies
11/21KVM: selftests: Print out failing MSR and value in vcpu_set_msr()tools/testing/selftests/kvm/include/x86_64/processor.h+23 -70 replies
12/21KVM: selftests: Verify KVM preserves userspace writes to "durable" MSRstools/testing/selftests/kvm/include/x86_64/processor.h+16 -10 replies
13/21KVM: selftests: Drop now-redundant checks on PERF_CAPABILITIES writestools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+0 -60 replies
14/21KVM: selftests: Test all fungible features in PERF_CAPABILITIEStools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+24 -50 replies
15/21KVM: selftests: Test all immutable non-format bits in PERF_CAPABILITIEStools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+27 -30 replies
16/21KVM: selftests: Expand negative testing of guest writes to PERF_CAPABILITIEStools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+54 -70 replies
17/21KVM: selftests: Test post-KVM_RUN writes to PERF_CAPABILITIEStools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+13 -00 replies
18/21KVM: selftests: Drop "all done!" printf() from PERF_CAPABILITIES testtools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+0 -20 replies
19/21KVM: selftests: Refactor LBR_FMT test to avoid use of separate macrotools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+6 -70 replies
20/21KVM: selftests: Add negative testcase for PEBS format in PERF_CAPABILITIEStools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+10 -00 replies
21/21KVM: selftests: Verify LBRs are disabled if vPMU is disabledtools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+29 -00 replies

Reviews trailers per patch

5 of 21 patches have a Reviewed-by or Acked-by.

PatchXiaoyao Li
1/21R-b
2/21R-b
3/21R-b
4/21R-b
5/21
6/21R-b
7/21
8/21
9/21
10/21
11/21
12/21
13/21
14/21
15/21
16/21
17/21
18/21
19/21
20/21
21/21

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

Read the v3 thread

Cover letter [PATCH v3 00/21] KVM: x86: Disallow writes to feature MSRs post-KVM_RUN

Give feature MSRs that same treatment as CPUID and disallow changing said MSRs after KVM_RUN. Fix a tangentially related bug in the vPMU where KVM leaves the vLBRs enabled after userspace disables the guest's entire vPMU.

The bulk of this series is a rework of the vmx_pmu_caps_test, a.k.a. the PERF_CAPABILITIES selftests, to expand its coverage. In addition to verifying that KVM rejects changes after KVM_RUN, verify other bits beyond full-width writes and the LBR format.

Note! There is a sneaky, small, but massive change buried halfway through this series that will affect all x86 selftests. Patch

Verify KVM preserves userspace writes to "durable" MSRs

adds a KVM_GET_MSRS after every KVM_SET_MSRS that writes a single MSR and expects to succeeded. The intent is to opportunistically verify that KVM provides "read what you wrote" for all "durable" MSRs. The PERF_CAPS test was manually verifying this behavior, and while it seems kinda gratuitous, the coverage is quite cheap from both a performance and maintenance cost, i.e. I can't think of a reason _not_ to do it.

v3:
- Collect reviews. [Xiaoyao]
- Fix the PMU selftests _before_ introducing the breaking KVM change. [Like]
- Actually use kvm_vcpu_has_run()... [Yu]

v2: https://lore.kernel.org/all/[email protected]

v1: https://lore.kernel.org/all/[email protected]

Sean Christopherson (21):
KVM: x86: Rename kvm_init_msr_list() to clarify it inits multiple
lists
KVM: x86: Add a helper to query whether or not a vCPU has ever run
KVM: x86: Add macros to track first...last VMX feature MSRs
KVM: x86: Generate set of VMX feature MSRs using first/last
definitions
KVM: selftests: Split PMU caps sub-tests to avoid writing MSR after
KVM_RUN
KVM: x86: Disallow writes to immutable feature MSRs after KVM_RUN
KVM: x86/pmu: WARN and bug the VM if PMU is refreshed after vCPU has
run
KVM: x86/pmu: Zero out LBR capabilities during PMU refresh
KVM: selftests: Move 0/initial value PERF_CAPS checks to dedicated
sub-test
KVM: selftests: Assert that full-width PMC writes are supported if

    PDCM=1

KVM: selftests: Print out failing MSR and value in vcpu_set_msr()
KVM: selftests: Verify KVM preserves userspace writes to "durable"
MSRs
KVM: selftests: Drop now-redundant checks on PERF_CAPABILITIES writes
KVM: selftests: Test all fungible features in PERF_CAPABILITIES
KVM: selftests: Test all immutable non-format bits in
PERF_CAPABILITIES
KVM: selftests: Expand negative testing of guest writes to
PERF_CAPABILITIES
KVM: selftests: Test post-KVM_RUN writes to PERF_CAPABILITIES
KVM: selftests: Drop "all done!" printf() from PERF_CAPABILITIES test
KVM: selftests: Refactor LBR_FMT test to avoid use of separate macro
KVM: selftests: Add negative testcase for PEBS format in
PERF_CAPABILITIES
KVM: selftests: Verify LBRs are disabled if vPMU is disabled

 arch/x86/kvm/cpuid.c                          |   2 +-
 arch/x86/kvm/mmu/mmu.c                        |   2 +-
 arch/x86/kvm/pmu.c                            |   3 +
 arch/x86/kvm/svm/svm.c                        |   2 +-
 arch/x86/kvm/vmx/pmu_intel.c                  |  10 +
 arch/x86/kvm/vmx/vmx.c                        |   8 +-
 arch/x86/kvm/x86.c                            | 102 ++++---
 arch/x86/kvm/x86.h                            |  13 +
 .../selftests/kvm/include/x86_64/processor.h  |  41 ++-
 .../selftests/kvm/x86_64/vmx_pmu_caps_test.c  | 248 ++++++++++++++----
 10 files changed, 341 insertions(+), 90 deletions(-)

base-commit: 45dd9bc75d9adc9483f0c7d662ba6e73ed698a0b

Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog