From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932832AbcGOMPg (ORCPT ); Fri, 15 Jul 2016 08:15:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38570 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932764AbcGOMPd (ORCPT ); Fri, 15 Jul 2016 08:15:33 -0400 Date: Fri, 15 Jul 2016 14:15:28 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, stable@vger.kernel.org, Borislav Petkov Subject: Re: [PATCH] KVM: SVM: fix trashing of MSR_TSC_AUX Message-ID: <20160715121528.GA3273@potion> References: <1467812596-18903-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1467812596-18903-1-git-send-email-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 15 Jul 2016 12:15:32 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2016-07-06 15:43+0200, Paolo Bonzini: > I don't know what I was thinking when I wrote commit 46896c73c1a4 ("KVM: > svm: add support for RDTSCP", 2015-11-12); I missed write_rdtscp_aux which > obviously uses MSR_TSC_AUX. > > Therefore we do need to save/restore MSR_TSC_AUX in svm_vcpu_run. Hm, MSR_TSC_AUX is in host_save_user_msrs[], so we save it on every svm_vcpu_load() and restore on svm_vcpu_put(). Linux does not use RDTSCP and every transition to userspace has svm_vcpu_put() in between. We also still do "wrmsrl(MSR_TSC_AUX, svm->tsc_aux);" in svm_set_msr() and can switch to userspace without performing svm_vcpu_run() first. Was this patch fixing the host userspace or something in the guest? Thanks. > Cc: stable@vger.kernel.org > Cc: Borislav Petkov > Fixes: 46896c73c1a4 ("KVM: svm: add support for RDTSCP") > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/svm.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 16ef31b87452..44f6368f8b45 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -43,6 +43,7 @@ > #include > > #include > +#include > #include "trace.h" > > #define __ex(x) __kvm_handle_fault_on_reboot(x) > @@ -1530,9 +1531,6 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > wrmsrl(MSR_AMD64_TSC_RATIO, tsc_ratio); > } > } > - /* This assumes that the kernel never uses MSR_TSC_AUX */ > - if (static_cpu_has(X86_FEATURE_RDTSCP)) > - wrmsrl(MSR_TSC_AUX, svm->tsc_aux); > > avic_vcpu_load(vcpu, cpu); > } > @@ -4474,6 +4472,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu) > svm->vmcb->save.cr2 = vcpu->arch.cr2; > > clgi(); > + if (static_cpu_has(X86_FEATURE_RDTSCP)) > + wrmsrl(MSR_TSC_AUX, svm->tsc_aux); > > local_irq_enable(); > > @@ -4550,6 +4550,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu) > #endif > ); > > + if (static_cpu_has(X86_FEATURE_RDTSCP)) > + wrmsrl(MSR_TSC_AUX, __getcpu()); > #ifdef CONFIG_X86_64 > wrmsrl(MSR_GS_BASE, svm->host.gs_base); > #else > -- > 1.8.3.1 > > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html