bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests
@ 2021-03-05 17:08 Ilya Leoshkevich
  2021-03-05 17:08 ` [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size Ilya Leoshkevich
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ilya Leoshkevich @ 2021-03-05 17:08 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich

The two tests here did not make it into the main BTF_KIND_FLOAT series
because of dependency on LLVM.

Ilya Leoshkevich (2):
  selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size
  selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax

 tools/testing/selftests/bpf/README.rst                   | 9 +++++++++
 tools/testing/selftests/bpf/prog_tests/core_reloc.c      | 1 +
 .../selftests/bpf/progs/btf_dump_test_case_syntax.c      | 7 +++++++
 tools/testing/selftests/bpf/progs/core_reloc_types.h     | 5 +++++
 tools/testing/selftests/bpf/progs/test_core_reloc_size.c | 3 +++
 5 files changed, 25 insertions(+)

-- 
2.29.2


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

* [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size
  2021-03-05 17:08 [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests Ilya Leoshkevich
@ 2021-03-05 17:08 ` Ilya Leoshkevich
  2021-03-05 21:30   ` Yonghong Song
  2021-03-07  3:21   ` Andrii Nakryiko
  2021-03-05 17:08 ` [PATCH bpf-next 2/2] selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax Ilya Leoshkevich
  2021-03-09 19:10 ` [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests Alexei Starovoitov
  2 siblings, 2 replies; 8+ messages in thread
From: Ilya Leoshkevich @ 2021-03-05 17:08 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich, John Fastabend

Verify that bpf_core_field_size() is working correctly with floats.
Also document the required clang version.

Suggested-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tools/testing/selftests/bpf/README.rst                   | 9 +++++++++
 tools/testing/selftests/bpf/prog_tests/core_reloc.c      | 1 +
 tools/testing/selftests/bpf/progs/core_reloc_types.h     | 5 +++++
 tools/testing/selftests/bpf/progs/test_core_reloc_size.c | 3 +++
 4 files changed, 18 insertions(+)

diff --git a/tools/testing/selftests/bpf/README.rst b/tools/testing/selftests/bpf/README.rst
index dbc8f6cc5c67..3464161c8eea 100644
--- a/tools/testing/selftests/bpf/README.rst
+++ b/tools/testing/selftests/bpf/README.rst
@@ -170,3 +170,12 @@ failures:
 .. _2: https://reviews.llvm.org/D85174
 .. _3: https://reviews.llvm.org/D83878
 .. _4: https://reviews.llvm.org/D83242
+
+Floating-point tests and Clang version
+======================================
+
+Certain selftests, e.g. core_reloc, require support for the floating-point
+types, which was introduced in `Clang 13`__. The older Clang versions will
+either crash when compiling these tests, or generate an incorrect BTF.
+
+__  https://reviews.llvm.org/D83289
diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
index 06eb956ff7bb..d94dcead72e6 100644
--- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c
+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
@@ -266,6 +266,7 @@ static int duration = 0;
 		.arr_elem_sz = sizeof(((type *)0)->arr_field[0]),	\
 		.ptr_sz = 8, /* always 8-byte pointer for BPF */	\
 		.enum_sz = sizeof(((type *)0)->enum_field),		\
+		.float_sz = sizeof(((type *)0)->float_field),		\
 	}
 
 #define SIZE_CASE(name) {						\
