Skip to content

Conversation

Asphaltt
Copy link
Contributor

@Asphaltt Asphaltt commented Jan 15, 2025

Fixes #483

There're two issue:

One is BPF_PROG_ADDR must be set via spec.Variable.

Another one is .bss map flag must be updated because go-ebpf v0.17.1 set BPF_F_MMAPABLE flag to created .bss map. As a result, we can reuse .bss map.

Here's the test result:

2025/01/15 15:14:26 Attaching tc-bpf progs...
2025/01/15 15:14:26 Attaching xdp progs...
2025/01/15 15:14:26 Attaching kprobes (via kprobe)...
29 / 29 [--------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
2025/01/15 15:14:26 Attached (ignored 0)
2025/01/15 15:14:26 Listening for events..
SKB                CPU PROCESS          NETNS      MARK/x        IFACE       PROTO  MTU   LEN   __sk_buff->cb[]                                          TUPLE FUNC
0xffffb5dd40600b00 6   <empty>:0        4026531840 0            ens33:2      0x0000 1500  98    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_3b185187f1855c4c_dummy[bpf](xdp)
0xffff995b7756d400 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff995b7756d400 6   <empty>:0        4026531840 0            ens33:2      0x0800 65536 64    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_rcv
0xffff995b7756d400 6   <empty>:0        4026531840 0            ens33:2      0x0800 65536 56    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_echo
0xffff995b7756d400 6   <empty>:0        4026531840 0            ens33:2      0x0800 65536 56    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_reply
^C2025/01/15 15:14:30 Received signal, exiting program..
2025/01/15 15:14:30 Detaching kprobes...
29 / 29 [------------------------------------------------------------------------------------------------------------------------------------] 100.00% 132 p/s

And there's only one .bss map:

# bpftool m | grep -c .bss
1

@Asphaltt Asphaltt requested a review from a team as a code owner January 15, 2025 15:26
@Asphaltt Asphaltt requested review from brb and removed request for a team January 15, 2025 15:26
There're two issue:

One is `BPF_PROG_ADDR` must be set via `spec.Variable`.

Another one is `.bss` map flag must be updated because go-ebpf v0.17.1
set `BPF_F_MMAPABLE` flag to created `.bss` map. As a result, we can reuse
`.bss` map.

Here's the test result:

```bash
$ sudo ./pwru --filter-trace-tc --filter-trace-xdp --filter-func '.*icmp.*' icmp
2025/01/15 15:14:26 Attaching tc-bpf progs...
2025/01/15 15:14:26 Attaching xdp progs...
2025/01/15 15:14:26 Attaching kprobes (via kprobe)...
29 / 29 [--------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
2025/01/15 15:14:26 Attached (ignored 0)
2025/01/15 15:14:26 Listening for events..
SKB                CPU PROCESS          NETNS      MARK/x        IFACE       PROTO  MTU   LEN   __sk_buff->cb[]                                          TUPLE FUNC
0xffffb5dd40600b00 6   <empty>:0        4026531840 0            ens33:2      0x0000 1500  98    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_3b185187f1855c4c_dummy[bpf](xdp)
0xffff995b7756d400 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff995b7756d400 6   <empty>:0        4026531840 0            ens33:2      0x0800 65536 64    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_rcv
0xffff995b7756d400 6   <empty>:0        4026531840 0            ens33:2      0x0800 65536 56    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_echo
0xffff995b7756d400 6   <empty>:0        4026531840 0            ens33:2      0x0800 65536 56    [0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 192.168.241.1:0->192.168.241.133:0(icmp) icmp_reply
^C2025/01/15 15:14:30 Received signal, exiting program..
2025/01/15 15:14:30 Detaching kprobes...
29 / 29 [------------------------------------------------------------------------------------------------------------------------------------] 100.00% 132 p/s
```

And there's only one `.bss` map:

```bash
$ sudo bpftool m | grep -c .bss
1
```

Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
Copy link
Member

@brb brb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@brb brb merged commit a5b31eb into cilium:main Jan 30, 2025
8 checks passed
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

Successfully merging this pull request may close these issues.

Failed to trace XDP: using replacement map .bss: Flags: 1024 changed to 0: map spec is incompatible with existing map
3 participants