From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1 11/13] perf bpf-filter: Copy bpf_filters in evsel__clone() and close on evsel__close()
Date: Mon, 23 Nov 2026 07:36:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-228822@kernel.org> (raw)
In-Reply-To: <20261123071913.653315-12-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf bpf-filter: evsel->bpf_skel leak when
bpf_program_profiler_ops is active
--
commit d719c3b8be630c9ad40c9c5d575ea564cff11cd7
Author: Ian Rogers <irogers@google.com>
perf bpf-filter: Copy bpf_filters in evsel__clone() and close on evsel__close()
This commit adds perf_bpf_filter__copy() to duplicate BPF filter expressions
during evsel__clone(), and introduces perf_bpf_filter__close() to tear down
BPF skeleton and pinned filter state when closing an evsel or evlist.
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 638d501a75316..5bcb5d0905ea7 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -1708,6 +1708,8 @@ void evlist__close(struct evlist *evlist)
> }
>
> evlist__for_each_entry_reverse(evlist, evsel) {
> + if (!evsel__is_bpf(evsel))
> + perf_bpf_filter__close(evsel);
> perf_evsel__free_fd(&evsel->core);
> perf_evsel__free_id(&evsel->core);
> }
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 64a9318554ee7..e7ceeb46e06c6 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
[ ... ]
> @@ -3261,6 +3263,8 @@ void evsel__close(struct evsel *evsel)
> {
> if (evsel__is_retire_lat(evsel))
> evsel__tpebs_close(evsel);
> + if (!evsel__is_bpf(evsel))
> + perf_bpf_filter__close(evsel);
> perf_evsel__close(&evsel->core);
> perf_evsel__free_id(&evsel->core);
> }
[Severity: Medium]
Should these checks in evlist__close() and evsel__close() test
!evsel__is_bperf(evsel) instead of !evsel__is_bpf(evsel) so that
evsel->bpf_skel is not leaked when profiling a BPF program?
Only bperf shares the evsel->bpf_skel union member with leader_skel and
follower_skel. When perf stat runs with both -b and --filter,
bpf_counter__load() sets evsel->bpf_counter_ops to
&bpf_program_profiler_ops (with a non-empty evsel->bpf_counter_list, so
evsel__is_bperf(evsel) is false while evsel__is_bpf(evsel) is true) and
perf_bpf_filter__prepare() populates evsel->bpf_skel (or pinned_filters).
Because evsel__is_bpf(evsel) is true, evlist__close() and evsel__close()
skip perf_bpf_filter__close(evsel). This leaks the sample_filter_bpf
skeleton or pinned_filter_idx entries across repeat runs (perf stat -r),
and at final teardown in evsel__exit(), bpf_counter__destroy() sets
evsel->bpf_skel = NULL before perf_bpf_filter__destroy() runs, leaking
the sample_filter_bpf skeleton on single runs as well.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123071913.653315-1-irogers@google.com?part=11
next prev parent reply other threads:[~2026-11-23 7:36 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 7:19 [PATCH v1 00/13] perf fixes: off-cpu, stat, tool PMU, bperf, and bpf-filter fixes Ian Rogers
2026-11-23 7:19 ` [PATCH v1 01/13] perf off-cpu: Bound callchain length in off_cpu_write() Ian Rogers
2026-11-23 7:19 ` [PATCH v1 02/13] perf off-cpu: Fix swapped PID and TID in direct off_cpu_dump() samples Ian Rogers
2026-11-23 7:19 ` [PATCH v1 03/13] libperf evlist: Recompute CPU map when an evsel goes system wide Ian Rogers
2026-11-23 7:19 ` [PATCH v1 04/13] perf stat: Give non-perf_event_open events unique IDs for stat record Ian Rogers
2026-11-23 7:37 ` sashiko-bot
2026-11-23 7:19 ` [PATCH v1 05/13] perf stat: Preserve per-evsel CPU maps across stat record and report Ian Rogers
2026-11-23 7:35 ` sashiko-bot
2026-11-23 17:12 ` Athira Rajeev
2026-11-24 4:23 ` Ian Rogers
2026-11-24 7:24 ` Athira Rajeev
2026-11-23 7:19 ` [PATCH v1 06/13] perf pmu: Don't treat tool PMU as a kernel software PMU for event grouping Ian Rogers
2026-11-23 23:12 ` TAKANO Mitsuhiro
2026-11-24 0:16 ` Namhyung Kim
2026-11-23 7:19 ` [PATCH v1 07/13] perf evlist: Enable tool PMU events when starting a workload Ian Rogers
2026-11-23 7:19 ` [PATCH v1 08/13] perf stat: Respect the enabled time of exited user_time/system_time events Ian Rogers
2026-11-23 7:19 ` [PATCH v1 09/13] perf stat: Fix --bpf-counters with non-bperf, hybrid, and mixed events Ian Rogers
2026-11-23 7:19 ` [PATCH v1 10/13] perf bpf-filter: Fix bpf_link leak by using PERF_EVENT_IOC_SET_BPF Ian Rogers
2026-11-23 7:19 ` [PATCH v1 11/13] perf bpf-filter: Copy bpf_filters in evsel__clone() and close on evsel__close() Ian Rogers
2026-11-23 7:36 ` sashiko-bot [this message]
2026-11-23 7:19 ` [PATCH v1 12/13] perf bpf-filter: Support BPF sample filters on tracepoint events Ian Rogers
2026-11-23 7:19 ` [PATCH v1 13/13] perf parse-events: Route non-field tracepoint filter terms to BPF filter Ian Rogers
2026-11-23 7:44 ` [PATCH v1 00/13] perf fixes: off-cpu, stat, tool PMU, bperf, and bpf-filter fixes 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-228822@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=irogers@google.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.