From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: KVM: x86: update masterclock when kvmclock_offset is calculated Date: Tue, 3 Sep 2013 10:56:00 -0300 Message-ID: <20130903135559.GA17834@amt.cnet> References: <20130820182012.GA814@amt.cnet> <521644D0.9050902@redhat.com> <20130828025243.GA13653@amt.cnet> <521DEF00.2030200@redhat.com> <20130903030351.GA3167@amt.cnet> <5225BD20.1000902@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm-devel , Gleb Natapov To: Paolo Bonzini Return-path: Received: from mx1.redhat.com ([209.132.183.28]:44429 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932991Ab3ICN4U (ORCPT ); Tue, 3 Sep 2013 09:56:20 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r83DuJNl001905 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 3 Sep 2013 09:56:19 -0400 Content-Disposition: inline In-Reply-To: <5225BD20.1000902@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Sep 03, 2013 at 12:42:40PM +0200, Paolo Bonzini wrote: > Il 03/09/2013 05:03, Marcelo Tosatti ha scritto: > > > Here is the code I was thinking of: > > > > > > spin_lock(&ka->pvclock_gtod_sync_lock); > > > make_all_cpus_request(kvm, KVM_REQ_CLOCK_UPDATE); > > > > > > /* > > > * No guest entries from this point: VCPUs will be spinning > > > * on pvclock_gtod_sync_lock in kvm_guest_time_update. > > > */ > > > pvclock_update_vm_gtod_copy(kvm); > > > > > > /* > > > * Let kvm_guest_time_update continue: entering the guest > > > * is now allowed too. > > > */ > > > spin_unlock(&ka->pvclock_gtod_sync_lock); > > > > > > KVM_REQ_CLOCK_UPDATE is used to cancel guest entry and execute > > > kvm_guest_time_update. But kvm_guest_time_update will spin on > > > pvclock_gtod_sync_lock until pvclock_update_vm_gtod_copy exits and > > > kvm_gen_update_masterclock releases the spinlock. > > > > Not safe because there are places which set KVM_REQ_CLOCK_UPDATE without > > kicking target vcpu out of guest mode. Unless you use a modified > > make_all_cpus_request. > > make_all_cpus_request does force an exit, even if the bit is already set > in vcpus->requests. But maybe here is where I'm missing something. No, you're right. My bad. > > The point of REQ_MCLOCK_INPROGRESS request is to guarantee that the > > following is not possible: > > > > - 2 vcpus in guest mode with per-vcpu kvmclock areas with > > different {system_timestamp, tsc_offset} values. > > Understood. > > > To achieve that: > > > > - Kick all vcpus out of guest mode (via a request bit that can't be > > cleared). > > - Update the {system_timestamp, tsc_offset} values. > > - Clear the request bit. > > After make_all_cpus_request, all VCPUs will be out of guest mode, and > the request bit will not be cleared until pvclock_gtod_sync_lock is > released. > > Paolo It seems more obfuscated to rely on an implicit pvclock_gtod_sync_lock blocking than an explicit request bit that can't be cleared, but perhaps thats personal opinion. OTOH, you can also argue that the request bit abuses the vcpu->requests request mechanism, because there is not a request in fact (it only blocks guest entry). If you have reasons to update, and you are sure its safe, feel free to modify it.