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

Use github.com/cilium/cilium/pkg/alignchecker to check C and Go structs offsets and sizes #28

Open
brb opened this issue Oct 22, 2021 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@brb
Copy link
Member

brb commented Oct 22, 2021

The Cilium's alignchecker should be extended to support BTF instead of DWARF. AFAIK, @ti-mo is planning to do so.

@brb brb added the enhancement New feature or request label Oct 22, 2021
@brb brb added the help wanted Extra attention is needed label Jan 24, 2022
Asphaltt added a commit to Asphaltt/pwru that referenced this issue Sep 24, 2024
It fails to run with --filter-trace-tc:

```bash
2024/09/24 12:59:02 Attaching tc-bpf progs...
2024/09/24 12:59:02 failed to trace TC progs: failed to trace bpf progs: failed to find address for function entry2 of bpf prog SchedCLS(entry2)cilium#28
```

Then, I fix it by extracting bpf prog name from /proc/kallsyms correctly,
and avoid `addr - 1` for tracing XDP and tc-bpf.

Signed-off-by: Leon Hwang <[email protected]>
Asphaltt added a commit to Asphaltt/pwru that referenced this issue Sep 24, 2024
It fails to run with --filter-trace-tc:

```bash
2024/09/24 12:59:02 Attaching tc-bpf progs...
2024/09/24 12:59:02 failed to trace TC progs: failed to trace bpf progs: failed to find address for function entry2 of bpf prog SchedCLS(entry2)cilium#28
```

Then, I fix it by extracting bpf prog name from /proc/kallsyms correctly,
and avoid `addr - 1` for tracing XDP and tc-bpf.

```bash
2024/09/24 13:00:49 Attaching tc-bpf progs...
2024/09/24 13:00:49 Attaching xdp progs...
2024/09/24 13:00:49 Attaching kprobes (via kprobe-multi)...
49 / 49 [--------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
2024/09/24 13:00:49 Attached (ignored 0)
2024/09/24 13:00:49 Listening for events..
SKB                CPU PROCESS          NETNS      MARK/x        IFACE       PROTO  MTU   LEN   TUPLE FUNC
0xffff8e151d39b500 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) entry1(tc)
0xffff8e151d39ab00 6   ~wru/pwru:437091 4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) entry1(tc)
0xffff8e151d39a200 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) entry1(tc)
0xffff8e151d39b100 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) entry1(tc)
^C2024/09/24 13:01:04 Received signal, exiting program..
2024/09/24 13:01:04 Detaching kprobes...
3 / 3 [---------------------------------------------------------------------------------------------------------------------------------------] 100.00% 52 p/s
```

Signed-off-by: Leon Hwang <[email protected]>
Asphaltt added a commit to Asphaltt/pwru that referenced this issue Sep 25, 2024
It fails to run with --filter-trace-tc:

```bash
2024/09/24 12:59:02 Attaching tc-bpf progs...
2024/09/24 12:59:02 failed to trace TC progs: failed to trace bpf progs: failed to find address for function entry2 of bpf prog SchedCLS(entry2)cilium#28
```

Then, I fix it by extracting bpf prog name from /proc/kallsyms correctly,
and avoid `addr - 1` for tracing XDP and tc-bpf.

```bash
2024/09/24 13:00:49 Attaching tc-bpf progs...
2024/09/24 13:00:49 Attaching xdp progs...
2024/09/24 13:00:49 Attaching kprobes (via kprobe-multi)...
49 / 49 [--------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
2024/09/24 13:00:49 Attached (ignored 0)
2024/09/24 13:00:49 Listening for events..
SKB                CPU PROCESS          NETNS      MARK/x        IFACE       PROTO  MTU   LEN   TUPLE FUNC
0xffff8e151d39b500 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) entry1(tc)
0xffff8e151d39ab00 6   ~wru/pwru:437091 4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) entry1(tc)
0xffff8e151d39a200 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) entry1(tc)
0xffff8e151d39b100 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) entry1(tc)
^C2024/09/24 13:01:04 Received signal, exiting program..
2024/09/24 13:01:04 Detaching kprobes...
3 / 3 [---------------------------------------------------------------------------------------------------------------------------------------] 100.00% 52 p/s
```

Signed-off-by: Leon Hwang <[email protected]>
Asphaltt added a commit to Asphaltt/pwru that referenced this issue Sep 25, 2024
It fails to run with --filter-trace-tc:

```bash
2024/09/24 12:59:02 Attaching tc-bpf progs...
2024/09/24 12:59:02 failed to trace TC progs: failed to trace bpf progs: failed to find address for function entry2 of bpf prog SchedCLS(entry2)cilium#28
```

Then, I fix it by matching prog ksym with prog tag.

And avoid `addr - 1` for `--filter-trace-{tc,xdp}`.

```bash
2024/09/25 13:57:00 Attaching tc-bpf progs...
2024/09/25 13:57:00 Attaching kprobes (via kprobe-multi)...
49 / 49 [--------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
2024/09/25 13:57:00 Attached (ignored 0)
2024/09/25 13:57:00 Listening for events..
SKB                CPU PROCESS          NETNS      MARK/x        IFACE       PROTO  MTU   LEN   TUPLE FUNC
0xffff8e151d39be00 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff8e151d39a500 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff8e151d39bd00 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff8e151d39a200 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff8e151d39a800 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
^C2024/09/25 14:02:16 Received signal, exiting program..
2024/09/25 14:02:16 Detaching kprobes...
3 / 3 [---------------------------------------------------------------------------------------------------------------------------------------] 100.00% 50 p/s
```

Signed-off-by: Leon Hwang <[email protected]>
brb pushed a commit that referenced this issue Sep 26, 2024
It fails to run with --filter-trace-tc:

```bash
2024/09/24 12:59:02 Attaching tc-bpf progs...
2024/09/24 12:59:02 failed to trace TC progs: failed to trace bpf progs: failed to find address for function entry2 of bpf prog SchedCLS(entry2)#28
```

Then, I fix it by matching prog ksym with prog tag.

And avoid `addr - 1` for `--filter-trace-{tc,xdp}`.

```bash
2024/09/25 13:57:00 Attaching tc-bpf progs...
2024/09/25 13:57:00 Attaching kprobes (via kprobe-multi)...
49 / 49 [--------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s
2024/09/25 13:57:00 Attached (ignored 0)
2024/09/25 13:57:00 Listening for events..
SKB                CPU PROCESS          NETNS      MARK/x        IFACE       PROTO  MTU   LEN   TUPLE FUNC
0xffff8e151d39be00 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff8e151d39a500 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff8e151d39bd00 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff8e151d39a200 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
0xffff8e151d39a800 6   <empty>:0        4026531840 0            ens33:2      0x0800 1500  98    192.168.241.1:0->192.168.241.133:0(icmp) bpf_prog_e20a685998fd41c8_entry1[bpf](tc)
^C2024/09/25 14:02:16 Received signal, exiting program..
2024/09/25 14:02:16 Detaching kprobes...
3 / 3 [---------------------------------------------------------------------------------------------------------------------------------------] 100.00% 50 p/s
```

Signed-off-by: Leon Hwang <[email protected]>
@Asphaltt
Copy link
Contributor

Asphaltt commented Oct 4, 2024

Golang supports struct's host layout since go1.23 by structs.HostLayout.

Would it be better to mark bpf2go-generated structs as host layout?

@ti-mo
Copy link

ti-mo commented Oct 4, 2024

It will when ebpf-go targets 1.23, we always target the second-newest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants