* [PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps
@ 2026-10-31 22:36 Hungyu Lin
2026-10-31 22:52 ` Alexei Starovoitov
2026-10-31 23:09 ` bot+bpf-ci
0 siblings, 2 replies; 3+ messages in thread
From: Hungyu Lin @ 2026-10-31 22:36 UTC (permalink / raw)
To: qmo, bpf; +Cc: ast, daniel, andrii, yonghong.song, linux-kernel, Hungyu Lin
When an enum64 data value does not match a named enumerator,
btf_dumper_enum64() always prints it as signed. Unsigned values with
bit 63 set therefore appear negative in BTF-formatted map dump and
lookup output, in both plain and JSON modes. For example,
0x8000000000000001 is printed as -9223372036854775807 instead of
9223372036854775809.
Choose the numeric writer according to the enum's signedness. Keep
signed values and named enumerators unchanged.
Fixes: 58a53978fdf6 ("bpftool: Add btf enum64 support")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
tools/bpf/bpftool/btf_dumper.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index 3267163119dc..88c0da29f246 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -204,7 +204,10 @@ static int btf_dumper_enum64(const struct btf_dumper *d,
}
}
- jsonw_int(d->jw, value);
+ if (btf_kflag(t))
+ jsonw_int(d->jw, value);
+ else
+ jsonw_uint(d->jw, value);
return 0;
}
base-commit: eaae576c34d7e001767b6845a5950b0b8db3e68a
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps
2026-10-31 22:36 [PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps Hungyu Lin
@ 2026-10-31 22:52 ` Alexei Starovoitov
2026-10-31 23:09 ` bot+bpf-ci
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2026-10-31 22:52 UTC (permalink / raw)
To: Hungyu Lin, qmo, bpf; +Cc: daniel, andrii, yonghong.song, linux-kernel
On Sat, Oct 31, 2026 at 03:36 PM Hungyu Lin <dennylin0707@gmail.com> wrote:
> @@ -204,7 +204,10 @@ static int btf_dumper_enum64(const struct btf_dumper *d,
> - jsonw_int(d->jw, value);
> + if (btf_kflag(t))
> + jsonw_int(d->jw, value);
> + else
> + jsonw_uint(d->jw, value);
btf_dumper_enum() has the same problem.
Fix all in one patch:
diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index 3267163..09dd428 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -149,7 +149,8 @@ static int btf_dumper_enum(const struct btf_dumper *d,
const void *data)
{
const struct btf_enum *enums = btf_enum(t);
- __s64 value;
+ bool is_signed = btf_kflag(t);
+ __s64 value, val;
__u32 i;
switch (t->size) {
@@ -157,20 +158,21 @@ static int btf_dumper_enum(const struct btf_dumper *d,
value = *(__s64 *)data;
break;
case 4:
- value = *(__s32 *)data;
+ value = is_signed ? (__s64)*(__s32 *)data : *(__u32 *)data;
break;
case 2:
- value = *(__s16 *)data;
+ value = is_signed ? *(__s16 *)data : *(__u16 *)data;
break;
case 1:
- value = *(__s8 *)data;
+ value = is_signed ? *(__s8 *)data : *(__u8 *)data;
break;
default:
return -EINVAL;
}
for (i = 0; i < btf_vlen(t); i++) {
- if (value == enums[i].val) {
+ val = is_signed ? (__s64)enums[i].val : (__u32)enums[i].val;
+ if (value == val) {
jsonw_string(d->jw,
btf__name_by_offset(d->btf,
enums[i].name_off));
@@ -178,7 +180,10 @@ static int btf_dumper_enum(const struct btf_dumper *d,
}
}
- jsonw_int(d->jw, value);
+ if (is_signed)
+ jsonw_int(d->jw, value);
+ else
+ jsonw_uint(d->jw, value);
return 0;
}
@@ -204,7 +209,10 @@ static int btf_dumper_enum64(const struct btf_dumper *d,
}
}
- jsonw_int(d->jw, value);
+ if (btf_kflag(t))
+ jsonw_int(d->jw, value);
+ else
+ jsonw_uint(d->jw, value);
return 0;
}
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps
2026-10-31 22:36 [PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps Hungyu Lin
2026-10-31 22:52 ` Alexei Starovoitov
@ 2026-10-31 23:09 ` bot+bpf-ci
1 sibling, 0 replies; 3+ messages in thread
From: bot+bpf-ci @ 2026-10-31 23:09 UTC (permalink / raw)
To: dennylin0707, qmo, bpf
Cc: ast, daniel, andrii, yonghong.song, linux-kernel, dennylin0707,
ast, andrii, daniel, martin.lau, eddyz87, yonghong.song, mason,
ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 1943 bytes --]
> bpftool: Preserve unsigned enum64 values in data dumps
TL;DR: Possible incomplete fix: as requested in the v1 review,
btf_dumper_enum() was left unchanged, so an unmatched unsigned 4-byte enum
value like 0xffffffff may still print as -1 in bpftool dumps.
> diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
> index 3267163119dc..88c0da29f246 100644
> --- a/tools/bpf/bpftool/btf_dumper.c
> +++ b/tools/bpf/bpftool/btf_dumper.c
[ ... ]
> @@ -204,7 +204,10 @@ static int btf_dumper_enum64(const struct btf_dumper *d,
> }
> }
>
> - jsonw_int(d->jw, value);
> + if (btf_kflag(t))
> + jsonw_int(d->jw, value);
> + else
> + jsonw_uint(d->jw, value);
> return 0;
> }
>
Alexei Starovoitov replied to v1 that btf_dumper_enum() has the same
problem and asked for both functions to be fixed in one patch, and he
supplied a diff for it. I could not find a v2 on lore, and this patch still
only touches btf_dumper_enum64().
Was the request to cover btf_dumper_enum() intentionally left out?
btf_dumper_enum() still sign-extends the 1, 2 and 4 byte loads and always
prints an unmatched value with jsonw_int():
static int btf_dumper_enum(const struct btf_dumper *d,
const struct btf_type *t,
const void *data)
{
...
switch (t->size) {
case 4:
value = *(__s32 *)data;
break;
...
}
...
jsonw_int(d->jw, value);
return 0;
}
For example, an unsigned 4-byte enum holding 0xffffffff that matches no
enumerator would still be printed as -1. Should btf_dumper_enum() pick the
zero- or sign-extending load based on btf_kflag(t), compare enumerators with
matching signedness, and call jsonw_uint() for unsigned enums, as in the
diff from the v1 review?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41249994972
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-31 23:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 22:36 [PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps Hungyu Lin
2026-10-31 22:52 ` Alexei Starovoitov
2026-10-31 23:09 ` bot+bpf-ci
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®