From: Song Liu <songliubraving@meta.com>
To: bpf <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Alan Maguire <alan.maguire@oracle.com>,
Jordan Rome <jordalgo@meta.com>, Yonghong Song <yhs@meta.com>,
Kernel Team <kernel-team@meta.com>
Subject: RFC: Mark "inlined by some callers" functions in BTF
Date: Thu, 11 Jan 2024 21:51:05 +0000 [thread overview]
Message-ID: <B653950A-A58F-44C0-AD9D-95370710810F@fb.com> (raw)
The problem
Inlining can cause surprises to tracing users, especially when the tool
appears to be working. For example, with
[root@ ~]# bpftrace -e 'kprobe:switch_mm {}'
Attaching 1 probe...
The user may not realize switch_mm() is inlined by leave_mm(), and we are
not tracing the code path leave_mm => switch_mm. (This is x86_64, and both
functions are in arch/x86/mm/tlb.c.)
We have folks working on ideas to create offline tools to detect such
issues for critical use cases at compile time. However, I think it is
necessary to handle it at program load/attach time.
Detect "inlined by some callers" functions
This appears to be straightforward in pahole. Something like the following
should do the work:
diff --git i/btf_encoder.c w/btf_encoder.c
index fd040086827e..e546a059eb4b 100644
--- i/btf_encoder.c
+++ w/btf_encoder.c
@@ -885,6 +885,15 @@ static int32_t btf_encoder__add_func(struct btf_encoder *encoder, struct functio
struct llvm_annotation *annot;
const char *name;
+ if (function__inlined(fn)) {
+ /* This function is inlined by some callers. */
+ }
+
btf_fnproto_id = btf_encoder__add_func_proto(encoder, &fn->proto);
name = function__name(fn);
btf_fn_id = btf_encoder__add_ref_type(encoder, BTF_KIND_FUNC, btf_fnproto_id, name, false);
Mark "inlined by some callers" functions
We have a few options to mark these functions.
1. We can set struct btf_type.info.kind_flag for inlined function. Or we
can use a bit from info.vlen.
2. We can simply not generate btf for these functions. This is similar to
--skip_encoding_btf_inconsistent_proto.
Handle tracing inlined functions
If we go with option 1 above, we have a few options to handle program
load/attach to "inlined by some callers" functions:
a) We can reject the load/attach;
b) We can rejuct the load/attach, unless the user set a new flag;
c) We can simply print a warning, and let the load/attach work.
Please share your comments on this. Is this something we want to handle?
If so, which of these options makes more sense?
Thanks,
Song
next reply other threads:[~2024-01-11 21:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 21:51 Song Liu [this message]
2024-01-11 22:48 ` RFC: Mark "inlined by some callers" functions in BTF Daniel Xu
2024-01-11 23:06 ` Song Liu
2024-01-11 23:49 ` Daniel Xu
2024-01-12 21:59 ` Song Liu
2024-01-23 0:30 ` Andrii Nakryiko
2024-01-23 10:32 ` Alan Maguire
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=B653950A-A58F-44C0-AD9D-95370710810F@fb.com \
--to=songliubraving@meta.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jordalgo@meta.com \
--cc=kernel-team@meta.com \
--cc=martin.lau@linux.dev \
--cc=yhs@meta.com \
/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;
as well as URLs for NNTP newsgroup(s).