* [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps
@ 2026-10-30 9:09 Hungyu Lin
2026-10-30 10:26 ` Quentin Monnet
2026-10-30 19:46 ` Andrii Nakryiko
0 siblings, 2 replies; 5+ messages in thread
From: Hungyu Lin @ 2026-10-30 9:09 UTC (permalink / raw)
To: qmo, bpf; +Cc: andrii, ast, daniel, linux-kernel, Hungyu Lin
The BTF enum value is stored in a signed 32-bit field even when the
enum is unsigned. Passing it directly to jsonw_uint_field(), which
takes a uint64_t, sign-extends values with bit 31 set. For example,
0xffffffffU is printed as 18446744073709551615 instead of 4294967295
by bpftool -j btf dump.
Cast the value to __u32 before widening it, matching the conversion
already used for plain-text output.
Fixes: c93cc69004df ("bpftool: add ability to dump BTF types")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
tools/bpf/bpftool/btf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index abd661db91e6..385521e6b028 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -482,7 +482,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
if (btf_kflag(t))
jsonw_int_field(w, "val", v->val);
else
- jsonw_uint_field(w, "val", v->val);
+ jsonw_uint_field(w, "val", (__u32)v->val);
jsonw_end_object(w);
} else {
if (btf_kflag(t))
base-commit: 7101b10cf281f629ac58c99697ca6f6d082b99a7
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps
2026-10-30 9:09 [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps Hungyu Lin
@ 2026-10-30 10:26 ` Quentin Monnet
2026-10-30 19:46 ` Andrii Nakryiko
1 sibling, 0 replies; 5+ messages in thread
From: Quentin Monnet @ 2026-10-30 10:26 UTC (permalink / raw)
To: Hungyu Lin, bpf; +Cc: andrii, ast, daniel, linux-kernel
2026-10-30 09:09 UTC+0000 ~ Hungyu Lin <dennylin0707@gmail.com>
> The BTF enum value is stored in a signed 32-bit field even when the
> enum is unsigned. Passing it directly to jsonw_uint_field(), which
> takes a uint64_t, sign-extends values with bit 31 set. For example,
> 0xffffffffU is printed as 18446744073709551615 instead of 4294967295
> by bpftool -j btf dump.
>
> Cast the value to __u32 before widening it, matching the conversion
> already used for plain-text output.
>
> Fixes: c93cc69004df ("bpftool: add ability to dump BTF types")
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
Looks correct, thank you.
Acked-by: Quentin Monnet <qmo@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps
2026-10-30 9:09 [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps Hungyu Lin
2026-10-30 10:26 ` Quentin Monnet
@ 2026-10-30 19:46 ` Andrii Nakryiko
2026-10-30 20:00 ` Hungyu Lin
1 sibling, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2026-10-30 19:46 UTC (permalink / raw)
To: Hungyu Lin; +Cc: qmo, bpf, andrii, ast, daniel, linux-kernel
On Fri, Oct 30, 2026 at 2:09 AM Hungyu Lin <dennylin0707@gmail.com> wrote:
>
> The BTF enum value is stored in a signed 32-bit field even when the
> enum is unsigned. Passing it directly to jsonw_uint_field(), which
> takes a uint64_t, sign-extends values with bit 31 set. For example,
> 0xffffffffU is printed as 18446744073709551615 instead of 4294967295
> by bpftool -j btf dump.
>
> Cast the value to __u32 before widening it, matching the conversion
> already used for plain-text output.
>
> Fixes: c93cc69004df ("bpftool: add ability to dump BTF types")
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
> tools/bpf/bpftool/btf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
please drop RFC tag and report with Quentin's ack
> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> index abd661db91e6..385521e6b028 100644
> --- a/tools/bpf/bpftool/btf.c
> +++ b/tools/bpf/bpftool/btf.c
> @@ -482,7 +482,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> if (btf_kflag(t))
> jsonw_int_field(w, "val", v->val);
> else
> - jsonw_uint_field(w, "val", v->val);
> + jsonw_uint_field(w, "val", (__u32)v->val);
> jsonw_end_object(w);
> } else {
> if (btf_kflag(t))
>
> base-commit: 7101b10cf281f629ac58c99697ca6f6d082b99a7
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps
2026-10-30 19:46 ` Andrii Nakryiko
@ 2026-10-30 20:00 ` Hungyu Lin
2026-10-30 20:02 ` Andrii Nakryiko
0 siblings, 1 reply; 5+ messages in thread
From: Hungyu Lin @ 2026-10-30 20:00 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: qmo, bpf, andrii, ast, daniel, linux-kernel
> please drop RFC tag and report with Quentin's ack
Reposted as v2 with the RFC tag removed and Quentin's ack added.
For future bpftool fixes during the merge window, would you prefer
regular bpf-next patches or RFCs?
Thanks,
Hungyu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps
2026-10-30 20:00 ` Hungyu Lin
@ 2026-10-30 20:02 ` Andrii Nakryiko
0 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2026-10-30 20:02 UTC (permalink / raw)
To: Hungyu Lin; +Cc: qmo, bpf, andrii, ast, daniel, linux-kernel
On Fri, Oct 30, 2026 at 1:00 PM Hungyu Lin <dennylin0707@gmail.com> wrote:
>
> > please drop RFC tag and report with Quentin's ack
>
> Reposted as v2 with the RFC tag removed and Quentin's ack added.
>
> For future bpftool fixes during the merge window, would you prefer
> regular bpf-next patches or RFCs?
>
regular, bpf-next is generally open during merge window
> Thanks,
> Hungyu
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-30 20:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-30 9:09 [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps Hungyu Lin
2026-10-30 10:26 ` Quentin Monnet
2026-10-30 19:46 ` Andrii Nakryiko
2026-10-30 20:00 ` Hungyu Lin
2026-10-30 20:02 ` Andrii Nakryiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®