From: Marcelo Tosatti <mtosatti@redhat.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Maxim Levitsky <mlevitsk@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
kvm@vger.kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Jonathan Corbet <corbet@lwn.net>,
Jim Mattson <jmattson@google.com>,
Wanpeng Li <wanpengli@tencent.com>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Sean Christopherson <sean.j.christopherson@intel.com>,
open list <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@redhat.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<x86@kernel.org>, Joerg Roedel <joro@8bytes.org>,
Borislav Petkov <bp@alien8.de>, Shuah Khan <shuah@kernel.org>,
Andrew Jones <drjones@redhat.com>,
Oliver Upton <oupton@google.com>,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE
Date: Mon, 7 Dec 2020 20:11:27 -0300 [thread overview]
Message-ID: <20201207231127.GB27492@fuller.cnet> (raw)
In-Reply-To: <885C1725-B479-47F6-B08D-A7181637A80A@amacapital.net>
On Mon, Dec 07, 2020 at 10:04:45AM -0800, Andy Lutomirski wrote:
>
> > On Dec 7, 2020, at 9:00 AM, Maxim Levitsky <mlevitsk@redhat.com> wrote:
> >
> > On Mon, 2020-12-07 at 08:53 -0800, Andy Lutomirski wrote:
> >>>> On Dec 7, 2020, at 8:38 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
> >>>
> >>> On Mon, Dec 07 2020 at 14:16, Maxim Levitsky wrote:
> >>>>> On Sun, 2020-12-06 at 17:19 +0100, Thomas Gleixner wrote:
> >>>>> From a timekeeping POV and the guests expectation of TSC this is
> >>>>> fundamentally wrong:
> >>>>>
> >>>>> tscguest = scaled(hosttsc) + offset
> >>>>>
> >>>>> The TSC has to be viewed systemwide and not per CPU. It's systemwide
> >>>>> used for timekeeping and for that to work it has to be synchronized.
> >>>>>
> >>>>> Why would this be different on virt? Just because it's virt or what?
> >>>>>
> >>>>> Migration is a guest wide thing and you're not migrating single vCPUs.
> >>>>>
> >>>>> This hackery just papers over he underlying design fail that KVM looks
> >>>>> at the TSC per vCPU which is the root cause and that needs to be fixed.
> >>>>
> >>>> I don't disagree with you.
> >>>> As far as I know the main reasons that kvm tracks TSC per guest are
> >>>>
> >>>> 1. cases when host tsc is not stable
> >>>> (hopefully rare now, and I don't mind making
> >>>> the new API just refuse to work when this is detected, and revert to old way
> >>>> of doing things).
> >>>
> >>> That's a trainwreck to begin with and I really would just not support it
> >>> for anything new which aims to be more precise and correct. TSC has
> >>> become pretty reliable over the years.
> >>>
> >>>> 2. (theoretical) ability of the guest to introduce per core tsc offfset
> >>>> by either using TSC_ADJUST (for which I got recently an idea to stop
> >>>> advertising this feature to the guest), or writing TSC directly which
> >>>> is allowed by Intel's PRM:
> >>>
> >>> For anything halfways modern the write to TSC is reflected in TSC_ADJUST
> >>> which means you get the precise offset.
> >>>
> >>> The general principle still applies from a system POV.
> >>>
> >>> TSC base (systemwide view) - The sane case
> >>>
> >>> TSC CPU = TSC base + TSC_ADJUST
> >>>
> >>> The guest TSC base is a per guest constant offset to the host TSC.
> >>>
> >>> TSC guest base = TSC host base + guest base offset
> >>>
> >>> If the guest want's this different per vCPU by writing to the MSR or to
> >>> TSC_ADJUST then you still can have a per vCPU offset in TSC_ADJUST which
> >>> is the offset to the TSC base of the guest.
> >>
> >> How about, if the guest wants to write TSC_ADJUST, it can turn off all paravirt features and keep both pieces?
> >>
> >
> > This is one of the things I had in mind recently.
> >
> > Even better, we can stop advertising TSC_ADJUST in CPUID to the guest
> > and forbid it from writing it at all.
>
> Seems reasonable to me.
>
> It also seems okay for some MSRs to stop working after the guest enabled new PV timekeeping.
>
> I do have a feature request, though: IMO it would be quite nifty if the new kvmclock structure could also expose NTP corrections. In other words, if you could expose enough info to calculate CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC, and CLOCK_REALTIME, then we could have paravirt NTP.
Hi Andy,
Any reason why drivers/ptp/ptp_kvm.c does not work for you?
> Bonus points if whatever you do for CLOCK_REALTIME also exposes leap seconds in a race free way :). But I suppose that just exposing TAI and letting the guest deal with the TAI - UTC offset itself would get the job done just fine.
next prev parent reply other threads:[~2020-12-08 14:25 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-03 17:11 [PATCH v2 0/3] RFC: Precise TSC migration Maxim Levitsky
2020-12-03 17:11 ` [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE Maxim Levitsky
2020-12-06 16:19 ` Thomas Gleixner
2020-12-07 12:16 ` Maxim Levitsky
2020-12-07 13:16 ` Vitaly Kuznetsov
2020-12-07 17:41 ` Thomas Gleixner
2020-12-08 9:48 ` Peter Zijlstra
2020-12-10 11:42 ` Paolo Bonzini
2020-12-10 12:14 ` Peter Zijlstra
2020-12-10 12:22 ` Paolo Bonzini
2020-12-10 13:01 ` Peter Zijlstra
2020-12-10 20:20 ` Thomas Gleixner
2020-12-07 16:38 ` Thomas Gleixner
2020-12-07 16:53 ` Andy Lutomirski
2020-12-07 17:00 ` Maxim Levitsky
2020-12-07 18:04 ` Andy Lutomirski
2020-12-07 23:11 ` Marcelo Tosatti [this message]
2020-12-08 17:43 ` Andy Lutomirski
2020-12-08 19:24 ` Thomas Gleixner
2020-12-08 20:32 ` Andy Lutomirski
2020-12-09 0:19 ` Thomas Gleixner
2020-12-09 4:08 ` Andy Lutomirski
2020-12-09 10:14 ` Thomas Gleixner
2020-12-10 23:42 ` Andy Lutomirski
2020-12-08 11:24 ` Maxim Levitsky
2020-12-08 9:35 ` Peter Zijlstra
2020-12-07 23:34 ` Marcelo Tosatti
2020-12-07 17:29 ` Oliver Upton
2020-12-08 11:13 ` Maxim Levitsky
2020-12-08 15:57 ` Oliver Upton
2020-12-08 15:58 ` Oliver Upton
2020-12-08 17:10 ` Maxim Levitsky
2020-12-08 16:40 ` Thomas Gleixner
2020-12-08 17:08 ` Maxim Levitsky
2020-12-10 11:48 ` Paolo Bonzini
2020-12-10 14:25 ` Maxim Levitsky
2020-12-07 23:29 ` Marcelo Tosatti
2020-12-08 14:50 ` Maxim Levitsky
2020-12-08 16:02 ` Thomas Gleixner
2020-12-08 16:25 ` Maxim Levitsky
2020-12-08 17:33 ` Andy Lutomirski
2020-12-08 21:25 ` Thomas Gleixner
2020-12-08 18:12 ` Marcelo Tosatti
2020-12-08 21:35 ` Thomas Gleixner
2020-12-08 21:20 ` Thomas Gleixner
2020-12-10 11:48 ` Paolo Bonzini
2020-12-10 14:52 ` Maxim Levitsky
2020-12-10 15:16 ` Andy Lutomirski
2020-12-10 17:59 ` Oliver Upton
2020-12-10 18:05 ` Paolo Bonzini
2020-12-10 18:13 ` Oliver Upton
2020-12-10 21:25 ` Thomas Gleixner
2020-12-10 22:01 ` Andy Lutomirski
2020-12-10 22:28 ` Thomas Gleixner
2020-12-10 23:19 ` Andy Lutomirski
2020-12-11 0:03 ` Thomas Gleixner
2020-12-08 18:11 ` Marcelo Tosatti
2020-12-08 21:33 ` Thomas Gleixner
2020-12-09 16:34 ` Marcelo Tosatti
2020-12-09 20:58 ` Thomas Gleixner
2020-12-10 15:26 ` Marcelo Tosatti
2020-12-10 21:48 ` Thomas Gleixner
2020-12-11 0:27 ` Marcelo Tosatti
2020-12-11 13:30 ` Thomas Gleixner
2020-12-11 14:18 ` Marcelo Tosatti
2020-12-11 21:04 ` Thomas Gleixner
2020-12-11 21:59 ` Paolo Bonzini
2020-12-12 13:03 ` Thomas Gleixner
2020-12-15 10:59 ` Marcelo Tosatti
2020-12-15 16:55 ` Andy Lutomirski
2020-12-15 22:34 ` Thomas Gleixner
2020-12-11 13:37 ` Paolo Bonzini
2020-12-08 17:35 ` Marcelo Tosatti
2020-12-03 17:11 ` [PATCH v2 2/3] KVM: x86: introduce KVM_X86_QUIRK_TSC_HOST_ACCESS Maxim Levitsky
2020-12-03 17:11 ` [PATCH v2 3/3] kvm/selftests: update tsc_msrs_test to cover KVM_X86_QUIRK_TSC_HOST_ACCESS Maxim Levitsky
2020-12-07 23:16 ` [PATCH v2 0/3] RFC: Precise TSC migration Marcelo Tosatti
2020-12-10 11:48 ` Paolo Bonzini
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=20201207231127.GB27492@fuller.cnet \
--to=mtosatti@redhat.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=drjones@redhat.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--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 NNTP newsgroup(s).