All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool
@ 2022-07-06 21:28 Daniel Müller
  2022-07-06 21:28 ` [PATCH bpf-next 1/2] bpftool: Add support for KIND_RESTRICT to gen min_core_btf command Daniel Müller
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Daniel Müller @ 2022-07-06 21:28 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, quentin, kernel-team

As pointed out in an earlier discussion [0] not all paths in bpftool's
minimization logic handle the restrict type qualifier properly. Specifically,
the gen min_core_btf command fails when encountering the corresponding BTF kind
for a TYPE_EXISTS relocation (TYPE_MATCHES support was added earlier):
  > Error: unsupported kind: restrict (26)

This patch set fixes this short coming.

[0]: https://lore.kernel.org/bpf/20220623212205.2805002-1-deso@posteo.net/T/#m4c75205145701762a4b398e0cdb911d5b5305ffc

Daniel Müller (2):
  bpftool: Add support for KIND_RESTRICT to gen min_core_btf command
  selftests/bpf: Add test involving restrict type qualifier

 tools/bpf/bpftool/gen.c                                   | 1 +
 tools/testing/selftests/bpf/prog_tests/core_reloc.c       | 2 ++
 tools/testing/selftests/bpf/progs/core_reloc_types.h      | 8 ++++++--
 .../selftests/bpf/progs/test_core_reloc_type_based.c      | 5 +++++
 4 files changed, 14 insertions(+), 2 deletions(-)

-- 
2.30.2


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

* [PATCH bpf-next 1/2] bpftool: Add support for KIND_RESTRICT to gen min_core_btf command
  2022-07-06 21:28 [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool Daniel Müller
@ 2022-07-06 21:28 ` Daniel Müller
  2022-07-06 21:28 ` [PATCH bpf-next 2/2] selftests/bpf: Add test involving restrict type qualifier Daniel Müller
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Müller @ 2022-07-06 21:28 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, quentin, kernel-team

This change adjusts bpftool's type marking logic, as used in conjunction
with TYPE_EXISTS relocations, to correctly recognize and handle the
RESTRICT BTF kind.

[0]: https://lore.kernel.org/bpf/20220623212205.2805002-1-deso@posteo.net/T/#m4c75205145701762a4b398e0cdb911d5b5305ffc

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Müller <deso@posteo.net>
---
 tools/bpf/bpftool/gen.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 3d35fbc..1cf53b 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -1762,6 +1762,7 @@ btfgen_mark_type(struct btfgen_info *info, unsigned int type_id, bool follow_poi
 		}
 		break;
 	case BTF_KIND_CONST:
+	case BTF_KIND_RESTRICT:
 	case BTF_KIND_VOLATILE:
 	case BTF_KIND_TYPEDEF:
 		err = btfgen_mark_type(info, btf_type->type, follow_pointers);
-- 
2.30.2


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

* [PATCH bpf-next 2/2] selftests/bpf: Add test involving restrict type qualifier
  2022-07-06 21:28 [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool Daniel Müller
  2022-07-06 21:28 ` [PATCH bpf-next 1/2] bpftool: Add support for KIND_RESTRICT to gen min_core_btf command Daniel Müller
