public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Roman Kagan <rkagan@virtuozzo.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	kvm-devel <kvm@vger.kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	pagupta@redhat.com
Subject: Re: [PATCH] KVM: x86: remove irq disablement around KVM_SET_CLOCK/KVM_GET_CLOCK
Date: Thu, 13 Apr 2017 15:27:29 +0200	[thread overview]
Message-ID: <20170413132728.GC23556@potion> (raw)
In-Reply-To: <20170413073203.GA14317@rkaganb.sw.ru>

2017-04-13 10:32+0300, Roman Kagan:
> Hmm, __get_kvmclock_ns used not to need a spinlock back when it was
> added...  Why does it now?

It accessed vcpu to get the data it now takes from the master clock.
The lock is there to protect master clock's consistency.

There were problems when accessing VCPUs from VM ioctls -- you first had
to conjure a VCPU out of thin air and then be extremely careful when
accessing it, which we didn't manage to and it resulted in an invalid
VMCS access bug, IIRC.  (I would bet there we other bugs.)

> Looking at its current state, I'm not sure I understand what it's
> supposed to do: it uses the host tsc rate rather than the guest one,
> which seems to just defeat the purpose of originally introducing it: to
> have a way to obtain the clock value exactly the same as the guest would
> see...
> 
> Am I missing anything obvious?

It is a bit obscure ... the current state is simulating what the vcpu
does when setting up its kvmclock, and should therefore yield the same
result as the guest kvmclock would see.

Without master clock, the guest kvmclock follows ktime_get_boot_ns().

With master clock, the guest follows host TSC (different frequency than
ktime_get_boot_ns()).  The guest might have extra scaling and offset on
that TSC, but both are known to KVM when computing the kvmclock
variables to get the 1GHz result.

We could first convert the host TSC to guest TSC and then compute
kvmclock from it, but we should obtain the same result when converting
to 1GHz directly from host TSC (within rouding errors, ofc).

This is possible as guest and host use the same physical TSC.

      reply	other threads:[~2017-04-13 13:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-12 17:23 [PATCH] KVM: x86: remove irq disablement around KVM_SET_CLOCK/KVM_GET_CLOCK Marcelo Tosatti
2017-04-12 17:40 ` Radim Krčmář
2017-04-13  6:06 ` Pankaj Gupta
2017-04-13 18:30   ` Marcelo Tosatti
2017-04-13 18:49   ` [PATCH v2] " Marcelo Tosatti
2017-04-17 11:05     ` Pankaj Gupta
2017-04-17 15:51       ` [PATCH v3] " Marcelo Tosatti
2017-04-18  5:06         ` Pankaj Gupta
2017-04-21 10:04         ` Paolo Bonzini
2017-04-13  7:32 ` [PATCH] " Roman Kagan
2017-04-13 13:27   ` Radim Krčmář [this message]

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=20170413132728.GC23556@potion \
    --to=rkrcmar@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pagupta@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkagan@virtuozzo.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