BPF List
 help / color / mirror / Atom feed
From: Tao Chen <chen.dylane@linux.dev>
To: Song Liu <song@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jiri Olsa <jolsa@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	bpf <bpf@vger.kernel.org>, Alan Maguire <alan.maguire@oracle.com>
Subject: Re: Question: fentry on kernel func optimized by compiler
Date: Fri, 28 Mar 2025 23:19:09 +0800	[thread overview]
Message-ID: <4c60f56a-8505-49f3-872b-d485d65813d7@linux.dev> (raw)
In-Reply-To: <CAPhsuW46kTsSzc+B5pE+kM24nc+OUXXGnkgSgZbu+T55HSJb7w@mail.gmail.com>

在 2025/3/28 01:19, Song Liu 写道:
> Hi Tao,
> 
> Compiler optimizations can cause issues for tracing kernel functions. Please
> refer to Yonghong and Alan's presentation [1] for various cases.
> 
> Thanks,
> Song
> 
> [1] https://lpc.events/event/18/contributions/1945/
> 
>

Hi Song,

Thank you for the materials you provided. I'll take a look at them.

> On Thu, Mar 27, 2025 at 9:03 AM Tao Chen <chen.dylane@linux.dev> wrote:
>>
>> Hi,
>>
>> I recently encountered a problem when using fentry to trace kernel
>> functions optimized by compiler, the specific situation is as follows:
>> https://github.com/bpftrace/bpftrace/issues/3940
>>
>> Simply put, some functions have been optimized by the compiler. The
>> original function names are found through BTF, but the optimized
>> functions are the ones that exist in kallsyms_lookup_name. Therefore,
>> the two do not match.
>>
>>           func_proto = btf_type_by_id(desc_btf, func->type);
>>           if (!func_proto || !btf_type_is_func_proto(func_proto)) {
>>                   verbose(env, "kernel function btf_id %u does not have a
>> valid func_proto\n",
>>                           func_id);
>>                   return -EINVAL;
>>           }
>>
>>           func_name = btf_name_by_offset(desc_btf, func->name_off);
>>           addr = kallsyms_lookup_name(func_name);
>>           if (!addr) {
>>                   verbose(env, "cannot find address for kernel function
>> %s\n",
>>                           func_name);
>>                   return -EINVAL;
>>           }
>>
>> I have made a simple statistics and there are approximately more than
>> 2,000 functions in Ubuntu 24.04.
>>
>> dylane@2404:~$ cat /proc/kallsyms | grep isra | wc -l
>> 2324
>>
>> So can we add a judgment from libbpf. If it is an optimized function,
>> pass the suffix of the optimized function from the user space to the
>> kernel, and then perform a function name concatenation, like:
>>
>>           func_name = btf_name_by_offset(desc_btf, func->name_off);
>>          if (optimize) {
>>                  func_name = func_name + ".isra.0"
>>          }
>>           addr = kallsyms_lookup_name(func_name);
>>
>> --
>> Best Regards
>> Tao Chen
>>


-- 
Best Regards
Tao Chen

  reply	other threads:[~2025-03-28 15:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-27 16:03 Question: fentry on kernel func optimized by compiler Tao Chen
2025-03-27 17:19 ` Song Liu
2025-03-28 15:19   ` Tao Chen [this message]
2025-03-28 17:21 ` Andrii Nakryiko
2025-03-31  9:54   ` Tao Chen
2025-03-31 10:13   ` Alan Maguire
2025-04-15 12:10     ` Tao Chen
2025-04-15 19:21       ` Jiri Olsa
2025-04-17 12:55         ` Tao Chen

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=4c60f56a-8505-49f3-872b-d485d65813d7@linux.dev \
    --to=chen.dylane@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@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