<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/bpf/core.c, branch v5.18</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v5.18</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v5.18'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2022-03-21T20:53:45Z</updated>
<entry>
<title>bpf: Fix bpf_prog_pack when PMU_SIZE is not defined</title>
<updated>2022-03-21T20:53:45Z</updated>
<author>
<name>Song Liu</name>
<email>song@kernel.org</email>
</author>
<published>2022-03-21T18:00:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e581094167beb674c8a3bc2c27362f50dc5dd617'/>
<id>urn:sha1:e581094167beb674c8a3bc2c27362f50dc5dd617</id>
<content type='text'>
PMD_SIZE is not available in some special config, e.g. ARCH=arm with
CONFIG_MMU=n. Use bpf_prog_pack of PAGE_SIZE in these cases.

Fixes: ef078600eec2 ("bpf: Select proper size for bpf_prog_pack")
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: Song Liu &lt;song@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220321180009.1944482-3-song@kernel.org
</content>
</entry>
<entry>
<title>bpf: Fix bpf_prog_pack for multi-node setup</title>
<updated>2022-03-21T20:53:45Z</updated>
<author>
<name>Song Liu</name>
<email>song@kernel.org</email>
</author>
<published>2022-03-21T18:00:08Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=96805674e5624b3c79780a2b41c7a3d6bc38dc76'/>
<id>urn:sha1:96805674e5624b3c79780a2b41c7a3d6bc38dc76</id>
<content type='text'>
module_alloc requires num_online_nodes * PMD_SIZE to allocate huge pages.
bpf_prog_pack uses pack of size num_online_nodes * PMD_SIZE.
OTOH, module_alloc returns addresses that are PMD_SIZE aligned (instead of
num_online_nodes * PMD_SIZE aligned). Therefore, PMD_MASK should be used
to calculate pack_ptr in bpf_prog_pack_free().

Fixes: ef078600eec2 ("bpf: Select proper size for bpf_prog_pack")
Reported-by: syzbot+c946805b5ce6ab87df0b@syzkaller.appspotmail.com
Signed-off-by: Song Liu &lt;song@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220321180009.1944482-2-song@kernel.org
</content>
</entry>
<entry>
<title>bpf: Select proper size for bpf_prog_pack</title>
<updated>2022-03-21T02:07:14Z</updated>
<author>
<name>Song Liu</name>
<email>song@kernel.org</email>
</author>
<published>2022-03-11T20:11:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ef078600eec20f20eb7833cf597d4a5edf2953c1'/>
<id>urn:sha1:ef078600eec20f20eb7833cf597d4a5edf2953c1</id>
<content type='text'>
Using HPAGE_PMD_SIZE as the size for bpf_prog_pack is not ideal in some
cases. Specifically, for NUMA systems, __vmalloc_node_range requires
PMD_SIZE * num_online_nodes() to allocate huge pages. Also, if the system
does not support huge pages (i.e., with cmdline option nohugevmalloc), it
is better to use PAGE_SIZE packs.

