<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/tools/lib/bpf, branch linux-5.11.y</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=linux-5.11.y</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=linux-5.11.y'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2021-05-19T08:29:44+00:00</updated>
<entry>
<title>libbpf: Fix signed overflow in ringbuf_process_ring</title>
<updated>2021-05-19T08:29:44+00:00</updated>
<author>
<name>Brendan Jackman</name>
<email>jackmanb@google.com</email>
</author>
<published>2021-04-29T13:05:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=7b8ea4953a3fd4eb690a1c0272015ade3e2cefc3'/>
<id>urn:sha1:7b8ea4953a3fd4eb690a1c0272015ade3e2cefc3</id>
<content type='text'>
[ Upstream commit 2a30f9440640c418bcfbea9b2b344d268b58e0a2 ]

One of our benchmarks running in (Google-internal) CI pushes data
through the ringbuf faster htan than userspace is able to consume
it. In this case it seems we're actually able to get &gt;INT_MAX entries
in a single ring_buffer__consume() call. ASAN detected that cnt
overflows in this case.

Fix by using 64-bit counter internally and then capping the result to
INT_MAX before converting to the int return type. Do the same for
the ring_buffer__poll().

Fixes: bf99c936f947 (libbpf: Add BPF ring buffer support)
Signed-off-by: Brendan Jackman &lt;jackmanb@google.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210429130510.1621665-1-jackmanb@google.com
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>selftests/bpf: Fix BPF_CORE_READ_BITFIELD() macro</title>
<updated>2021-05-14T08:50:17+00:00</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andrii@kernel.org</email>
</author>
<published>2021-04-26T19:29:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=68d98395c8c1dae10b85a61b8c309384ea99bd51'/>
<id>urn:sha1:68d98395c8c1dae10b85a61b8c309384ea99bd51</id>
<content type='text'>
[ Upstream commit 0f20615d64ee2ad5e2a133a812382d0c4071589b ]

Fix BPF_CORE_READ_BITFIELD() macro used for reading CO-RE-relocatable
bitfields. Missing breaks in a switch caused 8-byte reads always. This can
confuse libbpf because it does strict checks that memory load size corresponds
to the original size of the field, which in this case quite often would be
wrong.

After fixing that, we run into another problem, which quite subtle, so worth
documenting here. The issue is in Clang optimization and CO-RE relocation
interactions. Without that asm volatile construct (also known as
barrier_var()), Clang will re-order BYTE_OFFSET and BYTE_SIZE relocations and
will apply BYTE_OFFSET 4 times for each switch case arm. This will result in
the same error from libbpf about mismatch of memory load size and original
field size. I.e., if we were reading u32, we'd still have *(u8 *), *(u16 *),
*(u32 *), and *(u64 *) memory loads, three of which will fail. Using
barrier_var() forces Clang to apply BYTE_OFFSET relocation first (and once) to
calculate p, after which value of p is used without relocation in each of
switch case arms, doing appropiately-sized memory load.

Here's the list of relevant relocations and pieces of generated BPF code
before and after this patch for test_core_reloc_bitfields_direct selftests.

BEFORE
=====
 #45: core_reloc: insn #160 --&gt; [5] + 0:5: byte_sz --&gt; struct core_reloc_bitfields.u32
 #46: core_reloc: insn #167 --&gt; [5] + 0:5: byte_off --&gt; struct core_reloc_bitfields.u32
 #47: core_reloc: insn #174 --&gt; [5] + 0:5: byte_off --&gt; struct core_reloc_bitfields.u32
 #48: core_reloc: insn #178 --&gt; [5] + 0:5: byte_off --&gt; struct core_reloc_bitfields.u32
 #49: core_reloc: insn #182 --&gt; [5] + 0:5: byte_off --&gt; struct core_reloc_bitfields.u32

     157:       18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0 ll
     159:       7b 12 20 01 00 00 00 00 *(u64 *)(r2 + 288) = r1
     160:       b7 02 00 00 04 00 00 00 r2 = 4
