All of lore.kernel.org
 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 v8 2/6] perf ftrace: Support filtering return address comments
Date: Sun, 18 Oct 2026 02:46:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-175890@kernel.org> (raw)
In-Reply-To: <20261018023753.584873-3-atomlin@atomlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf ftrace: ftrace_filter_retaddr() strips leaf return values
--

commit bb5a10abc2299a6ae2ba0cbda70fab044e68ad36
Author: Aaron Tomlin <atomlin@atomlin.com>

perf ftrace: Support filtering return address comments

This commit introduces ftrace_parse_retaddr() and ftrace_filter_retaddr()
along with a --filter-retaddr command-line option and unit tests to strip
funcgraph-retaddr return address comments from function_graph trace output.

> diff --git a/tools/perf/tests/ftrace.c b/tools/perf/tests/ftrace.c
> new file mode 100644
> index 0000000000000..596cecee844e3
> --- /dev/null
> +++ b/tools/perf/tests/ftrace.c
> @@ -0,0 +1,80 @@

[ ... ]

> +static int test_filter_retaddr(void)
> +{
> +	char line1[] = "kernel_read() { /* <-load_elf_phdrs+0x6c/0xb0 */";
> +	char line2[] = "__cond_resched(); /* <-load_elf_phdrs+0x6c/0xb0 ret=0x0 */";
> +	char line3[] = "do_filp_open();";
> +
> +	ftrace_filter_retaddr(line1);
> +	TEST_ASSERT_EQUAL("filter standard retaddr", strcmp(line1, "kernel_read() {"), 0);
> +
> +	ftrace_filter_retaddr(line2);
> +	TEST_ASSERT_EQUAL("filter retaddr with ret", strcmp(line2, "__cond_resched();"), 0);
> +
> +	ftrace_filter_retaddr(line3);
> +	TEST_ASSERT_EQUAL("filter line without retaddr unchanged",
> +			  strcmp(line3, "do_filp_open();"), 0);
> +
> +	return TEST_OK;
> +}

[ ... ]

> diff --git a/tools/perf/util/ftrace.c b/tools/perf/util/ftrace.c
> new file mode 100644
> index 0000000000000..aaf108369c365
> --- /dev/null
> +++ b/tools/perf/util/ftrace.c
> @@ -0,0 +1,86 @@

[ ... ]

> +/**
> + * ftrace_filter_retaddr - Remove return address comment from trace line
> + * @str: The trace line to modify
> + *
> + * Find and strip the funcgraph-retaddr comment from the trace line
> + * in-place, removing trailing spaces where applicable.
> + */
> +void ftrace_filter_retaddr(char *str)
> +{
> +	char *start = strstr(str, "/* <-");
> +	char *end;
> +
> +	if (!start)
> +		return;
> +
> +	end = strstr(start, "*/");
> +	if (!end)
> +		return;
> +
> +	end += 2; /* skip end-of-comment delimiter */
> +
> +	/* Also backtrack any spaces before comment */
> +	while (start > str && *(start - 1) == ' ')
> +		start--;
> +
> +	memmove(start, end, strlen(end) + 1);
> +}

[Severity: Medium]
Does ftrace_filter_retaddr() unintentionally strip return values from leaf
functions when both funcgraph-retaddr and funcgraph-retval are enabled?

In kernel/trace/trace_functions_graph.c:print_graph_retval(), when both
TRACE_GRAPH_PRINT_RETADDR and TRACE_GRAPH_PRINT_RETVAL are active, the
kernel combines the return address and return value into a single comment on
leaf functions:

    __cond_resched(); /* <-load_elf_phdrs+0x6c/0xb0 ret=0x0 */

Non-leaf functions place the return address on the entry line and the return
value on the closing brace line, so their return values are unaffected.
However, on leaf functions, ftrace_filter_retaddr() removes the entire
comment from "/* <-" through "*/", discarding "ret=0x0" as well (which
test_filter_retaddr() also asserts).

When running with "--graph-opts retaddr,retval --filter-retaddr" (or when a
subsequent change such as "perf ftrace: Support display of inlined functions
in function graph tracer" automatically enables funcgraph-retaddr and
filter_retaddr alongside "--graph-opts retval"), shouldn't
ftrace_filter_retaddr() preserve the "/* ret=... */" portion of the comment
on leaf functions instead of removing the whole comment block?

([ ... ])

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

  reply	other threads:[~2026-10-18  2:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-18  2:37 [PATCH perf-tools-next v8 0/6] perf ftrace: Support inlined functions and display enhancements in function graph tracer Aaron Tomlin
2026-10-18  2:37 ` [PATCH perf-tools-next v8 1/6] perf ftrace: Optimise __cmd_ftrace() stack frame with strbuf streaming Aaron Tomlin
2026-10-18  2:49   ` sashiko-bot
2026-10-18  2:37 ` [PATCH perf-tools-next v8 2/6] perf ftrace: Support filtering return address comments Aaron Tomlin
2026-10-18  2:46   ` sashiko-bot [this message]
2026-10-18  2:37 ` [PATCH perf-tools-next v8 3/6] perf symbol: Introduce vmlinux_path__find() helper Aaron Tomlin
2026-10-18  2:45   ` sashiko-bot
2026-10-18  2:37 ` [PATCH perf-tools-next v8 4/6] perf ftrace: Support display of inlined functions in function graph tracer Aaron Tomlin
2026-10-18  3:00   ` sashiko-bot
2026-10-18  2:37 ` [PATCH perf-tools-next v8 5/6] perf ftrace: Support omitting execution duration " Aaron Tomlin
2026-10-18  2:51   ` sashiko-bot
2026-10-18  2:37 ` [PATCH perf-tools-next v8 6/6] perf ftrace: Filter extraneous functions " Aaron Tomlin
2026-10-18  2:55   ` 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-175890@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 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.