Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751528AbdLAIdq (ORCPT ); Fri, 1 Dec 2017 03:33:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40758 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751346AbdLAIde (ORCPT ); Fri, 1 Dec 2017 03:33:34 -0500 Subject: Re: [PATCH v3 7/9] KVM: x86: Implement Intel Processor Trace MSRs read/write To: "Kang, Luwei" , "kvm@vger.kernel.org" Cc: "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "rkrcmar@redhat.com" , "linux-kernel@vger.kernel.org" , "joro@8bytes.org" , Chao Peng References: <1511814242-12949-1-git-send-email-luwei.kang@intel.com> <1511814242-12949-8-git-send-email-luwei.kang@intel.com> <3cfad210-6633-66cf-0276-95d4ca1af273@redhat.com> <82D7661F83C1A047AF7DC287873BF1E167E4F3E1@SHSMSX101.ccr.corp.intel.com> From: Paolo Bonzini Message-ID: Date: Fri, 1 Dec 2017 09:33:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <82D7661F83C1A047AF7DC287873BF1E167E4F3E1@SHSMSX101.ccr.corp.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 01 Dec 2017 08:33:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1600 Lines: 48 On 01/12/2017 07:40, Kang, Luwei wrote: >>> + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: { >>> + u32 eax, ebx, ecx, edx; >>> + >>> + cpuid_count(0x14, 1, &eax, &ebx, &ecx, &edx); >> >> Please cache the cpuid_count result, or do the cpuid_count after testing >> vmx_pt_supported() (which you can use instead of going through kvm_x86_ops). > > Hi Paolo, > Thanks for your reply. I have cache EAX in "struct pt_desc" and will initialize in vmx_vcpu_setup(). > +struct pt_desc { > + unsigned int addr_num; > + struct pt_ctx host; > + struct pt_ctx guest; > +}; > But kvm_init_msr_list() is invoked too early, I have to read from hardware. So, what about change like this. > > - cpuid_count(0x14, 1, &eax, &ebx, &ecx, &edx); > - if (!kvm_x86_ops->pt_supported() || msrs_to_save[i] - > - MSR_IA32_RTIT_ADDR0_A >= (eax & 0x7)) > + if (!kvm_x86_ops->pt_supported()) > continue; > + cpuid_count(0x14, 1, &eax, &ebx, &ecx, &edx); > + if (msrs_to_save[i] - > + MSR_IA32_RTIT_ADDR0_A >= (eax & 0x7)) > + continue; For kvm_init_msr_list it's okay. But can you please add a pt_msr_count() function? Thanks, Paolo > Thanks, > Luwei Kang > >> >> Thanks, >> >> Paolo >> >>> + if (!kvm_x86_ops->pt_supported() || msrs_to_save[i] - >>> + MSR_IA32_RTIT_ADDR0_A >= (eax & 0x7)) >>> + continue; >>> + break; >