Skip to contentSkip to conversation

bpf: cap BPF_PROG_PACK_SIZE to 2MB * num_possible_nodes()

PATCH Superseded Puranjay Mohan 3 participants 3 messages Mar 8, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 ea2babac63d4 ("bpf: Simplify bpf_prog_pack_[size|mask]")
---
 kernel/bpf/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/bpf/core.c +9 -0
index 134b7979f537..83a3b6964e54 100644
@@ -893,8 +893,17 @@ static LIST_HEAD(pack_list);
  * CONFIG_MMU=n. Use PAGE_SIZE in these cases.
  */
 #ifdef PMD_SIZE
+/*
+ * PMD_SIZE is really big for some archs. It doesn't make sense to
+ * reserve too much memory in one allocation. Cap BPF_PROG_PACK_SIZE to
+ * 2MiB * num_possible_nodes().
+ */
+#if PMD_SIZE <= (1 << 21)
 #define BPF_PROG_PACK_SIZE (PMD_SIZE * num_possible_nodes())
 #else
+#define BPF_PROG_PACK_SIZE ((1 << 21) * num_possible_nodes())
+#endif
+#else
 #define BPF_PROG_PACK_SIZE PAGE_SIZE
 #endif
 
Signature · 1 line
2.40.1
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · Puranjay Mohan

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 ea2babac63d4 ("bpf: Simplify bpf_prog_pack_[size|mask]")
---
 kernel/bpf/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/bpf/core.c +0 -0
index 134b7979f537..83a3b6964e54 100644

kernel/bpf/core.c static LIST_HEAD(pack_list); · line 900

Quoted 8 lines
kernel/bpf/core.c +5 -0
@@ -893,8 +893,17 @@ static LIST_HEAD(pack_list);
  * CONFIG_MMU=n. Use PAGE_SIZE in these cases.
  */
 #ifdef PMD_SIZE
+/*
+ * PMD_SIZE is really big for some archs. It doesn't make sense to
+ * reserve too much memory in one allocation. Cap BPF_PROG_PACK_SIZE to
+ * 2MiB * num_possible_nodes().
+ */

In BPF code, we prefer a different style of multiple line comments:

/* PMD_SIZE is really big for some archs. It doesn't make sense to
* reserve too much memory in one allocation. Cap BPF_PROG_PACK_SIZE to
* 2MiB * num_possible_nodes().
*/

Other than this, this looks good to me.

Thanks,
Song

Quoted 8 lines
kernel/bpf/core.c +4 -0
+#if PMD_SIZE <= (1 << 21)
 #define BPF_PROG_PACK_SIZE (PMD_SIZE * num_possible_nodes())
 #else
+#define BPF_PROG_PACK_SIZE ((1 << 21) * num_possible_nodes())
+#endif
+#else
 #define BPF_PROG_PACK_SIZE PAGE_SIZE
 #endif
#2 lore raw
Quoted 35 lines · Song Liu
Quoted 22 lines · Puranjay Mohan

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 ea2babac63d4 ("bpf: Simplify bpf_prog_pack_[size|mask]")
---
 kernel/bpf/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/bpf/core.c +0 -0
index 134b7979f537..83a3b6964e54 100644

kernel/bpf/core.c static LIST_HEAD(pack_list); · line 900

Quoted 8 lines
kernel/bpf/core.c +5 -0
@@ -893,8 +893,17 @@ static LIST_HEAD(pack_list);
  * CONFIG_MMU=n. Use PAGE_SIZE in these cases.
  */
 #ifdef PMD_SIZE
+/*
+ * PMD_SIZE is really big for some archs. It doesn't make sense to
+ * reserve too much memory in one allocation. Cap BPF_PROG_PACK_SIZE to
+ * 2MiB * num_possible_nodes().
+ */

In BPF code, we prefer a different style of multiple line comments:

Quoted 4 lines

/* PMD_SIZE is really big for some archs. It doesn't make sense to
* reserve too much memory in one allocation. Cap BPF_PROG_PACK_SIZE to
* 2MiB * num_possible_nodes().
*/

Fixed up while applying. Thanks everyone.