From: Namhyung Kim <namhyung@kernel.org>
To: TAKANO Mitsuhiro <takano32@gmail.com>
Cc: linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>
Subject: Re: [PATCH] perf evsel: Skip group members without fds when walking a group
Date: Tue, 10 Nov 2026 22:16:26 -0800 [thread overview]
Message-ID: <avQIOtt7Y67oXQem@z2> (raw)
In-Reply-To: <20261023085629.1694941-1-takano32@gmail.com>
Hello,
On Fri, Oct 23, 2026 at 08:56:29AM +0000, TAKANO Mitsuhiro wrote:
> A group led by a userspace PMU event and containing kernel events is
> opened with group_fd = -1 for the members, because the kernel cannot
> group a userspace PMU with a kernel one. The members are therefore
> enabled from userspace when the leader is enabled, but their fd array is
> not set up in that case, so perf_evsel__enable_cpu() dereferences a NULL
> pointer:
>
> $ perf stat -a -e '{user_time,cycles}' -- sleep 0.05
> Segmentation fault
>
> $ perf stat -a -e '{system_time,cycles}' -- sleep 0.05
> Segmentation fault
>
> Only the leaders of such a group are opened with an fd in this path.
> Skip the members that have no fd, the same way __evlist__enable() skips
> leaders without one, in the four loops that walk the members of a group.
>
> Verified on an Ampere Altra (arm64, Neoverse-N1) with a perf built from
> this tree: the two commands above segfault before the change and print
> user_time/system_time after it, while plain groups such as
> '{cycles,instructions}', 'perf stat' with no event and '-r 2' are
> unchanged.
>
> Fixes: 0b18bced5444 ("perf tool_pmu: Make tool PMU events respect enable/disable")
> Assisted-by: LLM
> Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com>
> ---
Sorry for the delay, but it seems easier to fix the fd handling in
libperf like this (not tested).
Thanks,
Namhyung
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index f747c0bc692d8a61..43ea1dfcebf421e5 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -57,7 +57,7 @@ void perf_evsel__delete(struct perf_evsel *evsel)
}
#define FD(_evsel, _cpu_map_idx, _thread) \
- ((int *)xyarray__entry(_evsel->fd, _cpu_map_idx, _thread))
+ (_evsel->fd ? (int *)xyarray__entry(_evsel->fd, _cpu_map_idx, _thread) : NULL)
#define MMAP(_evsel, _cpu_map_idx, _thread) \
(_evsel->mmap ? ((struct perf_mmap *) xyarray__entry(_evsel->mmap, _cpu_map_idx, _thread)) \
: NULL)
next prev parent reply other threads:[~2026-11-11 6:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 8:56 [PATCH] perf evsel: Skip group members without fds when walking a group TAKANO Mitsuhiro
2026-10-23 9:20 ` sashiko-bot
2026-10-23 16:24 ` TAKANO Mitsuhiro
2026-11-10 3:08 ` Hang Zhengyang
2026-11-11 2:33 ` TAKANO Mitsuhiro
2026-11-11 3:48 ` Hang Zhengyang
2026-11-11 6:16 ` Namhyung Kim [this message]
2026-11-11 10:16 ` [PATCH v2] libperf: Handle an evsel without an fd array in enable/disable TAKANO Mitsuhiro
2026-11-11 10:28 ` 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=avQIOtt7Y67oXQem@z2 \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=takano32@gmail.com \
/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