From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH] x86/kvm: fix condition to update kvm master clocks Date: Fri, 17 Jun 2016 19:21:21 -0300 Message-ID: <20160617222119.GA15883@amt.cnet> References: <1464274195-31296-1-git-send-email-rkagan@virtuozzo.com> <20160529233844.GA14374@amt.cnet> <20160609032710.GA13318@amt.cnet> <20160609120945.GB2570@rkaganb.sw.ru> <20160609182501.GA24024@amt.cnet> <20160613171929.exgvqiw5hmnza2rp@rkaganb.sw.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: Roman Kagan , kvm@vger.kernel.org, "Denis V. Lunev" , Owen Hofmann , Paolo Bonzini Return-path: Received: from mx1.redhat.com ([209.132.183.28]:58237 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751801AbcFQXmH (ORCPT ); Fri, 17 Jun 2016 19:42:07 -0400 Content-Disposition: inline In-Reply-To: <20160613171929.exgvqiw5hmnza2rp@rkaganb.sw.ru> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Jun 13, 2016 at 08:19:30PM +0300, Roman Kagan wrote: > While we're at this: > > According to the comments in the code, the purpose of the masterclock > scheme is to prevent any vCPU from seeing an outdated hv_clock of > another vCPU. It prevents two vcpus from using different hv_clocks: " * To avoid that problem, do not allow visibility of distinct * system_timestamp/tsc_timestamp values simultaneously: use a master * copy of host monotonic time values. Update that master copy * in lockstep. " > However I'm missing how that is achieved. AFAICS the guest entry is > allowed as soon as all vCPUs are kicked from guest with > KVM_REQ_CLOCK_UPDATE set; what stops one vCPU from processing it and > entering the guest before another vCPU even started updating its > hv_clock? 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) kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); /* 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 }