The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Zide Chen <zide.chen@intel.com>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: kvm@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
	Jim Mattson <jmattson@google.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 07/23] perf/x86: Apply PMU partition mask on static constraints
Date: Wed, 26 Aug 2026 16:12:00 +0800	[thread overview]
Message-ID: <09251cc4-c795-411c-a9d9-9133a0d73e03@linux.intel.com> (raw)
In-Reply-To: <20260821222002.54907-8-zide.chen@intel.com>

It seems not a good practice for me to modify all the places calling these
static constraints. We could have to add new get_event_constraints()
helpers for future platforms, and we have to duplicate these
part_constraint() code.

Could we leverage the dynamic constraint mechanism?  We can set the
event->hw.dyn_constraint to be host counters mask, then we don't need any
specific change for these static constraints.

Thanks.

On 8/22/2026 6:19 AM, Zide Chen wrote:
> Static, counter-specific constraints used for attr.precise_ip == 3, or
> other special cases bypass intel_get_event_constraints(), which is
> where partition_mask is applied via dyn_constraint().
>
> As a result, such a host !exclude_guest event can still be scheduled
> onto a counter that partition_mask reserves for the guest, causing
> host and guest to share the same hardware counter.
>
> Some of these static constraint paths, e.g. glp or cmt, are currently
> only reachable on platforms that don't support PerfMon masking. Still,
> apply part_constraint() to all of them uniformly, so future platforms
> that combine PerfMon masking with these constraint paths are not
> silently exposed to this bug.
>
> Signed-off-by: Zide Chen <zide.chen@intel.com>
> ---
>  arch/x86/events/intel/core.c | 39 +++++++++++++++++++++++-------------
>  1 file changed, 25 insertions(+), 14 deletions(-)
>
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 7951accfcf2c..0f76e56fd2db 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -4459,6 +4459,9 @@ dyn_constraint(struct cpu_hw_events *cpuc, struct event_constraint *c, int idx)
>   * Mask out guest-owned counters from a constraint when PMU partition has been
>   * entered, so !exclude_guest host events are not scheduled onto them while
>   * the CPU is in non-root mode.
> + *
> + * This is also used by PMU-specific get_event_constraints() wrappers
> + * that hard-code a static, counter-specific constraint.
>   */
>  static struct event_constraint *
>  part_constraint(struct cpu_hw_events *cpuc, int idx,
> @@ -5568,7 +5571,7 @@ hsw_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
>  	/* Handle special quirk on in_tx_checkpointed only in counter 2 */
>  	if (event->hw.config & HSW_IN_TX_CHECKPOINTED) {
>  		if (c->idxmsk64 & (1U << 2))
> -			return &counter2_constraint;
> +			return part_constraint(cpuc, idx, event, &counter2_constraint);
>  		return &emptyconstraint;
>  	}
>  
> @@ -5585,7 +5588,7 @@ icl_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
>  	 */
>  	if ((event->attr.precise_ip == 3) &&
>  	    constraint_match(&fixed0_constraint, event->hw.config))
> -		return &fixed0_constraint;
> +		return part_constraint(cpuc, idx, event, &fixed0_constraint);
>  
>  	return hsw_get_event_constraints(cpuc, idx, event);
>  }
> @@ -5607,7 +5610,7 @@ glc_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
>  	if ((event->attr.precise_ip == 3) &&
>  	    !constraint_match(&fixed0_constraint, event->hw.config)) {
>  		if (c->idxmsk64 & BIT_ULL(0))
> -			return &counter0_constraint;
> +			return part_constraint(cpuc, idx, event, &counter0_constraint);
>  
>  		return &emptyconstraint;
>  	}
> @@ -5623,7 +5626,7 @@ glp_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
>  
>  	/* :ppp means to do reduced skid PEBS which is PMC0 only. */
>  	if (event->attr.precise_ip == 3)
> -		return &counter0_constraint;
> +		return part_constraint(cpuc, idx, event, &counter0_constraint);
>  
>  	c = intel_get_event_constraints(cpuc, idx, event);
>  
> @@ -5645,9 +5648,9 @@ tnt_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
>  	if (event->attr.precise_ip == 3) {
>  		/* Force instruction:ppp on PMC0 and Fixed counter 0 */
>  		if (constraint_match(&fixed0_constraint, event->hw.config))
> -			return &fixed0_counter0_constraint;
> +			return part_constraint(cpuc, idx, event, &fixed0_counter0_constraint);
>  
> -		return &counter0_constraint;
> +		return part_constraint(cpuc, idx, event, &counter0_constraint);
>  	}
>  
>  	return c;
> @@ -5705,22 +5708,30 @@ cmt_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
>  	if (event->attr.precise_ip == 3) {
>  		/* Force instruction:ppp on PMC0, 1 and Fixed counter 0 */
>  		if (constraint_match(&fixed0_constraint, event->hw.config)) {
> +			c = &fixed0_counter0_1_constraint;
> +
>  			/* The fixed counter 0 doesn't support LBR event logging. */
>  			if (branch_sample_counters(event))
> -				return &counter0_1_constraint;
> -			else
> -				return &fixed0_counter0_1_constraint;
> +				c = &counter0_1_constraint;
> +
> +			return part_constraint(cpuc, idx, event, c);
>  		}
>  
>  		switch (c->idxmsk64 & 0x3ull) {
>  		case 0x1:
> -			return &counter0_constraint;
> +			c = &counter0_constraint;
> +			break;
>  		case 0x2:
> -			return &counter1_constraint;
> +			c = &counter1_constraint;
> +			break;
>  		case 0x3:
> -			return &counter0_1_constraint;
> +			c = &counter0_1_constraint;
> +			break;
> +		default:
> +			c = &emptyconstraint;
> +			break;
>  		}
> -		return &emptyconstraint;
> +		return part_constraint(cpuc, idx, event, c);
>  	}
>  
>  	return c;
> @@ -5744,7 +5755,7 @@ rwc_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
>  		 */
>  		if (event->attr.precise_ip == 3)
>  			return &emptyconstraint;
> -		return &counters_1_7_constraint;
> +		return part_constraint(cpuc, idx, event, &counters_1_7_constraint);
>  	}
>  
>  	return c;

  reply	other threads:[~2026-08-26  8:12 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 22:19 [PATCH 00/23] perf/KVM: Support PMU partitioning for x86 platforms Zide Chen
2026-08-21 22:19 ` [PATCH 01/23] perf/x86/intel: Guard counter masks against zero counters Zide Chen
2026-08-26  7:53   ` Mi, Dapeng
2026-08-21 22:19 ` [PATCH 02/23] perf, perf/x86: Pass partition mask from KVM to perf/x86 Zide Chen
2026-08-21 22:19 ` [PATCH 03/23] perf/x86: Add GUEST_PMU states for PMU partitioning Zide Chen
2026-08-21 22:19 ` [PATCH 04/23] perf/x86: Split host/guest PMI handling under " Zide Chen
2026-08-21 22:19 ` [PATCH 05/23] perf/x86: Allow exclude_host events to run in non-root mode Zide Chen
2026-08-21 22:19 ` [PATCH 06/23] perf/x86: Restrict !exclude_guest events to host-owned counters Zide Chen
2026-08-21 22:19 ` [PATCH 07/23] perf/x86: Apply PMU partition mask on static constraints Zide Chen
2026-08-26  8:12   ` Mi, Dapeng [this message]
2026-08-21 22:19 ` [PATCH 08/23] perf/x86: Export available PMU counters to sysfs Zide Chen
2026-08-21 22:19 ` [PATCH 09/23] perf: Skip exclude_guest events on PMU partitioned counters Zide Chen
2026-08-21 22:19 ` [PATCH 10/23] perf: Reschedule events across PMU partition transitions Zide Chen
2026-08-21 22:19 ` [PATCH 11/23] perf, perf/x86: Allow host !exclude_guest events in PMU partitioning Zide Chen
2026-08-21 22:19 ` [PATCH 12/23] KVM: x86/pmu: Add the perfmon_mask module parameter Zide Chen
2026-08-26  8:18   ` Mi, Dapeng
2026-08-21 22:19 ` [PATCH 13/23] KVM: x86/pmu: Set up the PERFMON_MASK VMCS field Zide Chen
2026-08-21 22:19 ` [PATCH 14/23] KVM: x86/pmu, perf/x86: Update effective PMU partition mask Zide Chen
2026-08-21 22:19 ` [PATCH 15/23] KVM: x86/pmu: Relax MSR intercept policy under PerfMon masking Zide Chen
2026-08-21 22:19 ` [PATCH 16/23] KVM: x86/pmu: Handle FIXED_CTR_CTRL " Zide Chen
2026-08-26  8:43   ` Mi, Dapeng
2026-08-21 22:19 ` [PATCH 17/23] KVM: x86/pmu: Handle GLOBAL_CTRL " Zide Chen
2026-08-21 22:19 ` [PATCH 18/23] KVM: x86/pmu: Handle GLOBAL_STATUS MSRs " Zide Chen
2026-08-21 22:19 ` [PATCH 19/23] KVM: x86/pmu: Always intercept GLOBAL_INUSE " Zide Chen
2026-08-21 22:19 ` [PATCH 20/23] KVM: x86/pmu: Request guest PMI for guest-induced PMIs Zide Chen
2026-08-21 22:20 ` [PATCH 21/23] KVM: x86/pmu: Enable PerfMon masking Zide Chen
2026-08-21 22:20 ` [PATCH 22/23] KVM: selftests: Fix PERF_METRICS test by checking FC3 availability Zide Chen
2026-08-21 22:20 ` [PATCH 23/23] KVM: selftests: Allow no general purpose counters on the host Zide Chen
2026-08-26  7:52 ` [PATCH 00/23] perf/KVM: Support PMU partitioning for x86 platforms Mi, Dapeng

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=09251cc4-c795-411c-a9d9-9133a0d73e03@linux.intel.com \
    --to=dapeng1.mi@linux.intel.com \
    --cc=Manali.Shukla@amd.com \
    --cc=Sandipan.Das@amd.com \
    --cc=ak@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=zide.chen@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