Add logic to select proper size for bpf_prog_pack. This solution is not
ideal, as it makes assumption about the behavior of module_alloc and
__vmalloc_node_range. However, it appears to be the easiest solution as
it doesn't require changes in module_alloc and vmalloc code.

Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
Signed-off-by: Song Liu &lt;song@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220311201135.3573610-1-song@kernel.org
</content>
</entry>
<entry>
<title>bpf: Fix net.core.bpf_jit_harden race</title>
<updated>2022-03-16T22:13:36Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2022-03-09T12:33:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d2a3b7c5becc3992f8e7d2b9bf5eacceeedb9a48'/>
<id>urn:sha1:d2a3b7c5becc3992f8e7d2b9bf5eacceeedb9a48</id>
<content type='text'>
It is the bpf_jit_harden counterpart to commit 60b58afc96c9 ("bpf: fix
net.core.bpf_jit_enable race"). bpf_jit_harden will be tested twice
for each subprog if there are subprogs in bpf program and constant
blinding may increase the length of program, so when running
"./test_progs -t subprogs" and toggling bpf_jit_harden between 0 and 2,
jit_subprogs may fail because constant blinding increases the length
of subprog instructions during extra passs.

So cache the value of bpf_jit_blinding_enabled() during program
allocation, and use the cached value during constant blinding, subprog
JITing and args tracking of tail call.

Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220309123321.2400262-4-houtao1@huawei.com
</content>
</entry>
<entry>
<title>bpf, x86: Set header-&gt;size properly before freeing it</title>
<updated>2022-03-02T21:24:37Z</updated>
<author>
<name>Song Liu</name>
<email>song@kernel.org</email>
</author>
<published>2022-03-02T17:51:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=676b2daabaf9a993db0e02a5ce79b984aaa0388b'/>
<id>urn:sha1:676b2daabaf9a993db0e02a5ce79b984aaa0388b</id>
<content type='text'>
On do_jit failure path, the header is freed by bpf_jit_binary_pack_free.
While bpf_jit_binary_pack_free doesn't require proper ro_header-&gt;size,
bpf_prog_pack_free still uses it. Set header-&gt;size in bpf_int_jit_compile
before calling bpf_jit_binary_pack_free.

Fixes: 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")
Fixes: 33c9805860e5 ("bpf: Introduce bpf_jit_binary_pack_[alloc|finalize|free]")
Reported-by: Kui-Feng Lee &lt;kuifeng@fb.com&gt;
Signed-off-by: Song Liu &lt;song@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Yonghong Song &lt;yhs@fb.com&gt;
Link: https://lore.kernel.org/bpf/20220302175126.247459-3-song@kernel.org
</content>
</entry>
<entry>
<title>bpf: bpf_prog_pack: Set proper size before freeing ro_header</title>
<updated>2022-02-17T21:15:36Z</updated>
<author>
<name>Song Liu</name>
<email>song@kernel.org</email>
</author>
<published>2022-02-17T18:30:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d24d2a2b0a81dd5e9bb99aeb4559ec9734e1416f'/>
<id>urn:sha1:d24d2a2b0a81dd5e9bb99aeb4559ec9734e1416f</id>
<content type='text'>
bpf_prog_pack_free() uses header-&gt;size to decide whether the header
should be freed with module_memfree() or the bpf_prog_pack logic.
However, in kvmalloc() failure path of bpf_jit_binary_pack_alloc(),
header-&gt;size is not set yet. As a result, bpf_prog_pack_free() may treat
a slice of a pack as a standalone kvmalloc'd header and call
module_memfree() on the whole pack. This in turn causes use-after-free by
other users of the pack.

Fix this by setting ro_header-&gt;size before freeing ro_header.

Fixes: 33c9805860e5 ("bpf: Introduce bpf_jit_binary_pack_[alloc|finalize|free]")
Reported-by: syzbot+2f649ec6d2eea1495a8f@syzkaller.appspotmail.com
Reported-by: syzbot+ecb1e7e51c52f68f7481@syzkaller.appspotmail.com
Reported-by: syzbot+87f65c75f4a72db05445@syzkaller.appspotmail.com
Signed-off-by: Song Liu &lt;song@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220217183001.1876034-1-song@kernel.org
</content>
</entry>
<entry>
<title>bpf: Fix bpf_prog_pack build for ppc64_defconfig</title>
<updated>2022-02-11T02:59:32Z</updated>
<author>
<name>Song Liu</name>
<email>song@kernel.org</email>
</author>
<published>2022-02-11T02:49:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=4cc0991abd3954609a6929234bbb8c0fe7a0298d'/>
<id>urn:sha1:4cc0991abd3954609a6929234bbb8c0fe7a0298d</id>
<content type='text'>
bpf_prog_pack causes build error with powerpc ppc64_defconfig:

kernel/bpf/core.c:830:23: error: variably modified 'bitmap' at file scope
  830 |         unsigned long bitmap[BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT)];
      |                       ^~~~~~

