bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes
@ 2020-09-29 11:32 Alan Maguire
  2020-09-29 11:32 ` [PATCH bpf-next 1/2] selftests/bpf: fix unused-result warning in snprintf_btf.c Alan Maguire
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alan Maguire @ 2020-09-29 11:32 UTC (permalink / raw)
  To: ast, daniel, andriin
  Cc: kafai, songliubraving, yhs, john.fastabend, kpsingh,
	linux-kernel, netdev, bpf

Resolve issues in bpf selftests introduced with BTF-based kernel data
display selftests; these are

- a warning introduced in snprintf_btf.c; and
- compilation failures with old kernels vmlinux.h

Alan Maguire (2):
  selftests/bpf: fix unused-result warning in snprintf_btf.c
  selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with
    old vmlinux.h

 .../selftests/bpf/prog_tests/snprintf_btf.c        |  2 +-
 tools/testing/selftests/bpf/progs/bpf_iter.h       | 23 ++++++++++++++++++
 tools/testing/selftests/bpf/progs/btf_ptr.h        | 27 ++++++++++++++++++++++
 .../selftests/bpf/progs/netif_receive_skb.c        |  2 +-
 4 files changed, 52 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/btf_ptr.h

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 1/2] selftests/bpf: fix unused-result warning in snprintf_btf.c
  2020-09-29 11:32 [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes Alan Maguire
@ 2020-09-29 11:32 ` Alan Maguire
  2020-09-29 11:32 ` [PATCH bpf-next 2/2] selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h Alan Maguire
  2020-09-29 18:20 ` [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes patchwork-bot+bpf
  2 siblings, 0 replies; 5+ messages in thread
From: Alan Maguire @ 2020-09-29 11:32 UTC (permalink / raw)
  To: ast, daniel, andriin
  Cc: kafai, songliubraving, yhs, john.fastabend, kpsingh,
	linux-kernel, netdev, bpf

Daniel reports:

+    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");
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  [...]

Fixes: 076a95f5aff2 ("selftests/bpf: Add bpf_snprintf_btf helper tests")
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
 tools/testing/selftests/bpf/prog_tests/snprintf_btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/snprintf_btf.c b/tools/testing/selftests/bpf/prog_tests/snprintf_btf.c
index 3a8ecf8..3c63a70 100644
--- a/tools/testing/selftests/bpf/prog_tests/snprintf_btf.c
+++ b/tools/testing/selftests/bpf/prog_tests/snprintf_btf.c
@@ -27,7 +27,7 @@ void test_snprintf_btf(void)
 		goto cleanup;
 
 	/* generate receive event */
-	system("ping -c 1 127.0.0.1 > /dev/null");
+	(void) system("ping -c 1 127.0.0.1 > /dev/null");
 
 	if (bss->skip) {
 		printf("%s:SKIP:no __builtin_btf_type_id\n", __func__);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 2/2] selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h
  2020-09-29 11:32 [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes Alan Maguire
  2020-09-29 11:32 ` [PATCH bpf-next 1/2] selftests/bpf: fix unused-result warning in snprintf_btf.c Alan Maguire
@ 2020-09-29 11:32 ` Alan Maguire
  2020-09-29 18:08   ` Andrii Nakryiko
  2020-09-29 18:20 ` [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes patchwork-bot+bpf
  2 siblings, 1 reply; 5+ messages in thread
From: Alan Maguire @ 2020-09-29 11:32 UTC (permalink / raw)
  To: ast, daniel, andriin
  Cc: kafai, songliubraving, yhs, john.fastabend, kpsingh,
	linux-kernel, netdev, bpf

Andrii reports that bpf selftests relying on "struct btf_ptr" and BTF_F_*
values will not build as vmlinux.h for older kernels will not include
"struct btf_ptr" or the BTF_F_* enum values.  Undefine and redefine
them to work around this.

Fixes: b72091bd4ee4 ("selftests/bpf: Add test for bpf_seq_printf_btf helper")
Fixes: 076a95f5aff2 ("selftests/bpf: Add bpf_snprintf_btf helper tests")
Reported-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
 tools/testing/selftests/bpf/progs/bpf_iter.h       | 23 ++++++++++++++++++
 tools/testing/selftests/bpf/progs/btf_ptr.h        | 27 ++++++++++++++++++++++
 .../selftests/bpf/progs/netif_receive_skb.c        |  2 +-
 3 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/btf_ptr.h

diff --git a/tools/testing/selftests/bpf/progs/bpf_iter.h b/tools/testing/selftests/bpf/progs/bpf_iter.h
index df682af..6a12554 100644
--- a/tools/testing/selftests/bpf/progs/bpf_iter.h
+++ b/tools/testing/selftests/bpf/progs/bpf_iter.h
@@ -14,6 +14,11 @@
 #define bpf_iter__bpf_map_elem bpf_iter__bpf_map_elem___not_used
 #define bpf_iter__bpf_sk_storage_map bpf_iter__bpf_sk_storage_map___not_used
 #define bpf_iter__sockmap bpf_iter__sockmap___not_used
+#define btf_ptr btf_ptr___not_used
+#define BTF_F_COMPACT BTF_F_COMPACT___not_used
+#define BTF_F_NONAME BTF_F_NONAME___not_used
+#define BTF_F_PTR_RAW BTF_F_PTR_RAW___not_used
+#define BTF_F_ZERO BTF_F_ZERO___not_used
 #include "vmlinux.h"
 #undef bpf_iter_meta
 #undef bpf_iter__bpf_map
@@ -28,6 +33,11 @@
 #undef bpf_iter__bpf_map_elem
 #undef bpf_iter__bpf_sk_storage_map
 #undef bpf_iter__sockmap
+#undef btf_ptr
+#undef BTF_F_COMPACT
+#undef BTF_F_NONAME
+#undef BTF_F_PTR_RAW
+#undef BTF_F_ZERO
 
 struct bpf_iter_meta {
 	struct seq_file *seq;
@@ -105,3 +115,16 @@ struct bpf_iter__sockmap {
 	void *key;
 	struct sock *sk;
 };
+
+struct btf_ptr {
+	void *ptr;
+	__u32 type_id;
+	__u32 flags;
+};
+
+enum {
+	BTF_F_COMPACT	=	(1ULL << 0),
+	BTF_F_NONAME	=	(1ULL << 1),
+	BTF_F_PTR_RAW	=	(1ULL << 2),
+	BTF_F_ZERO	=	(1ULL << 3),
+};
diff --git a/tools/testing/selftests/bpf/progs/btf_ptr.h b/tools/testing/selftests/bpf/progs/btf_ptr.h
new file mode 100644
index 0000000..c3c9797
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/btf_ptr.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2020, Oracle and/or its affiliates. */
+/* "undefine" structs in vmlinux.h, because we "override" them below */
+#define btf_ptr btf_ptr___not_used
+#define BTF_F_COMPACT BTF_F_COMPACT___not_used
+#define BTF_F_NONAME BTF_F_NONAME___not_used
+#define BTF_F_PTR_RAW BTF_F_PTR_RAW___not_used
+#define BTF_F_ZERO BTF_F_ZERO___not_used
+#include "vmlinux.h"
+#undef btf_ptr
+#undef BTF_F_COMPACT
+#undef BTF_F_NONAME
+#undef BTF_F_PTR_RAW
+#undef BTF_F_ZERO
+
+struct btf_ptr {
+	void *ptr;
+	__u32 type_id;
+	__u32 flags;
+};
+
+enum {
+	BTF_F_COMPACT	=	(1ULL << 0),
+	BTF_F_NONAME	=	(1ULL << 1),
+	BTF_F_PTR_RAW	=	(1ULL << 2),
+	BTF_F_ZERO	=	(1ULL << 3),
+};
diff --git a/tools/testing/selftests/bpf/progs/netif_receive_skb.c b/tools/testing/selftests/bpf/progs/netif_receive_skb.c
index b873d80..6b67003 100644
--- a/tools/testing/selftests/bpf/progs/netif_receive_skb.c
+++ b/tools/testing/selftests/bpf/progs/netif_receive_skb.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2020, Oracle and/or its affiliates. */
 
-#include "vmlinux.h"
+#include "btf_ptr.h"
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 #include <bpf/bpf_core_read.h>
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 2/2] selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h
  2020-09-29 11:32 ` [PATCH bpf-next 2/2] selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h Alan Maguire
@ 2020-09-29 18:08   ` Andrii Nakryiko
  0 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2020-09-29 18:08 UTC (permalink / raw)
  To: Alan Maguire
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, open list,
	Networking, bpf

On Tue, Sep 29, 2020 at 5:26 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> Andrii reports that bpf selftests relying on "struct btf_ptr" and BTF_F_*
> values will not build as vmlinux.h for older kernels will not include
> "struct btf_ptr" or the BTF_F_* enum values.  Undefine and redefine
> them to work around this.
>
> Fixes: b72091bd4ee4 ("selftests/bpf: Add test for bpf_seq_printf_btf helper")
> Fixes: 076a95f5aff2 ("selftests/bpf: Add bpf_snprintf_btf helper tests")
> Reported-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---

That works, thanks!

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  tools/testing/selftests/bpf/progs/bpf_iter.h       | 23 ++++++++++++++++++
>  tools/testing/selftests/bpf/progs/btf_ptr.h        | 27 ++++++++++++++++++++++
>  .../selftests/bpf/progs/netif_receive_skb.c        |  2 +-
>  3 files changed, 51 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/bpf/progs/btf_ptr.h
>

[...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes
  2020-09-29 11:32 [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes Alan Maguire
  2020-09-29 11:32 ` [PATCH bpf-next 1/2] selftests/bpf: fix unused-result warning in snprintf_btf.c Alan Maguire
  2020-09-29 11:32 ` [PATCH bpf-next 2/2] selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h Alan Maguire
@ 2020-09-29 18:20 ` patchwork-bot+bpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+bpf @ 2020-09-29 18:20 UTC (permalink / raw)
  To: Alan Maguire; +Cc: bpf

Hello:

This series was applied to bpf/bpf-next.git (refs/heads/master):

On Tue, 29 Sep 2020 04:32:29 -0700 (PDT) you wrote:
> Resolve issues in bpf selftests introduced with BTF-based kernel data
> display selftests; these are
> 
> - a warning introduced in snprintf_btf.c; and
> - compilation failures with old kernels vmlinux.h
> 
> Alan Maguire (2):
>   selftests/bpf: fix unused-result warning in snprintf_btf.c
>   selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with
>     old vmlinux.h
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/2] selftests/bpf: fix unused-result warning in snprintf_btf.c
    https://git.kernel.org/bpf/bpf-next/c/96c48058db15
  - [bpf-next,2/2] selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h
    https://git.kernel.org/bpf/bpf-next/c/cfe77683b8d4

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-29 18:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29 11:32 [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes Alan Maguire
2020-09-29 11:32 ` [PATCH bpf-next 1/2] selftests/bpf: fix unused-result warning in snprintf_btf.c Alan Maguire
2020-09-29 11:32 ` [PATCH bpf-next 2/2] selftests/bpf: ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h Alan Maguire
2020-09-29 18:08   ` Andrii Nakryiko
2020-09-29 18:20 ` [PATCH bpf-next 0/2] selftests/bpf: BTF-based kernel data display fixes patchwork-bot+bpf

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).