; BYTE_SIZE relocation here                 ^^^
     161:       66 02 07 00 03 00 00 00 if w2 s&gt; 3 goto +7 &lt;LBB0_63&gt;
     162:       16 02 0d 00 01 00 00 00 if w2 == 1 goto +13 &lt;LBB0_65&gt;
     163:       16 02 01 00 02 00 00 00 if w2 == 2 goto +1 &lt;LBB0_66&gt;
     164:       05 00 12 00 00 00 00 00 goto +18 &lt;LBB0_69&gt;

0000000000000528 &lt;LBB0_66&gt;:
     165:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll
     167:       69 11 08 00 00 00 00 00 r1 = *(u16 *)(r1 + 8)
; BYTE_OFFSET relo here w/ WRONG size        ^^^^^^^^^^^^^^^^
     168:       05 00 0e 00 00 00 00 00 goto +14 &lt;LBB0_69&gt;

0000000000000548 &lt;LBB0_63&gt;:
     169:       16 02 0a 00 04 00 00 00 if w2 == 4 goto +10 &lt;LBB0_67&gt;
     170:       16 02 01 00 08 00 00 00 if w2 == 8 goto +1 &lt;LBB0_68&gt;
     171:       05 00 0b 00 00 00 00 00 goto +11 &lt;LBB0_69&gt;

0000000000000560 &lt;LBB0_68&gt;:
     172:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll
     174:       79 11 08 00 00 00 00 00 r1 = *(u64 *)(r1 + 8)
; BYTE_OFFSET relo here w/ WRONG size        ^^^^^^^^^^^^^^^^
     175:       05 00 07 00 00 00 00 00 goto +7 &lt;LBB0_69&gt;

0000000000000580 &lt;LBB0_65&gt;:
     176:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll
     178:       71 11 08 00 00 00 00 00 r1 = *(u8 *)(r1 + 8)
; BYTE_OFFSET relo here w/ WRONG size        ^^^^^^^^^^^^^^^^
     179:       05 00 03 00 00 00 00 00 goto +3 &lt;LBB0_69&gt;

00000000000005a0 &lt;LBB0_67&gt;:
     180:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll
     182:       61 11 08 00 00 00 00 00 r1 = *(u32 *)(r1 + 8)
; BYTE_OFFSET relo here w/ RIGHT size        ^^^^^^^^^^^^^^^^

00000000000005b8 &lt;LBB0_69&gt;:
     183:       67 01 00 00 20 00 00 00 r1 &lt;&lt;= 32
     184:       b7 02 00 00 00 00 00 00 r2 = 0
     185:       16 02 02 00 00 00 00 00 if w2 == 0 goto +2 &lt;LBB0_71&gt;
     186:       c7 01 00 00 20 00 00 00 r1 s&gt;&gt;= 32
     187:       05 00 01 00 00 00 00 00 goto +1 &lt;LBB0_72&gt;

00000000000005e0 &lt;LBB0_71&gt;:
     188:       77 01 00 00 20 00 00 00 r1 &gt;&gt;= 32

AFTER
=====

 #30: core_reloc: insn #132 --&gt; [5] + 0:5: byte_off --&gt; struct core_reloc_bitfields.u32
 #31: core_reloc: insn #134 --&gt; [5] + 0:5: byte_sz --&gt; struct core_reloc_bitfields.u32

     129:       18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0 ll
     131:       7b 12 20 01 00 00 00 00 *(u64 *)(r2 + 288) = r1
     132:       b7 01 00 00 08 00 00 00 r1 = 8
; BYTE_OFFSET relo here                     ^^^
; no size check for non-memory dereferencing instructions
     133:       0f 12 00 00 00 00 00 00 r2 += r1
     134:       b7 03 00 00 04 00 00 00 r3 = 4
; BYTE_SIZE relocation here                 ^^^
     135:       66 03 05 00 03 00 00 00 if w3 s&gt; 3 goto +5 &lt;LBB0_63&gt;
     136:       16 03 09 00 01 00 00 00 if w3 == 1 goto +9 &lt;LBB0_65&gt;
     137:       16 03 01 00 02 00 00 00 if w3 == 2 goto +1 &lt;LBB0_66&gt;
     138:       05 00 0a 00 00 00 00 00 goto +10 &lt;LBB0_69&gt;

0000000000000458 &lt;LBB0_66&gt;:
     139:       69 21 00 00 00 00 00 00 r1 = *(u16 *)(r2 + 0)
; NO CO-RE relocation here                   ^^^^^^^^^^^^^^^^
     140:       05 00 08 00 00 00 00 00 goto +8 &lt;LBB0_69&gt;

0000000000000468 &lt;LBB0_63&gt;:
     141:       16 03 06 00 04 00 00 00 if w3 == 4 goto +6 &lt;LBB0_67&gt;
     142:       16 03 01 00 08 00 00 00 if w3 == 8 goto +1 &lt;LBB0_68&gt;
     143:       05 00 05 00 00 00 00 00 goto +5 &lt;LBB0_69&gt;

0000000000000480 &lt;LBB0_68&gt;:
     144:       79 21 00 00 00 00 00 00 r1 = *(u64 *)(r2 + 0)
; NO CO-RE relocation here                   ^^^^^^^^^^^^^^^^
     145:       05 00 03 00 00 00 00 00 goto +3 &lt;LBB0_69&gt;

0000000000000490 &lt;LBB0_65&gt;:
     146:       71 21 00 00 00 00 00 00 r1 = *(u8 *)(r2 + 0)
; NO CO-RE relocation here                   ^^^^^^^^^^^^^^^^
     147:       05 00 01 00 00 00 00 00 goto +1 &lt;LBB0_69&gt;

00000000000004a0 &lt;LBB0_67&gt;:
     148:       61 21 00 00 00 00 00 00 r1 = *(u32 *)(r2 + 0)
; NO CO-RE relocation here                   ^^^^^^^^^^^^^^^^

00000000000004a8 &lt;LBB0_69&gt;:
     149:       67 01 00 00 20 00 00 00 r1 &lt;&lt;= 32
     150:       b7 02 00 00 00 00 00 00 r2 = 0
     151:       16 02 02 00 00 00 00 00 if w2 == 0 goto +2 &lt;LBB0_71&gt;
     152:       c7 01 00 00 20 00 00 00 r1 s&gt;&gt;= 32
     153:       05 00 01 00 00 00 00 00 goto +1 &lt;LBB0_72&gt;

00000000000004d0 &lt;LBB0_71&gt;:
     154:       77 01 00 00 20 00 00 00 r1 &gt;&gt;= 323

Fixes: ee26dade0e3b ("libbpf: Add support for relocatable bitfields")
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Lorenz Bauer &lt;lmb@cloudflare.com&gt;
Link: https://lore.kernel.org/bpf/20210426192949.416837-4-andrii@kernel.org
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Initialize the bpf_seq_printf parameters array field by field</title>
<updated>2021-05-14T08:50:13+00:00</updated>
<author>
<name>Florent Revest</name>
<email>revest@chromium.org</email>
</author>
<published>2021-04-19T15:52:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=d61645e187f9938ffa33d71928315280b4038a4f'/>
<id>urn:sha1:d61645e187f9938ffa33d71928315280b4038a4f</id>
<content type='text'>
[ Upstream commit 83cd92b46484aa8f64cdc0bff8ac6940d1f78519 ]

When initializing the __param array with a one liner, if all args are
const, the initial array value will be placed in the rodata section but
because libbpf does not support relocation in the rodata section, any
pointer in this array will stay NULL.

