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 can't create data on trace_pipe #8461

Closed
1 of 2 tasks
Arvintian opened this issue May 30, 2022 · 2 comments
Closed
1 of 2 tasks

bpf_printk can't create data on trace_pipe #8461

Arvintian opened this issue May 30, 2022 · 2 comments
Assignees

Comments

@Arvintian
Copy link

Version

Microsoft Windows [版本 10.0.22000.708]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.10.102.1

Distro Version

Ubuntu 20.04

Other Software

No response

Repro Steps

  • Setup libbpf-bootstrap and make minimal.
  • Mount debugfs sudo mount -t debugfs debugfs /sys/kernel/debug
  • exec example ebpf program sudo ./minimal
  • Cat&Tail ebpf program log sudo cat /sys/kernel/debug/tracing/trace_pipe

Expected Behavior

sudo cat /sys/kernel/debug/tracing/trace_pipe should echo the ebpf program's log.

Actual Behavior

Nothing has be print out.

Diagnostic Logs

libbpf: loading object 'minimal_bpf' from buffer
libbpf: elf: section(2) tp/syscalls/sys_enter_write, size 104, link 0, flags 6, type=1
libbpf: sec 'tp/syscalls/sys_enter_write': found program 'handle_tp' at insn offset 0 (0 bytes), code size 13 insns (104 bytes)
libbpf: elf: section(3) license, size 13, link 0, flags 3, type=1
libbpf: license of minimal_bpf is Dual BSD/GPL
libbpf: elf: section(4) .bss, size 4, link 0, flags 3, type=8
libbpf: elf: section(5) .rodata, size 28, link 0, flags 2, type=1
libbpf: elf: section(6) .BTF, size 606, link 0, flags 0, type=1
libbpf: elf: section(7) .BTF.ext, size 160, link 0, flags 0, type=1
libbpf: elf: section(8) .symtab, size 192, link 13, flags 0, type=2
libbpf: elf: section(9) .reltp/syscalls/sys_enter_write, size 32, link 8, flags 0, type=9
libbpf: looking for externs among 8 symbols...
libbpf: collected 0 externs total
libbpf: map 'minimal_.bss' (global data): at sec_idx 4, offset 0, flags 400.
libbpf: map 0 is "minimal_.bss"
libbpf: map 'minimal_.rodata' (global data): at sec_idx 5, offset 0, flags 480.
libbpf: map 1 is "minimal_.rodata"
libbpf: sec '.reltp/syscalls/sys_enter_write': collecting relocation for section(2) 'tp/syscalls/sys_enter_write'
libbpf: sec '.reltp/syscalls/sys_enter_write': relo #0: insn #2 against 'my_pid'
libbpf: prog 'handle_tp': found data map 0 (minimal_.bss, sec 4, off 0) for insn 2
libbpf: sec '.reltp/syscalls/sys_enter_write': relo #1: insn #6 against '.rodata'
libbpf: prog 'handle_tp': found data map 1 (minimal_.rodata, sec 5, off 0) for insn 6
libbpf: map 'minimal_.bss': created successfully, fd=4
libbpf: map 'minimal_.rodata': created successfully, fd=5
Successfully started! Please run `sudo cat /sys/kernel/debug/tracing/trace_pipe` to see output of the BPF programs.
@OneBlue OneBlue self-assigned this May 31, 2022
@X-QIANG
Copy link

X-QIANG commented Jun 27, 2022

I had the same problem, but if you remove

if (pid != my_pid)  
    return 0;

you can see the bpf_printk print event about other process, probably userspace code fprintf didn't trigger the event.

@X-QIANG
Copy link

X-QIANG commented Jun 28, 2022

I had the same problem, but if you remove

if (pid != my_pid)  
    return 0;

you can see the bpf_printk print event about other process, probably userspace code fprintf didn't trigger the event.

actually, process in wsl run in a pid namespace, so the pid get from userspace is the pid in namesapce, and the pid get by ebpf code 'bpf_get_current_pid_tgid' is the global pid,.They can only be consistent if you get the pid inside the namespace in kernel mode.

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