<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/bpf/memalloc.c, branch v6.7</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=v6.7</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.7'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2023-11-27T02:00:26Z</updated>
<entry>
<title>bpf: Add missed allocation hint for bpf_mem_cache_alloc_flags()</title>
<updated>2023-11-27T02:00:26Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2023-11-11T04:38:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=75a442581d05edaee168222ffbe00d4389785636'/>
<id>urn:sha1:75a442581d05edaee168222ffbe00d4389785636</id>
<content type='text'>
bpf_mem_cache_alloc_flags() may call __alloc() directly when there is no
free object in free list, but it doesn't initialize the allocation hint
for the returned pointer. It may lead to bad memory dereference when
freeing the pointer, so fix it by initializing the allocation hint.

Fixes: 822fb26bdb55 ("bpf: Add a hint to allocated objects.")
Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Acked-by: Yonghong Song &lt;yonghong.song@linux.dev&gt;
Link: https://lore.kernel.org/r/20231111043821.2258513-1-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Add more WARN_ON_ONCE checks for mismatched alloc and free</title>
<updated>2023-10-26T12:23:33Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2023-10-21T01:49:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c421c12586b3f00fb96b5c9af15c9a051a9090b1'/>
<id>urn:sha1:c421c12586b3f00fb96b5c9af15c9a051a9090b1</id>
<content type='text'>
There are two possible mismatched alloc and free cases in BPF memory
allocator:

1) allocate from cache X but free by cache Y with a different unit_size
2) allocate from per-cpu cache but free by kmalloc cache or vice versa

So add more WARN_ON_ONCE checks in free_bulk() and __free_by_rcu() to
spot these mismatched alloc and free early.

Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Link: https://lore.kernel.org/bpf/20231021014959.3563841-1-houtao@huaweicloud.com
</content>
</entry>
<entry>
<title>bpf: Use pcpu_alloc_size() in bpf_mem_free{_rcu}()</title>
<updated>2023-10-20T21:15:13Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2023-10-20T13:31:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=3f2189e4f77b7a3e979d143dc4ff586488c7e8a5'/>
<id>urn:sha1:3f2189e4f77b7a3e979d143dc4ff586488c7e8a5</id>
<content type='text'>
For bpf_global_percpu_ma, the pointer passed to bpf_mem_free_rcu() is
allocated by kmalloc() and its size is fixed (16-bytes on x86-64). So
no matter which cache allocates the dynamic per-cpu area, on x86-64
cache[2] will always be used to free the per-cpu area.

Fix the unbalance by checking whether the bpf memory allocator is
per-cpu or not and use pcpu_alloc_size() instead of ksize() to
find the correct cache for per-cpu free.

Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Link: https://lore.kernel.org/r/20231020133202.4043247-5-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Re-enable unit_size checking for global per-cpu allocator</title>
<updated>2023-10-20T21:15:13Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2023-10-20T13:31:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=baa8fdecd87bb8751237b45e3bcb5a179e5a12ca'/>
<id>urn:sha1:baa8fdecd87bb8751237b45e3bcb5a179e5a12ca</id>
<content type='text'>
With pcpu_alloc_size() in place, check whether or not the size of
the dynamic per-cpu area is matched with unit_size.

Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Link: https://lore.kernel.org/r/20231020133202.4043247-4-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net</title>
<updated>2023-10-05T20:16:47Z</updated>
<author>
<name>Jakub Kicinski</name>
<email>kuba@kernel.org</email>
</author>
<published>2023-10-05T20:16:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=2606cf059c56bfb86d5d6bd0f41bd7eedefc8b0a'/>
<id>urn:sha1:2606cf059c56bfb86d5d6bd0f41bd7eedefc8b0a</id>
<content type='text'>
Cross-merge networking fixes after downstream PR.

