Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable BTF support for ubuntu 20.04? #2948

Open
wwwzrb opened this issue Jun 3, 2020 · 8 comments
Open

How to enable BTF support for ubuntu 20.04? #2948

wwwzrb opened this issue Jun 3, 2020 · 8 comments

Comments

@wwwzrb
Copy link

wwwzrb commented Jun 3, 2020

I tried to enable BTF support by rebuilding kernel with CONFIG_DEBUG_INFO_BTF=y.

The specific configuration is shown below:

Kernel version:
image

Clang and LLVM version:
image
image

And /sys/kernel/btf/vmlinux exist.
image
bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h is OK.

However, I encouter this problem:
image

So actually opensnoop use kprobe and kretprobe to get the filled funcation arguments.
KFUNC and KRETFUNC are not load successfully.

I don't know what's going wrong. Is there anybody meet similar problems? Very gratefull if you have any suggestions!

@yonghong-song
Copy link
Collaborator

Could you make sure you have pahole >= 1.16 on your system?

@wwwzrb
Copy link
Author

wwwzrb commented Jun 3, 2020

Could you make sure you have pahole >= 1.16 on your system?

No, the pahole version is 1.15 in my system. I install pahole by warves package.

image

Is pahole the key problem?

@yonghong-song
Copy link
Collaborator

Yes, you need >= 1.16 pahole.

@wwwzrb
Copy link
Author

wwwzrb commented Jun 4, 2020

Yes, you need >= 1.16 pahole.

I rebuild my kernel with pahole 1.16 and also rebuild bcc. Now it works.

Pahole 1.16 solve the problem of "libbpf: bpf_prog_put is not found in vmulinux BTF"!

image

However, I encounter another problem.
Do KFUNC and KRETFUNC support all kernel functions?

I tried the opensnoop example and check whether KRETFUNC for do_sys_open is loaded successfully.

is_support_kfunc = BPF.support_kfunc()

if is_support_kfunc:

        print("w/ KFUNC/KRETFUNC_PROBE SUPPORT")

        bpf_text += bpf_text_kfunc

else:

        print("w/o KFUNC/KRETFUNC_PROBE SUPPORT")

        bpf_text += bpf_text_kprobe

Result shows that is_support_kfunc return a false value.

image

Or is this problem blame to not-upate-to-date kernel and clang/llvm version?
I'm using kernel 5.4.34 and clang/llvm 9.0.1-12.

Thanks for your help!

@yonghong-song
Copy link
Collaborator

I think 5.4 does not support kfunc/kretfunc. You probably need 5.6. cc @olsajiri

@wwwzrb
Copy link
Author

wwwzrb commented Jun 4, 2020

I think 5.4 does not support kfunc/kretfunc. You probably need 5.6. cc @olsajiri

Got it. I'll have a try for newer version!

@wwwzrb
Copy link
Author

wwwzrb commented Jun 4, 2020

I think 5.4 does not support kfunc/kretfunc. You probably need 5.6. cc @olsajiri

Hey, I'm using kernel 5.7 now. It works but another new problem comes.

I'm tring to get the filled arguments after function returns.

A simple example will be like this:

   KRETFUNC_PROBE(do_sys_open, int dfd, const char __user *filename, int flags, int mode, int ret)

Then I can get the filename which may be filled after the function returns.

The problem is that KREFUNC_PROBE cannot deal with the type of pointer to a struct. As attached below, struct sock * is unrecognized! Actually, the probe tries to pass void * of 'ctx[0]?' (I cannot remember exactly) to the first argument of the probed function, however, it cannot recognize the correct type.

image

By the way, when I tried to include "vmlinux.h" instead of using kernel header, it causes errors of duplicate definitions. Part results are attached below.

image

@iammattcoleman
Copy link

Canonical has updated Ubuntu 20.04's 5.4 kernel to include BTF support. Installing the kernel 5.4 package from the focal-updates repository will fix that issue. Additionally, the dwarves package currently provides pahole 1.21.

Here is the last 20.04 kernel config that did not have BTF support:

The next version has it enabled:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants