linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: cap BPF_PROG_PACK_SIZE to 2MB * num_possible_nodes()
@ 2024-03-08 12:07 Puranjay Mohan
  2024-03-08 16:55 ` Song Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Puranjay Mohan @ 2024-03-08 12:07 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	bpf, linux-kernel
  Cc: puranjay12

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]")
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Closes: https://lore.kernel.org/all/7e216c88-77ee-47b8-becc-a0f780868d3c@sirena.org.uk/
Suggested-by: Song Liu <song@kernel.org>
Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
---
 kernel/bpf/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 134b7979f537..83a3b6964e54 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -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
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: cap BPF_PROG_PACK_SIZE to 2MB * num_possible_nodes()
  2024-03-08 12:07 [PATCH bpf-next] bpf: cap BPF_PROG_PACK_SIZE to 2MB * num_possible_nodes() Puranjay Mohan
@ 2024-03-08 16:55 ` Song Liu
  2024-03-08 23:08   ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Song Liu @ 2024-03-08 16:55 UTC (permalink / raw)
  To: Puranjay Mohan
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	bpf, linux-kernel

On Fri, Mar 8, 2024 at 4:07 AM Puranjay Mohan <puranjay12@gmail.com> wrote:
>
> 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]")
> Reported-by: "kernelci.org bot" <bot@kernelci.org>
> Closes: https://lore.kernel.org/all/7e216c88-77ee-47b8-becc-a0f780868d3c@sirena.org.uk/
> Suggested-by: Song Liu <song@kernel.org>
> Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
> ---
>  kernel/bpf/core.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 134b7979f537..83a3b6964e54 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -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.

Acked-by: Song Liu <song@kernel.org>

Thanks,
Song

> +#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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: cap BPF_PROG_PACK_SIZE to 2MB * num_possible_nodes()
  2024-03-08 16:55 ` Song Liu
@ 2024-03-08 23:08   ` Alexei Starovoitov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2024-03-08 23:08 UTC (permalink / raw)
  To: Song Liu
  Cc: Puranjay Mohan, Alexei Starovoitov, Daniel Borkmann,
	John Fastabend, Andrii Nakryiko, Martin KaFai Lau,
	Eduard Zingerman, Yonghong Song, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, bpf, LKML

On Fri, Mar 8, 2024 at 8:55 AM Song Liu <song@kernel.org> wrote:
>
> On Fri, Mar 8, 2024 at 4:07 AM Puranjay Mohan <puranjay12@gmail.com> wrote:
> >
> > 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]")
> > Reported-by: "kernelci.org bot" <bot@kernelci.org>
> > Closes: https://lore.kernel.org/all/7e216c88-77ee-47b8-becc-a0f780868d3c@sirena.org.uk/
> > Suggested-by: Song Liu <song@kernel.org>
> > Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
> > ---
> >  kernel/bpf/core.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> > index 134b7979f537..83a3b6964e54 100644
> > --- a/kernel/bpf/core.c
> > +++ b/kernel/bpf/core.c
> > @@ -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().
>  */

Fixed up while applying. Thanks everyone.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-08 23:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08 12:07 [PATCH bpf-next] bpf: cap BPF_PROG_PACK_SIZE to 2MB * num_possible_nodes() Puranjay Mohan
2024-03-08 16:55 ` Song Liu
2024-03-08 23:08   ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).