Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oancea Catalin" <john3@mailbox.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v5 1/8] perf/core: Disable the PMU of the context in __perf_event_period()
Date: Sat, 05 Dec 2026 13:58:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-251611@kernel.org> (raw)
In-Reply-To: <20261205133221.3294-2-john3@mailbox.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf/core: __perf_event_period() skips disabling event->pmu
  in mixed groups
- [Medium] perf/core: __perf_event_period() stops disabling event->pmu
  in mixed groups
--

commit 54df77548d2b0f131559f285443e4651cf45fd41
Author: Oancea Catalin <john3@mailbox.org>

perf/core: Disable the PMU of the context in __perf_event_period()

This commit changes __perf_event_period() to disable and re-enable
event->pmu_ctx->pmu instead of event->pmu while updating the period and
unthrottling the event's group.

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4ab3919ac78e9..da4f217d633e1 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -6564,7 +6564,12 @@ static void __perf_event_period(struct perf_event *event,
>  
>  	active = (event->state == PERF_EVENT_STATE_ACTIVE);
>  	if (active) {
> -		perf_pmu_disable(event->pmu);
> +		/*
> +		 * Disable the PMU of the context, which for a software event in
> +		 * a group with hardware events is theirs: their NMI must not
> +		 * throttle the group while it is unthrottled below.
> +		 */
> +		perf_pmu_disable(event->pmu_ctx->pmu);
>  		event->pmu->stop(event, PERF_EF_UPDATE);
>  	}

[Severity: Medium]
Should __perf_event_period() still disable event->pmu in addition to
event->pmu_ctx->pmu?

When a perf_sw_context event is grouped with a hardware PMU, event->pmu
differs from event->pmu_ctx->pmu.  On s390, cf_diag uses perf_sw_context
and can be grouped with cpumf_sampling, while cpumf_pmu_stop() and
cpumf_pmu_start() rely on cpumf_pmu_disable()/enable() to execute lcctl().

Skipping perf_pmu_disable(event->pmu) and perf_pmu_enable(event->pmu)
causes cfdiag_getctr() to read live un-paused counters and can leave
hardware counter sets stopped while the event believes it is active.

Because perf_tp_event_match() gates on perf_pmu_enabled(event->pmu), a
grouped tracepoint such as msr:write_msr (from x86_pmu_start()) can also
fire during perf_event_unthrottle_group() and throttle the group mid-walk,
hitting WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)).

Commit "perf/core: Stop an event which overflows while it is throttled"
moves event->pmu->start() after perf_event_unthrottle_group(), mitigating
re-entry on event itself, but still leaves event->pmu enabled and does not
fix the s390 cf_diag regression.

Nesting perf_pmu_disable(event->pmu) and perf_pmu_enable(event->pmu) inside
the event->pmu_ctx->pmu calls, as event_sched_in() and event_sched_out()
do, avoids both regressions.

> @@ -6580,7 +6585,7 @@ static void __perf_event_period(struct perf_event *event,
>  		 */
>  		if (event->hw.interrupts == MAX_INTERRUPTS)
>  			perf_event_unthrottle_group(event, true);
> -		perf_pmu_enable(event->pmu);
> +		perf_pmu_enable(event->pmu_ctx->pmu);
>  	}
>  }

[Severity: Medium]
Can leaving event->pmu enabled here let a perf_kprobe sibling throttle the
group during perf_event_unthrottle_group()?

In a hardware group containing two perf_kprobe siblings and two hardware
siblings, where kprobe2 is attached to perf_event_update_userpage(),
calling PERF_EVENT_IOC_PERIOD on throttled kprobe1 no longer disables
&perf_kprobe, so perf_tp_event_match() still sees event->pmu as enabled:

__perf_event_period(kprobe1)
  perf_pmu_disable(hw_pmu)
  perf_event_unthrottle_group(kprobe1, true)
    perf_event_unthrottle(kprobe2, true)
    perf_event_unthrottle(hw_sibling1, true)
      x86_pmu_start(hw_sibling1, 0)
        perf_event_update_userpage()
          <kprobe2 fires synchronously>
            ... -> perf_swevent_overflow()
              perf_event_throttle_group()  <-- re-throttles group
    perf_event_unthrottle(hw_sibling2, true)  <-- starts while throttled

Returning from the kprobe lets perf_event_unthrottle_group() start
hw_sibling2 in a throttled group, so the next unthrottle hits
WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)) in x86_pmu_start().

Even after commit "perf/core: Stop an event which overflows while it is
throttled", this path still re-throttles the group mid-walk and also lets
__perf_event_period() start kprobe1 with hw.throttled set.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205133221.3294-1-john3@mailbox.org?part=1

  reply	other threads:[~2026-12-05 13:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 13:32 [PATCH v5 0/8] perf/x86: Handle overflows of counters stopped by a throttle Oancea Catalin
2026-12-05 13:32 ` [PATCH v5 1/8] perf/core: Disable the PMU of the context in __perf_event_period() Oancea Catalin
2026-12-05 13:58   ` sashiko-bot [this message]
2026-12-05 13:32 ` [PATCH v5 2/8] perf/core: Do not account overflows of a throttled event Oancea Catalin
2026-12-05 13:32 ` [PATCH v5 3/8] perf/x86/amd/core: Handle overflows of counters stopped by a throttle Oancea Catalin
2026-12-05 13:32 ` [PATCH v5 4/8] perf/x86: " Oancea Catalin
2026-12-05 13:32 ` [PATCH v5 5/8] perf/x86/intel: " Oancea Catalin
2026-12-05 13:32 ` [PATCH v5 6/8] perf/core: Keep the throttle mark out of hwc->interrupts Oancea Catalin
2026-12-05 13:57   ` sashiko-bot
2026-12-05 13:32 ` [PATCH v5 7/8] perf/core: Throttle an event only once Oancea Catalin
2026-12-05 13:32 ` [PATCH v5 8/8] perf/core: Stop an event which overflows while it is throttled Oancea Catalin
2026-12-05 14:24   ` sashiko-bot
2026-12-05 14:24 ` [PATCH v5 0/8] perf/x86: Handle overflows of counters stopped by a throttle sashiko-bot

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=sashiko-outbox-251611@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=john3@mailbox.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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