<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/tools/bpf/bpftool/btf.c, branch master</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=master</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2025-06-20T18:13:03Z</updated>
<entry>
<title>bpftool: Use appropriate permissions for map access</title>
<updated>2025-06-20T18:13:03Z</updated>
<author>
<name>Slava Imameev</name>
</author>
<published>2025-06-20T15:18:11Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d32179e8c2583f1613f7bc9710612091c3c038d8'/>
<id>urn:sha1:d32179e8c2583f1613f7bc9710612091c3c038d8</id>
<content type='text'>
Modify several functions in tools/bpf/bpftool/common.c to allow
specification of requested access for file descriptors, such as
read-only access.

Update bpftool to request only read access for maps when write
access is not required. This fixes errors when reading from maps
that are protected from modification via security_bpf_map.

Signed-off-by: Slava Imameev &lt;slava.imameev@crowdstrike.com&gt;
Reviewed-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Link: https://lore.kernel.org/r/20250620151812.13952-1-slava.imameev@crowdstrike.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Using the right format specifiers</title>
<updated>2025-03-17T20:50:56Z</updated>
<author>
<name>Jiayuan Chen</name>
</author>
<published>2025-03-11T11:28:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3775be3417cc3243b0df0492bd308559dcf0560b'/>
<id>urn:sha1:3775be3417cc3243b0df0492bd308559dcf0560b</id>
<content type='text'>
Fixed some formatting specifiers errors, such as using %d for int and %u
for unsigned int, as well as other byte-length types.

Perform type cast using the type derived from the data type itself, for
example, if it's originally an int, it will be cast to unsigned int if
forced to unsigned.

Signed-off-by: Jiayuan Chen &lt;jiayuan.chen@linux.dev&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20250311112809.81901-3-jiayuan.chen@linux.dev
</content>
</entry>
<entry>
<title>bpftool: btf: Support dumping a specific types from file</title>
<updated>2024-12-13T22:35:42Z</updated>
<author>
<name>Daniel Xu</name>
</author>
<published>2024-12-13T19:44:11Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a812d92ed2aee2d57dccb12b289377265f4ce5e7'/>
<id>urn:sha1:a812d92ed2aee2d57dccb12b289377265f4ce5e7</id>
<content type='text'>
Some projects, for example xdp-tools [0], prefer to check in a minimized
vmlinux.h rather than the complete file which can get rather large.

However, when you try to add a minimized version of a complex struct (eg
struct xfrm_state), things can get quite complex if you're trying to
manually untangle and deduplicate the dependencies.

This commit teaches bpftool to do a minimized dump of a specific types by
providing a optional root_id argument(s).

Example usage:

    $ ./bpftool btf dump file ~/dev/linux/vmlinux | rg "STRUCT 'xfrm_state'"
    [12643] STRUCT 'xfrm_state' size=912 vlen=58

    $ ./bpftool btf dump file ~/dev/linux/vmlinux root_id 12643 format c
    #ifndef __VMLINUX_H__
    #define __VMLINUX_H__

    [..]

    struct xfrm_type_offload;

    struct xfrm_sec_ctx;

    struct xfrm_state {
            possible_net_t xs_net;
            union {
                    struct hlist_node gclist;
                    struct hlist_node bydst;
            };
            union {
                    struct hlist_node dev_gclist;
                    struct hlist_node bysrc;
            };
            struct hlist_node byspi;
    [..]

[0]: https://github.com/xdp-project/xdp-tools/blob/master/headers/bpf/vmlinux.h

Signed-off-by: Daniel Xu &lt;dxu@dxuuu.xyz&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/04feb860c0a56a7da66f923551484e1483a72074.1734119028.git.dxu@dxuuu.xyz
</content>
</entry>
<entry>
<title>bpftool: btf: Validate root_type_ids early</title>
<updated>2024-12-13T22:35:42Z</updated>
<author>
<name>Daniel Xu</name>
</author>
<published>2024-12-13T19:44:10Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7f5819e1ace85632cf58c43ab6c38d2d4b0aa161'/>
<id>urn:sha1:7f5819e1ace85632cf58c43ab6c38d2d4b0aa161</id>
<content type='text'>
Handle invalid root_type_ids early, as an invalid ID will cause dumpers
to half-emit valid boilerplate and then bail with an unclean exit. This
is ugly and possibly confusing for users, so preemptively handle the
common error case before any dumping begins.

Signed-off-by: Daniel Xu &lt;dxu@dxuuu.xyz&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Reviewed-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Link: https://lore.kernel.org/bpf/33e09a08a6072f8381cb976218a009709309b7e1.1734119028.git.dxu@dxuuu.xyz
</content>
</entry>
<entry>
<title>bpftool: Cast variable `var` to long long</title>
<updated>2024-11-13T20:17:12Z</updated>
<author>
<name>Luo Yifan</name>
</author>
<published>2024-11-12T07:37:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b7b31f184f88c0cbd5d53dfc9a6532d851311135'/>
<id>urn:sha1:b7b31f184f88c0cbd5d53dfc9a6532d851311135</id>
<content type='text'>
When the SIGNED condition is met, the variable `var` should be cast to
`long long` instead of `unsigned long long`.

Signed-off-by: Luo Yifan &lt;luoyifan@cmss.chinamobile.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Reviewed-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20241112073701.283362-1-luoyifan@cmss.chinamobile.com
</content>
</entry>
<entry>
<title>bpftool: __bpf_fastcall for kfuncs marked with special decl_tag</title>
<updated>2024-10-04T00:47:53Z</updated>
<author>
<name>Eduard Zingerman</name>
</author>
<published>2024-09-16T09:17:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=bf7ce5416f68db058ac7105902adf497b3ce4e8c'/>
<id>urn:sha1:bf7ce5416f68db058ac7105902adf497b3ce4e8c</id>
<content type='text'>
Generate __attribute__((bpf_fastcall)) for kfuncs marked with
"bpf_fastcall" decl tag. E.g. for the following BTF:

    $ bpftool btf dump file vmlinux
    ...
    [A] FUNC 'bpf_rdonly_cast' type_id=...
    ...
    [B] DECL_TAG 'bpf_kfunc' type_id=A component_idx=-1
    [C] DECL_TAG 'bpf_fastcall' type_id=A component_idx=-1

Generate the following vmlinux.h:

    #ifndef __VMLINUX_H__
    #define __VMLINUX_H__
    ...
    #ifndef __bpf_fastcall
    #if __has_attribute(bpf_fastcall)
    #define __bpf_fastcall __attribute__((bpf_fastcall))
    #else
    #define __bpf_fastcall
    #endif
    #endif
    ...
    __bpf_fastcall extern void *bpf_rdonly_cast(...) ...;

The "bpf_fastcall" / "bpf_kfunc" tags pair would generated by pahole
when constructing vmlinux BTF.

While at it, sort printed kfuncs by name for better vmlinux.h
stability.

Signed-off-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20240916091712.2929279-5-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Improve btf c dump sorting stability</title>
<updated>2024-09-06T21:06:30Z</updated>
<author>
<name>Mykyta Yatsenko</name>
</author>
<published>2024-09-06T13:24:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f8c6b7913dfaa67475883f94261c278adbcaa0ae'/>
<id>urn:sha1:f8c6b7913dfaa67475883f94261c278adbcaa0ae</id>
<content type='text'>
Existing algorithm for BTF C dump sorting uses only types and names of
the structs and unions for ordering. As dump contains structs with the
same names but different contents, relative to each other ordering of
those structs will be accidental.
This patch addresses this problem by introducing a new sorting field
that contains hash of the struct/union field names and types to
disambiguate comparison of the non-unique named structs.

Signed-off-by: Mykyta Yatsenko &lt;yatsenko@meta.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20240906132453.146085-1-mykyta.yatsenko5@gmail.com
</content>
</entry>
<entry>
<title>bpftool: Fix handling enum64 in btf dump sorting</title>
<updated>2024-09-02T20:44:51Z</updated>
<author>
<name>Mykyta Yatsenko</name>
</author>
<published>2024-09-02T17:17:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b0222d1d9e6f8551a056b89b0bff38f515f3c9b5'/>
<id>urn:sha1:b0222d1d9e6f8551a056b89b0bff38f515f3c9b5</id>
<content type='text'>
Wrong function is used to access the first enum64 element. Substituting btf_enum(t)
with btf_enum64(t) for BTF_KIND_ENUM64.

Fixes: 94133cf24bb3 ("bpftool: Introduce btf c dump sorting")
Signed-off-by: Mykyta Yatsenko &lt;yatsenko@meta.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Acked-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20240902171721.105253-1-mykyta.yatsenko5@gmail.com
</content>
</entry>
<entry>
<title>bpftool: Support dumping kfunc prototypes from BTF</title>
<updated>2024-06-12T18:01:32Z</updated>
<author>
<name>Daniel Xu</name>
</author>
<published>2024-06-12T15:58:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=770abbb5a25a5b767f1c60ba366aea503728e957'/>
<id>urn:sha1:770abbb5a25a5b767f1c60ba366aea503728e957</id>
<content type='text'>
This patch enables dumping kfunc prototypes from bpftool. This is useful
b/c with this patch, end users will no longer have to manually define
kfunc prototypes. For the kernel tree, this also means we can optionally
drop kfunc prototypes from:

        tools/testing/selftests/bpf/bpf_kfuncs.h
        tools/testing/selftests/bpf/bpf_experimental.h

Example usage:

        $ make PAHOLE=/home/dxu/dev/pahole/build/pahole -j30 vmlinux

        $ ./tools/bpf/bpftool/bpftool btf dump file ./vmlinux format c | rg "__ksym;" | head -3
        extern void cgroup_rstat_updated(struct cgroup *cgrp, int cpu) __weak __ksym;
        extern void cgroup_rstat_flush(struct cgroup *cgrp) __weak __ksym;
        extern struct bpf_key *bpf_lookup_user_key(u32 serial, u64 flags) __weak __ksym;

Signed-off-by: Daniel Xu &lt;dxu@dxuuu.xyz&gt;
Link: https://lore.kernel.org/r/bf6c08f9263c4bd9d10a717de95199d766a13f61.1718207789.git.dxu@dxuuu.xyz
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Introduce btf c dump sorting</title>
<updated>2024-05-18T17:46:16Z</updated>
<author>
<name>Mykyta Yatsenko</name>
</author>
<published>2024-05-14T13:12:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=94133cf24bb33889aac267a7f0e3e6a08b8a8e5a'/>
<id>urn:sha1:94133cf24bb33889aac267a7f0e3e6a08b8a8e5a</id>
<content type='text'>
Sort bpftool c dump output; aiming to simplify vmlinux.h diffing and
forcing more natural type definitions ordering.

Definitions are sorted first by their BTF kind ranks, then by their base
type name and by their own name.

Type ranks

Assign ranks to btf kinds (defined in function btf_type_rank) to set
next order:
1. Anonymous enums/enums64
2. Named enums/enums64
3. Trivial types typedefs (ints, then floats)
4. Structs/Unions
5. Function prototypes
6. Forward declarations

Type rank is set to maximum for unnamed reference types, structs and
unions to avoid emitting those types early. They will be emitted as
part of the type chain starting with named type.

Lexicographical ordering

Each type is assigned a sort_name and own_name.
sort_name is the resolved name of the final base type for reference
types (typedef, pointer, array etc). Sorting by sort_name allows to
group typedefs of the same base type. sort_name for non-reference type
is the same as own_name. own_name is a direct name of particular type,
is used as final sorting step.

Signed-off-by: Mykyta Yatsenko &lt;yatsenko@meta.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Tested-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Reviewed-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20240514131221.20585-1-yatsenko@meta.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
</feed>
