Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Zide Chen <zide.chen@intel.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: kvm@vger.kernel.org, Jim Mattson <jmattson@google.com>,
	Yosry Ahmed <yosry@kernel.org>, Andi Kleen <ak@linux.intel.com>,
	Stephane Eranian <eranian@google.com>,
	linux-kernel@vger.kernel.org, Mingwei Zhang <mizhang@google.com>,
	Zide Chen <zide.chen@intel.com>,
	Das Sandipan <Sandipan.Das@amd.com>,
	Shukla Manali <Manali.Shukla@amd.com>,
	Dapeng Mi <dapeng1.mi@linux.intel.com>,
	Xudong Hao <xudong.hao@intel.com>
Subject: [PATCH v10 03/18] perf/x86/intel: Track common hybrid capabilities
Date: Tue, 24 Nov 2026 14:38:46 -0700	[thread overview]
Message-ID: <20261124213901.120572-4-zide.chen@intel.com> (raw)
In-Reply-To: <20261124213901.120572-1-zide.chen@intel.com>

Now that intel_update_pmu_caps() updates intel_cap on hybrid_pmu[],
the assignment in intel_pmu_init_hybrid() is obsolete and can be
dropped. Additionally, ADL P-cores report perf_metrics correctly, so
hardcoding perf_metrics for P-cores is not required.

Intersect capabilities across all online PMU types. This clears all
potentially inflated asymmetric features (such as rdpmc_metrics_clear)
from x86_pmu.intel_cap when the BSP is a P-core.

For erratum RPL018, set perf_metrics in the base x86_pmu.intel_cap
on all-P-core systems to keep x86_pmu consistent and allow consumers
like KVM to detect Topdown support.

Opportunistically fix a typo in the comment. 

Fixes: f83d2f91d259 ("perf/x86/intel: Add Alder Lake Hybrid support")
Signed-off-by: Zide Chen <zide.chen@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
v10: new patch.
---
 arch/x86/events/intel/core.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index dbd84d82f36d..44bede63f0c6 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -6280,11 +6280,23 @@ static void intel_update_pmu_caps(struct pmu *pmu)
 
 		/*
 		 * Restore perf_metrics on platforms with broken
-		 * perf_capablities.
+		 * perf_capabilities.
 		 */
 		if (intel_pmu_broken_perf_cap() &&
-		    hybrid_pmu(pmu)->pmu_type == hybrid_big)
+		    hybrid_pmu(pmu)->pmu_type == hybrid_big) {
 			hybrid(pmu, intel_cap).perf_metrics = 1;
+			if (!cpu_feature_enabled(X86_FEATURE_HYBRID_CPU))
+				x86_pmu.intel_cap.perf_metrics = 1;
+		}
+
+		/*
+		 * For hybrid, x86_pmu.intel_cap tracks common capabilities
+		 * across all online PMU types. A bitwise AND is safe because
+		 * multi-bit PEBS/LBR format fields are identical across core
+		 * types when supported, or zero if unsupported on a core.
+		 */
+		x86_pmu.intel_cap.capabilities &=
+			hybrid(pmu, intel_cap).capabilities;
 	}
 }
 
@@ -7746,14 +7758,10 @@ static __always_inline int intel_pmu_init_hybrid(enum hybrid_pmu_type pmus)
 				     __EVENT_CONSTRAINT(0, pmu->cntr_mask64,
 							0, x86_pmu_num_counters(&pmu->pmu), 0, 0);
 
-		pmu->intel_cap.capabilities = x86_pmu.intel_cap.capabilities;
-		if (pmu->pmu_type & hybrid_small_tiny) {
-			pmu->intel_cap.perf_metrics = 0;
+		if (pmu->pmu_type & hybrid_small_tiny)
 			pmu->mid_ack = true;
-		} else if (pmu->pmu_type & hybrid_big) {
-			pmu->intel_cap.perf_metrics = 1;
+		else if (pmu->pmu_type & hybrid_big)
 			pmu->late_ack = true;
-		}
 	}
 
 	return 0;
-- 
2.56.1


  parent reply	other threads:[~2026-11-24 21:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 21:38 [PATCH v10 00/18] KVM: x86/pmu: Add hardware Topdown metrics support Zide Chen
2026-11-24 21:38 ` [PATCH v10 01/18] perf/x86: Add INTEL_TD_METRIC_FIELD_{BITS,MASK} constants Zide Chen
2026-11-24 21:38 ` [PATCH v10 02/18] perf/x86/intel: Do not inflate capabilities for guests Zide Chen
2026-11-24 21:38 ` Zide Chen [this message]
2026-11-24 21:38 ` [PATCH v10 04/18] perf/x86: Expose perf_capabilities to KVM Zide Chen
2026-11-24 21:38 ` [PATCH v10 05/18] perf/x86: Expose number of Topdown metric events " Zide Chen
2026-11-24 21:38 ` [PATCH v10 06/18] KVM: x86/pmu: Do not map fixed counters >= 3 to generic perf events Zide Chen
2026-11-24 21:38 ` [PATCH v10 07/18] KVM: x86/pmu: Query perf-reported capabilities instead of RDMSR Zide Chen
2026-11-24 21:38 ` [PATCH v10 08/18] KVM: x86/pmu: Rename and move vcpu_get_perf_capabilities() to pmu.h Zide Chen
2026-11-24 21:38 ` [PATCH v10 09/18] KVM: x86/pmu: Mask only OS/USR bits when filtering fixed counters Zide Chen
2026-11-24 21:38 ` [PATCH v10 10/18] KVM: x86/pmu: Block PMU passthrough if guest lacks PERF_METRICS Zide Chen
2026-11-24 21:38 ` [PATCH v10 11/18] KVM: x86/pmu: Support Intel fixed counter 3 on mediated vPMU Zide Chen
2026-11-24 21:38 ` [PATCH v10 12/18] KVM: x86/pmu: Move RDPMC emulation into per-vendor callbacks Zide Chen
2026-11-24 21:38 ` [PATCH v10 13/18] KVM: x86/pmu: Emulate RDPMC on performance metrics Zide Chen
2026-11-24 21:38 ` [PATCH v10 14/18] KVM: x86/pmu: Support PERF_METRICS MSR in mediated vPMU Zide Chen
2026-11-24 21:38 ` [PATCH v10 15/18] KVM: x86/pmu: Support RDPMC Metrics Clear Mode Zide Chen
2026-11-24 21:38 ` [PATCH v10 16/18] KVM: selftests: Rework PMU guest measurement asm operands Zide Chen
2026-11-24 21:39 ` [PATCH v10 17/18] KVM: selftests: Move and generalize PMU guest measurement helpers Zide Chen
2026-11-24 21:39 ` [PATCH v10 18/18] KVM: selftests: Add Topdown PERF_METRICS test Zide Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124213901.120572-4-zide.chen@intel.com \
    --to=zide.chen@intel.com \
    --cc=Manali.Shukla@amd.com \
    --cc=Sandipan.Das@amd.com \
    --cc=ak@linux.intel.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mizhang@google.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=xudong.hao@intel.com \
    --cc=yosry@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox