From: Jack Allister <jalliste@amazon.com>
To: <jalliste@amazon.com>
Cc: <bp@alien8.de>, <corbet@lwn.net>, <dave.hansen@linux.intel.com>,
<dwmw2@infradead.org>, <hpa@zytor.com>, <kvm@vger.kernel.org>,
<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<mingo@redhat.com>, <paul@xen.org>, <pbonzini@redhat.com>,
<seanjc@google.com>, <tglx@linutronix.de>, <x86@kernel.org>
Subject: [PATCH v2 0/2] Add API for accurate KVM/PV clock migration
Date: Wed, 10 Apr 2024 09:52:42 +0000 [thread overview]
Message-ID: <20240410095244.77109-1-jalliste@amazon.com> (raw)
In-Reply-To: <20240408220705.7637-1-jalliste@amazon.com>
Guest VMs can be provided with a para-virtualized clock source to
perform timekeeping. A KVM guest can map in a PV clock via the
MSR_KVM_SYSTEM_TIME/MSR_KVM_SYSTEM_TIME_NEW virtualized MSRs.
Where as on a Xen guest this can be provided via the vcpu/shared
info pages.
These PV clocks both use a common structure which is mapped between
host <-> guest to provide the PVTI (paravirtual time information)
for the clock. This reference information is a guest TSC timestamp
and a host system time at a singular point in time.
Upon a live-update of a host or live-migration of an instance the
PVTI may be recalculated by KVM. Using the existing KVM_[GS]ET_CLOCK
functionality the relationship between the TSC and PV clock cannot
be precisely saved and restored by userspace.
This series adds in two patches, one to add in a new interface to
allow a VMM/userspace to perform a correction of the PVTI structure.
Then a second to verify the imprecision after a simulation of a
live-update/migration and then to verify the correction is to within
±1ns.
v1: https://lore.kernel.org/all/20240408220705.7637-1-jalliste@amazon.com/
v2:
- Moved new IOCTLs from vm to vcpu level.
- Adds extra error checks as suggested by Dongli Zhang / David Woodhouse.
- Adds on-demand calculation of PVTI if non currently present in vcpu.
- Adds proper synchronization for PV clock during correction.
- Added option to test without TSC scaling in sefltest.
- Updated commit messages to better explain the situation (thanks David).
Jack Allister (2):
KVM: x86: Add KVM_[GS]ET_CLOCK_GUEST for accurate KVM clock migration
KVM: selftests: Add KVM/PV clock selftest to prove timer correction
Documentation/virt/kvm/api.rst | 37 ++++
arch/x86/kvm/x86.c | 124 +++++++++++
include/uapi/linux/kvm.h | 3 +
tools/testing/selftests/kvm/Makefile | 1 +
.../selftests/kvm/x86_64/pvclock_test.c | 192 ++++++++++++++++++
5 files changed, 357 insertions(+)
create mode 100644 tools/testing/selftests/kvm/x86_64/pvclock_test.c
base-commit: 8cb4a9a82b21623dbb4b3051dd30d98356cf95bc
--
2.40.1
next prev parent reply other threads:[~2024-04-10 9:52 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 22:07 [PATCH 0/2] Add API to correct KVM/PV clock drift Jack Allister
2024-04-08 22:07 ` [PATCH 1/2] KVM: x86: Add KVM_[GS]ET_CLOCK_GUEST for KVM clock drift fixup Jack Allister
2024-04-09 0:34 ` Dongli Zhang
2024-04-09 3:50 ` David Woodhouse
2024-04-10 10:08 ` Allister, Jack
2024-04-08 22:07 ` [PATCH 2/2] KVM: selftests: Add KVM/PV clock selftest to prove timer drift correction Jack Allister
2024-04-09 0:43 ` Dongli Zhang
2024-04-09 4:23 ` David Woodhouse
2024-04-10 10:15 ` Allister, Jack
2024-04-11 13:28 ` David Woodhouse
2024-04-19 17:13 ` Chen, Zide
[not found] ` <17F1A2E9-6BAD-40E7-ACDD-B110CFC124B3@infradead.org>
2024-04-19 18:43 ` David Woodhouse
2024-04-19 23:54 ` Chen, Zide
2024-04-20 10:32 ` David Woodhouse
2024-04-20 16:03 ` David Woodhouse
2024-04-22 22:02 ` Chen, Zide
2024-04-23 7:49 ` David Woodhouse
2024-04-23 17:59 ` Chen, Zide
2024-04-23 21:02 ` David Woodhouse
2024-04-24 12:58 ` David Woodhouse
2024-04-19 19:34 ` David Woodhouse
2024-04-19 23:53 ` Chen, Zide
2024-04-10 9:52 ` Jack Allister [this message]
2024-04-10 9:52 ` [PATCH v2 1/2] KVM: x86: Add KVM_[GS]ET_CLOCK_GUEST for accurate KVM clock migration Jack Allister
2024-04-10 10:29 ` Paul Durrant
2024-04-10 12:09 ` David Woodhouse
2024-04-10 12:43 ` Paul Durrant
2024-04-17 19:50 ` David Woodhouse
2024-04-15 7:16 ` David Woodhouse
2024-04-10 9:52 ` [PATCH v2 2/2] KVM: selftests: Add KVM/PV clock selftest to prove timer correction Jack Allister
2024-04-10 10:36 ` Paul Durrant
2024-04-12 8:19 ` Dongli Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240410095244.77109-1-jalliste@amazon.com \
--to=jalliste@amazon.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).