On 10/8/19 10:36 PM, Andrii Nakryiko wrote: > On Fri, Oct 4, 2019 at 10:04 PM Alexei Starovoitov <ast@xxxxxxxxxx> wrote: >> >> Load basic cls_bpf program. >> Load raw_tracepoint program and attach to kfree_skb raw tracepoint. >> Trigger cls_bpf via prog_test_run. >> At the end of test_run kernel will call kfree_skb >> which will trigger trace_kfree_skb tracepoint. >> Which will call our raw_tracepoint program. >> Which will take that skb and will dump it into perf ring buffer. >> Check that user space received correct packet. >> >> Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> >> --- > > LGTM, few minor nits below. > > Acked-by: Andrii Nakryiko <andriin@xxxxxx> > > >> .../selftests/bpf/prog_tests/kfree_skb.c | 90 +++++++++++++++++++ >> tools/testing/selftests/bpf/progs/kfree_skb.c | 76 ++++++++++++++++ >> 2 files changed, 166 insertions(+) >> create mode 100644 tools/testing/selftests/bpf/prog_tests/kfree_skb.c >> create mode 100644 tools/testing/selftests/bpf/progs/kfree_skb.c >> >> diff --git a/tools/testing/selftests/bpf/prog_tests/kfree_skb.c b/tools/testing/selftests/bpf/prog_tests/kfree_skb.c >> new file mode 100644 >> index 000000000000..238bc7024b36 >> --- /dev/null >> +++ b/tools/testing/selftests/bpf/prog_tests/kfree_skb.c >> @@ -0,0 +1,90 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +#include <test_progs.h> >> + >> +static void on_sample(void *ctx, int cpu, void *data, __u32 size) >> +{ >> + int ifindex = *(int *)data, duration = 0; >> + struct ipv6_packet * pkt_v6 = data + 4; >> + >> + if (ifindex != 1) >> + /* spurious kfree_skb not on loopback device */ >> + return; >> + if (CHECK(size != 76, "check_size", "size %d != 76\n", size)) > > compiler doesn't complain about %d and size being unsigned? compile didn't complain. but I fixed it. >> +SEC("raw_tracepoint/kfree_skb") >> +int trace_kfree_skb(struct trace_kfree_skb* ctx) >> +{ >> + struct sk_buff *skb = ctx->skb; >> + struct net_device *dev; >> + int ifindex; >> + struct callback_head *ptr; >> + void *func; > > nit: style checker should have complained about missing empty line good point. Fixed checkpatch errors.