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 v3 1/4] perf/core: Do not account overflows of a throttled event
Date: Thu, 03 Dec 2026 06:56:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-247257@kernel.org> (raw)
In-Reply-To: <20261203062703.15346-2-john3@mailbox.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] perf/core: __perf_event_account_interrupt() returns 0 when
  already throttled
--

commit 40d109737111a5945f5515a646e8889ee1a090bc
Author: Oancea Catalin <john3@mailbox.org>

perf/core: Do not account overflows of a throttled event

This commit adds an early return to __perf_event_account_interrupt() when
hwc->interrupts is already MAX_INTERRUPTS, so reporting a pending overflow
for an already-throttled event does not overwrite the throttle marker.

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4ab3919ac78e9..cfe9ec01fdffa 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -10773,6 +10773,15 @@ __perf_event_account_interrupt(struct perf_event *event, int throttle,
>  	int ret = 0;
>  	u64 seq;
>  
> +	/*
> +	 * A PMU handler can report an overflow which was pending when a
> +	 * throttle stopped the event together with its group. Accounting it
> +	 * would overwrite MAX_INTERRUPTS, and the tick would no longer
> +	 * unthrottle the group if the event is its leader.
> +	 */
> +	if (unlikely(hwc->interrupts == MAX_INTERRUPTS))
> +		return 0;
> +
>  	seq = __this_cpu_read(perf_throttled_seq);
>  	if (seq != hwc->interrupts_seq) {
>  		hwc->interrupts_seq = seq;

[Severity: High]
Should this return 1 instead of 0 when hwc->interrupts == MAX_INTERRUPTS?

Callers of __perf_event_account_interrupt() and __perf_event_overflow()
expect a non-zero return value whenever the event is throttled.  For
example, perf_swevent_overflow() runs with IRQs disabled and relies on a
non-zero return to break out of its overflow loop:

kernel/events/core.c:perf_swevent_overflow() {
	for (; overflow; overflow--) {
		if (__perf_event_overflow(event, throttle,
					    data, regs)) {
			/*
			 * We inhibit the overflow from happening when
			 * hwc->interrupts == MAX_INTERRUPTS.
			 */
			break;
		}
		throttle = 1;
	}
}

If a grouped hardware sibling NMI throttles a tracepoint event with a large
overflow count (such as sched:sched_stat_*) during that loop, returning 0
prevents the loop from breaking while IRQs are disabled and can cause a hard
lockup.

Returning 0 also breaks other callers that check the throttled return value:
perf_swevent_hrtimer() will re-arm a throttled hrtimer instead of returning
HRTIMER_NORESTART, perf_ibs_handle_irq() in arch/x86/events/amd/ibs.c can
re-enable IBS hardware while perf_ibs_stop() is marking it stopped, and
hw_collect_samples() in arch/s390/kernel/perf_cpum_sf.c will keep delivering
samples and skip backing off the sampling rate.

Returning 1 here still lets __perf_event_overflow() deliver the pending
sample while signaling the throttled state to callers.

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

  reply	other threads:[~2026-12-03  6:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  6:26 [PATCH v3 0/4] perf/x86: Handle overflows of counters stopped by a throttle Oancea Catalin
2026-12-03  6:27 ` [PATCH v3 1/4] perf/core: Do not account overflows of a throttled event Oancea Catalin
2026-12-03  6:56   ` sashiko-bot [this message]
2026-12-03  6:27 ` [PATCH v3 2/4] perf/x86/amd/core: Handle overflows of counters stopped by a throttle Oancea Catalin
2026-12-03  6:27 ` [PATCH v3 3/4] perf/x86: " Oancea Catalin
2026-12-03  6:27 ` [PATCH v3 4/4] perf/x86/intel: " Oancea Catalin
2026-12-03  6:56 ` [PATCH v3 0/4] perf/x86: " 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-247257@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