From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrey Smetanin Subject: Re: [PATCH v1] kvm/x86: Hyper-V tsc page setup Date: Fri, 22 Jan 2016 14:11:46 +0300 Message-ID: <56A20E72.6050404@virtuozzo.com> References: <1450949580-25759-1-git-send-email-asmetanin@virtuozzo.com> <56A1FF8F.3050701@redhat.com> <56A20131.8090102@virtuozzo.com> <56A20C30.4020608@redhat.com> Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Cc: Gleb Natapov , Roman Kagan , "Denis V. Lunev" , To: Paolo Bonzini , Return-path: Received: from mx2.parallels.com ([199.115.105.18]:50574 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752729AbcAVLL4 (ORCPT ); Fri, 22 Jan 2016 06:11:56 -0500 In-Reply-To: <56A20C30.4020608@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 01/22/2016 02:02 PM, Paolo Bonzini wrote: > > > On 22/01/2016 11:15, Andrey Smetanin wrote: >>> >>> - unless KVM can use a master clock, it is incorrect to set up the TSC >>> page this way; the sequence needs to be 0xFFFFFFFF in that case >> 0xFFFFFFFF is not an invalid value for tsc page, >> see https://lkml.org/lkml/2015/11/2/655 > > oh, I see now. > >>> - writing the TSC page must be done while all VCPUs are stopped, because >>> the TSC page doesn't provide the possibility for the guest to retry in >>> the middle of an update (like seqcount in Linux doess) >> I think Windows guest gives tsc page address at boot time and protects >> against other vcpu's tsc page access. > > Sometimes the TSC is detected to be unstable and Linux switches to > another clocksource. At least in that case you can get a write to the > TSC page while the guest is running. I can't understand how write is possible. Linux Hyper-V driver hv_vmbus.ko does the following inside hv_init() drivers/hv/hv.c(line 256): wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64); clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100); So page is setup only once before registration clock source. > > In that case it would be enough to write a zero to tsc_sequence, which > _can_ be done atomically while the guest is running. However, KVM > already has a mechanism to stop all VCPUs (KVM_REQ_MASTERCLOCK_UPDATE) > so we might as well use it. > > Paolo >