Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: "Chen, Zide" <zide.chen@intel.com>
To: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>,
	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>,
	Andi Kleen <ak@linux.intel.com>,
	Stephane Eranian <eranian@google.com>,
	linux-kernel@vger.kernel.org, Mingwei Zhang <mizhang@google.com>,
	Das Sandipan <Sandipan.Das@amd.com>,
	Shukla Manali <Manali.Shukla@amd.com>,
	Xudong Hao <xudong.hao@intel.com>
Subject: Re: [PATCH v9 09/12] perf/x86: Add INTEL_TD_METRIC_FIELD_{BITS,MASK} constants
Date: Tue, 27 Oct 2026 16:39:16 -0500	[thread overview]
Message-ID: <8bb51068-461d-4eba-8e4c-0adf35a80839@intel.com> (raw)
In-Reply-To: <b73ffa7d-29ce-44b3-be1c-88068fc2f443@linux.intel.com>



On 9/21/2026 2:01 AM, Mi, Dapeng wrote:
> 
> On 9/19/2026 3:39 AM, Zide Chen wrote:
>> Replace the hard coded field width (8) and the equivalent 0xff mask
>> used for PERF_METRICS MSR field access with named constants
>> INTEL_TD_METRIC_FIELD_{BITS,MASK}.
>>
>> INTEL_TD_METRIC_FIELD_BITS will be used by a subsequent KVM patch to
>> validat reserved bits in the PERF_METRICS MSR.
>>
>> No functional change intended.
>>
>> Signed-off-by: Zide Chen <zide.chen@intel.com>
>> Cc: Peter Zijlstra <peterz@infradead.org>
>> ---
>> v9: new patch.
>> ---
>>  arch/x86/events/intel/core.c      | 8 +++++---
>>  arch/x86/include/asm/perf_event.h | 4 ++++
>>  2 files changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
>> index cc13164d948f..cbc9a179f2e5 100644
>> --- a/arch/x86/events/intel/core.c
>> +++ b/arch/x86/events/intel/core.c
>> @@ -3159,6 +3159,7 @@ DEFINE_STATIC_CALL(intel_pmu_set_topdown_event_period, x86_perf_event_set_period
>>  
>>  static inline u64 icl_get_metrics_event_value(u64 metric, u64 slots, int idx)
>>  {
>> +	int shift = (idx - INTEL_PMC_IDX_METRIC_BASE) * INTEL_TD_METRIC_FIELD_BITS;
>>  	u32 val;
>>  
>>  	/*
>> @@ -3166,8 +3167,8 @@ static inline u64 icl_get_metrics_event_value(u64 metric, u64 slots, int idx)
>>  	 * summing up to 0xff.
>>  	 * slots-in-metric = (Metric / 0xff) * slots
>>  	 */
>> -	val = (metric >> ((idx - INTEL_PMC_IDX_METRIC_BASE) * 8)) & 0xff;
>> -	return  mul_u64_u32_div(slots, val, 0xff);
>> +	val = (metric >> shift) & INTEL_TD_METRIC_FIELD_MASK;
>> +	return mul_u64_u32_div(slots, val, INTEL_TD_METRIC_FIELD_MASK);
>>  }
>>  
>>  static u64 icl_get_topdown_value(struct perf_event *event,
>> @@ -4742,7 +4743,8 @@ static int core_pmu_hw_config(struct perf_event *event)
>>  }
>>  
>>  #define INTEL_TD_METRIC_AVAILABLE_MAX	(INTEL_TD_METRIC_RETIRING + \
>> -					 ((x86_pmu.num_topdown_events - 1) << 8))
>> +					 ((x86_pmu.num_topdown_events - 1) << \
>> +					  INTEL_TD_METRIC_FIELD_BITS))
> 
> Sashiko comments,
> 
> "
> 
> Is it safe to replace the UMASK shift here with the hardware MSR metric
> field width?
> The original << 8 was used to shift the metric ID into the UMASK field
> (bits 8-15) of the software perf event configuration (attr.config).
> INTEL_TD_METRIC_FIELD_BITS represents the hardware width of metrics within
> the PERF_METRICS MSR.
> When evaluated in is_available_metric_event() during perf_event_open(), this
> currently functions because both values are 8. However, conflating a software
> API layout offset with a hardware register field width could cause this macro
> to calculate an invalid configuration mask if the MSR field width changes in
> future hardware.
> 
> "
> 
> It looks reasonable, we either don't change this, or define a macro to
> represent the UMASK shift. Thanks.

