From: Gleb Natapov <gleb@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm-devel <kvm@vger.kernel.org>
Subject: Re: KVM: x86: update masterclock when kvmclock_offset is calculated (v2)
Date: Wed, 28 Aug 2013 17:47:01 +0300 [thread overview]
Message-ID: <20130828144701.GW22899@redhat.com> (raw)
In-Reply-To: <20130828025529.GB13653@amt.cnet>
On Tue, Aug 27, 2013 at 11:55:29PM -0300, Marcelo Tosatti wrote:
>
> The offset to add to the hosts monotonic time, kvmclock_offset, is
> calculated against the monotonic time at KVM_SET_CLOCK ioctl time.
>
> Request a master clock update at this time, to reduce a potentially
> unbounded difference between the values of the masterclock and
> the clock value used to calculate kvmclock_offset.
>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>
Applied, thanks.
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d21bce5..0a93354 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1457,6 +1457,29 @@ static void pvclock_update_vm_gtod_copy(struct kvm *kvm)
> #endif
> }
>
> +static void kvm_gen_update_masterclock(struct kvm *kvm)
> +{
> +#ifdef CONFIG_X86_64
> + int i;
> + struct kvm_vcpu *vcpu;
> + struct kvm_arch *ka = &kvm->arch;
> +
> + spin_lock(&ka->pvclock_gtod_sync_lock);
> + kvm_make_mclock_inprogress_request(kvm);
> + /* no guest entries from this point */
> + pvclock_update_vm_gtod_copy(kvm);
> +
> + kvm_for_each_vcpu(i, vcpu, kvm)
> + set_bit(KVM_REQ_CLOCK_UPDATE, &vcpu->requests);
> +
> + /* guest entries allowed */
> + kvm_for_each_vcpu(i, vcpu, kvm)
> + clear_bit(KVM_REQ_MCLOCK_INPROGRESS, &vcpu->requests);
> +
> + spin_unlock(&ka->pvclock_gtod_sync_lock);
> +#endif
> +}
> +
> static int kvm_guest_time_update(struct kvm_vcpu *v)
> {
> unsigned long flags, this_tsc_khz;
> @@ -3806,6 +3829,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
> delta = user_ns.clock - now_ns;
> local_irq_enable();
> kvm->arch.kvmclock_offset = delta;
> + kvm_gen_update_masterclock(kvm);
> break;
> }
> case KVM_GET_CLOCK: {
> @@ -5689,29 +5713,6 @@ static void process_nmi(struct kvm_vcpu *vcpu)
> kvm_make_request(KVM_REQ_EVENT, vcpu);
> }
>
> -static void kvm_gen_update_masterclock(struct kvm *kvm)
> -{
> -#ifdef CONFIG_X86_64
> - int i;
> - struct kvm_vcpu *vcpu;
> - struct kvm_arch *ka = &kvm->arch;
> -
> - spin_lock(&ka->pvclock_gtod_sync_lock);
> - kvm_make_mclock_inprogress_request(kvm);
> - /* no guest entries from this point */
> - pvclock_update_vm_gtod_copy(kvm);
> -
> - kvm_for_each_vcpu(i, vcpu, kvm)
> - set_bit(KVM_REQ_CLOCK_UPDATE, &vcpu->requests);
> -
> - /* guest entries allowed */
> - kvm_for_each_vcpu(i, vcpu, kvm)
> - clear_bit(KVM_REQ_MCLOCK_INPROGRESS, &vcpu->requests);
> -
> - spin_unlock(&ka->pvclock_gtod_sync_lock);
> -#endif
> -}
> -
> static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
> {
> u64 eoi_exit_bitmap[4];
>
--
Gleb.
next prev parent reply other threads:[~2013-08-28 14:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-20 18:20 KVM: x86: update masterclock when kvmclock_offset is calculated Marcelo Tosatti
2013-08-22 17:05 ` Paolo Bonzini
2013-08-23 10:00 ` Paolo Bonzini
2013-08-28 2:55 ` KVM: x86: update masterclock when kvmclock_offset is calculated (v2) Marcelo Tosatti
2013-08-28 14:47 ` Gleb Natapov [this message]
2013-08-28 2:55 ` KVM: x86: update masterclock when kvmclock_offset is calculated Marcelo Tosatti
2013-08-28 2:52 ` Marcelo Tosatti
2013-08-28 12:37 ` Paolo Bonzini
2013-09-03 3:03 ` Marcelo Tosatti
2013-09-03 10:42 ` Paolo Bonzini
2013-09-03 13:56 ` Marcelo Tosatti
2013-09-03 14:20 ` 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=20130828144701.GW22899@redhat.com \
--to=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.