diff options
author | Hou Tao <houtao1@huawei.com> | 2024-10-30 18:05:13 +0800 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2024-10-30 12:13:46 -0700 |
commit | 62a898b07b83f6f407003d8a70f0827a5af08a59 (patch) | |
tree | e101cca91dec00f46cc3a9e4aaeaf8cb6a451ca1 /include/linux/bpf_mem_alloc.h | |
parent | 101ccfbabf4738041273ce64e2b116cf440dea13 (diff) | |
download | linux-62a898b07b83f6f407003d8a70f0827a5af08a59.tar.gz linux-62a898b07b83f6f407003d8a70f0827a5af08a59.tar.bz2 linux-62a898b07b83f6f407003d8a70f0827a5af08a59.zip |
bpf: Add bpf_mem_alloc_check_size() helper
Introduce bpf_mem_alloc_check_size() to check whether the allocation
size exceeds the limitation for the kmalloc-equivalent allocator. The
upper limit for percpu allocation is LLIST_NODE_SZ bytes larger than
non-percpu allocation, so a percpu argument is added to the helper.
The helper will be used in the following patch to check whether the size
parameter passed to bpf_mem_alloc() is too big.
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20241030100516.3633640-3-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include/linux/bpf_mem_alloc.h')
-rw-r--r-- | include/linux/bpf_mem_alloc.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/bpf_mem_alloc.h b/include/linux/bpf_mem_alloc.h index aaf004d94322..e45162ef59bb 100644 --- a/include/linux/bpf_mem_alloc.h +++ b/include/linux/bpf_mem_alloc.h @@ -33,6 +33,9 @@ int bpf_mem_alloc_percpu_init(struct bpf_mem_alloc *ma, struct obj_cgroup *objcg int bpf_mem_alloc_percpu_unit_init(struct bpf_mem_alloc *ma, int size); void bpf_mem_alloc_destroy(struct bpf_mem_alloc *ma); +/* Check the allocation size for kmalloc equivalent allocator */ +int bpf_mem_alloc_check_size(bool percpu, size_t size); + /* kmalloc/kfree equivalent: */ void *bpf_mem_alloc(struct bpf_mem_alloc *ma, size_t size); void bpf_mem_free(struct bpf_mem_alloc *ma, void *ptr); |