Re: [Patch v3 8/8] perf/x86/intel: Prevent drain_pebs() reentry

Peter Zijlstra <[email protected]>
Newsgroups org.kernel.vger.linux-perf-users,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Fri, Jul 17, 2026 at 04:03:42PM +0800, Dapeng Mi wrote:
> The PEBS buffer is shared by all events on a CPU, so drain_pebs() must
> not run concurrently. If it is reentered, one instance may observe stale
> buffer state and potentially access out-of-bound memory.
> 
> Most invocations happen in NMI context, which naturally prevents reentry.
> However, drain_pebs() is also reachable from process context via
> intel_pmu_drain_pebs_buffer().
> 
> In those paths, the PMU is often already disabled, but not guaranteed.
> For example, __intel_pmu_pebs_disable() only disables the target counter,
> so other active counters can still raise a PMI and interrupt an in-flight
> drain_pebs().
> 
> Introduce __intel_pmu_quiesce() and __intel_pmu_resume() helpers and
> use them in intel_pmu_drain_pebs_buffer() to disable the full PMU
> around the drain_pebs() call, preventing reentry.
> 

It is not at all clear to me where the exact recursion happens. (The
word you're looking for was recursion, not concurrent).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.