Skip to content

Commit 251aa12

Browse files
Copilotyunwei37
andauthored
Add troubleshooting guide for fentry attachment failures in 3-fentry-unlink (#200)
* Initial plan * Add troubleshooting section for fentry-unlink example with kernel compatibility guidance Co-authored-by: yunwei37 <34985212+yunwei37@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: yunwei37 <34985212+yunwei37@users.noreply.github.com>
1 parent 1d99584 commit 251aa12

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

src/3-fentry-unlink/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,72 @@ $ sudo cat /sys/kernel/debug/tracing/trace_pipe
8383
rm-9290 [004] d..2 4637.798843: bpf_trace_printk: fexit: pid = 9290, filename = test_file2, ret = 0
8484
```
8585

86+
## Troubleshooting
87+
88+
If you encounter errors when running this example, here are some common issues and solutions:
89+
90+
### Error: "failed to attach: ERROR: strerror_r(-524)=22"
91+
92+
This error (error code -524 = ENOTSUPP) typically means your kernel doesn't support fentry/fexit. Here's how to troubleshoot:
93+
94+
**1. Check your kernel version:**
95+
96+
```console
97+
$ uname -r
98+
```
99+
100+
You need:
101+
- Kernel 5.5 or newer for x86/x86_64 processors
102+
- Kernel 6.0 or newer for ARM/ARM64 processors
103+
104+
If your kernel is too old, you have two options:
105+
- Upgrade your kernel to a supported version
106+
- Use the kprobe example instead (see [example 2-kprobe-unlink](../2-kprobe-unlink/))
107+
108+
**2. Verify BTF (BPF Type Format) support:**
109+
110+
BTF is required for fentry/fexit to work. Check if it's enabled:
111+
112+
```console
113+
$ cat /boot/config-$(uname -r) | grep CONFIG_DEBUG_INFO_BTF
114+
CONFIG_DEBUG_INFO_BTF=y
115+
```
116+
117+
If BTF is not enabled, you'll need to either:
118+
- Use a kernel with BTF support enabled
119+
- Use the kprobe example as an alternative
120+
121+
**3. Check if the kernel function exists:**
122+
123+
The function `do_unlinkat` may have a different name or may not be exported in some kernel versions. You can check available functions:
124+
125+
```console
126+
$ sudo cat /sys/kernel/debug/tracing/available_filter_functions | grep unlink
127+
```
128+
129+
If `do_unlinkat` is not listed, the function may not be available for tracing on your kernel.
130+
131+
**4. Verify your kernel configuration:**
132+
133+
Ensure your kernel was compiled with the necessary eBPF features:
134+
135+
```console
136+
$ cat /boot/config-$(uname -r) | grep BPF
137+
```
138+
139+
Look for these important settings:
140+
- `CONFIG_BPF=y`
141+
- `CONFIG_BPF_SYSCALL=y`
142+
- `CONFIG_DEBUG_INFO_BTF=y`
143+
- `CONFIG_BPF_JIT=y`
144+
145+
If you're still experiencing issues after checking these items, please report your kernel version and OS distribution by running:
146+
147+
```console
148+
$ uname -a
149+
$ cat /etc/os-release
150+
```
151+
86152
## Summary
87153

88154
This program is an eBPF program that captures the `do_unlinkat` and `do_unlinkat_exit` functions using fentry and fexit, and uses `bpf_get_current_pid_tgid` and `bpf_printk` functions to obtain the ID, filename, and return value of the process calling do_unlinkat, and print them in the kernel log.

src/3-fentry-unlink/README.zh.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,72 @@ $ sudo cat /sys/kernel/debug/tracing/trace_pipe
9191
rm-9290 [004] d..2 4637.798843: bpf_trace_printk: fexit: pid = 9290, filename = test_file2, ret = 0
9292
```
9393

94+
## 故障排查
95+
96+
如果您在运行此示例时遇到错误,以下是一些常见问题和解决方案:
97+
98+
### 错误:"failed to attach: ERROR: strerror_r(-524)=22"
99+
100+
此错误(错误代码 -524 = ENOTSUPP)通常表示您的内核不支持 fentry/fexit。以下是排查方法:
101+
102+
**1. 检查内核版本:**
103+
104+
```console
105+
$ uname -r
106+
```
107+
108+
您需要:
109+
- x86/x86_64 处理器需要内核 5.5 或更高版本
110+
- ARM/ARM64 处理器需要内核 6.0 或更高版本
111+
112+
如果您的内核版本过旧,您有两个选择:
113+
- 将内核升级到支持的版本
114+
- 使用 kprobe 示例代替(参见 [示例 2-kprobe-unlink](../2-kprobe-unlink/)
115+
116+
**2. 验证 BTF(BPF Type Format)支持:**
117+
118+
fentry/fexit 需要 BTF 支持。检查是否已启用:
119+
120+
```console
121+
$ cat /boot/config-$(uname -r) | grep CONFIG_DEBUG_INFO_BTF
122+
CONFIG_DEBUG_INFO_BTF=y
123+
```
124+
125+
如果 BTF 未启用,您需要:
126+
- 使用已启用 BTF 支持的内核
127+
- 使用 kprobe 示例作为替代方案
128+
129+
**3. 检查内核函数是否存在:**
130+
131+
`do_unlinkat` 函数在某些内核版本中可能有不同的名称或未导出。您可以检查可用的函数:
132+
133+
```console
134+
$ sudo cat /sys/kernel/debug/tracing/available_filter_functions | grep unlink
135+
```
136+
137+
如果未列出 `do_unlinkat`,则该函数可能在您的内核上无法用于跟踪。
138+
139+
**4. 验证内核配置:**
140+
141+
确保您的内核编译时包含了必要的 eBPF 功能:
142+
143+
```console
144+
$ cat /boot/config-$(uname -r) | grep BPF
145+
```
146+
147+
查找这些重要设置:
148+
- `CONFIG_BPF=y`
149+
- `CONFIG_BPF_SYSCALL=y`
150+
- `CONFIG_DEBUG_INFO_BTF=y`
151+
- `CONFIG_BPF_JIT=y`
152+
153+
如果检查这些项目后仍然遇到问题,请通过运行以下命令报告您的内核版本和操作系统发行版:
154+
155+
```console
156+
$ uname -a
157+
$ cat /etc/os-release
158+
```
159+
94160
## 总结
95161

96162
这段程序是一个 eBPF 程序,通过使用 fentry 和 fexit 捕获 `do_unlinkat``do_unlinkat_exit` 函数,并通过使用 `bpf_get_current_pid_tgid``bpf_printk` 函数获取调用 do_unlinkat 的进程的 ID、文件名和返回值,并在内核日志中打印出来。

0 commit comments

Comments
 (0)