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

Attach all insns matching the same line, output with CALL #9

Merged
merged 1 commit into from
Jan 12, 2025

Conversation

jschwinger233
Copy link
Owner

Otherwise we'll miss some important execution flows.

For example, the following insns are matched to the same line:

(gdb) disas/m __netif_receive_skb_one_core
5540	in /build/linux-hwe-6.8-vrBNIF/linux-hwe-6.8-6.8.0/net/core/dev.c
   0xffffffff81edd377 <+71>:	mov    -0x20(%rbp),%rdi
   0xffffffff81edd37b <+75>:	mov    0x10(%rdx),%rax
   0xffffffff81edd37f <+79>:	mov    %rbx,%rcx
   0xffffffff81edd382 <+82>:	mov    0x10(%rdi),%rsi
   0xffffffff81edd386 <+86>:	cmp    $0xffffffff8206b770,%rax
   0xffffffff81edd38c <+92>:	jne    0xffffffff81edd3b4 <__netif_receive_skb_one_core+132>
   0xffffffff81edd38e <+94>:	call   0xffffffff8206b770 <ipv6_rcv>
   0xffffffff81edd3b4 <+132>:	cmp    $0xffffffff81f9a460,%rax
   0xffffffff81edd3ba <+138>:	jne    0xffffffff81edd3c3 <__netif_receive_skb_one_core+147>
   0xffffffff81edd3bc <+140>:	call   0xffffffff81f9a460 <ip_rcv>
   0xffffffff81edd3c1 <+145>:	jmp    0xffffffff81edd393 <__netif_receive_skb_one_core+99>
   0xffffffff81edd3c3 <+147>:	call   0xffffffff822209e0 <__x86_indirect_thunk_array>

There are multiple different call insns, we'll have to attach bpf to all of them.

Also this commit parses indirect call such as call *%rax.

The typical output with this patch looks like:

no   skb                skb->len   pc                 ksym
1    ffff8f775f4184e8   60         ffffffff91ae0891   __netif_receive_skb_one_core+1 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
2    ffff8f775f4184e8   60         ffffffff91ae0896   __netif_receive_skb_one_core+6 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
3    ffff8f775f4184e8   60         ffffffff91ae0897   __netif_receive_skb_one_core+7 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5538
4    ffff8f775f4184e8   60         ffffffff91ae089b   __netif_receive_skb_one_core+11 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
5    ffff8f775f4184e8   60         ffffffff91ae089e   __netif_receive_skb_one_core+14
6    ffff8f775f4184e8   60         ffffffff91ae089f   __netif_receive_skb_one_core+15
7    ffff8f775f4184e8   60         ffffffff91ae08a3   __netif_receive_skb_one_core+19 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
8    ffff8f775f4184e8   60         ffffffff91ae08a7   __netif_receive_skb_one_core+23 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5534
9    ffff8f775f4184e8   60         ffffffff91ae08ab   __netif_receive_skb_one_core+27 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5538
10   ffff8f775f4184e8   60         ffffffff91ae08af   __netif_receive_skb_one_core+31 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
11   ffff8f775f4184e8   60         ffffffff91ae08b8   __netif_receive_skb_one_core+40
12   ffff8f775f4184e8   60         ffffffff91ae08bc   __netif_receive_skb_one_core+44
13   ffff8f775f4184e8   60         ffffffff91ae08be   __netif_receive_skb_one_core+46 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5538
14   ffff8f775f4184e8   60         ffffffff91ae08c2   __netif_receive_skb_one_core+50 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5535
15   ffff8f775f4184e8   60         ffffffff91ae08ca   __netif_receive_skb_one_core+58 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5538 // CALL __netif_receive_skb_core.constprop.0
16   ffff8f775f4184e8   60         ffffffff91ae08cf   __netif_receive_skb_one_core+63 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5539
17   ffff8f775f4184e8   60         ffffffff91ae08d3   __netif_receive_skb_one_core+67 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5539
18   ffff8f775f4184e8   60         ffffffff91ae08d6   __netif_receive_skb_one_core+70
19   ffff8f775f4184e8   60         ffffffff91ae08d8   __netif_receive_skb_one_core+72 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5540
20   ffff8f775f4184e8   60         ffffffff91ae08dc   __netif_receive_skb_one_core+76
21   ffff8f775f4184e8   60         ffffffff91ae08e0   __netif_receive_skb_one_core+80 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5540
22   ffff8f775f4184e8   60         ffffffff91ae08e3   __netif_receive_skb_one_core+83
23   ffff8f775f4184e8   60         ffffffff91ae08e7   __netif_receive_skb_one_core+87
24   ffff8f775f4184e8   60         ffffffff91ae08ed   __netif_receive_skb_one_core+93
25   ffff8f775f4184e8   60         ffffffff91ae0915   __netif_receive_skb_one_core+133 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5540
26   ffff8f775f4184e8   60         ffffffff91ae091b   __netif_receive_skb_one_core+139
27   ffff8f775f4184e8   60         ffffffff91ae0924   __netif_receive_skb_one_core+148 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5540 // CALL packet_rcv

Otherwise we'll miss some important execution flows.

For example, the following insns are matched to the same line:

