Re: [PATCH v3 bpf-next 3/6] bpftool: Support 24-bit vlen

Mykyta Yatsenko
2026-04-17T18:36:32Z

On 4/17/26 3:30 PM, Alan Maguire wrote:
> Adjust btf_vlen() usage to handle 24-bit vlen.
>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---
> tools/bpf/bpftool/btf.c | 17 ++++++-----------
> tools/bpf/bpftool/btf_dumper.c | 4 ++--
> tools/bpf/bpftool/gen.c | 16 +++++++++-------
> 3 files changed, 17 insertions(+), 20 deletions(-)
>
> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> index 2e899e940034..6ef908adf3a4 100644
> --- a/tools/bpf/bpftool/btf.c
> +++ b/tools/bpf/bpftool/btf.c
> @@ -179,8 +179,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> case BTF_KIND_STRUCT:
> case BTF_KIND_UNION: {
> const struct btf_member *m = (const void *)(t + 1);
> - __u16 vlen = BTF_INFO_VLEN(t->info);
> - int i;
> + __u32 i, vlen = BTF_INFO_VLEN(t->info);
>
> if (json_output) {
> jsonw_uint_field(w, "size", t->size);
> @@ -225,9 +224,8 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> }
> case BTF_KIND_ENUM: {
> const struct btf_enum *v = (const void *)(t + 1);
> - __u16 vlen = BTF_INFO_VLEN(t->info);
> + __u32 i, vlen = BTF_INFO_VLEN(t->info);
> const char *encoding;
> - int i;
>
> encoding = btf_kflag(t) ? "SIGNED" : "UNSIGNED";
> if (json_output) {
> @@ -263,9 +261,8 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> }
> case BTF_KIND_ENUM64: {
> const struct btf_enum64 *v = btf_enum64(t);
> - __u16 vlen = btf_vlen(t);
> + __u32 i, vlen = btf_vlen(t);
> const char *encoding;
> - int i;
>
> encoding = btf_kflag(t) ? "SIGNED" : "UNSIGNED";
> if (json_output) {
> @@ -325,8 +322,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> }
> case BTF_KIND_FUNC_PROTO: {
> const struct btf_param *p = (const void *)(t + 1);
> - __u16 vlen = BTF_INFO_VLEN(t->info);
> - int i;
> + __u32 i, vlen = BTF_INFO_VLEN(t->info);
>
> if (json_output) {
> jsonw_uint_field(w, "ret_type_id", t->type);
> @@ -369,8 +365,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> case BTF_KIND_DATASEC: {
> const struct btf_var_secinfo *v = (const void *)(t + 1);
> const struct btf_type *vt;
> - __u16 vlen = BTF_INFO_VLEN(t->info);
> - int i;
> + __u32 i, vlen = BTF_INFO_VLEN(t->info);
>
> if (json_output) {
> jsonw_uint_field(w, "size", t->size);
> @@ -675,7 +670,7 @@ static __u64 btf_name_hasher(__u64 hash, const struct btf *btf, __u32 name_off)
> static __u64 btf_type_disambig_hash(const struct btf *btf, __u32 id, bool include_members)
> {
> const struct btf_type *t = btf__type_by_id(btf, id);
> - int i;
> + __u32 i;

in libbpf, kernel and btf_dumper.c we did not migrate those callsites
that use int for vlen, but we do it here. Not an issue, of course,
either way it's correct.

> size_t hash = 0;
>
> hash = btf_name_hasher(hash, btf, t->name_off);
> diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
> index def297e879f4..9dc8425b1789 100644
> --- a/tools/bpf/bpftool/btf_dumper.c
> +++ b/tools/bpf/bpftool/btf_dumper.c
> @@ -150,7 +150,7 @@ static int btf_dumper_enum(const struct btf_dumper *d,
> {
> const struct btf_enum *enums = btf_enum(t);
> __s64 value;
> - __u16 i;
> + __u32 i;
>
> switch (t->size) {
> case 8:
> @@ -189,7 +189,7 @@ static int btf_dumper_enum64(const struct btf_dumper *d,
> const struct btf_enum64 *enums = btf_enum64(t);
> __u32 val_lo32, val_hi32;
> __u64 value;
> - __u16 i;
> + __u32 i;
>
> value = *(__u64 *)data;
> val_lo32 = (__u32)value;
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index 2f9e10752e28..37159e02f418 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -2094,7 +2094,8 @@ btfgen_mark_type(struct btfgen_info *info, unsigned int type_id, bool follow_poi
> struct btf_type *cloned_type;
> struct btf_param *param;
> struct btf_array *array;
> - int err, i;
> + __u32 i;
> + int err;
>
> if (type_id == 0)
> return 0;
> @@ -2229,7 +2230,8 @@ static int btfgen_mark_type_match(struct btfgen_info *info, __u32 type_id, bool
> const struct btf_type *btf_type;
> struct btf *btf = info->src_btf;
> struct btf_type *cloned_type;
> - int i, err;
> + int err;
> + __u32 i;
>
> if (type_id == 0)
> return 0;
> @@ -2249,7 +2251,7 @@ static int btfgen_mark_type_match(struct btfgen_info *info, __u32 type_id, bool
> case BTF_KIND_STRUCT:
> case BTF_KIND_UNION: {
> struct btf_member *m = btf_members(btf_type);
> - __u16 vlen = btf_vlen(btf_type);
> + __u32 vlen = btf_vlen(btf_type);
>
> if (behind_ptr)
> break;
> @@ -2286,7 +2288,7 @@ static int btfgen_mark_type_match(struct btfgen_info *info, __u32 type_id, bool
> break;
> }
> case BTF_KIND_FUNC_PROTO: {
> - __u16 vlen = btf_vlen(btf_type);
> + __u32 vlen = btf_vlen(btf_type);
> struct btf_param *param;
>
> /* mark ret type */
> @@ -2492,8 +2494,9 @@ static struct btf *btfgen_get_btf(struct btfgen_info *info)
> {
> struct btf *btf_new = NULL;
> unsigned int *ids = NULL;
> - unsigned int i, n = btf__type_cnt(info->marked_btf);
> + unsigned int n = btf__type_cnt(info->marked_btf);
> int err = 0;
> + __u32 i;
>
> btf_new = btf__new_empty();
> if (!btf_new) {
> @@ -2523,8 +2526,7 @@ static struct btf *btfgen_get_btf(struct btfgen_info *info)
> /* add members for struct and union */
> if (btf_is_composite(type)) {
> struct btf_member *cloned_m, *m;
> - unsigned short vlen;
> - int idx_src;
> + __u32 vlen, idx_src;
>
> name = btf__str_by_offset(info->src_btf, type->name_off);
>