Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aaron Tomlin" <atomlin@atomlin.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH perf-tools-next 1/3] perf trace: Introduce kernel symbol beautifier for virtual addresses
Date: Sat, 15 Aug 2026 23:44:46 +0000	[thread overview]
Message-ID: <20260815234446.84F6D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260815233651.527936-2-atomlin@atomlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Memory leak of reference-counted `struct map` handle in `syscall_arg__scnprintf_ksym`.
--

--- Patch [1]: [PATCH perf-tools-next 1/3] perf trace: Introduce kernel symbol beautifier for virtual addresses ---
commit 0ff39d14d9508d5e3c586057a78b07cbcda7f7fb
Author: Aaron Tomlin <atomlin@atomlin.com>

perf trace: Introduce kernel symbol beautifier for virtual addresses

This commit adds a kernel symbol beautifier for perf trace to translate
raw kernel virtual addresses into human-readable symbol names and offsets.
It uses machine__find_kernel_symbol() to look up the symbols dynamically.

> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index c3c7f1f85c530..102221b301a54 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c

[ ... ]

> @@ -750,6 +750,30 @@ size_t syscall_arg__scnprintf_ptr(char *bf, size_t size, struct syscall_arg *arg
>  	return syscall_arg__scnprintf_hex(bf, size, arg);
>  }
>  
> +size_t syscall_arg__scnprintf_ksym(char *bf, size_t size, struct syscall_arg *arg)
> +{
> +	if (arg->val == 0)
> +		return scnprintf(bf, size, "NULL");
> +
> +	if (arg->trace && arg->trace->host) {
> +		struct map *map;
> +		struct symbol *sym = machine__find_kernel_symbol(arg->trace->host,
> +								 arg->val, &map);
> +
> +		if (sym) {
> +			u64 start = map__unmap_ip(map, sym->start);
> +			u64 offset = arg->val - start;
> +
> +			if (offset == 0)
> +				return scnprintf(bf, size, "%s", sym->name);
> +			return scnprintf(bf, size, "%s+0x%" PRIx64,
> +					 sym->name, offset);

[Severity: High]
Does this code leak the struct map reference?

When machine__find_kernel_symbol() populates the map pointer, it acquires a
reference that the caller takes ownership of.

However, this function returns directly on both success paths and the fallback
path without calling map__put(map). This will cause a memory leak for every
formatted event that resolves to a valid map, which can quickly lead to memory
exhaustion or LSAN crashes when running perf trace.

> +		}
> +	}
> +
> +	return syscall_arg__scnprintf_hex(bf, size, arg);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260815233651.527936-1-atomlin@atomlin.com?part=1

  reply	other threads:[~2026-08-15 23:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-15 23:36 [PATCH perf-tools-next 0/3] perf trace: Symbolise kernel virtual addresses and function pointers Aaron Tomlin
2026-08-15 23:36 ` [PATCH perf-tools-next 1/3] perf trace: Introduce kernel symbol beautifier for virtual addresses Aaron Tomlin
2026-08-15 23:44   ` sashiko-bot [this message]
2026-08-16  1:50     ` Aaron Tomlin
2026-08-15 23:36 ` [PATCH perf-tools-next 2/3] perf trace: Auto-assign kernel symbol beautifier to function pointer fields Aaron Tomlin
2026-08-15 23:47   ` sashiko-bot
2026-08-15 23:36 ` [PATCH perf-tools-next 3/3] perf trace: Enhance BTF type formatting to symbolise kernel function pointers Aaron Tomlin
2026-08-15 23:50   ` 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=20260815234446.84F6D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=atomlin@atomlin.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox