Message ID | 1601292670-1616-1-git-send-email-alan.maguire@oracle.com |
---|---|
Headers | show |
Series | bpf: add helpers to support BTF-based kernel data display | expand |
On Mon, Sep 28, 2020 at 4:33 AM Alan Maguire <alan.maguire@oracle.com> wrote: > > Default output for an sk_buff looks like this (zeroed fields > are omitted): > > (struct sk_buff){ > .transport_header = (__u16)65535, > .mac_header = (__u16)65535, > .end = (sk_buff_data_t)192, > .head = (unsigned char *)0x000000007524fd8b, > .data = (unsigned char *)0x000000007524fd8b, > .truesize = (unsigned int)768, > .users = (refcount_t){ > .refs = (atomic_t){ > .counter = (int)1, > }, > }, > } > > Flags can modify aspects of output format; see patch 3 > for more details. Applied. Thanks a lot.
On Mon, Sep 28, 2020 at 4:36 AM Alan Maguire <alan.maguire@oracle.com> wrote: > > Add a test verifying iterating over tasks and displaying BTF > representation of task_struct succeeds. > > Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com> > Signed-off-by: Alan Maguire <alan.maguire@oracle.com> > --- Hey Alan, These selftests rely on having struct btf_ptr and BTF_F_COMPACT (and other) flags to be present in vmlinux.h. While there is nothing wrong with that per se, it does break selftests builds on older kernels, because there struct btf_ptr isn't yet present in kernel: progs/netif_receive_skb.c:131:21: error: use of undeclared identifier 'BTF_F_NONAME' TEST_BTF(str, int, BTF_F_NONAME, "0", 0); ^ progs/netif_receive_skb.c:131:2: error: use of undeclared identifier 'BTF_F_COMPACT'; did you mean 'TT_COMPAT'? TEST_BTF(str, int, BTF_F_NONAME, "0", 0); ^ progs/netif_receive_skb.c:50:28: note: expanded from macro 'TEST_BTF' __u64 _hflags = _flags | BTF_F_COMPACT; \ ^ /data/users/andriin/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:330:2: note: 'TT_COMPAT' declared here TT_COMPAT = 2, ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] progs/bpf_iter_task_btf.c:21:24: error: variable has incomplete type 'struct btf_ptr' static struct btf_ptr ptr = { }; ^ /data/users/andriin/linux/tools/testing/selftests/bpf/tools/include/bpf/bpf_helper_defs.h:33:8: note: forward declaration of 'struct btf_ptr' struct btf_ptr; We actually do build the very latest selftests against old kernels (4.9 and 5.5 at the moment) as part of libbpf CI, so it would be nice to fix this problem and keep selftests compilable. Do you mind following up with a change to define struct btf_ptr and those BTF_F_xxx flags explicitly for selftests only, similarly to how we do it for bpf_iter context structs? See progs/bpf_iter.h for examples. Thanks. > tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 74 ++++++++++++++++++++++ > .../selftests/bpf/progs/bpf_iter_task_btf.c | 50 +++++++++++++++ > 2 files changed, 124 insertions(+) > create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_task_btf.c > [...]
On 9/28/20 1:31 PM, Alan Maguire wrote: > Tests verifying snprintf()ing of various data structures, > flags combinations using a tp_btf program. Tests are skipped > if __builtin_btf_type_id is not available to retrieve BTF > type ids. > > Signed-off-by: Alan Maguire <alan.maguire@oracle.com> [...] > +void test_snprintf_btf(void) > +{ > + struct netif_receive_skb *skel; > + struct netif_receive_skb__bss *bss; > + int err, duration = 0; > + > + skel = netif_receive_skb__open(); > + if (CHECK(!skel, "skel_open", "failed to open skeleton\n")) > + return; > + > + err = netif_receive_skb__load(skel); > + if (CHECK(err, "skel_load", "failed to load skeleton: %d\n", err)) > + goto cleanup; > + > + bss = skel->bss; > + > + err = netif_receive_skb__attach(skel); > + if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err)) > + goto cleanup; > + > + /* generate receive event */ > + system("ping -c 1 127.0.0.1 > /dev/null"); This generates the following new warning when compiling BPF selftests: [...] EXT-OBJ [test_progs] cgroup_helpers.o EXT-OBJ [test_progs] trace_helpers.o EXT-OBJ [test_progs] network_helpers.o EXT-OBJ [test_progs] testing_helpers.o TEST-OBJ [test_progs] snprintf_btf.test.o /root/bpf-next/tools/testing/selftests/bpf/prog_tests/snprintf_btf.c: In function ‘test_snprintf_btf’: /root/bpf-next/tools/testing/selftests/bpf/prog_tests/snprintf_btf.c:30:2: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result [-Wunused-result] system("ping -c 1 127.0.0.1 > /dev/null"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [...] Please fix, thx!