Fixes: c09add2fbc5a ("tools/libbpf: Add bpf_iter support")
Signed-off-by: Florent Revest &lt;revest@chromium.org&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/20210419155243.1632274-5-revest@chromium.org
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Add explicit padding to btf_dump_emit_type_decl_opts</title>
<updated>2021-05-14T08:50:01+00:00</updated>
<author>
<name>KP Singh</name>
<email>kpsingh@kernel.org</email>
</author>
<published>2021-03-19T19:21:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=75ad96b0077bd344a667c1fea41076ec82e531ed'/>
<id>urn:sha1:75ad96b0077bd344a667c1fea41076ec82e531ed</id>
<content type='text'>
[ Upstream commit ea24b19562fe5f72c78319dbb347b701818956d9 ]

Similar to
https://lore.kernel.org/bpf/20210313210920.1959628-2-andrii@kernel.org/

When DECLARE_LIBBPF_OPTS is used with inline field initialization, e.g:

  DECLARE_LIBBPF_OPTS(btf_dump_emit_type_decl_opts, opts,
    .field_name = var_ident,
    .indent_level = 2,
    .strip_mods = strip_mods,
  );

and compiled in debug mode, the compiler generates code which
leaves the padding uninitialized and triggers errors within libbpf APIs
which require strict zero initialization of OPTS structs.

Adding anonymous padding field fixes the issue.

Fixes: 9f81654eebe8 ("libbpf: Expose BTF-to-C type declaration emitting API")
Suggested-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: KP Singh &lt;kpsingh@kernel.org&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210319192117.2310658-1-kpsingh@kernel.org
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Add explicit padding to bpf_xdp_set_link_opts</title>
<updated>2021-05-14T08:50:00+00:00</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andrii@kernel.org</email>
</author>
<published>2021-03-13T21:09:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=68dc346c93ce30773ebb5c25ee03fc8143a2f8ed'/>
<id>urn:sha1:68dc346c93ce30773ebb5c25ee03fc8143a2f8ed</id>
<content type='text'>
[ Upstream commit dde7b3f5f2f458297aeccfd4783e53ab8ca046db ]

Adding such anonymous padding fixes the issue with uninitialized portions of
bpf_xdp_set_link_opts when using LIBBPF_DECLARE_OPTS macro with inline field
initialization:

DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, .old_fd = -1);

When such code is compiled in debug mode, compiler is generating code that
leaves padding bytes uninitialized, which triggers error inside libbpf APIs
that do strict zero initialization checks for OPTS structs.

Adding anonymous padding field fixes the issue.

Fixes: bd5ca3ef93cd ("libbpf: Add function to set link XDP fd while specifying old program")
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210313210920.1959628-2-andrii@kernel.org
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Fix potential NULL pointer dereference</title>
<updated>2021-04-21T11:13:24+00:00</updated>
<author>
<name>Ciara Loftus</name>
<email>ciara.loftus@intel.com</email>
</author>
<published>2021-04-08T05:20:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b33f7e0d5e86e1c758d76838ef7e831d99b176bf'/>
<id>urn:sha1:b33f7e0d5e86e1c758d76838ef7e831d99b176bf</id>
<content type='text'>
commit afd0be7299533bb2e2b09104399d8a467ecbd2c5 upstream.

Wait until after the UMEM is checked for null to dereference it.

Fixes: 43f1bc1efff1 ("libbpf: Restore umem state after socket create failure")
Signed-off-by: Ciara Loftus &lt;ciara.loftus@intel.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Link: https://lore.kernel.org/bpf/20210408052009.7844-1-ciara.loftus@intel.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Only create rx and tx XDP rings when necessary</title>
<updated>2021-04-14T06:47:11+00:00</updated>
<author>
<name>Ciara Loftus</name>
<email>ciara.loftus@intel.com</email>
</author>
<published>2021-03-31T06:12:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=68629be80fc6e0f9d44e779972e0ab8595933fda'/>
<id>urn:sha1:68629be80fc6e0f9d44e779972e0ab8595933fda</id>
<content type='text'>
commit ca7a83e2487ad0bc9a3e0e7a8645354aa1782f13 upstream.

