Re: [PATCH bpf-next v2 2/3] bpf: Use kmalloc_nolock() universally in local storage

bot+bpf-ci
2026-04-11T02:36:19Z

[-- Attachment #1: Type: text/plain, Size: 2323 bytes --]

> diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
> index cad17ca8552f..bc687b9d25a9 100644
> --- a/kernel/bpf/bpf_local_storage.c
> +++ b/kernel/bpf/bpf_local_storage.c

[ ... ]

> @@ -75,18 +75,12 @@ bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,
> if (mem_charge(smap, owner, smap->elem_size))
> return NULL;
>
> - if (smap->use_kmalloc_nolock) {
> - selem = bpf_map_kmalloc_nolock(&smap->map, smap->elem_size,
> - __GFP_ZERO, NUMA_NO_NODE);
> - } else {
> - selem = bpf_map_kzalloc(&smap->map, smap->elem_size,
> - gfp_flags | __GFP_NOWARN);
> - }
> + selem = bpf_map_kmalloc_nolock(&smap->map, smap->elem_size,
> + __GFP_ZERO, NUMA_NO_NODE);

With this change, socket and inode local storage now always go through
kmalloc_nolock(). kmalloc_nolock_noprof() in mm/slub.c has a hard size
limit:

if (unlikely(size > KMALLOC_MAX_CACHE_SIZE))
return NULL;

KMALLOC_MAX_CACHE_SIZE is 1 << (PAGE_SHIFT + 1), which is 8KB on
x86_64 with 4KB pages. But BPF_LOCAL_STORAGE_MAX_VALUE_SIZE in
bpf_local_storage.h is calculated from KMALLOC_MAX_SIZE (not
KMALLOC_MAX_CACHE_SIZE):

#define BPF_LOCAL_STORAGE_MAX_VALUE_SIZE \
min_t(u32, \
(KMALLOC_MAX_SIZE - MAX_BPF_STACK - \
sizeof(struct bpf_local_storage_elem)), \
(U16_MAX - sizeof(struct bpf_local_storage_elem)))

This allows value sizes up to ~65KB. Before this patch, socket and
inode storage used bpf_map_kzalloc() (backed by regular kmalloc)
which could handle those large sizes. After this patch, any
elem_size above KMALLOC_MAX_CACHE_SIZE will silently fail: the map
creation succeeds via bpf_local_storage_map_alloc_check() but every
element allocation returns NULL.

Should BPF_LOCAL_STORAGE_MAX_VALUE_SIZE be updated to use
KMALLOC_MAX_CACHE_SIZE instead of KMALLOC_MAX_SIZE now that all
storage types go through kmalloc_nolock()?

Slava Imameev raised the same concern for task storage in
https://lore.kernel.org/bpf/20260410014341.47043-1-slava.imameev@crowdstrike.com/

[ ... ]

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/24272235145