From: Glauber Costa Subject: [PATCH 2/2] [PATCH] disable kvm clock unless addr's LSB is set. Date: Thu, 6 Mar 2008 11:45:44 -0300 Message-ID: <1204814744-12595-3-git-send-email-gcosta@redhat.com> References: <1204814744-12595-1-git-send-email-gcosta@redhat.com> <1204814744-12595-2-git-send-email-gcosta@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: chrisw@sous-sol.org, avi@qumranet.com, Glauber Costa To: kvm-devel@lists.sourceforge.net Return-path: In-Reply-To: <1204814744-12595-2-git-send-email-gcosta@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org Use LSB of the address passed through the msr to enable/disable the clock. Setting it to 1 enables it, setting it to 0 disables it. As the guest data structures are aligned anyway, this won't be a problem, as this bit is free. Guest is changed accordingly Signed-off-by: Glauber Costa --- arch/x86/kernel/kvmclock.c | 2 +- arch/x86/kvm/x86.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 7c481a3..f654a12 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -125,7 +125,7 @@ static int kvm_register_clock(void) { int cpu = smp_processor_id(); int low, high; - low = (int)__pa(&per_cpu(hv_clock, cpu)); + low = (int)__pa(&per_cpu(hv_clock, cpu)) | 1; high = ((u64)__pa(&per_cpu(hv_clock, cpu)) >> 32); return native_write_msr_safe(MSR_KVM_SYSTEM_TIME, low, high); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6abd784..64beff6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -591,8 +591,15 @@ int kvm_set_msr_common(struct kvm_vcpu * if (vcpu->arch.time_page) kvm_release_page_dirty(vcpu->arch.time_page); + /* we verify if the enable bit is set... */ + if (!(data & 1)) { + vcpu->arch.time = NULL; + break; + } + vcpu->arch.time = data & PAGE_MASK; - vcpu->arch.time_offset = data & ~PAGE_MASK; + /* ...but clean it before doing the actual write */ + vcpu->arch.time_offset = data & ~(PAGE_MASK | 1); vcpu->arch.hv_clock.tsc_to_system_mul = clocksource_khz2mult(tsc_khz, 22); -- 1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/