Prior to this commit xsk_socket__create(_shared) always attempted to create
the rx and tx rings for the socket. However this causes an issue when the
socket being setup is that which shares the fd with the UMEM. If a
previous call to this function failed with this socket after the rings were
set up, a subsequent call would always fail because the rings are not torn
down after the first call and when we try to set them up again we encounter
an error because they already exist. Solve this by remembering whether the
rings were set up by introducing new bools to struct xsk_umem which
represent the ring setup status and using them to determine whether or
not to set up the rings.

Fixes: 1cad07884239 ("libbpf: add support for using AF_XDP sockets")
Signed-off-by: Ciara Loftus &lt;ciara.loftus@intel.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210331061218.1647-4-ciara.loftus@intel.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Restore umem state after socket create failure</title>
<updated>2021-04-14T06:47:11+00:00</updated>
<author>
<name>Ciara Loftus</name>
<email>ciara.loftus@intel.com</email>
</author>
<published>2021-03-31T06:12:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=00b6712eae9f046cb6f820a9ff9fd6b966f01f9c'/>
<id>urn:sha1:00b6712eae9f046cb6f820a9ff9fd6b966f01f9c</id>
<content type='text'>
commit 43f1bc1efff16f553dd573d02eb7a15750925568 upstream.

If the call to xsk_socket__create fails, the user may want to retry the
socket creation using the same umem. Ensure that the umem is in the
same state on exit if the call fails by:
1. ensuring the umem _save pointers are unmodified.
2. not unmapping the set of umem rings that were set up with the umem
during xsk_umem__create, since those maps existed before the call to
xsk_socket__create and should remain in tact even in the event of
failure.

Fixes: 2f6324a3937f ("libbpf: Support shared umems between queues and devices")
Signed-off-by: Ciara Loftus &lt;ciara.loftus@intel.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210331061218.1647-3-ciara.loftus@intel.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Ensure umem pointer is non-NULL before dereferencing</title>
<updated>2021-04-14T06:47:11+00:00</updated>
<author>
<name>Ciara Loftus</name>
<email>ciara.loftus@intel.com</email>
</author>
<published>2021-03-31T06:12:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b34f81c3d1a62bb2482c49f7b3affcbe8330447f'/>
<id>urn:sha1:b34f81c3d1a62bb2482c49f7b3affcbe8330447f</id>
<content type='text'>
commit df662016310aa4475d7986fd726af45c8fe4f362 upstream.

Calls to xsk_socket__create dereference the umem to access the
fill_save and comp_save pointers. Make sure the umem is non-NULL
before doing this.

Fixes: 2f6324a3937f ("libbpf: Support shared umems between queues and devices")
Signed-off-by: Ciara Loftus &lt;ciara.loftus@intel.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Magnus Karlsson &lt;magnus.karlsson@intel.com&gt;
Link: https://lore.kernel.org/bpf/20210331061218.1647-2-ciara.loftus@intel.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Fix bail out from 'ringbuf_process_ring()' on error</title>
<updated>2021-04-14T06:47:11+00:00</updated>
<author>
<name>Pedro Tammela</name>
<email>pctammela@gmail.com</email>
</author>
<published>2021-03-25T15:01:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a6a96bddfb42119fe515b58903e71a706350dd3b'/>
<id>urn:sha1:a6a96bddfb42119fe515b58903e71a706350dd3b</id>
<content type='text'>
commit 6032ebb54c60cae24329f6aba3ce0c1ca8ad6abe upstream.

The current code bails out with negative and positive returns.
If the callback returns a positive return code, 'ring_buffer__consume()'
and 'ring_buffer__poll()' will return a spurious number of records
consumed, but mostly important will continue the processing loop.

This patch makes positive returns from the callback a no-op.

Fixes: bf99c936f947 ("libbpf: Add BPF ring buffer support")
Signed-off-by: Pedro Tammela &lt;pctammela@mojatatu.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210325150115.138750-1-pctammela@mojatatu.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