No conflicts (or adjacent changes of note).

Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Use kmalloc_size_roundup() to adjust size_index</title>
<updated>2023-09-30T16:39:28Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2023-09-28T10:15:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=9077fc228f09c9f975c498c55f5d2e882cd0da59'/>
<id>urn:sha1:9077fc228f09c9f975c498c55f5d2e882cd0da59</id>
<content type='text'>
Commit d52b59315bf5 ("bpf: Adjust size_index according to the value of
KMALLOC_MIN_SIZE") uses KMALLOC_MIN_SIZE to adjust size_index, but as
reported by Nathan, the adjustment is not enough, because
__kmalloc_minalign() also decides the minimal alignment of slab object
as shown in new_kmalloc_cache() and its value may be greater than
KMALLOC_MIN_SIZE (e.g., 64 bytes vs 8 bytes under a riscv QEMU VM).

Instead of invoking __kmalloc_minalign() in bpf subsystem to find the
maximal alignment, just using kmalloc_size_roundup() directly to get the
corresponding slab object size for each allocation size. If these two
sizes are unmatched, adjust size_index to select a bpf_mem_cache with
unit_size equal to the object_size of the underlying slab cache for the
allocation size.

Fixes: 822fb26bdb55 ("bpf: Add a hint to allocated objects.")
Reported-by: Nathan Chancellor &lt;nathan@kernel.org&gt;
Closes: https://lore.kernel.org/bpf/20230914181407.GA1000274@dev-arch.thelio-3990X/
Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Tested-by: Emil Renner Berthing &lt;emil.renner.berthing@canonical.com&gt;
Link: https://lore.kernel.org/r/20230928101558.2594068-1-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net</title>
<updated>2023-09-21T19:49:45Z</updated>
<author>
<name>Paolo Abeni</name>
<email>pabeni@redhat.com</email>
</author>
<published>2023-09-21T19:49:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e9cbc89067cce78211c8629c78e931c0fe64e29d'/>
<id>urn:sha1:e9cbc89067cce78211c8629c78e931c0fe64e29d</id>
<content type='text'>
Cross-merge networking fixes after downstream PR.

No conflicts.

Signed-off-by: Paolo Abeni &lt;pabeni@redhat.com&gt;
</content>
</entry>
<entry>
<title>bpf: Skip unit_size checking for global per-cpu allocator</title>
<updated>2023-09-15T17:22:24Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2023-09-13T13:59:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=dca7acd84e93f2881e3f63465bbb5d89a40b5d17'/>
<id>urn:sha1:dca7acd84e93f2881e3f63465bbb5d89a40b5d17</id>
<content type='text'>
For global per-cpu allocator, the size of free object in free list
doesn't match with unit_size and now there is no way to get the size of
per-cpu pointer saved in free object, so just skip the checking.

Reported-by: Stephen Rothwell &lt;sfr@canb.auug.org.au&gt;
Closes: https://lore.kernel.org/bpf/20230913133436.0eeec4cb@canb.auug.org.au/
Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Tested-by: Biju Das &lt;biju.das.jz@bp.renesas.com&gt;
Link: https://lore.kernel.org/r/20230913135943.3137292-1-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Ensure unit_size is matched with slab cache object size</title>
<updated>2023-09-11T19:41:37Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2023-09-08T13:39:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c930472552022bd09aab3cd946ba3f243070d5c7'/>
<id>urn:sha1:c930472552022bd09aab3cd946ba3f243070d5c7</id>
<content type='text'>
Add extra check in bpf_mem_alloc_init() to ensure the unit_size of
bpf_mem_cache is matched with the object_size of underlying slab cache.
If these two sizes are unmatched, print a warning once and return
-EINVAL in bpf_mem_alloc_init(), so the mismatch can be found early and
the potential issue can be prevented.

Suggested-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Link: https://lore.kernel.org/r/20230908133923.2675053-4-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Don't prefill for unused bpf_mem_cache</title>
<updated>2023-09-11T19:41:37Z</updated>
<author>
<name>Hou Tao</name>
<email>houtao1@huawei.com</email>
</author>
<published>2023-09-08T13:39:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=b1d53958b69312e43c118d4093d8f93d3f6f80af'/>
<id>urn:sha1:b1d53958b69312e43c118d4093d8f93d3f6f80af</id>
<content type='text'>
When the unit_size of a bpf_mem_cache is unmatched with the object_size
of the underlying slab cache, the bpf_mem_cache will not be used, and
the allocation will be redirected to a bpf_mem_cache with a bigger
unit_size instead, so there is no need to prefill for these
unused bpf_mem_caches.

Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Link: https://lore.kernel.org/r/20230908133923.2675053-3-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
</feed>