Yes, I can revert this change.

  reply	other threads:[~2026-10-27 21:39 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 19:39 [PATCH v9 00/12] KVM: x86/pmu: Add hardware Topdown metrics support Zide Chen
2026-09-18 19:39 ` [PATCH v9 01/12] KVM: x86/pmu: Do not map fixed counters >= 3 to generic perf events Zide Chen
2026-09-18 19:39 ` [PATCH v9 02/12] KVM: x86/pmu: Support Intel fixed counter 3 on mediated vPMU Zide Chen
2026-09-18 19:39 ` [PATCH v9 03/12] KVM: x86/pmu: Rename and move vcpu_get_perf_capabilities() to pmu.h Zide Chen
2026-09-18 19:39 ` [PATCH v9 04/12] KVM: x86/pmu: Snapshot host IA32_PERF_CAPABILITIES in kvm_host Zide Chen
2026-09-18 19:39 ` [PATCH v9 05/12] KVM: x86/pmu: Support PERF_METRICS MSR in mediated vPMU Zide Chen
2026-10-23 18:27   ` Jim Mattson
2026-10-27 21:30     ` Chen, Zide
2026-09-18 19:39 ` [PATCH v9 06/12] KVM: x86/pmu: Move RDPMC emulation into per-vendor callbacks Zide Chen
2026-09-18 19:39 ` [PATCH v9 07/12] KVM: x86/pmu: Emulate RDPMC on performance metrics Zide Chen
2026-10-23 18:33   ` Jim Mattson
2026-09-18 19:39 ` [PATCH v9 08/12] KVM: selftests: Add PERF_METRICS and fixed counter 3 tests Zide Chen
2026-09-18 20:08   ` sashiko-bot
2026-09-18 20:45     ` Chen, Zide
2026-09-18 19:39 ` [PATCH v9 09/12] perf/x86: Add INTEL_TD_METRIC_FIELD_{BITS,MASK} constants Zide Chen
2026-09-18 19:59   ` sashiko-bot
2026-09-18 20:45     ` Chen, Zide
2026-09-21  7:01   ` Mi, Dapeng
2026-10-27 21:39     ` Chen, Zide [this message]
2026-09-18 19:39 ` [PATCH v9 10/12] perf/x86: Expose number of Topdown metric events to KVM Zide Chen
2026-09-21  7:06   ` Mi, Dapeng
2026-09-18 19:39 ` [PATCH v9 11/12] KVM: x86/pmu: Reject writes to reserved MSR_PERF_METRICS bits Zide Chen
2026-09-21  7:11   ` Mi, Dapeng
2026-10-23 18:45   ` Jim Mattson
2026-10-27 22:09     ` Chen, Zide
2026-09-18 19:39 ` [PATCH v9 12/12] KVM: x86/pmu: Support RDPMC Metrics Clear Mode Zide Chen
2026-09-18 20:22   ` sashiko-bot
2026-09-18 21:08     ` Chen, Zide
2026-09-21  9:39     ` Mi, Dapeng
2026-10-27 22:56       ` Chen, Zide
2026-10-23 18:55   ` Jim Mattson
2026-10-27 22:17     ` Chen, Zide

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=8bb51068-461d-4eba-8e4c-0adf35a80839@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 \
    /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