diff --git a/tools/testing/selftests/bpf/progs/core_reloc_types.h b/tools/testing/selftests/bpf/progs/core_reloc_types.h
index 9a2850850121..3a2149c5863c 100644
--- a/tools/testing/selftests/bpf/progs/core_reloc_types.h
+++ b/tools/testing/selftests/bpf/progs/core_reloc_types.h
@@ -807,6 +807,7 @@ struct core_reloc_size_output {
 	int arr_elem_sz;
 	int ptr_sz;
 	int enum_sz;
+	int float_sz;
 };
 
 struct core_reloc_size {
@@ -816,6 +817,7 @@ struct core_reloc_size {
 	int arr_field[4];
 	void *ptr_field;
 	enum { VALUE = 123 } enum_field;
+	float float_field;
 };
 
 struct core_reloc_size___diff_sz {
@@ -825,6 +827,7 @@ struct core_reloc_size___diff_sz {
 	char arr_field[10];
 	void *ptr_field;
 	enum { OTHER_VALUE = 0xFFFFFFFFFFFFFFFF } enum_field;
+	float float_field;
 };
 
 /* Error case of two candidates with the fields (int_field) at the same
@@ -839,6 +842,7 @@ struct core_reloc_size___err_ambiguous1 {
 	int arr_field[4];
 	void *ptr_field;
 	enum { VALUE___1 = 123 } enum_field;
+	float float_field;
 };
 
 struct core_reloc_size___err_ambiguous2 {
@@ -850,6 +854,7 @@ struct core_reloc_size___err_ambiguous2 {
 	int arr_field[4];
 	void *ptr_field;
 	enum { VALUE___2 = 123 } enum_field;
+	float float_field;
 };
 
 /*
diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_size.c b/tools/testing/selftests/bpf/progs/test_core_reloc_size.c
index d7fb6cfc7891..7b2d576aeea1 100644
--- a/tools/testing/selftests/bpf/progs/test_core_reloc_size.c
+++ b/tools/testing/selftests/bpf/progs/test_core_reloc_size.c
@@ -21,6 +21,7 @@ struct core_reloc_size_output {
 	int arr_elem_sz;
 	int ptr_sz;
 	int enum_sz;
+	int float_sz;
 };
 
 struct core_reloc_size {
@@ -30,6 +31,7 @@ struct core_reloc_size {
 	int arr_field[4];
 	void *ptr_field;
 	enum { VALUE = 123 } enum_field;
+	float float_field;
 };
 
 SEC("raw_tracepoint/sys_enter")
@@ -45,6 +47,7 @@ int test_core_size(void *ctx)
 	out->arr_elem_sz = bpf_core_field_size(in->arr_field[0]);
 	out->ptr_sz = bpf_core_field_size(in->ptr_field);
 	out->enum_sz = bpf_core_field_size(in->enum_field);
+	out->float_sz = bpf_core_field_size(in->float_field);
 
 	return 0;
 }
-- 
2.29.2


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

* [PATCH bpf-next 2/2] selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax
  2021-03-05 17:08 [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests Ilya Leoshkevich
  2021-03-05 17:08 ` [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size Ilya Leoshkevich
@ 2021-03-05 17:08 ` Ilya Leoshkevich
  2021-03-05 21:31   ` Yonghong Song
  2021-03-07  3:23   ` Andrii Nakryiko
  2021-03-09 19:10 ` [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests Alexei Starovoitov
  2 siblings, 2 replies; 8+ messages in thread
From: Ilya Leoshkevich @ 2021-03-05 17:08 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich, Andrii Nakryiko

Check that dumping various floating-point types produces a valid C
code.

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 .../selftests/bpf/progs/btf_dump_test_case_syntax.c        | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
index 31975c96e2c9..09d8d1e01ed6 100644
--- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
+++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
@@ -205,6 +205,12 @@ struct struct_with_embedded_stuff {
 	int t[11];
 };
 
+struct float_struct {
+	float *f;
+	const double *d;
+	volatile long double *ld;
+};
+
 struct root_struct {
 	enum e1 _1;
 	enum e2 _2;
@@ -219,6 +225,7 @@ struct root_struct {
 	union_fwd_t *_12;
 	union_fwd_ptr_t _13;
 	struct struct_with_embedded_stuff _14;
+	struct float_struct _15;
 };
 
 /* ------ END-EXPECTED-OUTPUT ------ */
-- 
2.29.2


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

* Re: [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size
  2021-03-05 17:08 ` [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size Ilya Leoshkevich
@ 2021-03-05 21:30   ` Yonghong Song
  2021-03-07  3:21   ` Andrii Nakryiko
  1 sibling, 0 replies; 8+ messages in thread
From: Yonghong Song @ 2021-03-05 21:30 UTC (permalink / raw)
  To: Ilya Leoshkevich, Alexei Starovoitov, Daniel Borkmann
  Cc: bpf, Heiko Carstens, Vasily Gorbik, John Fastabend



On 3/5/21 9:08 AM, Ilya Leoshkevich wrote:
> Verify that bpf_core_field_size() is working correctly with floats.
> Also document the required clang version.
> 
> Suggested-by: John Fastabend <john.fastabend@gmail.com>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

Acked-by: Yonghong Song <yhs@fb.com>

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

* Re: [PATCH bpf-next 2/2] selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax
  2021-03-05 17:08 ` [PATCH bpf-next 2/2] selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax Ilya Leoshkevich
@ 2021-03-05 21:31   ` Yonghong Song
  2021-03-07  3:23   ` Andrii Nakryiko
  1 sibling, 0 replies; 8+ messages in thread
From: Yonghong Song @ 2021-03-05 21:31 UTC (permalink / raw)
  To: Ilya Leoshkevich, Alexei Starovoitov, Daniel Borkmann
  Cc: bpf, Heiko Carstens, Vasily Gorbik, Andrii Nakryiko



On 3/5/21 9:08 AM, Ilya Leoshkevich wrote:
> Check that dumping various floating-point types produces a valid C
> code.
> 
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

Acked-by: Yonghong Song <yhs@fb.com>

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

* Re: [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size
  2021-03-05 17:08 ` [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size Ilya Leoshkevich
  2021-03-05 21:30   ` Yonghong Song
@ 2021-03-07  3:21   ` Andrii Nakryiko
  1 sibling, 0 replies; 8+ messages in thread
From: Andrii Nakryiko @ 2021-03-07  3:21 UTC (permalink / raw)
  To: Ilya Leoshkevich
  Cc: Alexei Starovoitov, Daniel Borkmann, bpf, Heiko Carstens,
	Vasily Gorbik, John Fastabend

On Fri, Mar 5, 2021 at 9:12 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> Verify that bpf_core_field_size() is working correctly with floats.
> Also document the required clang version.
>
> Suggested-by: John Fastabend <john.fastabend@gmail.com>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tools/testing/selftests/bpf/README.rst                   | 9 +++++++++
>  tools/testing/selftests/bpf/prog_tests/core_reloc.c      | 1 +
>  tools/testing/selftests/bpf/progs/core_reloc_types.h     | 5 +++++
>  tools/testing/selftests/bpf/progs/test_core_reloc_size.c | 3 +++
>  4 files changed, 18 insertions(+)
>

[...]

> diff --git a/tools/testing/selftests/bpf/progs/core_reloc_types.h b/tools/testing/selftests/bpf/progs/core_reloc_types.h
> index 9a2850850121..3a2149c5863c 100644
> --- a/tools/testing/selftests/bpf/progs/core_reloc_types.h
> +++ b/tools/testing/selftests/bpf/progs/core_reloc_types.h
> @@ -807,6 +807,7 @@ struct core_reloc_size_output {
>         int arr_elem_sz;
>         int ptr_sz;
>         int enum_sz;
> +       int float_sz;
>  };
>
>  struct core_reloc_size {
> @@ -816,6 +817,7 @@ struct core_reloc_size {
>         int arr_field[4];
>         void *ptr_field;
>         enum { VALUE = 123 } enum_field;
> +       float float_field;
>  };
>
>  struct core_reloc_size___diff_sz {
> @@ -825,6 +827,7 @@ struct core_reloc_size___diff_sz {
>         char arr_field[10];
>         void *ptr_field;
>         enum { OTHER_VALUE = 0xFFFFFFFFFFFFFFFF } enum_field;
> +       float float_field;

here the point is to test differently sized field, so it would be good
to have `double float_field;` instead

>  };
>
>  /* Error case of two candidates with the fields (int_field) at the same
> @@ -839,6 +842,7 @@ struct core_reloc_size___err_ambiguous1 {
>         int arr_field[4];
>         void *ptr_field;
>         enum { VALUE___1 = 123 } enum_field;
> +       float float_field;
>  };
>
>  struct core_reloc_size___err_ambiguous2 {
> @@ -850,6 +854,7 @@ struct core_reloc_size___err_ambiguous2 {
>         int arr_field[4];
>         void *ptr_field;
>         enum { VALUE___2 = 123 } enum_field;
> +       float float_field;
>  };
>
>  /*

[...]

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

* Re: [PATCH bpf-next 2/2] selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax
  2021-03-05 17:08 ` [PATCH bpf-next 2/2] selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax Ilya Leoshkevich
  2021-03-05 21:31   ` Yonghong Song
@ 2021-03-07  3:23   ` Andrii Nakryiko
  1 sibling, 0 replies; 8+ messages in thread
From: Andrii Nakryiko @ 2021-03-07  3:23 UTC (permalink / raw)
  To: Ilya Leoshkevich
  Cc: Alexei Starovoitov, Daniel Borkmann, bpf, Heiko Carstens,
	Vasily Gorbik, Andrii Nakryiko

On Fri, Mar 5, 2021 at 9:09 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> Check that dumping various floating-point types produces a valid C
> code.
>
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  .../selftests/bpf/progs/btf_dump_test_case_syntax.c        | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> index 31975c96e2c9..09d8d1e01ed6 100644
> --- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> +++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> @@ -205,6 +205,12 @@ struct struct_with_embedded_stuff {
>         int t[11];
>  };
>
> +struct float_struct {
> +       float *f;

just for a bit more diversity, try this one without a pointer?

> +       const double *d;
> +       volatile long double *ld;
> +};
> +
>  struct root_struct {
>         enum e1 _1;
>         enum e2 _2;
> @@ -219,6 +225,7 @@ struct root_struct {
>         union_fwd_t *_12;
>         union_fwd_ptr_t _13;
>         struct struct_with_embedded_stuff _14;
> +       struct float_struct _15;
>  };
>
>  /* ------ END-EXPECTED-OUTPUT ------ */
> --
> 2.29.2
>

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

* Re: [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests
  2021-03-05 17:08 [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests Ilya Leoshkevich
  2021-03-05 17:08 ` [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size Ilya Leoshkevich
  2021-03-05 17:08 ` [PATCH bpf-next 2/2] selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax Ilya Leoshkevich
@ 2021-03-09 19:10 ` Alexei Starovoitov
  2 siblings, 0 replies; 8+ messages in thread
From: Alexei Starovoitov @ 2021-03-09 19:10 UTC (permalink / raw)
  To: Ilya Leoshkevich
  Cc: Alexei Starovoitov, Daniel Borkmann, bpf, Heiko Carstens, Vasily Gorbik

On Fri, Mar 5, 2021 at 9:09 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> The two tests here did not make it into the main BTF_KIND_FLOAT series
> because of dependency on LLVM.

Applied. Thanks

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

end of thread, other threads:[~2021-03-09 19:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 17:08 [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests Ilya Leoshkevich
2021-03-05 17:08 ` [PATCH bpf-next 1/2] selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size Ilya Leoshkevich
2021-03-05 21:30   ` Yonghong Song
2021-03-07  3:21   ` Andrii Nakryiko
2021-03-05 17:08 ` [PATCH bpf-next 2/2] selftests/bpf: Add BTF_KIND_FLOAT to btf_dump_test_case_syntax Ilya Leoshkevich
2021-03-05 21:31   ` Yonghong Song
2021-03-07  3:23   ` Andrii Nakryiko
2021-03-09 19:10 ` [PATCH bpf-next 0/2] selftests/bpf: Add clang-based BTF_KIND_FLOAT tests Alexei Starovoitov

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