Skip to content

Commit 643714f

Browse files
puranjaymohanAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpf: cap BPF_PROG_PACK_SIZE to 2MB * num_possible_nodes()
On some architectures like ARM64, PMD_SIZE can be really large in some configurations. Like with CONFIG_ARM64_64K_PAGES=y the PMD_SIZE is 512MB. Use 2MB * num_possible_nodes() as the upper limit for allocations done through the prog pack allocator. Fixes: ea2baba ("bpf: Simplify bpf_prog_pack_[size|mask]") Reported-by: "kernelci.org bot" <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Suggested-by: Song Liu <[email protected]> Signed-off-by: Puranjay Mohan <[email protected]> Acked-by: Song Liu <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent a27e896 commit 643714f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kernel/bpf/core.c

+8
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,16 @@ static LIST_HEAD(pack_list);
893893
* CONFIG_MMU=n. Use PAGE_SIZE in these cases.
894894
*/
895895
#ifdef PMD_SIZE
896+
/* PMD_SIZE is really big for some archs. It doesn't make sense to
897+
* reserve too much memory in one allocation. Cap BPF_PROG_PACK_SIZE to
898+
* 2MiB * num_possible_nodes().
899+
*/
900+
#if PMD_SIZE <= (1 << 21)
896901
#define BPF_PROG_PACK_SIZE (PMD_SIZE * num_possible_nodes())
897902
#else
903+
#define BPF_PROG_PACK_SIZE ((1 << 21) * num_possible_nodes())
904+
#endif
905+
#else
898906
#define BPF_PROG_PACK_SIZE PAGE_SIZE
899907
#endif
900908

0 commit comments

Comments
 (0)