Skip to content

KVM_{GET,SET}_TSC_OFFSET ioctls

Oliver Upton kvm 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest5 patches 11 repliesIn review
  2. v25 patches 0 repliesSuperseded
  3. v14 patches 5 repliesSuperseded

Changes in v3 from the cover letter

- Mark kvm_write_tsc_offset() as static (whoops)

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5kvm: x86: refactor masterclock sync heuristics out of kvm_write_tscarch/x86/kvm/x86.c+54 -440 replies
2/5kvm: x86: add KVM_{GET,SET}_TSC_OFFSET ioctlsDocumentation/virt/kvm/api.rst arch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c +1 more+86 -00 replies
3/5kvm: vmx: check tsc offsetting with nested_cpu_has()arch/x86/kvm/vmx/vmx.c+1 -10 replies
4/5selftests: kvm: use a helper function for reading cpuidtools/testing/selftests/kvm/include/x86_64/processor.h tools/testing/selftests/kvm/include/x86_64/svm_util.h+17 -50 replies
5/5selftests: kvm: introduce tsc_offset_testtools/testing/selftests/kvm/.gitignore tools/testing/selftests/kvm/Makefile tools/testing/selftests/kvm/include/test_util.h +5 more+393 -00 replies

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchJim MattsonPeter Shier
1/5R-b R-b
2/5R-b R-b
3/5R-b R-b
4/5R-b R-b
5/5R-b R-b

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 0/5] KVM_{GET,SET}_TSC_OFFSET ioctls

To date, VMMs have typically restored the guest's TSCs by value using the KVM_SET_MSRS ioctl for each vCPU. However, restoring the TSCs by value introduces some challenges with synchronization as the TSCs continue to tick throughout the restoration process. As such, KVM has some heuristics around TSC writes to infer whether or not the guest or host is attempting to synchronize the TSCs.

Instead of guessing at the intentions of a VMM, it'd be better to provide an interface that allows for explicit synchronization of the guest's TSCs. To that end, this series introduces the KVM_{GET,SET}_TSC_OFFSET ioctls, yielding control of the TSC offset to userspace.

v2 => v3:
- Mark kvm_write_tsc_offset() as static (whoops)

v1 => v2:
- Added clarification to the documentation of KVM_SET_TSC_OFFSET to indicate that it can be used instead of an IA32_TSC MSR restore through KVM_SET_MSRS
- Fixed KVM_SET_TSC_OFFSET to participate in the existing TSC synchronization heuristics, thereby enabling the KVM masterclock when all vCPUs are in phase.

Oliver Upton (4):
kvm: x86: refactor masterclock sync heuristics out of kvm_write_tsc
kvm: vmx: check tsc offsetting with nested_cpu_has()
selftests: kvm: use a helper function for reading cpuid
selftests: kvm: introduce tsc_offset_test

Peter Hornyack (1):
kvm: x86: add KVM_{GET,SET}_TSC_OFFSET ioctls

 Documentation/virt/kvm/api.rst                |  31 ++
 arch/x86/include/asm/kvm_host.h               |   1 +
 arch/x86/kvm/vmx/vmx.c                        |   2 +-
 arch/x86/kvm/x86.c                            | 147 ++++---
 include/uapi/linux/kvm.h                      |   5 +
 tools/testing/selftests/kvm/.gitignore        |   1 +
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../testing/selftests/kvm/include/test_util.h |   3 +
 .../selftests/kvm/include/x86_64/processor.h  |  15 +
 .../selftests/kvm/include/x86_64/svm_util.h   |  10 +-
 .../selftests/kvm/include/x86_64/vmx.h        |   9 +
 tools/testing/selftests/kvm/lib/kvm_util.c    |   1 +
 tools/testing/selftests/kvm/lib/x86_64/vmx.c  |  11 +
 .../selftests/kvm/x86_64/tsc_offset_test.c    | 362 ++++++++++++++++++
 14 files changed, 550 insertions(+), 49 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86_64/tsc_offset_test.c
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog