* [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' for struct with padding only fields
@ 2022-10-01 10:44 Eduard Zingerman
2022-10-01 10:44 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test btf dump " Eduard Zingerman
2022-10-05 22:30 ` [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' " patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Eduard Zingerman @ 2022-10-01 10:44 UTC (permalink / raw)
To: bpf, ast, andrii, daniel, kernel-team; +Cc: Eduard Zingerman
btf_dump_emit_struct_def attempts to print empty structures at a
single line, e.g. `struct empty {}`. However, it has to account for a
case when there are no regular but some padding fields in the struct.
In such case `vlen` would be zero, but size would be non-zero.
E.g. here is struct bpf_timer from vmlinux.h before this patch:
struct bpf_timer {
long: 64;
long: 64;};
And after this patch:
struct bpf_dynptr {
long: 64;
long: 64;
};
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
tools/lib/bpf/btf_dump.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 4221f73a74d0..e4da6de68d8f 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -944,7 +944,11 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
lvl + 1);
}
- if (vlen)
+ /*
+ * Keep `struct empty {}` on a single line,
+ * only print newline when there are regular or padding fields.
+ */
+ if (vlen || t->size)
btf_dump_printf(d, "\n");
btf_dump_printf(d, "%s}", pfx(lvl));
if (packed)
--
2.37.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH bpf-next v2 2/2] selftests/bpf: Test btf dump for struct with padding only fields
2022-10-01 10:44 [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' for struct with padding only fields Eduard Zingerman
@ 2022-10-01 10:44 ` Eduard Zingerman
2022-10-05 22:30 ` [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' " patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Eduard Zingerman @ 2022-10-01 10:44 UTC (permalink / raw)
To: bpf, ast, andrii, daniel, kernel-team; +Cc: Eduard Zingerman
Structures with zero regular fields but some padding constitute a
special case in btf_dump.c:btf_dump_emit_struct_def with regards to
newline before closing '}'.
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
.../selftests/bpf/progs/btf_dump_test_case_padding.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
index f2661c8d2d90..7cb522d22a66 100644
--- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
+++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
@@ -102,12 +102,21 @@ struct zone {
struct zone_padding __pad__;
};
+/* ----- START-EXPECTED-OUTPUT ----- */
+struct padding_wo_named_members {
+ long: 64;
+ long: 64;
+};
+
+/* ------ END-EXPECTED-OUTPUT ------ */
+
int f(struct {
struct padded_implicitly _1;
struct padded_explicitly _2;
struct padded_a_lot _3;
struct padded_cache_line _4;
struct zone _5;
+ struct padding_wo_named_members _6;
} *_)
{
return 0;
--
2.37.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' for struct with padding only fields
2022-10-01 10:44 [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' for struct with padding only fields Eduard Zingerman
2022-10-01 10:44 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test btf dump " Eduard Zingerman
@ 2022-10-05 22:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-10-05 22:30 UTC (permalink / raw)
To: Eduard Zingerman; +Cc: bpf, ast, andrii, daniel, kernel-team
Hello:
This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Sat, 1 Oct 2022 13:44:24 +0300 you wrote:
> btf_dump_emit_struct_def attempts to print empty structures at a
> single line, e.g. `struct empty {}`. However, it has to account for a
> case when there are no regular but some padding fields in the struct.
> In such case `vlen` would be zero, but size would be non-zero.
>
> E.g. here is struct bpf_timer from vmlinux.h before this patch:
>
> [...]
Here is the summary with links:
- [bpf-next,v2,1/2] bpftool: Print newline before '}' for struct with padding only fields
https://git.kernel.org/bpf/bpf-next/c/44a726c3f23c
- [bpf-next,v2,2/2] selftests/bpf: Test btf dump for struct with padding only fields
https://git.kernel.org/bpf/bpf-next/c/d503f1176b14
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] 3+ messages in thread
end of thread, other threads:[~2022-10-05 22:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-01 10:44 [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' for struct with padding only fields Eduard Zingerman
2022-10-01 10:44 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test btf dump " Eduard Zingerman
2022-10-05 22:30 ` [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' " 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.