Skip to content

KVM: x86: Fix nested TSC scaling edge cases

Sean Christopherson kvm lkml sashiko-reviews 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 Latest21 patches 8 repliesIn review

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/21KVM: x86: Saturate L2's TSC frequency if it exceeds hardware supportsarch/x86/kvm/x86.c+51 -40 replies
2/21KVM: SVM: Fallback to the default TSC ratio if KVM tries to use a bad multiplierarch/x86/kvm/svm/svm.c+9 -00 replies
3/21KVM: x86: Allow userspace to set KVM's max supported guest TSC frequencyarch/x86/kvm/x86.c+4 -30 replies
4/21KVM: selftests: Use KVM's pRNG to randomize L1's TSC ratio in TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+1 -20 replies
5/21KVM: selftests: Drop redundant VMWRITE of TSC_MULTIPLIER_HIGHtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+0 -10 replies
6/21KVM: selftests: Drop unnecessary use of PRIu64 in nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+7 -140 replies
7/21KVM: selftests: Randomize L2's scale factor in nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+9 -120 replies
8/21KVM: selftests: Rename TSC freq checkers in nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+9 -91 reply
9/21KVM: selftests: Extract guts of nested TSC scaling test to helper functiontools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+30 -240 replies
10/21KVM: selftests: Track L2 multiplier, not scale-up factor, in nested TSC testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+10 -80 replies
11/21KVM: selftests: Print out the failing L{0,1,2} level in nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+5 -50 replies
12/21KVM: selftests: Allow +/- 1 tolerance if expected TSC frequency is <100tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+2 -20 replies
13/21KVM: selftests: Use KVM's reported TSC KHz as L0's frequency (sanity checked)tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+17 -86 replies
14/21KVM: selftests: Explicitly pass TSC frequencies to guts of TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+17 -250 replies
15/21KVM: selftests: Sanity check KVM's default TSC freq in nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+3 -00 replies
16/21KVM: selftests: Test L1 "up" and L2 "down" in nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+28 -50 replies
17/21KVM: selftests: Verify that KVM saturates L2 TSC freq on {under,over}flowtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+35 -00 replies
18/21KVM: selftests: Test non-zero TSC offset on SVM in nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+1 -00 replies
19/21KVM: selftests: Randomize L2's TSC offset in the nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+7 -50 replies
20/21KVM: selftests: Use GUEST_SYNC2() in nested TSC scaling testtools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+2 -50 replies
21/21KVM: selftests: Spell out UCALL in nested TSC scaling test's enumstools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c+12 -120 replies

Reviews trailers per patch

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

Read the v3 thread

Cover letter [PATCH v3 00/21] KVM: x86: Fix nested TSC scaling edge cases

Amirmohammad's fix to saturate L2's TSC frequency when stacking scale up/down ratios across L1+L2 yields a final scaling ratio that can't be plugged into hardware. The actual fix is functionally the same as v2, but I rewrote the comments and changelog to try and make them more approachable to KVM developers (AI has a habit of generating extremely verbose, "mathy" descriptions of bugs and fixes).

Patch 2 fixes a flaw pointed out by Sashiko.

Patch 3 fixes an off-by-one issue in KVM_SET_TSC_KHZ that is a complete non-issue in practice, but confused the heck out of me and made writing the testcases unnecessarily annoying.

The rest of the pile extends and cleans up the nested TSC scaling test to validate the saturation fixes, and to test all four combinations of scaling L1+L2 up+down (the existing code testing only L1 down, L2 up).

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

Amirmohammad Eftekhar (1):
KVM: x86: Saturate L2's TSC frequency if it exceeds hardware supports

Sean Christopherson (20):
KVM: SVM: Fallback to the default TSC ratio if KVM tries to use a bad
multiplier
KVM: x86: Allow userspace to set KVM's max supported guest TSC
frequency
KVM: selftests: Use KVM's pRNG to randomize L1's TSC ratio in TSC
scaling test
KVM: selftests: Drop redundant VMWRITE of TSC_MULTIPLIER_HIGH
KVM: selftests: Drop unnecessary use of PRIu64 in nested TSC scaling
test
KVM: selftests: Randomize L2's scale factor in nested TSC scaling test
KVM: selftests: Rename TSC freq checkers in nested TSC scaling test
KVM: selftests: Extract guts of nested TSC scaling test to helper
function
KVM: selftests: Track L2 multiplier, not scale-up factor, in nested
TSC test
KVM: selftests: Print out the failing L{0,1,2} level in nested TSC
scaling test
KVM: selftests: Allow +/- 1 tolerance if expected TSC frequency is

    <100

KVM: selftests: Use KVM's reported TSC KHz as L0's frequency (sanity
checked)
KVM: selftests: Explicitly pass TSC frequencies to guts of TSC scaling
test
KVM: selftests: Sanity check KVM's default TSC freq in nested TSC
scaling test
KVM: selftests: Test L1 "up" and L2 "down" in nested TSC scaling test
KVM: selftests: Verify that KVM saturates L2 TSC freq on
{under,over}flow
KVM: selftests: Test non-zero TSC offset on SVM in nested TSC scaling
test
KVM: selftests: Randomize L2's TSC offset in the nested TSC scaling
test
KVM: selftests: Use GUEST_SYNC2() in nested TSC scaling test
KVM: selftests: Spell out UCALL in nested TSC scaling test's enums

 arch/x86/kvm/svm/svm.c                        |   9 +
 arch/x86/kvm/x86.c                            |  62 ++++-
 .../kvm/x86/nested_tsc_scaling_test.c         | 232 +++++++++++-------
 3 files changed, 209 insertions(+), 94 deletions(-)

base-commit: b378201ccd5280d0fff89bbe55e1eb00620ec0d5

Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog