Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rui Qi" <qirui.001@bytedance.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2] perf: Extract is_mapping_symbol() helper for kernel mapping symbol filtering
Date: Wed, 06 May 2026 10:43:04 +0000	[thread overview]
Message-ID: <20260506104305.2D54DC2BCB8@smtp.kernel.org> (raw)
In-Reply-To: <20260506073820.2419087-1-qirui.001@bytedance.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Asymmetric mapping symbol filtering leads to map/symbol deletion during ksymbol unregistration.
- [Medium] Incomplete refactoring leaves ELF mapping symbol logic fragile and inconsistent.
--

commit f27956b5bf680b8ef41ba119f6dc5cedae4567f5
Author: Rui Qi <qirui.001@bytedance.com>

perf: Extract is_mapping_symbol() helper for kernel mapping symbol filtering

This patch introduces an is_mapping_symbol() inline helper to consolidate
logic for filtering out ELF mapping symbols across architectures. It also
adds the helper to machine__process_ksymbol_register() and
map__process_kallsym_symbol().

> The perf tool currently has ad-hoc logic to filter out ELF mapping
> symbols scattered across multiple files and architectures.  ARM,
> AArch64 and RISC-V each have their own inline checks in
> dso__load_sym_internal(), and kallsym processing in map__process_kallsym_symbol()
> has yet another check for ARM module symbols.
> 
> This is fragile: adding support for a new architecture or adjusting
> which prefixes are considered mapping symbols requires touching
> multiple places, and it is easy for the checks to diverge.  It also
> does not match the kernel's own is_mapping_symbol() logic, which
> additionally covers x86 local symbols ('.L*' and 'L0*').

This commit message claims to convert dso__load_sym_internal() to use the
new helper. However, this patch does not modify dso__load_sym_internal()
in tools/perf/util/symbol-elf.c at all, leaving the scattered inline checks
untouched.

Because x86 local symbols (.L*) were added to the new helper, does this
omission introduce a new inconsistency where kallsyms parsing will correctly
filter x86 .L* symbols, but kernel module parsing via ELF (.ko) will not?

> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index e76f8c86e62a6..e0dcf8bfb896e 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -729,9 +729,15 @@ static int machine__process_ksymbol_register(struct machine *machine,
>  {
>  	struct symbol *sym;
>  	struct dso *dso = NULL;
> -	struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
> +	struct map *map;
>  	int err = 0;
>  
> +	/* Ignore mapping symbols in ksymbol events - check early before any state mutation */
> +	if (is_mapping_symbol(event->ksymbol.name))
> +		return 0;

If a PERF_RECORD_KSYMBOL event arrives with the UNREGISTER flag,
machine__process_ksymbol() routes it to machine__process_ksymbol_unregister().

Because machine__process_ksymbol_unregister() does not have the same
is_mapping_symbol() filter, could maps__find() return the enclosing map
(such as the BPF JIT map or a loaded kernel module's map) that covers the
mapping symbol's address?

tools/perf/util/machine.c:machine__process_ksymbol_unregister() {
...
	map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
	if (!map)
		return 0;

	if (!RC_CHK_EQUAL(map, machine->vmlinux_map))
		maps__remove(machine__kernel_maps(machine), map);
...
}

If so, will the unregister path incorrectly call maps__remove() on that
parent map, prematurely destroying legitimate tracking state and breaking
symbol resolution for subsequent samples in that memory region?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260506073820.2419087-1-qirui.001@bytedance.com?part=1

  reply	other threads:[~2026-05-06 10:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06  7:38 [PATCH v2] perf: Extract is_mapping_symbol() helper for kernel mapping symbol filtering Rui Qi
2026-05-06 10:43 ` sashiko-bot [this message]
2026-05-07  6:27   ` Rui Qi
2026-05-07  7:11 ` [PATCH v3] perf: Add " Rui Qi
2026-05-07 15:23   ` Ian Rogers
2026-05-07 20:38   ` 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=20260506104305.2D54DC2BCB8@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=qirui.001@bytedance.com \
    --cc=sashiko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox