All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf
@ 2021-11-15 16:39 Yonghong Song
  2021-11-15 16:39 ` [PATCH bpf-next 1/2] libbpf: fix a couple of missed btf_type_tag handling in btf.c Yonghong Song
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yonghong Song @ 2021-11-15 16:39 UTC (permalink / raw)
  To: bpf; +Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team

Commit 2dc1e488e5cd ("libbpf: Support BTF_KIND_TYPE_TAG") added
BTF_KIND_TYPE_TAG support. But BTF_KIND_TYPE_TAG is not handled
properly in libbpf btf_dedup_is_equiv() which will cause pahole dedup
failure if the kernel has the following hack:
  #define __user __attribute__((btf_type_tag("user")))

Patch 1 fixed the issue and Patch 2 added a test for it.

Yonghong Song (2):
  libbpf: fix a couple of missed btf_type_tag handling in btf.c
  selftests/bpf: add a dedup selftest with equivalent structure types

 tools/lib/bpf/btf.c                          |  2 ++
 tools/testing/selftests/bpf/prog_tests/btf.c | 26 ++++++++++++++++++++
 2 files changed, 28 insertions(+)

-- 
2.30.2


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

* [PATCH bpf-next 1/2] libbpf: fix a couple of missed btf_type_tag handling in btf.c
  2021-11-15 16:39 [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf Yonghong Song
@ 2021-11-15 16:39 ` Yonghong Song
  2021-11-15 16:39 ` [PATCH bpf-next 2/2] selftests/bpf: add a dedup selftest with equivalent structure types Yonghong Song
  2021-11-16 12:20 ` [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Yonghong Song @ 2021-11-15 16:39 UTC (permalink / raw)
  To: bpf; +Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team

Commit 2dc1e488e5cd ("libbpf: Support BTF_KIND_TYPE_TAG") added
BTF_KIND_TYPE_TAG support. But to test vmlinux build with
  #define __user __attribute__((btf_type_tag("user")))
I need to sync libbpf repo and manually copy libbpf sources
to pahole. To simplify process, I used BTF_KIND_RESTRICT to
simulate BTF_KIND_TYPE_TAG with vmlinux build as "restrict"
modifier is barely used in kernel. But this approach missed
one case in dedup with structures where BTF_KIND_RESTRICT is
handled and BTF_KIND_TYPE_TAG is not handled in
btf_dedup_is_equiv(), and this will result in pahole dedup
failure. This patch fixed this issue and a selftest is added in
the subsequent patch to test this scenario.

The other missed handling is in btf__resolve_size().
Currently the compiler always emit like PTR->TYPE_TAG->...
so in practice we don't hit the missing BTF_KIND_TYPE_TAG handling
issue with compiler generated code. But let us added
case BTF_KIND_TYPE_TAG in the switch statement
to be future proof.

Fixes: 2dc1e488e5cd ("libbpf: Support BTF_KIND_TYPE_TAG")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/lib/bpf/btf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index fadf089ae8fe..b6be579e0dc6 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -610,6 +610,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
 		case BTF_KIND_RESTRICT:
 		case BTF_KIND_VAR:
 		case BTF_KIND_DECL_TAG:
+		case BTF_KIND_TYPE_TAG:
 			type_id = t->type;
 			break;
 		case BTF_KIND_ARRAY:
@@ -4023,6 +4024,7 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
 	case BTF_KIND_PTR:
 	case BTF_KIND_TYPEDEF:
 	case BTF_KIND_FUNC:
+	case BTF_KIND_TYPE_TAG:
 		if (cand_type->info != canon_type->info)
 			return 0;
 		return btf_dedup_is_equiv(d, cand_type->type, canon_type->type);
-- 
2.30.2


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

* [PATCH bpf-next 2/2] selftests/bpf: add a dedup selftest with equivalent structure types
  2021-11-15 16:39 [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf Yonghong Song
  2021-11-15 16:39 ` [PATCH bpf-next 1/2] libbpf: fix a couple of missed btf_type_tag handling in btf.c Yonghong Song
@ 2021-11-15 16:39 ` Yonghong Song
  2021-11-16 12:27   ` Daniel Borkmann
  2021-11-16 12:20 ` [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Yonghong Song @ 2021-11-15 16:39 UTC (permalink / raw)
  To: bpf; +Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team

Without previous libbpf patch, the following error will occur:
  $ ./test_progs -t btf
  ...
  do_test_dedup:FAIL:check btf_dedup failed errno:-22#13/205 btf/dedup: btf_type_tag #5, struct:FAIL

And the previfous libbpf patch fixed the issue.

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/testing/selftests/bpf/prog_tests/btf.c | 26 ++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
index 4aa6343dc4c8..f9326a13badb 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf.c
@@ -7352,6 +7352,32 @@ static struct btf_dedup_test dedup_tests[] = {
 		BTF_STR_SEC("\0tag1"),
 	},
 },
+{
+	.descr = "dedup: btf_type_tag #5, struct",
+	.input = {
+		.raw_types = {
+			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),				/* [1] */
+			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),					/* [2] */
+			BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4),	/* [3] */
+			BTF_MEMBER_ENC(NAME_NTH(3), 2, BTF_MEMBER_OFFSET(0, 0)),
+			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),					/* [4] */
+			BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4),	/* [5] */
+			BTF_MEMBER_ENC(NAME_NTH(3), 4, BTF_MEMBER_OFFSET(0, 0)),
+			BTF_END_RAW,
+		},
+		BTF_STR_SEC("\0tag1\0t\0m"),
+	},
+	.expect = {
+		.raw_types = {
+			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),				/* [1] */
+			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),					/* [2] */
+			BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4),	/* [3] */
+			BTF_MEMBER_ENC(NAME_NTH(3), 2, BTF_MEMBER_OFFSET(0, 0)),
+			BTF_END_RAW,
+		},
+		BTF_STR_SEC("\0tag1\0t\0m"),
+	},
+},
 
 };
 
