From patchwork Tue Feb 14 02:19:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luwei Kang X-Patchwork-Id: 9571025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB42860442 for ; Tue, 14 Feb 2017 02:23:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAADC27F82 for ; Tue, 14 Feb 2017 02:23:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF57F27FAE; Tue, 14 Feb 2017 02:23:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7185127F82 for ; Tue, 14 Feb 2017 02:23:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cdSjx-0000wF-BL; Tue, 14 Feb 2017 02:21:13 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cdSjw-0000w9-Lt for xen-devel@lists.xen.org; Tue, 14 Feb 2017 02:21:12 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id BE/B0-01703-79962A85; Tue, 14 Feb 2017 02:21:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrALMWRWlGSWpSXmKPExsXS1tYhoTs9c1G Ewc93chZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bc17oFj2QqujsnMzYwPhPrYuTiEBKYzihx bvYV5i5GTg4JAV6JI8tmsELYfhJL//5mAbGFBKokfr9+CFbDJqAusfX9RrAaEQFpiWufLzOC2 MwCoRKnP51lA7GFBawk9p65D2azCKhK9NxYxQ5i8wq4SLxf08wGMV9O4ua5TuYJjNwLGBlWMa oXpxaVpRbpGuklFWWmZ5TkJmbm6BoamOrlphYXJ6an5iQmFesl5+duYgT6lgEIdjB+/+N0iFG Sg0lJlDd208IIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8/emLIoQEi1LTUyvSMnOAQQaTluDg URLhnZMBlOYtLkjMLc5Mh0idYtTlOHXj9EsmIZa8/LxUKXHelyAzBECKMkrz4EbAAv4So6yUM C8j0FFCPAWpRbmZJajyrxjFORiVhHkXgKziycwrgdv0CugIJqAjWOMWghxRkoiQkmpg3FOZ+f TJts6gygDpH3nr32x0Wr3DTk1w0dKi6iCWx5XPbPhficzIkbj8WkOuZ4HyPV5x3otLc15463l ucs9aHcgle//dPivrl69c2M9m6/rXTGzbZeOafXpvcJ6+x+PjP9fxZjb03pLw2cZwsqPgyLy6 yX5u92sqA/bFPBeuOcmw80zsR1Y9JZbijERDLeai4kQApMVWy3MCAAA= X-Env-Sender: luwei.kang@intel.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1487038869!48448334!1 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42898 invoked from network); 14 Feb 2017 02:21:11 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-12.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Feb 2017 02:21:11 -0000 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2017 18:21:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,158,1484035200"; d="scan'208";a="65412760" Received: from vmm-dell.bj.intel.com ([10.238.154.151]) by fmsmga006.fm.intel.com with ESMTP; 13 Feb 2017 18:21:06 -0800 From: Luwei Kang To: xen-devel@lists.xen.org Date: Tue, 14 Feb 2017 10:19:22 +0800 Message-Id: <1487038762-24020-1-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 2.7.4 Cc: andrew.cooper3@citrix.com, Luwei Kang , jbeulich@suse.com Subject: [Xen-devel] [PATCH] x86/vpmu: fix vpmu can't enabled in guest X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP vpmu_enable() can not use for check if vpmu is enabled in guest during booting up. Because linux kernel get the status of if supported pmu is earler than xen vpmu initialise. vpmu_enable() will return false even if vpmu has been enabled in guest. Signed-off-by: Luwei Kang --- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/cpuid.c | 11 +++++------ xen/include/asm-x86/vpmu.h | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c index 35a9403..8c8ffc9 100644 --- a/xen/arch/x86/cpu/vpmu.c +++ b/xen/arch/x86/cpu/vpmu.c @@ -50,7 +50,7 @@ CHECK_pmu_params; * "vpmu=arch" : vpmu enabled for predef arch counters only (restrictive) * flag combinations are allowed, eg, "vpmu=ipc,bts". */ -static unsigned int __read_mostly opt_vpmu_enabled; +unsigned int __read_mostly opt_vpmu_enabled; unsigned int __read_mostly vpmu_mode = XENPMU_MODE_OFF; unsigned int __read_mostly vpmu_features = 0; static void parse_vpmu_params(char *s); diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index e0a387e..b63c5d8 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -713,8 +713,7 @@ static void pv_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res) } } - if ( vpmu_enabled(curr) && - vpmu_is_set(vcpu_vpmu(curr), VPMU_CPU_HAS_DS) ) + if ( opt_vpmu_enabled && boot_cpu_has(X86_FEATURE_DS) ) { res->d |= cpufeat_mask(X86_FEATURE_DS); if ( cpu_has(¤t_cpu_data, X86_FEATURE_DTES64) ) @@ -726,7 +725,7 @@ static void pv_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res) case 0x0000000a: /* Architectural Performance Monitor Features (Intel) */ if ( boot_cpu_data.x86_vendor != X86_VENDOR_INTEL || - !vpmu_enabled(curr) ) + !opt_vpmu_enabled ) goto unsupported; /* Report at most version 3 since that's all we currently emulate. */ @@ -793,8 +792,7 @@ static void hvm_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res) if ( !hap_enabled(d) && !hvm_pae_enabled(v) ) res->d &= ~cpufeat_mask(X86_FEATURE_PSE36); - if ( vpmu_enabled(v) && - vpmu_is_set(vcpu_vpmu(v), VPMU_CPU_HAS_DS) ) + if ( opt_vpmu_enabled && boot_cpu_has(X86_FEATURE_DS) ) { res->d |= cpufeat_mask(X86_FEATURE_DS); if ( cpu_has(¤t_cpu_data, X86_FEATURE_DTES64) ) @@ -811,7 +809,8 @@ static void hvm_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res) break; case 0x0000000a: /* Architectural Performance Monitor Features (Intel) */ - if ( boot_cpu_data.x86_vendor != X86_VENDOR_INTEL || !vpmu_enabled(v) ) + if ( boot_cpu_data.x86_vendor != X86_VENDOR_INTEL || + !opt_vpmu_enabled ) { *res = EMPTY_LEAF; break; diff --git a/xen/include/asm-x86/vpmu.h b/xen/include/asm-x86/vpmu.h index e50618f..1148d66 100644 --- a/xen/include/asm-x86/vpmu.h +++ b/xen/include/asm-x86/vpmu.h @@ -25,7 +25,6 @@ #define vcpu_vpmu(vcpu) (&(vcpu)->arch.vpmu) #define vpmu_vcpu(vpmu) container_of((vpmu), struct vcpu, arch.vpmu) -#define vpmu_enabled(vcpu) vpmu_is_set(vcpu_vpmu(vcpu), VPMU_CONTEXT_ALLOCATED) #define MSR_TYPE_COUNTER 0 #define MSR_TYPE_CTRL 1 @@ -121,6 +120,7 @@ static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) return vpmu_do_msr(msr, msr_content, 0, 0); } +extern unsigned int opt_vpmu_enabled; extern unsigned int vpmu_mode; extern unsigned int vpmu_features;