From patchwork Wed Sep 27 03:31:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 145651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2989005vqu; Wed, 27 Sep 2023 17:37:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJC7tPOfoTUzKaRxI/EgKDVn1hwrJ3oguAIfIw2vFwoZNL0H5NhuIwm+E8fYK8Vl/cIqUX X-Received: by 2002:a05:6a00:3199:b0:693:394f:5d99 with SMTP id bj25-20020a056a00319900b00693394f5d99mr2391682pfb.8.1695861449826; Wed, 27 Sep 2023 17:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695861449; cv=none; d=google.com; s=arc-20160816; b=BYG67xqQVMW1I8APIzA08jV2KCCniYt2G3Qc0AW6DqBAFPVI0s9qyHqzwGSJ7yYEJt +uhEzXXbnfXcdy6HKUKgwAdgJJr4SjFtOS4RJ/o4pEBqYWOJ38VkBCTsYLPtcKlBCEc9 biJw0Rvn9wXJCxiIUcYiZdx5cBfyGP/ehqiscKrAbuup/BkdSkED0TbGqqj3bLoHFMLy o0sy+Zfa5sWzl2EXHcdMtRFF7BwE3Zkj0fOa+NNNvpR7UeaRmH5oOd5sKBTc962C1YmY zIRXdu9rA4dY3sIFOO+v34Ev2H2dEVTBoNBC4+yKt1QSnsNp1CIcsEbapud9d4QTL6I5 6+XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NjH9KpPo2KmNFEq2f+VGMIGDDEQ07CSfMMoKWKLut60=; fh=SYwTdU7AJ6bh+wuJYieKOpYo9FOAEtzrlv0Krk9EVUs=; b=brzNLbTIBrgyl0BMvsCJ3PNfC3uVrpplVj4Ttl+cstEnRZ0F1SopJNGNA6XkHYn2w/ 1/jrxR8P6/BaWgCi8AsIQ+V4jG506XJKlTqQBlg9vbbLL4gWRpq8iDgwqD0n9Atm+5ho YfgboTASpfLPKZIQLFy5p+tACxs5P9T+CMKscJiRhsTE1vzOuumYaV90BNOO337uo4Jf RMI1Zd7gIvttSrziTlADhqU1AwI7DFVMdsiGh9etOAqYTYeinfXssvNHlQZDEw1p4nmZ QocsEUwkeU8AZsVf/9cRDz/OxWQrtLirTaSep6NrUF95Brxn0vX9jTCAYzun3zaLCmAh 8peQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nv2XGAy8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a7-20020a056a000c8700b00690f8edee16si17484371pfv.275.2023.09.27.17.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 17:37:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nv2XGAy8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3A91B806E55D; Tue, 26 Sep 2023 21:10:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229497AbjI0EKp (ORCPT + 26 others); Wed, 27 Sep 2023 00:10:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbjI0EJ1 (ORCPT ); Wed, 27 Sep 2023 00:09:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B664140D7; Tue, 26 Sep 2023 20:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695785118; x=1727321118; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MqAR84HcFnlcSI6e30scf9vscDeb/onORUUaIdDgZzU=; b=nv2XGAy8QEDl5vq/pQwk+seeTCzQAk18MO4wt74uD1I2kw3AMUsBH6QL rykZYZNqbRpS7mpwPWjhz91P8bNdiVrV/7rn/dg80tFFJ1qVLI7n1TiEZ Fm7TyCcWnDbPbFXozGJ6jfBnyjg6bcndTvkM1vZ3uGsfVJE4oWXY0wk8v /0+suvZBljCGCdZDfQWyhQdciPjdE6j8nWlSawuh6hYltJDTDfZDplYDJ kD0kP5sUxIM0Xcdp6QxboeixNd5UJv7EoEN8lrY7C5hSxdYYZf5QEWmt+ J58Wdqn388aodBqBs+7PzuO2l9ic0Ecujjh+EyMzQABlRp8wjuK/nykOT A==; X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="366780898" X-IronPort-AV: E=Sophos;i="6.03,179,1694761200"; d="scan'208";a="366780898" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 20:25:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="864637335" X-IronPort-AV: E=Sophos;i="6.03,179,1694761200"; d="scan'208";a="864637335" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga002.fm.intel.com with ESMTP; 26 Sep 2023 20:25:12 -0700 From: Dapeng Mi To: Sean Christopherson , Paolo Bonzini , Peter Zijlstra , Arnaldo Carvalho de Melo , Kan Liang , Like Xu , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter Cc: kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Lv Zhiyuan , Yang Weijiang , Dapeng Mi , Dapeng Mi Subject: [Patch v4 13/13] KVM: x86/pmu: Expose Topdown in MSR_IA32_PERF_CAPABILITIES Date: Wed, 27 Sep 2023 11:31:24 +0800 Message-Id: <20230927033124.1226509-14-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230927033124.1226509-1-dapeng1.mi@linux.intel.com> References: <20230927033124.1226509-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 26 Sep 2023 21:10:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778239615640453990 X-GMAIL-MSGID: 1778239615640453990 Topdown support is enumerated via IA32_PERF_CAPABILITIES[bit 15]. Enable this bit for guest when the feature is available on host. Co-developed-by: Yang Weijiang Signed-off-by: Yang Weijiang Signed-off-by: Dapeng Mi --- arch/x86/kvm/vmx/pmu_intel.c | 3 +++ arch/x86/kvm/vmx/vmx.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 04ccb8c6f7e4..5783cde00054 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -614,6 +614,9 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) (((1ull << pmu->nr_arch_fixed_counters) - 1) << INTEL_PMC_IDX_FIXED)); pmu->global_ctrl_mask = counter_mask; + if (intel_pmu_metrics_is_enabled(vcpu)) + pmu->global_ctrl_mask &= ~(1ULL << GLOBAL_CTRL_EN_PERF_METRICS); + /* * GLOBAL_STATUS and GLOBAL_OVF_CONTROL (a.k.a. GLOBAL_STATUS_RESET) * share reserved bit definitions. The kernel just happens to use diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 72e3943f3693..5686a74c14bb 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7850,6 +7850,8 @@ static u64 vmx_get_perf_capabilities(void) perf_cap &= ~PERF_CAP_PEBS_BASELINE; } + perf_cap |= host_perf_cap & PMU_CAP_PERF_METRICS; + return perf_cap; }