From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: Re: [PATCH v2 1/2] KVM: x86: hyper-v: Properly divide maybe-negative 'hv_clock->system_time' in compute_tsc_page_parameters()
Date: Wed, 31 Mar 2021 08:29:43 +0200 [thread overview]
Message-ID: <87a6qju97s.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <4d7f375c-c912-fbeb-edd1-03d742d49dcb@redhat.com>
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 30/03/21 16:44, Vitaly Kuznetsov wrote:
>> We could've solved the problem by reducing the precision a bit and
>> instead of doing
>>
>> now_ns = get_kvmclock_ns(kvm);
>>
>> in KVM_SET_CLOCK() handling we could do
>>
>> now_ns = ka->master_kernel_ns
>>
>> and that would make vcpu->hv_clock.system_time == 0 after
>> kvm_guest_time_update() but it'd hurt 'normal' use-cases to fix the
>> corner case.
>
> Marcelo is right, and I guess instead of a negative system time you
> *should* have a slightly larger tsc_timestamp that corresponds to a zero
> system_time. E.g. instead of -70 ns in the system time you'd have 210
> more clock cycles in the tsc_timestamp and 0 in the system time.
>
> In the end it's impossible to achieve absolute precision; does the
> KVM_SET_CLOCK value refer to the nanosecond value before entering the
> kernel, or after, or what? The difference is much more than these 70
> ns. So what you propose above seems to be really the best solution
> within the constraints of the KVM_SET_CLOCK API (a better API, which
> Maxim had started working on and I should revisit, would pass a
> TSC+nanosecond pair).
I'm leaning towards making a v3 and depending on how complex it's going
to look like we can decide which way to go.
>
> On the other hand you'd have to take into account what happens if the
> masterclock is not in use, which would make things a bit more complex
> than what you sketched.
(I really wish we establish a plan to get rid of !masterclock logic some
day ... )
> If guests probably do not look at the
> system_time and just add it blindly to the result, then treating
> system_time as signed as in v2 is the easiest.
--
Vitaly
next prev parent reply other threads:[~2021-03-31 6:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-29 11:47 [PATCH v2 0/2] KVM: x86: hyper-v: Fix TSC page update after KVM_SET_CLOCK(0) call Vitaly Kuznetsov
2021-03-29 11:47 ` [PATCH v2 1/2] KVM: x86: hyper-v: Properly divide maybe-negative 'hv_clock->system_time' in compute_tsc_page_parameters() Vitaly Kuznetsov
2021-03-29 17:24 ` Sean Christopherson
2021-03-30 10:21 ` Vitaly Kuznetsov
2021-03-30 14:12 ` Marcelo Tosatti
2021-03-30 13:12 ` Marcelo Tosatti
2021-03-30 14:44 ` Vitaly Kuznetsov
2021-03-30 15:44 ` Paolo Bonzini
2021-03-31 6:29 ` Vitaly Kuznetsov [this message]
2021-03-31 6:52 ` Paolo Bonzini
2021-03-31 9:59 ` Vitaly Kuznetsov
2021-03-31 10:58 ` Paolo Bonzini
2021-03-29 11:48 ` [PATCH v2 2/2] selftests: kvm: Check that TSC page value is small after KVM_SET_CLOCK(0) Vitaly Kuznetsov
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=87a6qju97s.fsf@vitty.brq.redhat.com \
--to=vkuznets@redhat.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=wanpengli@tencent.com \
/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