From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796480698; b=MMU+0E8dReZR2+wb76W2/N+OVeaADTeRuSNGVoyrv6V5EAbBRfWE7KgAMDX9pMJ2umVq h2smmo54iBayfOpqGSE+bX/pzuKSNI3k0yziv6V5tuifICYzmeGsqLAbsHg2Oe6tMRFmk pwIpkPtdNwFnfTtTtDhfZckGLhSxF1uKY3bcuGtG9nyLGqhZ0o0wWcY3ORslPEupJclo3 EC3OfxFjNKVbcxSQCJvQJ9DknqZBjhWMFjQ8nESqJBy0pkZ+No/L5e/4E6a7SlD39skxK OOQ/H+khLZBMXXa6i1qn/k7yUhtu2EsE/ORBzhTuDVSFHZYzgRzA04qpAuboAjgBOlQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796480698; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=+qXYuiupfxSFKWkgWfEPJeD2n4UMnWgEIQTosikHuo4=; b=UkDIwhPjJK4jt31RhaL/w2kVZROoQl8ItMBP5TZ2gYG8UzoSjSlsd1H324G3SZKAF0Gi qGd36yAb3DC4aGAt4z7YVLgTEoTnxuiPtsWFhofFNIfeixs/9+hAPMBXZDJ85PQ3v7Nny uy1EeOh1vSOl5c+kvI2rOZ5X0c8S7CrrPrMLIrUbTDi5QOVQ5gzyjd90f2RRJmgcAM5Ib EXABNBXxAxMzvo2vVKZ/4XIi6CIULZqED6GsTWsn3BdG0tINJKsMDgDa/WjGTKdWniSZ+ FTp+MvL6SbmwPswUQ4vZg9IIMJUKW84N2UbxcZ5n3W4qk5UK+xMZ4y2oGm35Ye9khAA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HUYE0Ap3; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D77EA60A2638 for ; Sat, 5 Dec 2026 14:24:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HUYE0Ap3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A8D71F0182B; Sat, 5 Dec 2026 14:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796480698; bh=+qXYuiupfxSFKWkgWfEPJeD2n4UMnWgEIQTosikHuo4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HUYE0Ap39HQ3RL0memG6G94TXVtzJrsaMEOq0f74hAB4Gl5cIgJ7A9S4z40QBltrG PMjgCDFEjW4iBi15gz/FFSoF+slewp1wkoVhod5rlet86YOYBFU/QSnkNi6TpFuCz7 y0fu8/4MBk8hEQ5OpL8aCefYEjwnpx4PdZQd0ZSaC13KHkOMZc5fIOI+Ol8CpE8te6 MRM+EafLCY2JTjAPKbI2QWOksqF7+OD/S7efYh4L5FhsCIWhenQD1yKKoNRHi9ut9y yHIw8SaReDnKHo5/eX2BVhKL7RPKGkoc0Ow3M/wnx6OR3dqrcjSLWpfxjrmNZCWmjx Iz9Bmzb2U7Mhw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 8/8] perf/core: Stop an event which overflows while it is throttled Reply-To: sashiko-reviews@lists.linux.dev To: "Oancea Catalin" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261205133221.3294-9-john3@mailbox.org> References: <20261205133221.3294-1-john3@mailbox.org> <20261205133221.3294-9-john3@mailbox.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 14:24:58 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] perf/core: perf_throttling guard misses non-throttle x86_pmu_stop() callers - [Medium] perf/core: unthrottle-vs-NMI race still starts events with hw.throttled set -- commit 4a662d074649b317ca9a70b8242cd52b4a4419b2 Author: Oancea Catalin perf/core: Stop an event which overflows while it is throttled This commit stops a throttled event in __perf_event_account_interrupt() when it overflows outside perf_event_throttle_group(), using a per-CPU perf_throttling counter to avoid nesting stops during a group throttle walk. It also moves perf_event_unthrottle_group() before event->pmu->start() in __perf_event_period(). > diff --git a/kernel/events/core.c b/kernel/events/core.c > index fdc7335c7321b..9706c2ea69f4f 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c [ ... ] > @@ -6581,15 +6586,17 @@ static void __perf_event_period(struct perf_event= *event, > local64_set(&event->hw.period_left, 0); > =20 > if (active) { > - event->pmu->start(event, PERF_EF_RELOAD); > /* > * Once the period is force-reset, the event starts immediately. > * But the event/group could be throttled. Unthrottle the > * event/group now to avoid the next tick trying to unthrottle > - * while we already re-started the event/group. > + * while we already re-started the event/group. Do that before > + * the start: an event which overflows while it is throttled is > + * stopped, and nothing would start it again. > */ > if (event->hw.throttled) > perf_event_unthrottle_group(event, true); > + event->pmu->start(event, PERF_EF_RELOAD); > perf_pmu_enable(event->pmu_ctx->pmu); > } > } [Severity: Medium] Does moving perf_event_unthrottle_group() before event->pmu->start() open the same unthrottle-vs-NMI window here, while stopping reactively on overflow still leaves events running with hw.throttled set? An NMI that throttles the group between clearing hw.throttled and calling pmu->start() (in perf_event_unthrottle() or __perf_event_period()) starts the event with hw.throttled set. Non-sampling siblings return early at !is_sampling_event(event) in __perf_event_overflow(), so they never reach __perf_event_account_interrupt() and keep counting across the throttled interval, skewing group counts. Whenever the next tick or __perf_event_period() unthrottles the group before an overflow (or for any non-sampling sibling), perf_event_unthrottle() calls pmu->start() on an already-running event and hits WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)) in x86_pmu_start(). Closing the window at the unthrottle and start sites instead -- for example, WRITE_ONCE(event->hw.throttled, 0) and barrier() before pmu->start(), followed by re-checking READ_ONCE(event->hw.throttled) and calling pmu->stop(event, 0) while perf_pmu_disable() is held -- would avoid leaving events running while throttled. [ ... ] > @@ -10788,9 +10795,16 @@ __perf_event_account_interrupt(struct perf_event= *event, int throttle, > * perf_event_throttle() has stopped it, or one that was pending when > * it was stopped. Do not account it, that could throttle the group a > * second time. > + * > + * Nothing would throttle an event which counts with the mark set, so > + * stop it here. Not inside a throttle on this CPU: that one stops the > + * events it has marked itself. > */ > - if (unlikely(hwc->throttled)) > + if (unlikely(hwc->throttled)) { > + if (!__this_cpu_read(perf_throttling)) > + event->pmu->stop(event, 0); > return 1; > + } [Severity: Medium] Can this re-enter x86_pmu_stop() from an NMI when a non-throttle caller is already stopping the event? perf_throttling is only incremented in perf_event_throttle_group(), leaving callers such as __perf_event_period() and event_sched_out() unguarded. In x86_pmu_stop(), cpuc->active_mask remains set across x86_pmu_disable() before PERF_HES_STOPPED is set, and on AMD amd_pmu_disable_event() explicitly waits for a pending overflow NMI there via amd_pmu_wait_on_overflow(): __perf_event_period() x86_pmu_stop(event, PERF_EF_UPDATE) test_bit(hwc->idx, cpuc->active_mask) x86_pmu_disable(event) perf_event_overflow() __perf_event_account_interrupt() /* hwc->throttled !=3D 0, perf_throttling =3D=3D 0 */ x86_pmu_stop(event, 0) x86_pmu_disable(event) __clear_bit(hwc->idx, cpuc->active_mask) hwc->state |=3D PERF_HES_STOPPED __clear_bit(hwc->idx, cpuc->active_mask) WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED) <-- fires On return from the NMI, the outer x86_pmu_stop() triggers WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED). On Intel PEBS and BTS events, the nested intel_pmu_disable_event() also re-enters non-reentrant disable and drain paths. Separately, because perf_throttling is a single per-CPU counter rather than scoped to the group, throttling one group from a software event suppresses this stop for an unrelated throttled group whose NMI arrives on the same CPU during that walk. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205133221.3294= -1-john3@mailbox.org?part=3D8