```
(gdb) disas/m __netif_receive_skb_one_core
5540	in /build/linux-hwe-6.8-vrBNIF/linux-hwe-6.8-6.8.0/net/core/dev.c
   0xffffffff81edd377 <+71>:	mov    -0x20(%rbp),%rdi
   0xffffffff81edd37b <+75>:	mov    0x10(%rdx),%rax
   0xffffffff81edd37f <+79>:	mov    %rbx,%rcx
   0xffffffff81edd382 <+82>:	mov    0x10(%rdi),%rsi
   0xffffffff81edd386 <+86>:	cmp    $0xffffffff8206b770,%rax
   0xffffffff81edd38c <+92>:	jne    0xffffffff81edd3b4 <__netif_receive_skb_one_core+132>
   0xffffffff81edd38e <+94>:	call   0xffffffff8206b770 <ipv6_rcv>
   0xffffffff81edd3b4 <+132>:	cmp    $0xffffffff81f9a460,%rax
   0xffffffff81edd3ba <+138>:	jne    0xffffffff81edd3c3 <__netif_receive_skb_one_core+147>
   0xffffffff81edd3bc <+140>:	call   0xffffffff81f9a460 <ip_rcv>
   0xffffffff81edd3c1 <+145>:	jmp    0xffffffff81edd393 <__netif_receive_skb_one_core+99>
   0xffffffff81edd3c3 <+147>:	call   0xffffffff822209e0 <__x86_indirect_thunk_array>
```

There are multiple different call insns, we'll have to attach bpf to all
of them.

Also this commit parses indirect call such as `call *%rax`.

The typical output with this patch looks like:

```
no   skb                skb->len   pc                 ksym
1    ffff8f775f4184e8   60         ffffffff91ae0891   __netif_receive_skb_one_core+1 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
2    ffff8f775f4184e8   60         ffffffff91ae0896   __netif_receive_skb_one_core+6 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
3    ffff8f775f4184e8   60         ffffffff91ae0897   __netif_receive_skb_one_core+7 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5538
4    ffff8f775f4184e8   60         ffffffff91ae089b   __netif_receive_skb_one_core+11 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
5    ffff8f775f4184e8   60         ffffffff91ae089e   __netif_receive_skb_one_core+14
6    ffff8f775f4184e8   60         ffffffff91ae089f   __netif_receive_skb_one_core+15
7    ffff8f775f4184e8   60         ffffffff91ae08a3   __netif_receive_skb_one_core+19 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
8    ffff8f775f4184e8   60         ffffffff91ae08a7   __netif_receive_skb_one_core+23 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5534
9    ffff8f775f4184e8   60         ffffffff91ae08ab   __netif_receive_skb_one_core+27 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5538
10   ffff8f775f4184e8   60         ffffffff91ae08af   __netif_receive_skb_one_core+31 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5533
11   ffff8f775f4184e8   60         ffffffff91ae08b8   __netif_receive_skb_one_core+40
12   ffff8f775f4184e8   60         ffffffff91ae08bc   __netif_receive_skb_one_core+44
13   ffff8f775f4184e8   60         ffffffff91ae08be   __netif_receive_skb_one_core+46 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5538
14   ffff8f775f4184e8   60         ffffffff91ae08c2   __netif_receive_skb_one_core+50 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5535
15   ffff8f775f4184e8   60         ffffffff91ae08ca   __netif_receive_skb_one_core+58 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5538 // CALL __netif_receive_skb_core.constprop.0
16   ffff8f775f4184e8   60         ffffffff91ae08cf   __netif_receive_skb_one_core+63 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5539
17   ffff8f775f4184e8   60         ffffffff91ae08d3   __netif_receive_skb_one_core+67 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5539
18   ffff8f775f4184e8   60         ffffffff91ae08d6   __netif_receive_skb_one_core+70
19   ffff8f775f4184e8   60         ffffffff91ae08d8   __netif_receive_skb_one_core+72 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5540
20   ffff8f775f4184e8   60         ffffffff91ae08dc   __netif_receive_skb_one_core+76
21   ffff8f775f4184e8   60         ffffffff91ae08e0   __netif_receive_skb_one_core+80 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5540
22   ffff8f775f4184e8   60         ffffffff91ae08e3   __netif_receive_skb_one_core+83
23   ffff8f775f4184e8   60         ffffffff91ae08e7   __netif_receive_skb_one_core+87
24   ffff8f775f4184e8   60         ffffffff91ae08ed   __netif_receive_skb_one_core+93
25   ffff8f775f4184e8   60         ffffffff91ae0915   __netif_receive_skb_one_core+133 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5540
26   ffff8f775f4184e8   60         ffffffff91ae091b   __netif_receive_skb_one_core+139
27   ffff8f775f4184e8   60         ffffffff91ae0924   __netif_receive_skb_one_core+148 /build/linux-hwe-6.8-GtMYNi/linux-hwe-6.8-6.8.0/net/core/dev.c:5540 // CALL packet_rcv
```
@jschwinger233 jschwinger233 merged commit 2a83bd5 into main Jan 12, 2025
1 check passed
@jschwinger233 jschwinger233 deleted the pr/gray/attach-by-calls branch January 12, 2025 15:35
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.

1 participant