linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Radim Krcmar <rkrcmar@redhat.com>
To: Andy Lutomirski <luto@kernel.org>
Cc: x86@kernel.org, Marcelo Tosatti <mtosatti@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Alexander Graf <agraf@suse.de>
Subject: Re: [PATCH 1/5] x86/kvm: On KVM re-enable (e.g. after suspend), update clocks
Date: Wed, 16 Mar 2016 23:06:00 +0100	[thread overview]
Message-ID: <20160316220502.GA7040@potion.brq.redhat.com> (raw)
In-Reply-To: <861716d768a1da6d1fd257b7972f8df13baf7f85.1449702533.git.luto@kernel.org>

2015-12-09 15:12-0800, Andy Lutomirski:
> This gets rid of the "did TSC go backwards" logic and just updates
> all clocks.  It should work better (no more disabling of fast
> timing) and more reliably (all of the clocks are actually updated).
> 
> Signed-off-by: Andy Lutomirski <luto@kernel.org>
> ---
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> @@ -7369,88 +7366,22 @@ int kvm_arch_hardware_enable(void)
>  	list_for_each_entry(kvm, &vm_list, vm_list) {
>  		kvm_for_each_vcpu(i, vcpu, kvm) {
> +			if (vcpu->cpu == smp_processor_id()) {

(vmm_exclusive sets vcpu->cpu to -1, so KVM_REQ_MASTERCLOCK_UPDATE might
 not run, but vmm_exclusive probably doesn't work anyway.)

>  				kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
> +				kvm_make_request(KVM_REQ_MASTERCLOCK_UPDATE,
> +						vcpu);
>  			}

(Requesting KVM_REQ_MASTERCLOCK_UPDATE once per VM is enough.)

> -	if (backwards_tsc) {
> -		u64 delta_cyc = max_tsc - local_tsc;
> -		backwards_tsc_observed = true;
> -		list_for_each_entry(kvm, &vm_list, vm_list) {
> -			kvm_for_each_vcpu(i, vcpu, kvm) {
> -				vcpu->arch.tsc_offset_adjustment += delta_cyc;
> -				vcpu->arch.last_host_tsc = local_tsc;

tsc_offset_adjustment was set for

  	/* Apply any externally detected TSC adjustments (due to suspend) */
  	if (unlikely(vcpu->arch.tsc_offset_adjustment)) {
  		adjust_tsc_offset_host(vcpu, vcpu->arch.tsc_offset_adjustment);
  		vcpu->arch.tsc_offset_adjustment = 0;
  		kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
  	}

Guest TSC is going to jump backward with this patch, which would make
the guest think that a lot of cycles passed.  This has no bearing on
guest timekeeping, because the guest shouldn't be using raw TSC.
If we wanted to do something though, there are at least two options:
1) Fake that TSC continued at roughly its specified rate:  compute how
   many cycles could have elapsed while the CPU was suspended (using
   host time before/after suspend and guest TSC frequency) and adjust
   guest TSC.
2) Resume guest TSC at its last cycle before suspend.
   (Roughly what KVM does now.)

What are your opinions on TSC faking?

Thanks.


---
Btw. I'll be spending some days to decipher kvmclock, so I'd also fix
the masterclock+suspend issue, if you don't mind ... So far, I don't
even see a reason to update kvmclock on kvm_arch_hardware_enable().
Suspend is a condition that we want to handle, so kvm_resume would be a
better place, but we handle suspend only because TSC and timekeeping has
changed, so I think that the right place is in their event notifiers.

  parent reply	other threads:[~2016-03-16 22:06 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-09 23:12 [PATCH 0/5] x86: KVM vdso and clock improvements Andy Lutomirski
2015-12-09 23:12 ` [PATCH 1/5] x86/kvm: On KVM re-enable (e.g. after suspend), update clocks Andy Lutomirski
2015-12-14  8:16   ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2015-12-14 10:18     ` Paolo Bonzini
2016-03-16 22:06   ` Radim Krcmar [this message]
2016-03-16 22:15     ` [PATCH 1/5] " Andy Lutomirski
2016-03-16 22:59       ` Radim Krcmar
2016-03-16 23:07         ` Andy Lutomirski
2016-03-17 15:10           ` Radim Krcmar
2016-03-17 18:22             ` Andy Lutomirski
2016-03-17 19:58               ` Radim Krcmar
2015-12-09 23:12 ` [PATCH 2/5] x86, vdso, pvclock: Simplify and speed up the vdso pvclock reader Andy Lutomirski
2015-12-10  9:09   ` Paolo Bonzini
2015-12-11  7:52     ` Ingo Molnar
2015-12-11  8:42       ` Paolo Bonzini
2015-12-11 18:03         ` Andy Lutomirski
2015-12-14  8:16   ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2015-12-09 23:12 ` [PATCH 3/5] x86/vdso: Get pvclock data from the vvar VMA instead of the fixmap Andy Lutomirski
2015-12-10  9:09   ` Paolo Bonzini
2015-12-14  8:17   ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2015-12-09 23:12 ` [PATCH 4/5] x86/vdso: Remove pvclock fixmap machinery Andy Lutomirski
2015-12-10  9:09   ` Paolo Bonzini
2015-12-11  8:06   ` [PATCH] x86/platform/uv: Include clocksource.h for clocksource_touch_watchdog() Ingo Molnar
2015-12-11 17:33     ` Andy Lutomirski
2015-12-14  8:17   ` [tip:x86/asm] x86/vdso: Remove pvclock fixmap machinery tip-bot for Andy Lutomirski
2015-12-09 23:12 ` [PATCH 5/5] x86/vdso: Enable vdso pvclock access on all vdso variants Andy Lutomirski
2015-12-10  9:10   ` Paolo Bonzini
2015-12-14  8:17   ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2015-12-11  3:21 ` [PATCH 0/5] x86: KVM vdso and clock improvements Andy Lutomirski

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=20160316220502.GA7040@potion.brq.redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=agraf@suse.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.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).