This is because the marco expands as:

unsigned long bitmap[((((((1UL) &lt;&lt; (16 + __pte_index_size)) / (1 &lt;&lt; 6))) \
     + ((sizeof(long) * 8)) - 1) / ((sizeof(long) * 8)))];

where __pte_index_size is a global variable.

Fix it by turning bitmap into a 0-length array.

Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
Reported-by: Stephen Rothwell &lt;sfr@canb.auug.org.au&gt;
Signed-off-by: Song Liu &lt;song@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220211024939.2962537-1-song@kernel.org
</content>
</entry>
<entry>
<title>bpf: Fix bpf_prog_pack build HPAGE_PMD_SIZE</title>
<updated>2022-02-09T02:37:10Z</updated>
<author>
<name>Song Liu</name>
<email>song@kernel.org</email>
</author>
<published>2022-02-08T22:05:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c1b13a9451ab9d46eefb80a2cc4b8b3206460829'/>
<id>urn:sha1:c1b13a9451ab9d46eefb80a2cc4b8b3206460829</id>
<content type='text'>
Fix build with CONFIG_TRANSPARENT_HUGEPAGE=n with BPF_PROG_PACK_SIZE as
PAGE_SIZE.

Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: Song Liu &lt;song@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220208220509.4180389-3-song@kernel.org
</content>
</entry>
<entry>
<title>bpf: Introduce bpf_jit_binary_pack_[alloc|finalize|free]</title>
<updated>2022-02-08T02:13:01Z</updated>
<author>
<name>Song Liu</name>
<email>songliubraving@fb.com</email>
</author>
<published>2022-02-04T18:57:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=33c9805860e584b194199cab1a1e81f4e6395408'/>
<id>urn:sha1:33c9805860e584b194199cab1a1e81f4e6395408</id>
<content type='text'>
This is the jit binary allocator built on top of bpf_prog_pack.

bpf_prog_pack allocates RO memory, which cannot be used directly by the
JIT engine. Therefore, a temporary rw buffer is allocated for the JIT
engine. Once JIT is done, bpf_jit_binary_pack_finalize is used to copy
the program to the RO memory.

bpf_jit_binary_pack_alloc reserves 16 bytes of extra space for illegal
instructions, which is small than the 128 bytes space reserved by
bpf_jit_binary_alloc. This change is necessary for bpf_jit_binary_hdr
to find the correct header. Also, flag use_bpf_prog_pack is added to
differentiate a program allocated by bpf_jit_binary_pack_alloc.

Signed-off-by: Song Liu &lt;songliubraving@fb.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220204185742.271030-9-song@kernel.org
</content>
</entry>
<entry>
<title>bpf: Introduce bpf_prog_pack allocator</title>
<updated>2022-02-08T02:13:01Z</updated>
<author>
<name>Song Liu</name>
<email>song@kernel.org</email>
</author>
<published>2022-02-04T18:57:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=57631054fae6dcc9c892ae6310b58bbb6f6e5048'/>
<id>urn:sha1:57631054fae6dcc9c892ae6310b58bbb6f6e5048</id>
<content type='text'>
Most BPF programs are small, but they consume a page each. For systems
with busy traffic and many BPF programs, this could add significant
pressure to instruction TLB. High iTLB pressure usually causes slow down
for the whole system, which includes visible performance degradation for
production workloads.

Introduce bpf_prog_pack allocator to pack multiple BPF programs in a huge
page. The memory is then allocated in 64 byte chunks.

Memory allocated by bpf_prog_pack allocator is RO protected after initial
allocation. To write to it, the user (jit engine) need to use text poke
API.

Signed-off-by: Song Liu &lt;song@kernel.org&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220204185742.271030-8-song@kernel.org
</content>
</entry>
</feed>