@ 2022-07-06 21:28 ` Daniel Müller
  2022-07-07  9:14 ` [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool Quentin Monnet
  2022-07-08 12:30 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Müller @ 2022-07-06 21:28 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, quentin, kernel-team

This change adds a type based test involving the restrict type qualifier
to the BPF selftests. On the btfgen path, this will verify that bpftool
correctly handles the corresponding RESTRICT BTF kind.

Signed-off-by: Daniel Müller <deso@posteo.net>
---
 tools/testing/selftests/bpf/prog_tests/core_reloc.c       | 2 ++
 tools/testing/selftests/bpf/progs/core_reloc_types.h      | 8 ++++++--
 .../selftests/bpf/progs/test_core_reloc_type_based.c      | 5 +++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
index a6f65e2..c8655ba 100644
--- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c
+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
@@ -764,6 +764,7 @@ static const struct core_reloc_test_case test_cases[] = {
 		.typedef_int_exists = 1,
 		.typedef_enum_exists = 1,
 		.typedef_void_ptr_exists = 1,
+		.typedef_restrict_ptr_exists = 1,
 		.typedef_func_proto_exists = 1,
 		.typedef_arr_exists = 1,
 
@@ -777,6 +778,7 @@ static const struct core_reloc_test_case test_cases[] = {
 		.typedef_int_matches = 1,
 		.typedef_enum_matches = 1,
 		.typedef_void_ptr_matches = 1,
+		.typedef_restrict_ptr_matches = 1,
 		.typedef_func_proto_matches = 1,
 		.typedef_arr_matches = 1,
 
diff --git a/tools/testing/selftests/bpf/progs/core_reloc_types.h b/tools/testing/selftests/bpf/progs/core_reloc_types.h
index 7ef91d..fd8e1b 100644
--- a/tools/testing/selftests/bpf/progs/core_reloc_types.h
+++ b/tools/testing/selftests/bpf/progs/core_reloc_types.h
@@ -874,6 +874,7 @@ struct core_reloc_type_based_output {
 	bool typedef_int_exists;
 	bool typedef_enum_exists;
 	bool typedef_void_ptr_exists;
+	bool typedef_restrict_ptr_exists;
 	bool typedef_func_proto_exists;
 	bool typedef_arr_exists;
 
@@ -887,6 +888,7 @@ struct core_reloc_type_based_output {
 	bool typedef_int_matches;
 	bool typedef_enum_matches;
 	bool typedef_void_ptr_matches;
+	bool typedef_restrict_ptr_matches;
 	bool typedef_func_proto_matches;
 	bool typedef_arr_matches;
 
@@ -939,6 +941,7 @@ typedef int int_typedef;
 typedef enum { TYPEDEF_ENUM_VAL1, TYPEDEF_ENUM_VAL2 } enum_typedef;
 
 typedef void *void_ptr_typedef;
+typedef int *restrict restrict_ptr_typedef;
 
 typedef int (*func_proto_typedef)(long);
 
@@ -955,8 +958,9 @@ struct core_reloc_type_based {
 	int_typedef f8;
 	enum_typedef f9;
 	void_ptr_typedef f10;
-	func_proto_typedef f11;
-	arr_typedef f12;
+	restrict_ptr_typedef f11;
+	func_proto_typedef f12;
+	arr_typedef f13;
 };
 
 /* no types in target */
diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_type_based.c b/tools/testing/selftests/bpf/progs/test_core_reloc_type_based.c
index d95bc08..2edb4d 100644
--- a/tools/testing/selftests/bpf/progs/test_core_reloc_type_based.c
+++ b/tools/testing/selftests/bpf/progs/test_core_reloc_type_based.c
@@ -51,6 +51,7 @@ typedef int int_typedef;
 typedef enum { TYPEDEF_ENUM_VAL1, TYPEDEF_ENUM_VAL2 } enum_typedef;
 
 typedef void *void_ptr_typedef;
+typedef int *restrict restrict_ptr_typedef;
 
 typedef int (*func_proto_typedef)(long);
 
@@ -67,6 +68,7 @@ struct core_reloc_type_based_output {
 	bool typedef_int_exists;
 	bool typedef_enum_exists;
 	bool typedef_void_ptr_exists;
+	bool typedef_restrict_ptr_exists;
 	bool typedef_func_proto_exists;
 	bool typedef_arr_exists;
 
@@ -80,6 +82,7 @@ struct core_reloc_type_based_output {
 	bool typedef_int_matches;
 	bool typedef_enum_matches;
 	bool typedef_void_ptr_matches;
+	bool typedef_restrict_ptr_matches;
 	bool typedef_func_proto_matches;
 	bool typedef_arr_matches;
 
@@ -118,6 +121,7 @@ int test_core_type_based(void *ctx)
 	out->typedef_int_exists = bpf_core_type_exists(int_typedef);
 	out->typedef_enum_exists = bpf_core_type_exists(enum_typedef);
 	out->typedef_void_ptr_exists = bpf_core_type_exists(void_ptr_typedef);
+	out->typedef_restrict_ptr_exists = bpf_core_type_exists(restrict_ptr_typedef);
 	out->typedef_func_proto_exists = bpf_core_type_exists(func_proto_typedef);
 	out->typedef_arr_exists = bpf_core_type_exists(arr_typedef);
 
@@ -131,6 +135,7 @@ int test_core_type_based(void *ctx)
 	out->typedef_int_matches = bpf_core_type_matches(int_typedef);
 	out->typedef_enum_matches = bpf_core_type_matches(enum_typedef);
 	out->typedef_void_ptr_matches = bpf_core_type_matches(void_ptr_typedef);
+	out->typedef_restrict_ptr_matches = bpf_core_type_matches(restrict_ptr_typedef);
 	out->typedef_func_proto_matches = bpf_core_type_matches(func_proto_typedef);
 	out->typedef_arr_matches = bpf_core_type_matches(arr_typedef);
 
-- 
2.30.2


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

* Re: [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool
  2022-07-06 21:28 [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool Daniel Müller
  2022-07-06 21:28 ` [PATCH bpf-next 1/2] bpftool: Add support for KIND_RESTRICT to gen min_core_btf command Daniel Müller
  2022-07-06 21:28 ` [PATCH bpf-next 2/2] selftests/bpf: Add test involving restrict type qualifier Daniel Müller
@ 2022-07-07  9:14 ` Quentin Monnet
  2022-07-08 12:30 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Quentin Monnet @ 2022-07-07  9:14 UTC (permalink / raw)
  To: Daniel Müller, bpf, ast, andrii, daniel, kernel-team

On 06/07/2022 22:28, Daniel Müller wrote:
> As pointed out in an earlier discussion [0] not all paths in bpftool's
> minimization logic handle the restrict type qualifier properly. Specifically,
> the gen min_core_btf command fails when encountering the corresponding BTF kind
> for a TYPE_EXISTS relocation (TYPE_MATCHES support was added earlier):
>   > Error: unsupported kind: restrict (26)
> 
> This patch set fixes this short coming.
> 
> [0]: https://lore.kernel.org/bpf/20220623212205.2805002-1-deso@posteo.net/T/#m4c75205145701762a4b398e0cdb911d5b5305ffc
> 
> Daniel Müller (2):
>   bpftool: Add support for KIND_RESTRICT to gen min_core_btf command
>   selftests/bpf: Add test involving restrict type qualifier
> 
>  tools/bpf/bpftool/gen.c                                   | 1 +
>  tools/testing/selftests/bpf/prog_tests/core_reloc.c       | 2 ++
>  tools/testing/selftests/bpf/progs/core_reloc_types.h      | 8 ++++++--
>  .../selftests/bpf/progs/test_core_reloc_type_based.c      | 5 +++++
>  4 files changed, 14 insertions(+), 2 deletions(-)
> 

Acked-by: Quentin Monnet <quentin@isovalent.com>
Thanks!

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

* Re: [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool
  2022-07-06 21:28 [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool Daniel Müller
                   ` (2 preceding siblings ...)
  2022-07-07  9:14 ` [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool Quentin Monnet
@ 2022-07-08 12:30 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-08 12:30 UTC (permalink / raw)
  To: =?utf-8?q?Daniel_M=C3=BCller_=3Cdeso=40posteo=2Enet=3E?=
  Cc: bpf, ast, andrii, daniel, quentin, kernel-team

Hello:

This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Wed,  6 Jul 2022 21:28:53 +0000 you wrote:
> As pointed out in an earlier discussion [0] not all paths in bpftool's
> minimization logic handle the restrict type qualifier properly. Specifically,
> the gen min_core_btf command fails when encountering the corresponding BTF kind
> for a TYPE_EXISTS relocation (TYPE_MATCHES support was added earlier):
>   > Error: unsupported kind: restrict (26)
> 
> This patch set fixes this short coming.
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/2] bpftool: Add support for KIND_RESTRICT to gen min_core_btf command
    https://git.kernel.org/bpf/bpf-next/c/aad53f17f0ad
  - [bpf-next,2/2] selftests/bpf: Add test involving restrict type qualifier
    https://git.kernel.org/bpf/bpf-next/c/32e0d9b31048

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:[~2022-07-08 12:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06 21:28 [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool Daniel Müller
2022-07-06 21:28 ` [PATCH bpf-next 1/2] bpftool: Add support for KIND_RESTRICT to gen min_core_btf command Daniel Müller
2022-07-06 21:28 ` [PATCH bpf-next 2/2] selftests/bpf: Add test involving restrict type qualifier Daniel Müller
2022-07-07  9:14 ` [PATCH bpf-next 0/2] Add KIND_RESTRICT support to bpftool Quentin Monnet
2022-07-08 12:30 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.