bpf: Limit up to 512 bytes for bpf_global_percpu_ma allocation
authorYonghong Song <yonghong.song@linux.dev>
Fri, 22 Dec 2023 03:18:01 +0000 (19:18 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 4 Jan 2024 05:08:26 +0000 (21:08 -0800)
commit5c1a37653260ed5d9c8b26fb7fe7b99629612982
tree9cd3e4d1531ee6e46147d65ebc3dce1259409b15
parent0e2ba9f96f9b82893ba19170ae48d46003f8ef44
bpf: Limit up to 512 bytes for bpf_global_percpu_ma allocation

For percpu data structure allocation with bpf_global_percpu_ma,
the maximum data size is 4K. But for a system with large
number of cpus, bigger data size (e.g., 2K, 4K) might consume
a lot of memory. For example, the percpu memory consumption
with unit size 2K and 1024 cpus will be 2K * 1K * 1k = 2GB
memory.

We should discourage such usage. Let us limit the maximum data
size to be 512 for bpf_global_percpu_ma allocation.

Acked-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20231222031801.1290841-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c