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

[FEATURE] Add trace_pipe support for bpf_printk #157

Open
Officeyutong opened this issue Jan 27, 2024 · 9 comments · May be fixed by #253
Open

[FEATURE] Add trace_pipe support for bpf_printk #157

Officeyutong opened this issue Jan 27, 2024 · 9 comments · May be fixed by #253
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Officeyutong
Copy link
Contributor

Officeyutong commented Jan 27, 2024

The bpf_prink helper currently output the results to the target program. This is different from the kernel eBPF behavior and may break the target program.

We may need a feature that allow agent to send the output of bpf_printk to shm and buffer them, so that we could see logs using bpftime cli, or display them when using remote attach.

@Officeyutong Officeyutong added the enhancement New feature or request label Jan 27, 2024
@yunwei37 yunwei37 changed the title [FEATURE] Add ability to display the output of bpf printk on bpftime cli when using remote attaching mode [FEATURE] Add trace_pipe support Jan 27, 2024
@yunwei37
Copy link
Member

yunwei37 commented Jan 27, 2024

I think the bpf_printk output should not be sent to the shm. We can use a name pipe.

It can be similar like kernel /sys/kernel/debug/tracing/trace_pipe

The cli can read the data from the pipe, and the pipe can also be shared between processes.

@yunwei37 yunwei37 added good first issue Good for newcomers help wanted Extra attention is needed labels Jan 27, 2024
@yunwei37
Copy link
Member

And maybe all the log from bpftime runtime should also be sent to the name pipe for debug.

@yunwei37 yunwei37 changed the title [FEATURE] Add trace_pipe support [FEATURE] Add trace_pipe support for bpf_printk Jan 27, 2024
@agentzh
Copy link

agentzh commented Jan 27, 2024

+1. I hope the bpf_printk's output goes to the stderr stream of the bpftime load program so that it's easier to separate the debugging output from the normal output data currently going to stdout.

@aneeshdamle11
Copy link
Contributor

Hello, I am new to the code, and had a doubt after reading the issue comments and the code - Will the cli have a new option for reading the data from the pipe?

@Officeyutong
Copy link
Contributor Author

Hello, I am new to the code, and had a doubt after reading the issue comments and the code - Will the cli have a new option for reading the data from the pipe?

Yes

@aneeshdamle11
Copy link
Contributor

aneeshdamle11 commented Mar 2, 2024

I think it is an interesting issue, and would love to explore more. Also, would the implementation of bpf_printk change, or will there be a new function to write in the tracepipe?

@Officeyutong
Copy link
Contributor Author

I think it is an interesting issue, and would love to explore more. Also, would the implementation of bpf_printk change, or will there be a new function to write in the tracepipe?

bpf_printk should keep its current function, but we could use attach config (such as an option when invoking bpftime attach) to make bpf_printk output things to the pipe

@aneeshdamle11
Copy link
Contributor

I read more on the issue and referring to: https://eunomia.dev/bpftime/documents/usage/#uprobe-and-uretprobe, bpf_printk's result is shown in the output of the target (victim) program a) when it is called with the start option, or b) when the attach option works on the PID.
Hence, start and attach are responsible for dealing with bpf_printk's results.
I read some corresponding code and tried to identify the areas where tracelog is being read. Could you please help with any areas in the code I could concentrate on further?

@Officeyutong
Copy link
Contributor Author

I read more on the issue and referring to: https://eunomia.dev/bpftime/documents/usage/#uprobe-and-uretprobe, bpf_printk's result is shown in the output of the target (victim) program a) when it is called with the start option, or b) when the attach option works on the PID. Hence, start and attach are responsible for dealing with bpf_printk's results. I read some corresponding code and tried to identify the areas where tracelog is being read. Could you please help with any areas in the code I could concentrate on further?

bpf_trace_printk (which is the function that bpf_printk internally calls), is a bpf helper implemented at

uint64_t bpftime_trace_printk(uint64_t fmt, uint64_t fmt_size, ...)
, in the bpftime agent runtime.

In both bpftime start and bpftime attach, the agent was injected to the process that we want to monitor. So in the current implementation, call to bpf_trace_printk will result a message printed to stdout, at the process that was injected with agent

@aneeshdamle11 aneeshdamle11 linked a pull request Mar 21, 2024 that will close this issue
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants