* [PATCH net-next] selftests/bpf: check the instruction dumps are populated
@ 2017-08-25 21:39 Jakub Kicinski
2017-08-26 1:16 ` Daniel Borkmann
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2017-08-25 21:39 UTC (permalink / raw)
To: netdev; +Cc: daniel, kafai, oss-drivers, Jakub Kicinski
Add a basic test for checking whether kernel is populating
the jited and xlated BPF images. It was used to confirm
the behaviour change from commit d777b2ddbecf ("bpf: don't
zero out the info struct in bpf_obj_get_info_by_fd()"),
which made bpf_obj_get_info_by_fd() usable for retrieving
the image dumps.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
tools/testing/selftests/bpf/test_progs.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 1cb037803679..11ee25cea227 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -279,7 +279,7 @@ static void test_bpf_obj_id(void)
/* +1 to test for the info_len returned by kernel */
struct bpf_prog_info prog_infos[nr_iters + 1];
struct bpf_map_info map_infos[nr_iters + 1];
- char jited_insns[128], xlated_insns[128];
+ char jited_insns[128], xlated_insns[128], zeros[128];
__u32 i, next_id, info_len, nr_id_found, duration = 0;
int sysctl_fd, jit_enabled = 0, err = 0;
__u64 array_value;
@@ -305,6 +305,7 @@ static void test_bpf_obj_id(void)
objs[i] = NULL;
/* Check bpf_obj_get_info_by_fd() */
+ bzero(zeros, sizeof(zeros));
for (i = 0; i < nr_iters; i++) {
err = bpf_prog_load(file, BPF_PROG_TYPE_SOCKET_FILTER,
&objs[i], &prog_fds[i]);
@@ -318,6 +319,8 @@ static void test_bpf_obj_id(void)
/* Check getting prog info */
info_len = sizeof(struct bpf_prog_info) * 2;
bzero(&prog_infos[i], info_len);
+ bzero(jited_insns, sizeof(jited_insns));
+ bzero(xlated_insns, sizeof(xlated_insns));
prog_infos[i].jited_prog_insns = ptr_to_u64(jited_insns);
prog_infos[i].jited_prog_len = sizeof(jited_insns);
prog_infos[i].xlated_prog_insns = ptr_to_u64(xlated_insns);
@@ -328,15 +331,20 @@ static void test_bpf_obj_id(void)
prog_infos[i].type != BPF_PROG_TYPE_SOCKET_FILTER ||
info_len != sizeof(struct bpf_prog_info) ||
(jit_enabled && !prog_infos[i].jited_prog_len) ||
- !prog_infos[i].xlated_prog_len,
+ (jit_enabled &&
+ !memcmp(jited_insns, zeros, sizeof(zeros))) ||
+ !prog_infos[i].xlated_prog_len ||
+ !memcmp(xlated_insns, zeros, sizeof(zeros)),
"get-prog-info(fd)",
- "err %d errno %d i %d type %d(%d) info_len %u(%lu) jit_enabled %d jited_prog_len %u xlated_prog_len %u\n",
+ "err %d errno %d i %d type %d(%d) info_len %u(%lu) jit_enabled %d jited_prog_len %u xlated_prog_len %u jited_prog %d xlated_prog %d\n",
err, errno, i,
prog_infos[i].type, BPF_PROG_TYPE_SOCKET_FILTER,
info_len, sizeof(struct bpf_prog_info),
jit_enabled,
prog_infos[i].jited_prog_len,
- prog_infos[i].xlated_prog_len))
+ prog_infos[i].xlated_prog_len,
+ !!memcmp(jited_insns, zeros, sizeof(zeros)),
+ !!memcmp(xlated_insns, zeros, sizeof(zeros))))
goto done;
map_fds[i] = bpf_find_map(__func__, objs[i], "test_map_id");
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] selftests/bpf: check the instruction dumps are populated
2017-08-25 21:39 [PATCH net-next] selftests/bpf: check the instruction dumps are populated Jakub Kicinski
@ 2017-08-26 1:16 ` Daniel Borkmann
2017-08-28 17:19 ` Martin KaFai Lau
2017-08-28 22:35 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2017-08-26 1:16 UTC (permalink / raw)
To: Jakub Kicinski, netdev; +Cc: kafai, oss-drivers
On 08/25/2017 11:39 PM, Jakub Kicinski wrote:
> Add a basic test for checking whether kernel is populating
> the jited and xlated BPF images. It was used to confirm
> the behaviour change from commit d777b2ddbecf ("bpf: don't
> zero out the info struct in bpf_obj_get_info_by_fd()"),
> which made bpf_obj_get_info_by_fd() usable for retrieving
> the image dumps.
>
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
[...]
> @@ -328,15 +331,20 @@ static void test_bpf_obj_id(void)
> prog_infos[i].type != BPF_PROG_TYPE_SOCKET_FILTER ||
> info_len != sizeof(struct bpf_prog_info) ||
> (jit_enabled && !prog_infos[i].jited_prog_len) ||
> - !prog_infos[i].xlated_prog_len,
> + (jit_enabled &&
> + !memcmp(jited_insns, zeros, sizeof(zeros))) ||
> + !prog_infos[i].xlated_prog_len ||
> + !memcmp(xlated_insns, zeros, sizeof(zeros)),
There could still be the case where a JIT could bail out
for some reason and punt to the interpreter instead, but
I'm fine assuming for the specific test cases we have it
has to succeed, and if not JIT misses features or has other
issues. ;) Thus:
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] selftests/bpf: check the instruction dumps are populated
2017-08-25 21:39 [PATCH net-next] selftests/bpf: check the instruction dumps are populated Jakub Kicinski
2017-08-26 1:16 ` Daniel Borkmann
@ 2017-08-28 17:19 ` Martin KaFai Lau
2017-08-28 22:35 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Martin KaFai Lau @ 2017-08-28 17:19 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: netdev, daniel, oss-drivers
On Fri, Aug 25, 2017 at 02:39:57PM -0700, Jakub Kicinski wrote:
> Add a basic test for checking whether kernel is populating
> the jited and xlated BPF images. It was used to confirm
> the behaviour change from commit d777b2ddbecf ("bpf: don't
> zero out the info struct in bpf_obj_get_info_by_fd()"),
> which made bpf_obj_get_info_by_fd() usable for retrieving
> the image dumps.
Acked-by: Martin KaFai Lau <kafai@fb.com>
>
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> ---
> tools/testing/selftests/bpf/test_progs.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> index 1cb037803679..11ee25cea227 100644
> --- a/tools/testing/selftests/bpf/test_progs.c
> +++ b/tools/testing/selftests/bpf/test_progs.c
> @@ -279,7 +279,7 @@ static void test_bpf_obj_id(void)
> /* +1 to test for the info_len returned by kernel */
> struct bpf_prog_info prog_infos[nr_iters + 1];
> struct bpf_map_info map_infos[nr_iters + 1];
> - char jited_insns[128], xlated_insns[128];
> + char jited_insns[128], xlated_insns[128], zeros[128];
> __u32 i, next_id, info_len, nr_id_found, duration = 0;
> int sysctl_fd, jit_enabled = 0, err = 0;
> __u64 array_value;
> @@ -305,6 +305,7 @@ static void test_bpf_obj_id(void)
> objs[i] = NULL;
>
> /* Check bpf_obj_get_info_by_fd() */
> + bzero(zeros, sizeof(zeros));
> for (i = 0; i < nr_iters; i++) {
> err = bpf_prog_load(file, BPF_PROG_TYPE_SOCKET_FILTER,
> &objs[i], &prog_fds[i]);
> @@ -318,6 +319,8 @@ static void test_bpf_obj_id(void)
> /* Check getting prog info */
> info_len = sizeof(struct bpf_prog_info) * 2;
> bzero(&prog_infos[i], info_len);
> + bzero(jited_insns, sizeof(jited_insns));
> + bzero(xlated_insns, sizeof(xlated_insns));
> prog_infos[i].jited_prog_insns = ptr_to_u64(jited_insns);
> prog_infos[i].jited_prog_len = sizeof(jited_insns);
> prog_infos[i].xlated_prog_insns = ptr_to_u64(xlated_insns);
> @@ -328,15 +331,20 @@ static void test_bpf_obj_id(void)
> prog_infos[i].type != BPF_PROG_TYPE_SOCKET_FILTER ||
> info_len != sizeof(struct bpf_prog_info) ||
> (jit_enabled && !prog_infos[i].jited_prog_len) ||
> - !prog_infos[i].xlated_prog_len,
> + (jit_enabled &&
> + !memcmp(jited_insns, zeros, sizeof(zeros))) ||
> + !prog_infos[i].xlated_prog_len ||
> + !memcmp(xlated_insns, zeros, sizeof(zeros)),
> "get-prog-info(fd)",
> - "err %d errno %d i %d type %d(%d) info_len %u(%lu) jit_enabled %d jited_prog_len %u xlated_prog_len %u\n",
> + "err %d errno %d i %d type %d(%d) info_len %u(%lu) jit_enabled %d jited_prog_len %u xlated_prog_len %u jited_prog %d xlated_prog %d\n",
> err, errno, i,
> prog_infos[i].type, BPF_PROG_TYPE_SOCKET_FILTER,
> info_len, sizeof(struct bpf_prog_info),
> jit_enabled,
> prog_infos[i].jited_prog_len,
> - prog_infos[i].xlated_prog_len))
> + prog_infos[i].xlated_prog_len,
> + !!memcmp(jited_insns, zeros, sizeof(zeros)),
> + !!memcmp(xlated_insns, zeros, sizeof(zeros))))
> goto done;
>
> map_fds[i] = bpf_find_map(__func__, objs[i], "test_map_id");
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] selftests/bpf: check the instruction dumps are populated
2017-08-25 21:39 [PATCH net-next] selftests/bpf: check the instruction dumps are populated Jakub Kicinski
2017-08-26 1:16 ` Daniel Borkmann
2017-08-28 17:19 ` Martin KaFai Lau
@ 2017-08-28 22:35 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-08-28 22:35 UTC (permalink / raw)
To: jakub.kicinski; +Cc: netdev, daniel, kafai, oss-drivers
From: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Fri, 25 Aug 2017 14:39:57 -0700
> Add a basic test for checking whether kernel is populating
> the jited and xlated BPF images. It was used to confirm
> the behaviour change from commit d777b2ddbecf ("bpf: don't
> zero out the info struct in bpf_obj_get_info_by_fd()"),
> which made bpf_obj_get_info_by_fd() usable for retrieving
> the image dumps.
>
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-08-28 22:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-25 21:39 [PATCH net-next] selftests/bpf: check the instruction dumps are populated Jakub Kicinski
2017-08-26 1:16 ` Daniel Borkmann
2017-08-28 17:19 ` Martin KaFai Lau
2017-08-28 22:35 ` David Miller
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).