public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Vadim Rozenfeld <vrozenfe@redhat.com>
Cc: kvm@vger.kernel.org, pl@dlhnet.de, pbonzini@redhat.com
Subject: Re: [RFC PATCH v3 2/2] add support for Hyper-V partition reference time enlightenment
Date: Tue, 14 Jan 2014 11:54:49 -0200	[thread overview]
Message-ID: <20140114135449.GA18231@amt.cnet> (raw)
In-Reply-To: <980575286.212048.1389672700594.JavaMail.root@redhat.com>

On Mon, Jan 13, 2014 at 11:11:40PM -0500, Vadim Rozenfeld wrote:
> 
> 
> ----- Original Message -----
> From: "Marcelo Tosatti" <mtosatti@redhat.com>
> To: "Vadim Rozenfeld" <vrozenfe@redhat.com>
> Cc: kvm@vger.kernel.org, pl@dlhnet.de, pbonzini@redhat.com
> Sent: Thursday, December 12, 2013 6:27:00 AM
> Subject: Re: [RFC PATCH v3 2/2] add support for Hyper-V partition reference time enlightenment
> 
> On Sun, Dec 08, 2013 at 10:33:39PM +1100, Vadim Rozenfeld wrote:
> > The following patch allows to activate a partition reference
> > time enlightenment that is based on the host platform's support
> > for an Invariant Time Stamp Counter (iTSC).
> > 
> > v2 -> v3
> > Handle TSC sequence, scale, and offest changing during migration.
> > 
> > ---
> >  arch/x86/include/asm/kvm_host.h |  1 +
> >  arch/x86/kvm/x86.c              | 29 +++++++++++++++++++++++++++--
> >  2 files changed, 28 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> > index 2fd0753..81fdff0 100644
> > --- a/arch/x86/include/asm/kvm_host.h
> > +++ b/arch/x86/include/asm/kvm_host.h
> > @@ -607,6 +607,7 @@ struct kvm_arch {
> >  	u64 hv_hypercall;
> >  	u64 hv_ref_count;
> >  	u64 hv_tsc_page;
> > +	u64 hv_ref_time;
> >  
> >  	#ifdef CONFIG_KVM_MMU_AUDIT
> >  	int audit_point;
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 5e4e495a..cb6766a 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -1882,14 +1882,19 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
> >  			break;
> >  		}
> >  		gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
> > -		addr = gfn_to_hva(kvm, data >>
> > -			HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);
> > +		addr = gfn_to_hva(kvm, gfn);
> >  		if (kvm_is_error_hva(addr))
> >  			return 1;
> > +		tsc_ref.tsc_sequence =
> > +			boot_cpu_has(X86_FEATURE_CONSTANT_TSC) ? 1 : 0;
> > +		tsc_ref.tsc_scale =
> > +			((10000LL << 32) / vcpu->arch.virtual_tsc_khz) << 32;
> > +		tsc_ref.tsc_offset = 0;
> >  		if (__copy_to_user((void __user *)addr, &tsc_ref, sizeof(tsc_ref)))
> >  			return 1;
> >  		mark_page_dirty(kvm, gfn);
> >  		kvm->arch.hv_tsc_page = data;
> > +		kvm->arch.hv_ref_count = 0;
> >  		break;
> >  	}
> >  	default:
> > @@ -3879,6 +3884,19 @@ long kvm_arch_vm_ioctl(struct file *filp,
> >  		local_irq_enable();
> >  		kvm->arch.kvmclock_offset = delta;
> >  		kvm_gen_update_masterclock(kvm);
> > +
> > +		if (kvm->arch.hv_tsc_page & HV_X64_MSR_TSC_REFERENCE_ENABLE) {
> > +			HV_REFERENCE_TSC_PAGE* tsc_ref;
> > +			u64 curr_time;
> > +			tsc_ref = (HV_REFERENCE_TSC_PAGE*)gfn_to_hva(kvm, 
> > +				kvm->arch.hv_tsc_page >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);
> > +			tsc_ref->tsc_sequence =
> > +				boot_cpu_has(X86_FEATURE_CONSTANT_TSC) ? tsc_ref->tsc_sequence + 1 : 0;
> > +			tsc_ref->tsc_scale = ((10000LL << 32) / __get_cpu_var(cpu_tsc_khz)) << 32;
> > +			curr_time = (((tsc_ref->tsc_scale >> 32) * native_read_tsc()) >> 32) + 
> > +				tsc_ref->tsc_offset;
> > +			tsc_ref->tsc_offset = kvm->arch.hv_ref_time - curr_time;
> > +		}
> >  		break;
> >  	}
> >  	case KVM_GET_CLOCK: {
> > @@ -3896,6 +3914,13 @@ long kvm_arch_vm_ioctl(struct file *filp,
> >  		if (copy_to_user(argp, &user_ns, sizeof(user_ns)))
> >  			goto out;
> >  		r = 0;
> > +		if (kvm->arch.hv_tsc_page & HV_X64_MSR_TSC_REFERENCE_ENABLE) {
> > +			HV_REFERENCE_TSC_PAGE* tsc_ref;
> > +			tsc_ref = (HV_REFERENCE_TSC_PAGE*)gfn_to_hva(kvm,
> > +				kvm->arch.hv_tsc_page >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);
> 
> kvm_read_guest_cached.
> 
> > +			kvm->arch.hv_ref_time = (((tsc_ref->tsc_scale >> 32) * 
> > +				native_read_tsc()) >> 32) + tsc_ref->tsc_offset;
> 
> Why native_read_tsc and not ->read_l1_tsc?
> 
> [VR]
> Is it possible to get pointer to the vcpu instance at this point?

See the suggestion to move this code to kvm_guest_time_update.


> Thanks,
> Vadim. 
> 
> It is easier to trust on the host to check reliability of the TSC: if
> it uses TSC clocksource, then the TSCs are stable. So could condition
> exposing the TSC ref page when ka->use_master_clock=1, see kvm_guest_time_update.
> And hook into pvclock_gtod_notify.
> 
> So in addition to X86_FEATURE_CONSTANT_TSC, check
> ka->use_master_clock=1
> 

      reply	other threads:[~2014-01-14 15:49 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-08 11:33 [RFC PATCH v3 0/2] Hyper-V timers Vadim Rozenfeld
2013-12-08 11:33 ` [RFC PATCH v3 1/2] add support for Hyper-V reference time counter Vadim Rozenfeld
2013-12-09 14:23   ` Paolo Bonzini
2013-12-10 10:46     ` Vadim Rozenfeld
2013-12-11 18:53   ` Marcelo Tosatti
2013-12-11 18:59     ` Marcelo Tosatti
2013-12-12  9:33       ` Paolo Bonzini
2014-01-02 16:52       ` Peter Lieven
2014-01-07  9:36         ` Vadim Rozenfeld
2014-01-07 17:52           ` Peter Lieven
2014-01-08  9:40             ` Vadim Rozenfeld
2014-01-08 10:15               ` Peter Lieven
2014-01-08 10:44                 ` Vadim Rozenfeld
2014-01-08 11:48                   ` Peter Lieven
2014-01-08 12:12                     ` Vadim Rozenfeld
2014-01-08 14:54                       ` Peter Lieven
2014-01-08 20:08                         ` Vadim Rozenfeld
2014-01-08 22:20                           ` Peter Lieven
2014-01-09 11:10                             ` Vadim Rozenfeld
2014-01-12 12:08                             ` Vadim Rozenfeld
2014-01-12 20:35                               ` Peter Lieven
2014-01-02 13:15     ` Peter Lieven
2014-01-02 13:57       ` Marcelo Tosatti
2014-01-02 16:08         ` Peter Lieven
2014-01-02 20:05           ` Marcelo Tosatti
2014-01-13 12:10     ` Vadim Rozenfeld
2013-12-08 11:33 ` [RFC PATCH v3 2/2] add support for Hyper-V partition reference time enlightenment Vadim Rozenfeld
2013-12-09 14:32   ` Paolo Bonzini
2013-12-10 11:23     ` Vadim Rozenfeld
2013-12-10 16:52       ` Paolo Bonzini
2013-12-11 10:58         ` Vadim Rozenfeld
2013-12-11 12:28           ` Paolo Bonzini
2013-12-11 19:28       ` Marcelo Tosatti
2013-12-11 19:27   ` Marcelo Tosatti
2013-12-12  9:34     ` Paolo Bonzini
2014-01-14  4:11     ` Vadim Rozenfeld
2014-01-14 13:54       ` Marcelo Tosatti [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=20140114135449.GA18231@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=pl@dlhnet.de \
    --cc=vrozenfe@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox