<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/tools/lib/bpf/gen_loader.c, branch linux-5.16.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.16.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.16.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2022-01-27T11:01:45Z</updated>
<entry>
<title>libbpf: Fix gen_loader assumption on number of programs.</title>
<updated>2022-01-27T11:01:45Z</updated>
<author>
<name>Alexei Starovoitov</name>
</author>
<published>2021-12-12T01:16:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8f485f3fd73ecd3c25c519a6a38b0ea438bbe822'/>
<id>urn:sha1:8f485f3fd73ecd3c25c519a6a38b0ea438bbe822</id>
<content type='text'>
[ Upstream commit 259172bb6514758ce3be1610c500b51a9f44212a ]

libbpf's obj-&gt;nr_programs includes static and global functions. That number
could be higher than the actual number of bpf programs going be loaded by
gen_loader. Passing larger nr_programs to bpf_gen__init() doesn't hurt. Those
exra stack slots will stay as zero. bpf_gen__finish() needs to check that
actual number of progs that gen_loader saw is less than or equal to
obj-&gt;nr_programs.

Fixes: ba05fd36b851 ("libbpf: Perform map fd cleanup for gen_loader in case of error")
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Clean gen_loader's attach kind.</title>
<updated>2022-01-27T11:01:38Z</updated>
<author>
<name>Alexei Starovoitov</name>
</author>
<published>2021-12-01T18:10:34Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4e8f70e3e9cc9391f68e79be4477d3f9c89815f5'/>
<id>urn:sha1:4e8f70e3e9cc9391f68e79be4477d3f9c89815f5</id>
<content type='text'>
[ Upstream commit 19250f5fc0c283892a61f3abf9d65e6325f63897 ]

The gen_loader has to clear attach_kind otherwise the programs
without attach_btf_id will fail load if they follow programs
with attach_btf_id.

Fixes: 67234743736a ("libbpf: Generate loader program out of BPF ELF file.")
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211201181040.23337-12-alexei.starovoitov@gmail.com
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Fix non-C89 loop variable declaration in gen_loader.c</title>
<updated>2022-01-27T11:01:27Z</updated>
<author>
<name>Andrii Nakryiko</name>
</author>
<published>2021-11-05T19:10:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a6309d82228ba56f83b26f377cf9d01e1753b02a'/>
<id>urn:sha1:a6309d82228ba56f83b26f377cf9d01e1753b02a</id>
<content type='text'>
[ Upstream commit b8b5cb55f5d3f03cc1479a3768d68173a10359ad ]

Fix the `int i` declaration inside the for statement. This is non-C89
compliant. See [0] for user report breaking BCC build.

  [0] https://github.com/libbpf/libbpf/issues/403

Fixes: 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Kumar Kartikeya Dwivedi &lt;memxor@gmail.com&gt;
Link: https://lore.kernel.org/bpf/20211105191055.3324874-1-andrii@kernel.org
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Perform map fd cleanup for gen_loader in case of error</title>
<updated>2021-11-13T01:23:46Z</updated>
<author>
<name>Kumar Kartikeya Dwivedi</name>
</author>
<published>2021-11-12T23:20:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ba05fd36b8512d6aeefe9c2c5b6a25b726c4bfff'/>
<id>urn:sha1:ba05fd36b8512d6aeefe9c2c5b6a25b726c4bfff</id>
<content type='text'>
Alexei reported a fd leak issue in gen loader (when invoked from
bpftool) [0]. When adding ksym support, map fd allocation was moved from
stack to loader map, however I missed closing these fds (relevant when
cleanup label is jumped to on error). For the success case, the
allocated fd is returned in loader ctx, hence this problem is not
noticed.

Make three changes, first MAX_USED_MAPS in MAX_FD_ARRAY_SZ instead of
MAX_USED_PROGS, the braino was not a problem until now for this case as
we didn't try to close map fds (otherwise use of it would have tried
closing 32 additional fds in ksym btf fd range). Then, do a cleanup for
all nr_maps fds in cleanup label code, so that in case of error all
temporary map fds from bpf_gen__map_create are closed.

Then, adjust the cleanup label to only generate code for the required
number of program and map fds.  To trim code for remaining program
fds, lay out prog_fd array in stack in the end, so that we can
directly skip the remaining instances.  Still stack size remains same,
since changing that would require changes in a lot of places
(including adjustment of stack_off macro), so nr_progs_sz variable is
only used to track required number of iterations (and jump over
cleanup size calculated from that), stack offset calculation remains
unaffected.

The difference for test_ksyms_module.o is as follows:
libbpf: //prog cleanup iterations: before = 34, after = 5
libbpf: //maps cleanup iterations: before = 64, after = 2

Also, move allocation of gen-&gt;fd_array offset to bpf_gen__init. Since
offset can now be 0, and we already continue even if add_data returns 0
in case of failure, we do not need to distinguish between 0 offset and
failure case 0, as we rely on bpf_gen__finish to check errors. We can
also skip check for gen-&gt;fd_array in add_*_fd functions, since
bpf_gen__init will take care of it.

  [0]: https://lore.kernel.org/bpf/CAADnVQJ6jSitKSNKyxOrUzwY2qDRX0sPkJ=VLGHuCLVJ=qOt9g@mail.gmail.com

Fixes: 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")
Reported-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Kumar Kartikeya Dwivedi &lt;memxor@gmail.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211112232022.899074-1-memxor@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Add weak ksym support to gen_loader</title>
<updated>2021-10-28T23:30:06Z</updated>
<author>
<name>Kumar Kartikeya Dwivedi</name>
</author>
<published>2021-10-28T06:34:56Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=585a3571981d8a93e2211e1ac835d31a63e68cd8'/>
<id>urn:sha1:585a3571981d8a93e2211e1ac835d31a63e68cd8</id>
<content type='text'>
This extends existing ksym relocation code to also support relocating
weak ksyms. Care needs to be taken to zero out the src_reg (currently
BPF_PSEUOD_BTF_ID, always set for gen_loader by bpf_object__relocate_data)
when the BTF ID lookup fails at runtime.  This is not a problem for
libbpf as it only sets ext-&gt;is_set when BTF ID lookup succeeds (and only
proceeds in case of failure if ext-&gt;is_weak, leading to src_reg
remaining as 0 for weak unresolved ksym).

A pattern similar to emit_relo_kfunc_btf is followed of first storing
the default values and then jumping over actual stores in case of an
error. For src_reg adjustment, we also need to perform it when copying
the populated instruction, so depending on if copied insn[0].imm is 0 or
not, we decide to jump over the adjustment.

We cannot reach that point unless the ksym was weak and resolved and
zeroed out, as the emit_check_err will cause us to jump to cleanup
label, so we do not need to recheck whether the ksym is weak before
doing the adjustment after copying BTF ID and BTF FD.

This is consistent with how libbpf relocates weak ksym. Logging
statements are added to show the relocation result and aid debugging.

Signed-off-by: Kumar Kartikeya Dwivedi &lt;memxor@gmail.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211028063501.2239335-4-memxor@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Add typeless ksym support to gen_loader</title>
<updated>2021-10-28T23:30:06Z</updated>
<author>
<name>Kumar Kartikeya Dwivedi</name>
</author>
<published>2021-10-28T06:34:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c24941cd3766b6de682dbe6809bd6af12271ab5b'/>
<id>urn:sha1:c24941cd3766b6de682dbe6809bd6af12271ab5b</id>
<content type='text'>
This uses the bpf_kallsyms_lookup_name helper added in previous patches
to relocate typeless ksyms. The return value ENOENT can be ignored, and
the value written to 'res' can be directly stored to the insn, as it is
overwritten to 0 on lookup failure. For repeating symbols, we can simply
copy the previously populated bpf_insn.

Also, we need to take care to not close fds for typeless ksym_desc, so
reuse the 'off' member's space to add a marker for typeless ksym and use
that to skip them in cleanup_relos.

We add a emit_ksym_relo_log helper that avoids duplicating common
logging instructions between typeless and weak ksym (for future commit).

Signed-off-by: Kumar Kartikeya Dwivedi &lt;memxor@gmail.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211028063501.2239335-3-memxor@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Add "map_extra" as a per-map-type extra flag</title>
<updated>2021-10-28T20:22:49Z</updated>
<author>
<name>Joanne Koong</name>
</author>
<published>2021-10-27T23:45:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=47512102cde2d252d7b984d9675cfd3420b48ad9'/>
<id>urn:sha1:47512102cde2d252d7b984d9675cfd3420b48ad9</id>
<content type='text'>
This patch adds the libbpf infrastructure for supporting a
per-map-type "map_extra" field, whose definition will be
idiosyncratic depending on map type.

For example, for the bloom filter map, the lower 4 bits of
map_extra is used to denote the number of hash functions.

Please note that until libbpf 1.0 is here, the
"bpf_create_map_params" struct is used as a temporary
means for propagating the map_extra field to the kernel.

Signed-off-by: Joanne Koong &lt;joannekoong@fb.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211027234504.30744-3-joannekoong@fb.com
</content>
</entry>
<entry>
<title>libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations</title>
<updated>2021-10-06T00:07:42Z</updated>
<author>
<name>Kumar Kartikeya Dwivedi</name>
</author>
<published>2021-10-02T01:17:56Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=18f4fccbf314fdb07d276f4cd3eaf53f1825550d'/>
<id>urn:sha1:18f4fccbf314fdb07d276f4cd3eaf53f1825550d</id>
<content type='text'>
This change updates the BPF syscall loader to relocate BTF_KIND_FUNC
relocations, with support for weak kfunc relocations. The general idea
is to move map_fds to loader map, and also use the data for storing
kfunc BTF fds. Since both reuse the fd_array parameter, they need to be
kept together.

For map_fds, we reserve MAX_USED_MAPS slots in a region, and for kfunc,
we reserve MAX_KFUNC_DESCS. This is done so that insn-&gt;off has more
chances of being &lt;= INT16_MAX than treating data map as a sparse array
and adding fd as needed.

When the MAX_KFUNC_DESCS limit is reached, we fall back to the sparse
array model, so that as long as it does remain &lt;= INT16_MAX, we pass an
index relative to the start of fd_array.

We store all ksyms in an array where we try to avoid calling the
bpf_btf_find_by_name_kind helper, and also reuse the BTF fd that was
already stored. This also speeds up the loading process compared to
emitting calls in all cases, in later tests.

Signed-off-by: Kumar Kartikeya Dwivedi &lt;memxor@gmail.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211002011757.311265-9-memxor@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Make gen_loader data aligned.</title>
<updated>2021-09-29T20:27:19Z</updated>
<author>
<name>Alexei Starovoitov</name>
</author>
<published>2021-09-27T14:59:37Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=66fe33241726d1f872e55d95a35c063d58602ae1'/>
<id>urn:sha1:66fe33241726d1f872e55d95a35c063d58602ae1</id>
<content type='text'>
Align gen_loader data to 8 byte boundary to make sure union bpf_attr,
bpf_insns and other structs are aligned.

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210927145941.1383001-9-memxor@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Cleanup temp FDs when intermediate sys_bpf fails.</title>
<updated>2021-05-18T22:40:44Z</updated>
<author>
<name>Alexei Starovoitov</name>
</author>
<published>2021-05-14T00:36:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=30f51aedabda92b74927979b2b3b50169e285f6b'/>
<id>urn:sha1:30f51aedabda92b74927979b2b3b50169e285f6b</id>
<content type='text'>
Fix loader program to close temporary FDs when intermediate
sys_bpf command fails.

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210514003623.28033-16-alexei.starovoitov@gmail.com
</content>
</entry>
</feed>
