From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
Martin KaFai Lau <kafai@fb.com>,
Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v2 18/20] tools/bpf: selftests: add iterator programs for ipv6_route and netlink
Date: Wed, 6 May 2020 18:09:42 -0700 [thread overview]
Message-ID: <318a33ef-4b9e-e25c-f153-c063b87b2c50@fb.com> (raw)
In-Reply-To: <CAEf4Bzae=1h4Rky+ojeoaxUR6OHM5Q6OzXFqPrhoOM4D3EYuCA@mail.gmail.com>
On 5/5/20 11:01 PM, Andrii Nakryiko wrote:
> On Sun, May 3, 2020 at 11:30 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> Two bpf programs are added in this patch for netlink and ipv6_route
>> target. On my VM, I am able to achieve identical
>> results compared to /proc/net/netlink and /proc/net/ipv6_route.
>>
>> $ cat /proc/net/netlink
>> sk Eth Pid Groups Rmem Wmem Dump Locks Drops Inode
>> 000000002c42d58b 0 0 00000000 0 0 0 2 0 7
>> 00000000a4e8b5e1 0 1 00000551 0 0 0 2 0 18719
>> 00000000e1b1c195 4 0 00000000 0 0 0 2 0 16422
>> 000000007e6b29f9 6 0 00000000 0 0 0 2 0 16424
>> ....
>> 00000000159a170d 15 1862 00000002 0 0 0 2 0 1886
>> 000000009aca4bc9 15 3918224839 00000002 0 0 0 2 0 19076
>> 00000000d0ab31d2 15 1 00000002 0 0 0 2 0 18683
>> 000000008398fb08 16 0 00000000 0 0 0 2 0 27
>> $ cat /sys/fs/bpf/my_netlink
>> sk Eth Pid Groups Rmem Wmem Dump Locks Drops Inode
>> 000000002c42d58b 0 0 00000000 0 0 0 2 0 7
>> 00000000a4e8b5e1 0 1 00000551 0 0 0 2 0 18719
>> 00000000e1b1c195 4 0 00000000 0 0 0 2 0 16422
>> 000000007e6b29f9 6 0 00000000 0 0 0 2 0 16424
>> ....
>> 00000000159a170d 15 1862 00000002 0 0 0 2 0 1886
>> 000000009aca4bc9 15 3918224839 00000002 0 0 0 2 0 19076
>> 00000000d0ab31d2 15 1 00000002 0 0 0 2 0 18683
>> 000000008398fb08 16 0 00000000 0 0 0 2 0 27
>>
>> $ cat /proc/net/ipv6_route
>> fe800000000000000000000000000000 40 00000000000000000000000000000000 00 00000000000000000000000000000000 00000100 00000001 00000000 00000001 eth0
>> 00000000000000000000000000000000 00 00000000000000000000000000000000 00 00000000000000000000000000000000 ffffffff 00000001 00000000 00200200 lo
>> 00000000000000000000000000000001 80 00000000000000000000000000000000 00 00000000000000000000000000000000 00000000 00000003 00000000 80200001 lo
>> fe80000000000000c04b03fffe7827ce 80 00000000000000000000000000000000 00 00000000000000000000000000000000 00000000 00000002 00000000 80200001 eth0
>> ff000000000000000000000000000000 08 00000000000000000000000000000000 00 00000000000000000000000000000000 00000100 00000003 00000000 00000001 eth0
>> 00000000000000000000000000000000 00 00000000000000000000000000000000 00 00000000000000000000000000000000 ffffffff 00000001 00000000 00200200 lo
>> $ cat /sys/fs/bpf/my_ipv6_route
>> fe800000000000000000000000000000 40 00000000000000000000000000000000 00 00000000000000000000000000000000 00000100 00000001 00000000 00000001 eth0
>> 00000000000000000000000000000000 00 00000000000000000000000000000000 00 00000000000000000000000000000000 ffffffff 00000001 00000000 00200200 lo
>> 00000000000000000000000000000001 80 00000000000000000000000000000000 00 00000000000000000000000000000000 00000000 00000003 00000000 80200001 lo
>> fe80000000000000c04b03fffe7827ce 80 00000000000000000000000000000000 00 00000000000000000000000000000000 00000000 00000002 00000000 80200001 eth0
>> ff000000000000000000000000000000 08 00000000000000000000000000000000 00 00000000000000000000000000000000 00000100 00000003 00000000 00000001 eth0
>> 00000000000000000000000000000000 00 00000000000000000000000000000000 00 00000000000000000000000000000000 ffffffff 00000001 00000000 00200200 lo
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>
> Looks good, but something weird with printf below...
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>
>
>> .../selftests/bpf/progs/bpf_iter_ipv6_route.c | 63 ++++++++++++++++
>> .../selftests/bpf/progs/bpf_iter_netlink.c | 74 +++++++++++++++++++
>> 2 files changed, 137 insertions(+)
>> create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c
>> create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_netlink.c
>>
>> diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c b/tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c
>> new file mode 100644
>> index 000000000000..0dee4629298f
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c
>> @@ -0,0 +1,63 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (c) 2020 Facebook */
>> +#include "vmlinux.h"
>> +#include <bpf/bpf_helpers.h>
>> +#include <bpf/bpf_tracing.h>
>> +#include <bpf/bpf_endian.h>
>> +
>> +char _license[] SEC("license") = "GPL";
>> +
>> +extern bool CONFIG_IPV6_SUBTREES __kconfig __weak;
>> +
>> +#define RTF_GATEWAY 0x0002
>> +#define IFNAMSIZ 16
>
> nit: these look weirdly unaligned :)
>
>> +#define fib_nh_gw_family nh_common.nhc_gw_family
>> +#define fib_nh_gw6 nh_common.nhc_gw.ipv6
>> +#define fib_nh_dev nh_common.nhc_dev
>> +
>
> [...]
>
>
>> + dev = fib6_nh->fib_nh_dev;
>> + if (dev)
>> + BPF_SEQ_PRINTF(seq, "%08x %08x %08x %08x %8s\n", rt->fib6_metric,
>> + rt->fib6_ref.refs.counter, 0, flags, dev->name);
>> + else
>> + BPF_SEQ_PRINTF(seq, "%08x %08x %08x %08x %8s\n", rt->fib6_metric,
>> + rt->fib6_ref.refs.counter, 0, flags);
>
> hmm... how does it work? you specify 4 params, but format string
> expects 5. Shouldn't this fail?
Thanks for catching this. Unfortunately, we can only detech this at
runtime when BPF_SEQ_PRINTF is executed since only then we do
format/argument checking.
In the above, if I flip condition "if (dev)" to "if (!dev)", the
BPF_SEQ_PRRINTF will not print anything and returns -EINVAL.
I am wondering whether verifier should do some verification at prog load
time to ensure
# of args in packed u64 array >= # of format specifier
This should capture this case. Or we just assume users should do
adequate testing to capture such cases.
Note that this won't affect safety of the program so it is totally
okay for verifier to delay the checking to runtime.
>
>> +
>> + return 0;
>> +}
>> diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_netlink.c b/tools/testing/selftests/bpf/progs/bpf_iter_netlink.c
>> new file mode 100644
>> index 000000000000..0a85a621a36d
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/bpf_iter_netlink.c
>> @@ -0,0 +1,74 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (c) 2020 Facebook */
>> +#include "vmlinux.h"
>> +#include <bpf/bpf_helpers.h>
>> +#include <bpf/bpf_tracing.h>
>> +#include <bpf/bpf_endian.h>
>> +
>> +char _license[] SEC("license") = "GPL";
>> +
>> +#define sk_rmem_alloc sk_backlog.rmem_alloc
>> +#define sk_refcnt __sk_common.skc_refcnt
>> +
>> +#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
>> +#define container_of(ptr, type, member) \
>> + ({ \
>> + void *__mptr = (void *)(ptr); \
>> + ((type *)(__mptr - offsetof(type, member))); \
>> + })
>
> we should probably put offsetof(), offsetofend() and container_of()
> macro into bpf_helpers.h, seems like universal things for kernel
> datastructs :)
>
> [...]
>
next prev parent reply other threads:[~2020-05-07 1:10 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-04 6:25 [PATCH bpf-next v2 00/20] bpf: implement bpf iterator for kernel data Yonghong Song
2020-05-04 6:25 ` [PATCH bpf-next v2 01/20] bpf: implement an interface to register bpf_iter targets Yonghong Song
2020-05-05 21:19 ` Andrii Nakryiko
2020-05-04 6:25 ` [PATCH bpf-next v2 02/20] bpf: allow loading of a bpf_iter program Yonghong Song
2020-05-05 21:29 ` Andrii Nakryiko
2020-05-06 0:07 ` Yonghong Song
2020-05-04 6:25 ` [PATCH bpf-next v2 03/20] bpf: support bpf tracing/iter programs for BPF_LINK_CREATE Yonghong Song
2020-05-05 21:30 ` Andrii Nakryiko
2020-05-06 0:14 ` Yonghong Song
2020-05-06 0:54 ` Alexei Starovoitov
2020-05-06 3:09 ` Andrii Nakryiko
2020-05-06 18:08 ` Alexei Starovoitov
2020-05-04 6:25 ` [PATCH bpf-next v2 04/20] bpf: support bpf tracing/iter programs for BPF_LINK_UPDATE Yonghong Song
2020-05-05 21:32 ` Andrii Nakryiko
2020-05-04 6:25 ` [PATCH bpf-next v2 05/20] bpf: implement bpf_seq_read() for bpf iterator Yonghong Song
2020-05-05 19:56 ` Andrii Nakryiko
2020-05-05 19:57 ` Alexei Starovoitov
2020-05-05 20:25 ` Yonghong Song
2020-05-05 21:08 ` Andrii Nakryiko
2020-05-04 6:25 ` [PATCH bpf-next v2 06/20] bpf: create anonymous " Yonghong Song
2020-05-05 20:11 ` Andrii Nakryiko
2020-05-05 20:28 ` Yonghong Song
2020-05-04 6:25 ` [PATCH bpf-next v2 07/20] bpf: create file " Yonghong Song
2020-05-05 20:15 ` Andrii Nakryiko
2020-05-04 6:25 ` [PATCH bpf-next v2 08/20] bpf: implement common macros/helpers for target iterators Yonghong Song
2020-05-05 20:25 ` Andrii Nakryiko
2020-05-05 20:30 ` Yonghong Song
2020-05-05 21:10 ` Andrii Nakryiko
2020-05-04 6:25 ` [PATCH bpf-next v2 09/20] bpf: add bpf_map iterator Yonghong Song
2020-05-06 5:11 ` Andrii Nakryiko
2020-05-04 6:25 ` [PATCH bpf-next v2 10/20] net: bpf: add netlink and ipv6_route bpf_iter targets Yonghong Song
2020-05-06 5:21 ` Andrii Nakryiko
2020-05-06 17:32 ` Yonghong Song
2020-05-04 6:25 ` [PATCH bpf-next v2 11/20] bpf: add task and task/file iterator targets Yonghong Song
2020-05-06 7:30 ` Andrii Nakryiko
2020-05-06 18:24 ` Yonghong Song
2020-05-06 20:51 ` Andrii Nakryiko
2020-05-06 21:20 ` Yonghong Song
2020-05-04 6:26 ` [PATCH bpf-next v2 12/20] bpf: add PTR_TO_BTF_ID_OR_NULL support Yonghong Song
2020-05-05 20:27 ` Andrii Nakryiko
2020-05-04 6:26 ` [PATCH bpf-next v2 13/20] bpf: add bpf_seq_printf and bpf_seq_write helpers Yonghong Song
2020-05-06 17:37 ` Andrii Nakryiko
2020-05-06 21:42 ` Yonghong Song
2020-05-08 18:15 ` Andrii Nakryiko
2020-05-04 6:26 ` [PATCH bpf-next v2 14/20] bpf: handle spilled PTR_TO_BTF_ID properly when checking stack_boundary Yonghong Song
2020-05-06 17:38 ` Andrii Nakryiko
2020-05-06 21:47 ` Yonghong Song
2020-05-04 6:26 ` [PATCH bpf-next v2 15/20] bpf: support variable length array in tracing programs Yonghong Song
2020-05-06 17:40 ` Andrii Nakryiko
2020-05-04 6:26 ` [PATCH bpf-next v2 16/20] tools/libbpf: add bpf_iter support Yonghong Song
2020-05-06 5:44 ` Andrii Nakryiko
2020-05-04 6:26 ` [PATCH bpf-next v2 17/20] tools/bpftool: add bpf_iter support for bptool Yonghong Song
2020-05-04 6:26 ` [PATCH bpf-next v2 18/20] tools/bpf: selftests: add iterator programs for ipv6_route and netlink Yonghong Song
2020-05-06 6:01 ` Andrii Nakryiko
2020-05-07 1:09 ` Yonghong Song [this message]
2020-05-08 18:17 ` Andrii Nakryiko
2020-05-06 6:04 ` Andrii Nakryiko
2020-05-06 23:07 ` Yonghong Song
2020-05-04 6:26 ` [PATCH bpf-next v2 19/20] tools/bpf: selftests: add iter progs for bpf_map/task/task_file Yonghong Song
2020-05-06 6:14 ` Andrii Nakryiko
2020-05-04 6:26 ` [PATCH bpf-next v2 20/20] tools/bpf: selftests: add bpf_iter selftests Yonghong Song
2020-05-06 6:39 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=318a33ef-4b9e-e25c-f153-c063b87b2c50@fb.com \
--to=yhs@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox