You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Kernel function inlining has caused a lot of trouble for tracing in the past (e.g., #703, #1667, #2252, #2373, #3913, #4638, just to name a few)
I posted a proof of concept at #4638 (comment) to attach kprobes to inlined functions with the help of the debug info.
In short, we can
Download the debug info of the kernel image.
Look for the address of the inlined function (inside the caller function) and the location of the parameter (since the inlined function does not follow the calling convention).
Attach to the inlined function, and manually read the parameter from the register or stack.
The purpose of this post is to discuss whether this approach is feasible and if it can be implemented in a more general way.
Some of the challenges I can think of are:
BTF does not record the address of inlined functions, so we have to rely on the debug info, which adds another dependency. Adding this information to BTF might be possible if people find it useful (and it does not increase the size too much).
Usually, the location of the parameter can be found in some register. However, in the general case, it might require resolving DWARF expressions (see Chapter 2.5 at https://dwarfstd.org/doc/DWARF5.pdf). To automate this process, we might need to implement a DWARF expressions evaluator in BPF.
Whether or not this approach is feasible depends on the quality of the debug info. I have seen cases where the compiler does not generate debug info for functions marked as __always_inline.
Here are the original proof of concept posted at #4638 (comment):
Download the debug info of the kernel image (e.g., sudo apt install linux-image-$(uname -r)-dbgsym for Ubuntu. Need to add the package list first following this link)
From the output above, we know that this inlined call site for blk_account_io_start is at 0xffffffff8174428e (or blk_execute_rq_nowait+0x8e with symbol table info) and the first parameter req is at r12. Similar information can be found for other inlined call sites.
Given that, we can write an eBPF program to attach to inlined functions. The full code is shown below:
ShawnZhong
changed the title
Here is a proof of concept to attach kprobes to inline functions and read the arguments given the debug info.
[Proposal] Tracing inline functions
Aug 27, 2024
Kernel function inlining has caused a lot of trouble for tracing in the past (e.g., #703, #1667, #2252, #2373, #3913, #4638, just to name a few)
I posted a proof of concept at #4638 (comment) to attach kprobes to inlined functions with the help of the debug info.
In short, we can
The purpose of this post is to discuss whether this approach is feasible and if it can be implemented in a more general way.
Some of the challenges I can think of are:
__always_inline
.Here are the original proof of concept posted at #4638 (comment):
Download the debug info of the kernel image (e.g.,
sudo apt install linux-image-$(uname -r)-dbgsym
for Ubuntu. Need to add the package list first following this link)Dump the address of inlined function:
For example, one of the inlined sites is shown as follows:
From the output above, we know that this inlined call site for
blk_account_io_start
is at0xffffffff8174428e
(orblk_execute_rq_nowait+0x8e
with symbol table info) and the first parameterreq
is atr12
. Similar information can be found for other inlined call sites.Given that, we can write an eBPF program to attach to inlined functions. The full code is shown below:
with output:
The text was updated successfully, but these errors were encountered: