Re: [PATCH] perf evsel: Restrict incremental open error unwind
From: Arnaldo Carvalho de Melo
Date: Tue Sep 22 2026 - 09:51:31 EST
On Mon, Sep 21, 2026 at 09:00:43AM -0700, Ian Rogers wrote:
> On Sun, Sep 13, 2026 at 6:17 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> >
> > On Sat, Sep 12, 2026 at 12:11:10PM +0900, Hui Su wrote:
> > > evsel__open_cpu(), evsel__tool_pmu_open() and
> > > evsel__hwmon_pmu_open() support opening a subrange of a CPU map, bounded
> > > by [start_cpu_map_idx, end_cpu_map_idx).
> > >
> > > Their error paths, however, unwind using "while (--idx >= 0)" all the way
> > > back to CPU index 0 regardless of start_cpu_map_idx. If lower CPU indices
> > > were opened by an earlier invocation, a later incremental open failure
> > > therefore closes those existing file descriptors and overwrites their
> > > slots with -1.
> > >
> > > Before this fix, running the new incremental open test demonstrates this
> > > corruption:
> > >
> > > $ perf test -v "Tool PMU"
> > > 12: Tool PMU:
> > > 12.1: Tool PMU : Ok
> > > 12.2: Tool PMU leader : Ok
> > > 12.3: Incremental open error unwind boundary:
> > > FAILED: CPU 0 FD overwritten: FD(evsel, 0, 0)=-1, expected 4
> > > FAILED!
> > >
> > > Stop the unwind at start_cpu_map_idx so that only file descriptors
> > > opened by the current invocation are rolled back.
> > >
> > > After this fix:
> > >
> > > $ perf test -v "Tool PMU"
> > > 12: Tool PMU:
> > > 12.1: Tool PMU : Ok
> > > 12.2: Tool PMU leader : Ok
> > > 12.3: Incremental open error unwind boundary : Ok
> > >
> > > Fixes: 4804e0111662 ("perf stat: Use affinity for opening events")
> > > Fixes: 240505b2d0ad ("perf tool_pmu: Factor tool events into their own PMU")
> > > Fixes: 53cc0b351ec9 ("perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs")
> >
> > Maybe we just need to last one?
> >
> > Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>
>
> Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo