From: sashiko-bot@kernel.org
To: "Donglin Peng" <dolinux.peng@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v5 3/3] tracing: Update funcgraph-retval documentation
Date: Tue, 01 Sep 2026 14:20:15 +0000 [thread overview]
Message-ID: <20260901142015.C81DD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901134604.4052265-4-dolinux.peng@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Undefined behavior in `btf_trim_retval()` when evaluating `GENMASK()` for zero-sized types like empty structs.
- [Medium] Zero-extension of signed return values breaks display formatting for negative integers.
--
commit 9a068f6032f17c7055ec2012793c0a9a00b1e9a0
Author: pengdonglin <pengdonglin@xiaomi.com>
tracing: Update funcgraph-retval documentation
The existing documentation for funcgraph-retval is outdated and partially
incorrect, as it describes limitations that have now been resolved. Recent
changes (e.g., using BTF to obtain function return types) have addressed
key issues.
> diff --git a/Documentation/trace/ftrace.rst b/Documentation/trace/ftrace.rst
> index 7261f25f8b4ba..696bfbede5905 100644
> --- a/Documentation/trace/ftrace.rst
> +++ b/Documentation/trace/ftrace.rst
[ ... ]
> +- Under certain procedure-call standards (e.g., arm64's AAPCS64), when the return
> + type is smaller than a general-purpose register (GPR), the caller is responsible
> + for narrowing the value; the upper bits of the register may contain undefined data.
> + For instance, when a u8 is returned in 64-bit GPR, bits [63:8] can hold arbitrary
> + values, especially when larger types are truncated (explicitly or implicitly). It
> + is therefore advisable to inspect the code in such cases. If CONFIG_DEBUG_INFO_BTF
> + is enabled (y), the return value is automatically trimmed to the width of the return
> + type.
[Severity: High]
Does the trimming logic in btf_trim_retval() handle empty structs correctly?
Looking at btf_trim_retval() in kernel/trace/trace_btf.c:
msb = BITS_PER_BYTE * t->size - 1;
*retval &= GENMASK(msb, 0);
If a function returns a zero-sized type (like an empty struct), t->size is 0.
This causes msb to underflow to 0xFFFFFFFF, which means GENMASK(0xFFFFFFFF, 0)
attempts a shift by 64. Can this trigger undefined behavior and potentially a
UBSAN panic if CONFIG_UBSAN_SHIFT is enabled?
[Severity: Medium]
Also, does this zero-extension break display formatting for negative integers?
When a function returns a negative value, btf_trim_retval() zeroes out the
upper bits. Later in kernel/trace/trace_functions_graph.c:print_graph_retval():
if (!IS_ERR_VALUE(err_code))
err_code = 0;
// ...
trace_seq_printf(s, " ret=%ld", err_code ?: retval);
For non-error negative values (like -5000) or small signed types (like s8),
IS_ERR_VALUE() evaluates to false, resetting err_code to 0. The code then
falls back to printing the zero-extended retval as a positive number using
%ld. Won't this cause these negative returns to be printed as large positive
numbers instead?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260901134604.4052265-1-dolinux.peng@gmail.com?part=3
next prev parent reply other threads:[~2026-09-01 14:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 13:46 [PATCH v5 0/3] Use BTF to trim return values Donglin Peng
2026-09-01 13:46 ` [PATCH v5 1/3] ftrace: Build trace_btf.c when CONFIG_DEBUG_INFO_BTF is enabled Donglin Peng
2026-09-02 14:58 ` Masami Hiramatsu
2026-09-01 13:46 ` [PATCH v5 2/3] fgraph: Enhance funcgraph-retval with BTF-based type-aware output Donglin Peng
2026-09-01 14:10 ` sashiko-bot
2026-09-01 13:46 ` [PATCH v5 3/3] tracing: Update funcgraph-retval documentation Donglin Peng
2026-09-01 14:20 ` sashiko-bot [this message]
2026-09-01 17:57 ` [PATCH v5 0/3] Use BTF to trim return values Steven Rostedt
2026-09-02 3:25 ` Peng Donglin
2026-09-02 14:55 ` Masami Hiramatsu
2026-09-03 16:17 ` Donglin Peng
2026-09-03 16:36 ` Steven Rostedt
2026-09-03 23:48 ` Masami Hiramatsu
2026-09-04 0:30 ` Steven Rostedt
2026-09-04 1:34 ` Donglin Peng
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=20260901142015.C81DD1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dolinux.peng@gmail.com \
--cc=linux-trace-kernel@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.