Skip to content

Use BTF to trim return values

Donglin Peng linux-trace-kernel lkml 6 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest4 patches 0 repliesNew
  2. v53 patches 9 repliesSuperseded
  3. v43 patches 4 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v32 patches2 repliesSuperseded
v22 patches3 repliesSuperseded
v12 patches0 repliesSuperseded

Changes in v6 from the cover letter

- Avoid BTF lookup in atomic context or with interrupts disabled
- Add the atomic-context fix as a separate patch.

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4tracing: Avoid BTF lookup in atomic contextkernel/trace/trace_btf.c+3 -00 replies
2/4ftrace: Build trace_btf.c when CONFIG_DEBUG_INFO_BTF is enabledkernel/trace/Kconfig kernel/trace/Makefile+2 -20 replies
3/4fgraph: Enhance funcgraph-retval with BTF-based type-aware outputkernel/trace/trace_btf.c kernel/trace/trace_btf.h kernel/trace/trace_functions_graph.c+144 -130 replies
4/4tracing: Update funcgraph-retval documentationDocumentation/trace/ftrace.rst+58 -380 replies

Reviews trailers per patch

1 of 4 patches has a Reviewed-by or Acked-by.

PatchMasami Hiramatsu (Google)
1/4
2/4A-b
3/4
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v6 thread

Cover letter [PATCH v6 0/4] Use BTF to trim return values

From: pengdonglin <[email protected]>

The funcgraph-retval option currently records one machine-word return value without considering the function's declared return type. As a result, void-returning functions can produce meaningless output, and return values narrower than a general-purpose register can include undefined high bits.

This series uses kernel BTF to identify the return type of traced functions and to improve funcgraph-retval output:

- Do not print a return value for functions with a void return type.
- Trim integer, enum, struct, and union values to the available return value width when the BTF type provides suitable size information.
- Format integer, enum, and boolean values according to their BTF encoding.
- Mark values as "(trunc)" when the return type is wider than the value captured by the function graph tracer.

Here is an output comparison:

Before:

 # perf ftrace -G vfs_read --graph-opts retval
 ...
 1)               |   touch_atime() {
 1)               |     atime_needs_update() {
 1)   0.069 us    |       make_vfsuid(); /* ret=0x0 */
 1)   0.067 us    |       make_vfsgid(); /* ret=0x0 */
 1)               |       current_time() {
 1)   0.197 us    |         ktime_get_coarse_real_ts64_mg(); /* ret=0x187f886aec3ed6f5 */
 1)   0.352 us    |       } /* current_time ret=0x69380753 */
 1)   0.792 us    |     } /* atime_needs_update ret=0x0 */
 1)   0.937 us    |   } /* touch_atime ret=0x0 */

After:

 # perf ftrace -G vfs_read --graph-opts retval
 ...
 2)               |   touch_atime() {
 2)               |     atime_needs_update() {
 2)   0.070 us    |       make_vfsuid(); /* ret=0x0 */
 2)   0.070 us    |       make_vfsgid(); /* ret=0x0 */
 2)               |       current_time() {
 2)   0.162 us    |         ktime_get_coarse_real_ts64_mg();
 2)   0.312 us    |       } /* current_time ret=0x69380649 (trunc) */
 2)   0.753 us    |     } /* atime_needs_update ret=false */
 2)   0.899 us    |   } /* touch_atime */

Note that funcgraph-retval still captures only the return value exposed by ftrace_regs_get_return_value(). Return values that require multiple registers are therefore still incomplete and are marked "(trunc)" when the BTF type indicates that the declared type is wider than one machine word.

Changelog:

v6:
- Avoid BTF lookup in atomic context or with interrupts disabled
- Add the atomic-context fix as a separate patch.

v5:
- Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/
- Add an inline fallback for btf_trim_retval() when
CONFIG_DEBUG_INFO_BTF is disabled.
- Release the BTF reference after return type lookup.

v4:
- Link: https://lore.kernel.org/all/[email protected]/
- Build trace_btf.c when CONFIG_DEBUG_INFO_BTF is enabled.
- Remove the redundant BPF_SYSCALL dependency from CONFIG_PROBE_EVENTS_BTF_ARGS.
- Update the funcgraph-retval documentation and cover letter.

v3:
- Link: https://lore.kernel.org/all/[email protected]/
- Print the return value based on its type for human readability, thanks Masami.
- Update the documentation and cover letter.

v2:
- Link: https://lore.kernel.org/all/[email protected]/
- Update the funcgraph-retval documentation.
- Revise the cover letter.

v1:
- Link: https://lore.kernel.org/all/[email protected]/

pengdonglin (4):
tracing: Avoid BTF lookup in atomic context
ftrace: Build trace_btf.c when CONFIG_DEBUG_INFO_BTF is enabled
fgraph: Enhance funcgraph-retval with BTF-based type-aware output
tracing: Update funcgraph-retval documentation

 Documentation/trace/ftrace.rst       | 96 +++++++++++++++++-----------
 kernel/trace/Kconfig                 |  2 +-
 kernel/trace/Makefile                |  2 +-
 kernel/trace/trace_btf.c             | 86 +++++++++++++++++++++++++
 kernel/trace/trace_btf.h             | 18 ++++++
 kernel/trace/trace_functions_graph.c | 56 ++++++++++++----
 6 files changed, 207 insertions(+), 53 deletions(-)
Signature · 1 line
2.34.1