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

bpf_printk doesn't create data on trace_pipe #75

Closed
andreybleme opened this issue May 24, 2022 · 9 comments
Closed

bpf_printk doesn't create data on trace_pipe #75

andreybleme opened this issue May 24, 2022 · 9 comments

Comments

@andreybleme
Copy link

My minimal app executes correctly:

image

But when I cat the "/sys/kernel/debug/tracing/trace_pipe" file it looks empty:

image

I'm running a Ubuntu 22.04 LTS docker container on privileged mode.

This is how I have manually mounted my debugfs:
mount -t debugfs none /sys/kernel/debug

Am I missing anything? Appreciate your help.

@anakryiko
Copy link
Member

Not really, but I've had cases when something in kernel "broke" w.r.t. trace_pipe and BPF program stopped emitting anything into it. Can you try rebooting and trying ./minimal again before you do anything else with the system?

I also see

mount | rg debug
debugfs on /sys/kernel/debug type debugfs (rw,relatime,mode=755)
tracefs on /sys/kernel/debug/tracing type tracefs (rw,relatime)

So maybe try mounting tracefs as well?

@andreybleme
Copy link
Author

andreybleme commented May 24, 2022

Thanks for replying @anakryiko!
After mounting tracefs mount -t tracefs nodev /sys/kernel/tracing, I see:

$ mount | rg debug
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tracefs on /sys/kernel/debug/tracing type tracefs (rw,relatime)

And the BPF program still doesn't write into /sys/kernel/debug/tracing/trace_pipe.
Interesting that when I cat, tail, or try to open the trace_pipe file with vi, the process doesn't finish with the empty output as it does with regular empty files. It actually gets stuck:

image

The file stat is:

File: /sys/kernel/debug/tracing/trace_pipe
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: ah/10d	Inode: 12206       Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-05-23 23:07:10.643999999 +0000
Modify: 2022-05-23 23:07:10.643999999 +0000
Change: 2022-05-24 00:30:11.248272170 +0000
 Birth: -

All files from debugfs looking normal (permissions):

image

Already tried mounting debugfs and tracefs again, restarting the container etc... Any additional ideas?

@anakryiko
Copy link
Member

I have no idea, tbh. If you are trying it from inside the container, have you tried reading that file from outside any container? Also make sure that you don't have any other process opening this file, because I think trace_pipe doesn't support multiple readers reading it simultaneously.

@andreybleme
Copy link
Author

I see. I'm executing this by running "./minimal", and after I see the dots from the userspace application indicating the BPF program is running, I stop the processes (CTRL + C) and then run the cat command. Should I be checking for debug messages in a different way?

@anakryiko
Copy link
Member

you can run cat in parallel, but even if you run afterwards you should still see previous output.

Do you have a chance to try this on some other system? It might be some (unknown to me) kernel config dependencies. Other than that, I'm not sure how to help you.

@andreybleme
Copy link
Author

This was simply a mistake in the eBPF program. Having the if statement:

if (pid != my_pid)
        return 0;

With this initial declaration:

int my_pid = 0;

This causes the BPF program never to actually execute the bpf_printk. When I removed the if statement, the cat command worked.

Thanks again for your time @anakryiko !

@Arvintian
Copy link

This may causes by the pid namespace. I had the same problem in wsl microsoft/WSL#8461. The same as you are run the BPF program in the container, it pid namespace not is global namespace. Tansks @X-QIANG.

@lzh-lab
Copy link

lzh-lab commented Dec 2, 2022

I have the same problem in a host and reboot solved it.

@novitoll
Copy link

Make sure that tracing_on is enabled.

echo 1 > /sys/kernel/debug/tracing/tracing_on
cat /sys/kernel/debug/tracing/trace_pipe

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

5 participants