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=1796358996; b=2xFzxuaFGiQMsly6gjjedVIvKMCL/y5si2ZaXFYEhd+zup4JkJv2OWXorZ10r/cwr396 R05aPg6jezp2QTVqGRk/yR/pU0/eAHoyQIBOj3FTKWEDCw50tK23DS++GpcEiHSpB7Bp0 WByQr5Av5/2JsCVl1JWeSprNG1a8az8W5hv2d2LzbKsML5PTnQP5j/ujprcn2EJCTMyqg sFy9H1p7rpavBk0YulqfMajui9M75J/DmTzWW48Xx10qLpOLQeRSZvdnyt3+MhAzbVy/M 1PcrHFFGKIg1MXGTrL/DCvk8gv0vqHy+xzHzM520aTJUKTuzQf9KHiXFcF3mSjLTfBw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796358996; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ljMKI5TuzEtCz7bHUbzQFT/nmvQ0RmLavVKrFAigiIY=; b=iKjEbjb3/qZClhP75zr2HcGi8IU+diNRj11gDpG136k+4QMUacoAOOE8tLLO3La4B7Sv aHJAHwnElt21YLdb4Z1HSLhpOhdRoFAajtiG5eUnxS2sSKuKMU41gvNmvBduSCuQVWATY nBjxns0fgteAl5ivnb3hsCYXfUp1Le+yE/ZRFWYS5jUjC/oaCDnRuvngCClg8Isf6jtJC mp4gjZZb2S7A3q5L5jHCT1Ekv0uNX4BxAl/ZNt06DCxBPTGyotUMUkDegj8jvflKjIDpJ dJ4deNi3wl9cUsRuZq7iLt+1k1/0FOVs2Z0JweJ9ox8EWr9qjFY+w9v6gWvc2DuqXWw== 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=RoTNmHKe; 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 0F989606A322 for ; Fri, 4 Dec 2026 04:36:35 +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=RoTNmHKe Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BF881F000CE; Fri, 4 Dec 2026 04:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796358995; bh=ljMKI5TuzEtCz7bHUbzQFT/nmvQ0RmLavVKrFAigiIY=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=RoTNmHKeGvtjFwG4t6c6Z+Ra0DVS8aoLED2Q8Jy0Apo7c4N6exfn1UD52/hmdGxQ6 xMa8Sroix8XJDr09Jw+sWGqpbENQUXUzID51uGj3gblJHiIyZzkY6zEuhCl4kUBPPW +kHiIR/MixpVRgiibZJdOWHdsMyBxOQMCMMO1i0LSUKl8en1Rm7Fd3hWKtZAlxOax2 u7msT7pbmUHwfGHRq36Fv6xw3AAlrEQjyJmFnV2rTVHPMmiztlc+aR9Iuu1gOa7DF3 hLnIudu12IwHkLY1S2k9siwRexqrCULOLirJOYGoqp/RHsZZakjOnmdyrcDbxBFui1 Wqp728ab4nWLA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v13 1/2] perf stat: Refuse a group mixing tool and kernel events Reply-To: sashiko-reviews@lists.linux.dev To: "TAKANO Mitsuhiro" , linux-perf-users@vger.kernel.org In-Reply-To: <20261204041444.1078407-1-takano32@gmail.com> References: <20261202053312.2695722-1-takano32@gmail.com> <20261204041444.1078407-1-takano32@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 04:36:35 +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 4 potential issues to consider: - [Medium] perf: get_group_fd() EINVAL causes infinite retry loop in record__open() - [Medium] perf test: hybrid_core_types() does not strip running percentages - [Medium] perf test: stat+tool_group.sh -C picks CPU 0 without matching core PMU - [Low] perf stat: quadratic evlist scan in check_unopened_in_group() -- commit 5aa05b6d313e575c95aee1475611bfc35b8273a1 Author: TAKANO Mitsuhiro perf stat: Refuse a group mixing tool and kernel events This commit rejects event groups in perf stat that mix kernel events with events perf does not open via perf_event_open(), updates get_group_fd() and evsel enable/disable paths to handle leaders and members without kernel descriptors, and adds a shell test covering tool event groups. Link: https://lore.kernel.org/all/sashiko-outbox-227849@kernel.org/ Link: https://lore.kernel.org/all/sashiko-outbox-231330@kernel.org/ Link: https://lore.kernel.org/all/sashiko-outbox-232396@kernel.org/ Link: https://lore.kernel.org/all/20261111-tool-pmu-leader-v2-1-3faa0fb98c5= 1@gmail.com/ Link: https://lore.kernel.org/all/awC_aZXD5FBGu4mO@google.com/ Link: https://lore.kernel.org/all/awTXdgY38s2bijW5@google.com/ Link: https://lore.kernel.org/all/20261123071913.653315-7-irogers@google.co= m/ [ ... ] > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 37752d6bfef45..4fa3958c4cf33 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -2469,6 +2469,77 @@ static int parse_tpebs_mode(const struct option *o= pt, const char *str, > } > #endif // HAVE_ARCH_X86_64_SUPPORT [ ... ] > +static int check_unopened_in_group(struct evlist *evlist) > +{ > + struct evsel *leader, *evsel; > + > + evlist__for_each_entry(evlist, leader) { > + struct evsel *unopened =3D NULL; > + bool has_kernel =3D false, weak =3D false; > + > + if (!evsel__is_group_leader(leader) || leader->core.nr_members < 2) > + continue; > + > + /* > + * The members of a group are not necessarily adjacent in the > + * evlist: evlist__check_cpu_maps() makes a removed member a > + * leader of its own without moving it. > + */ > + evlist__for_each_entry(evlist, evsel) { > + if (!evsel__has_leader(evsel, leader)) > + continue; [Severity: Low] Can this nested evlist scan cause noticeable startup overhead on large grouped workloads? cmd_stat() calls check_unopened_in_group() after evlist__expand_cgroup(), which multiplies both the evlist length and the number of group leaders by the number of cgroups. Scanning the full evlist for every multi-member leader makes startup O(C^2) even when no tool, hwmon, or drm events are present. A linear pre-check for any evsel__is_non_perf_event_open_pmu() event in a multi-member group (or stopping the inner loop once leader->core.nr_members entries are visited) would avoid the quadratic scan in the common case. [ ... ] > diff --git a/tools/perf/tests/shell/stat+tool_group.sh b/tools/perf/tests= /shell/stat+tool_group.sh > new file mode 100755 > index 0000000000000..4a2aae62321c0 > --- /dev/null > +++ b/tools/perf/tests/shell/stat+tool_group.sh [ ... ] > +hybrid_core_types() { > + awk 'function bare(name) { > + gsub(/\/$/, "", name) > + sub(/^[^\/]*\//, "", name) > + return name > + } > + FNR =3D=3D NR { > + sub(/#.*/, "") > + if ($1 ~ /^[0-9][0-9,.]*$/) > + counted[bare($(NF))] =3D 1 > + next > + } > + // { > + sub(/#.*/, "") > + if (bare($(NF)) in counted) > + found =3D 1 > + } > + END { exit !found }' "${out}" "${out}" > +} [Severity: Medium] Does hybrid_core_types() fail to extract the event name when print_running_std() appends a running percentage? When run !=3D ena, print_running_std() prints a trailing "(XX.XX%)" after t= he event name, so $(NF) evaluates to "(0.00%)" on an unexecuted hybrid core PMU line like " cpu_atom/cycles/ (0.00%)" and accepted() fails. Follow-up commit "perf stat: Fix hybrid test failure and respect $PERF in stat+tool_group.sh" strips the percentage in the // block, but omits the same strip from the FNR =3D=3D NR block, where a multiplexed coun= ted event without a "#" metric comment still records counted["(XX.XX%)"]. Stripping the trailing percentage in both passes would handle both cases. [ ... ] > +if grep -qE '(^|,)0(,|$)' /sys/devices/system/cpu/online 2>/dev/null; th= en > + refused '{cycles,duration_time}' duration_time -C 0 > +else > + echo "CPU 0 is not online, cannot test -C [Skipped]" > + skipped=3D$((skipped + 1)) > +fi [Severity: Medium] Will this -C 0 test silently skip on SMP systems and hang perf stat on hybrid systems? The regex '(^|,)0(,|$)' does not match standard cpulist range notation such as "0-7", so multi-CPU systems skip the check. Follow-up commit "perf stat: Fix hybrid test failure and respect $PERF in stat+tool_group.sh" fixes the range parsing, but still picks CPU 0 without checking which core PMU covers it. On a hybrid Intel machine where CPU 0 belongs to cpu_core and cpu_atom (sorted first in core_pmus) covers higher CPUs, '{cycles,duration_time}' makes cpu_atom/cycles/ the group leader. __perf_evlist__propagate_maps() then unlinks it via list_del_init() while duration_time still points to it. evlist__check_cpu_maps() -> evsel__group_desc() -> for_each_group_evsel() then loops forever on the self-linked leader, hanging perf stat. Picking an online CPU from a core PMU's cpus file and qualifying cycles with that PMU would avoid this. [ ... ] > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index d060fca8090f6..ff8e8e3228588 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c [ ... ] > @@ -2371,23 +2418,59 @@ static int get_group_fd(struct evsel *evsel, int = cpu_map_idx, int thread) [ ... ] > + if (fd =3D=3D -1) { > + /* > + * A weak group is split on EINVAL, but a strong group must > + * keep the leader's errno: an unprivileged open that failed > + * with EACCES has to keep reporting the perf_event_paranoid > + * diagnostic rather than turn into "Invalid argument". > + */ > + if (evsel->weak_group) > + errno =3D EINVAL; > + return -2; > + } [Severity: Medium] Can overwriting errno with EINVAL here cause an infinite retry loop in record__open()? If an unprivileged user runs perf record -e '{slots,topdown-retiring}:W' on an x86 Intel CPU under perf_event_paranoid restrictions, slots fails evsel__open() with EACCES (leaving fd =3D=3D -1) and is marked skippable. Opening topdown-retiring then hits get_group_fd(), which now overwrites errno to EINVAL and returns -2. tools/perf/builtin-record.c:record__open() { ... if ((errno =3D=3D EINVAL || errno =3D=3D EBADF) && pos->core.leader !=3D &pos->core && pos->weak_group) { pos =3D evlist__reset_weak_group(evlist, pos, true); goto try_again; } ... } Because arch_evsel__must_be_in_group() is true for topdown-retiring, evsel__remove_from_group() refuses to ungroup it and leaves pos->weak_group intact. evlist__reset_weak_group() rewinds pos back to slots, so record__open() retries indefinitely and floods stderr. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204041444.1078= 407-1-takano32@gmail.com?part=3D1