* [PATCH bpf] samples/bpf: Fix broken tracex1 due to kprobe argument change
@ 2021-04-16 15:48 Yaqi Chen
2021-04-16 17:47 ` Yonghong Song
2021-04-20 4:33 ` Andrii Nakryiko
0 siblings, 2 replies; 3+ messages in thread
From: Yaqi Chen @ 2021-04-16 15:48 UTC (permalink / raw)
To: ast, daniel, andrii, songliubraving, yhs; +Cc: bpf, Yaqi Chen
From commit c0bbbdc32feb ("__netif_receive_skb_core: pass skb by
reference"), the first argument passed into __netif_receive_skb_core
has changed to reference of a skb pointer.
This commit fixes by using bpf_probe_read_kernel.
Signed-off-by: Yaqi Chen <chendotjs@gmail.com>
---
samples/bpf/tracex1_kern.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/samples/bpf/tracex1_kern.c b/samples/bpf/tracex1_kern.c
index 3f4599c9a202..ef30d2b353b0 100644
--- a/samples/bpf/tracex1_kern.c
+++ b/samples/bpf/tracex1_kern.c
@@ -26,7 +26,7 @@
SEC("kprobe/__netif_receive_skb_core")
int bpf_prog1(struct pt_regs *ctx)
{
- /* attaches to kprobe netif_receive_skb,
+ /* attaches to kprobe __netif_receive_skb_core,
* looks for packets on loobpack device and prints them
*/
char devname[IFNAMSIZ];
@@ -35,7 +35,7 @@ int bpf_prog1(struct pt_regs *ctx)
int len;
/* non-portable! works for the given kernel only */
- skb = (struct sk_buff *) PT_REGS_PARM1(ctx);
+ bpf_probe_read_kernel(&skb, sizeof(skb), (void *)PT_REGS_PARM1(ctx));
dev = _(skb->dev);
len = _(skb->len);
--
2.18.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] samples/bpf: Fix broken tracex1 due to kprobe argument change
2021-04-16 15:48 [PATCH bpf] samples/bpf: Fix broken tracex1 due to kprobe argument change Yaqi Chen
@ 2021-04-16 17:47 ` Yonghong Song
2021-04-20 4:33 ` Andrii Nakryiko
1 sibling, 0 replies; 3+ messages in thread
From: Yonghong Song @ 2021-04-16 17:47 UTC (permalink / raw)
To: Yaqi Chen, ast, daniel, andrii, songliubraving; +Cc: bpf
On 4/16/21 8:48 AM, Yaqi Chen wrote:
> From commit c0bbbdc32feb ("__netif_receive_skb_core: pass skb by
> reference"), the first argument passed into __netif_receive_skb_core
> has changed to reference of a skb pointer.
>
> This commit fixes by using bpf_probe_read_kernel.
>
> Signed-off-by: Yaqi Chen <chendotjs@gmail.com>
Acked-by: Yonghong Song <yhs@fb.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] samples/bpf: Fix broken tracex1 due to kprobe argument change
2021-04-16 15:48 [PATCH bpf] samples/bpf: Fix broken tracex1 due to kprobe argument change Yaqi Chen
2021-04-16 17:47 ` Yonghong Song
@ 2021-04-20 4:33 ` Andrii Nakryiko
1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2021-04-20 4:33 UTC (permalink / raw)
To: Yaqi Chen
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Song Liu,
Yonghong Song, bpf
On Fri, Apr 16, 2021 at 8:48 AM Yaqi Chen <chendotjs@gmail.com> wrote:
>
> From commit c0bbbdc32feb ("__netif_receive_skb_core: pass skb by
> reference"), the first argument passed into __netif_receive_skb_core
> has changed to reference of a skb pointer.
>
> This commit fixes by using bpf_probe_read_kernel.
>
> Signed-off-by: Yaqi Chen <chendotjs@gmail.com>
> ---
> samples/bpf/tracex1_kern.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/samples/bpf/tracex1_kern.c b/samples/bpf/tracex1_kern.c
> index 3f4599c9a202..ef30d2b353b0 100644
> --- a/samples/bpf/tracex1_kern.c
> +++ b/samples/bpf/tracex1_kern.c
> @@ -26,7 +26,7 @@
> SEC("kprobe/__netif_receive_skb_core")
> int bpf_prog1(struct pt_regs *ctx)
This is a good opportunity to use BPF_KPROBE from bpf_tracing.h
helper. It would look like:
SEC("kprobe/__netif_receive_skb_core")
int BPF_KPROBE(struct sk_buff **pskb, bool pfmemalloc, struct
packet_type **ppt_prev)
{
/* and here you'll be able to read sk_buff pointer as */
bpf_probe_read_kernel(&skb, sizeof(skb), pskb);
}
> {
> - /* attaches to kprobe netif_receive_skb,
> + /* attaches to kprobe __netif_receive_skb_core,
> * looks for packets on loobpack device and prints them
> */
> char devname[IFNAMSIZ];
> @@ -35,7 +35,7 @@ int bpf_prog1(struct pt_regs *ctx)
> int len;
>
> /* non-portable! works for the given kernel only */
> - skb = (struct sk_buff *) PT_REGS_PARM1(ctx);
> + bpf_probe_read_kernel(&skb, sizeof(skb), (void *)PT_REGS_PARM1(ctx));
> dev = _(skb->dev);
> len = _(skb->len);
>
> --
> 2.18.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-20 4:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16 15:48 [PATCH bpf] samples/bpf: Fix broken tracex1 due to kprobe argument change Yaqi Chen
2021-04-16 17:47 ` Yonghong Song
2021-04-20 4:33 ` Andrii Nakryiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).