From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 4/4] KVM: VMX: Add instruction rdtscp support for guest Date: Wed, 16 Dec 2009 11:47:44 +0200 Message-ID: <4B28ACC0.8050702@redhat.com> References: <1260942485-19156-1-git-send-email-sheng@linux.intel.com> <1260942485-19156-5-git-send-email-sheng@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , kvm@vger.kernel.org To: Sheng Yang Return-path: Received: from mx1.redhat.com ([209.132.183.28]:39376 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752448AbZLPJrq (ORCPT ); Wed, 16 Dec 2009 04:47:46 -0500 In-Reply-To: <1260942485-19156-5-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On 12/16/2009 07:48 AM, Sheng Yang wrote: > Before enabling, execution of "rdtscp" in guest would result in #UD. > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 4f865e8..3a84acf 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -532,6 +532,7 @@ struct kvm_x86_ops { > int (*get_tdp_level)(void); > u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio); > bool (*gb_page_enable)(void); > + bool (*rdtscp_enable)(void); > Naming - a better name is rdtsp_supported(). rdtscp_enable sounds like you change it from disabled to enabled. > @@ -913,6 +924,9 @@ static void setup_msrs(struct vcpu_vmx *vmx) > index = __find_msr_index(vmx, MSR_CSTAR); > if (index>= 0) > move_msr_up(vmx, index, save_nmsrs++); > + index = __find_msr_index(vmx, MSR_TSC_AUX); > + if (index>= 0) > + move_msr_up(vmx, index, save_nmsrs++); > Only if rdtscp is enabled in the guest's cpuid, so we don't play with this unnecessarily. If it isn't, we should trap rdtscp and inject #UD. If it is, support the msr and don't trap. > /* > * MSR_K6_STAR is only needed on long mode guests, and only > * if efer.sce is enabled. > @@ -1002,6 +1016,10 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) > case MSR_IA32_SYSENTER_ESP: > data = vmcs_readl(GUEST_SYSENTER_ESP); > break; > + case MSR_TSC_AUX: > + if (!vmx_rdtscp_enable()) > + return 1; > Again, check the guest rdtscp bit, not (just) the host's. -- error compiling committee.c: too many arguments to function