-- 
2.30.2


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

* Re: [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf
  2021-11-15 16:39 [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf Yonghong Song
  2021-11-15 16:39 ` [PATCH bpf-next 1/2] libbpf: fix a couple of missed btf_type_tag handling in btf.c Yonghong Song
  2021-11-15 16:39 ` [PATCH bpf-next 2/2] selftests/bpf: add a dedup selftest with equivalent structure types Yonghong Song
@ 2021-11-16 12:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-16 12:20 UTC (permalink / raw)
  To: Yonghong Song; +Cc: bpf, ast, andrii, daniel, kernel-team

Hello:

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

On Mon, 15 Nov 2021 08:39:32 -0800 you wrote:
> Commit 2dc1e488e5cd ("libbpf: Support BTF_KIND_TYPE_TAG") added
> BTF_KIND_TYPE_TAG support. But BTF_KIND_TYPE_TAG is not handled
> properly in libbpf btf_dedup_is_equiv() which will cause pahole dedup
> failure if the kernel has the following hack:
>   #define __user __attribute__((btf_type_tag("user")))
> 
> Patch 1 fixed the issue and Patch 2 added a test for it.
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/2] libbpf: fix a couple of missed btf_type_tag handling in btf.c
    https://git.kernel.org/bpf/bpf-next/c/69a055d54615
  - [bpf-next,2/2] selftests/bpf: add a dedup selftest with equivalent structure types
    https://git.kernel.org/bpf/bpf-next/c/4746158305e9

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] 6+ messages in thread

* Re: [PATCH bpf-next 2/2] selftests/bpf: add a dedup selftest with equivalent structure types
  2021-11-15 16:39 ` [PATCH bpf-next 2/2] selftests/bpf: add a dedup selftest with equivalent structure types Yonghong Song
@ 2021-11-16 12:27   ` Daniel Borkmann
  2021-11-16 16:19     ` Yonghong Song
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Borkmann @ 2021-11-16 12:27 UTC (permalink / raw)
  To: Yonghong Song, bpf; +Cc: Alexei Starovoitov, Andrii Nakryiko, kernel-team

On 11/15/21 5:39 PM, Yonghong Song wrote:
> Without previous libbpf patch, the following error will occur:
>    $ ./test_progs -t btf
>    ...
>    do_test_dedup:FAIL:check btf_dedup failed errno:-22#13/205 btf/dedup: btf_type_tag #5, struct:FAIL
> 
> And the previfous libbpf patch fixed the issue.

Fixed up the typo above while applying and also formatted the 1/2 a bit better.
checkpatch usually has a lot of noise in its output, but it would catch things
like typos when quickly running before submission, fwiw. Anyway, thanks!

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

* Re: [PATCH bpf-next 2/2] selftests/bpf: add a dedup selftest with equivalent structure types
  2021-11-16 12:27   ` Daniel Borkmann
@ 2021-11-16 16:19     ` Yonghong Song
  0 siblings, 0 replies; 6+ messages in thread
From: Yonghong Song @ 2021-11-16 16:19 UTC (permalink / raw)
  To: Daniel Borkmann, bpf; +Cc: Alexei Starovoitov, Andrii Nakryiko, kernel-team



On 11/16/21 4:27 AM, Daniel Borkmann wrote:
> On 11/15/21 5:39 PM, Yonghong Song wrote:
>> Without previous libbpf patch, the following error will occur:
>>    $ ./test_progs -t btf
>>    ...
>>    do_test_dedup:FAIL:check btf_dedup failed errno:-22#13/205 
>> btf/dedup: btf_type_tag #5, struct:FAIL
>>
>> And the previfous libbpf patch fixed the issue.
> 
> Fixed up the typo above while applying and also formatted the 1/2 a bit 
> better.
> checkpatch usually has a lot of noise in its output, but it would catch 
> things
> like typos when quickly running before submission, fwiw. Anyway, thanks!

Thanks for the fixup! I need to remember to run checkpatch even for
small patches!


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

end of thread, other threads:[~2021-11-16 16:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 16:39 [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf Yonghong Song
2021-11-15 16:39 ` [PATCH bpf-next 1/2] libbpf: fix a couple of missed btf_type_tag handling in btf.c Yonghong Song
2021-11-15 16:39 ` [PATCH bpf-next 2/2] selftests/bpf: add a dedup selftest with equivalent structure types Yonghong Song
2021-11-16 12:27   ` Daniel Borkmann
2021-11-16 16:19     ` Yonghong Song
2021-11-16 12:20 ` [PATCH bpf-next 0/2] bpf: fix a couple of missed btf_type_tag handling in libbpf 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.