[PATCH bpf-next 0/2] fix bpf_prog_pack build errors

STALE1673d

6 messages, 4 authors, 2022-02-10 · open the first message on its own page

[PATCH bpf-next 0/2] fix bpf_prog_pack build errors

From: Song Liu <song@kernel.org>
Date: 2022-02-08 22:26:53

Fix build errors reported by kernel test robot.

Song Liu (2):
  bpf: fix leftover header->pages in sparc and powerpc code.
  bpf: fix bpf_prog_pack build HPAGE_PMD_SIZE

 arch/powerpc/net/bpf_jit_comp.c  | 2 +-
 arch/sparc/net/bpf_jit_comp_64.c | 2 +-
 kernel/bpf/core.c                | 4 ++++
 3 files changed, 6 insertions(+), 2 deletions(-)

--
2.30.2

[PATCH bpf-next 2/2] bpf: fix bpf_prog_pack build HPAGE_PMD_SIZE

From: Song Liu <song@kernel.org>
Date: 2022-02-08 22:23:16

Fix build with CONFIG_TRANSPARENT_HUGEPAGE=n with BPF_PROG_PACK_SIZE as
PAGE_SIZE.

Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
Reported-by: kernel test robot <redacted>
Signed-off-by: Song Liu <song@kernel.org>
---
 kernel/bpf/core.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 306aa63fa58e..9519264ab1ee 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -814,7 +814,11 @@ int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
  * allocator. The prog_pack allocator uses HPAGE_PMD_SIZE page (2MB on x86)
  * to host BPF programs.
  */
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 #define BPF_PROG_PACK_SIZE	HPAGE_PMD_SIZE
+#else
+#define BPF_PROG_PACK_SIZE	PAGE_SIZE
+#endif
 #define BPF_PROG_CHUNK_SHIFT	6
 #define BPF_PROG_CHUNK_SIZE	(1 << BPF_PROG_CHUNK_SHIFT)
 #define BPF_PROG_CHUNK_MASK	(~(BPF_PROG_CHUNK_SIZE - 1))
-- 
2.30.2

[PATCH bpf-next 1/2] bpf: fix leftover header->pages in sparc and powerpc code.

From: Song Liu <song@kernel.org>
Date: 2022-02-08 22:53:08

Replace header->pages * PAGE_SIZE with new header->size.

Fixes: ed2d9e1a26cc ("bpf: Use size instead of pages in bpf_binary_header")
Reported-by: kernel test robot <redacted>
Signed-off-by: Song Liu <song@kernel.org>
---
 arch/powerpc/net/bpf_jit_comp.c  | 2 +-
 arch/sparc/net/bpf_jit_comp_64.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index d6ffdd0f2309..9003c313475d 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -247,7 +247,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
 	fp->jited = 1;
 	fp->jited_len = proglen + FUNCTION_DESCR_SIZE;
 
-	bpf_flush_icache(bpf_hdr, (u8 *)bpf_hdr + (bpf_hdr->pages * PAGE_SIZE));
+	bpf_flush_icache(bpf_hdr, (u8 *)bpf_hdr + bpf_hdr->size);
 	if (!fp->is_func || extra_pass) {
 		bpf_jit_binary_lock_ro(bpf_hdr);
 		bpf_prog_fill_jited_linfo(fp, addrs);
diff --git a/arch/sparc/net/bpf_jit_comp_64.c b/arch/sparc/net/bpf_jit_comp_64.c
index b1e38784eb23..fa0759bfe498 100644
--- a/arch/sparc/net/bpf_jit_comp_64.c
+++ b/arch/sparc/net/bpf_jit_comp_64.c
@@ -1599,7 +1599,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
 	if (bpf_jit_enable > 1)
 		bpf_jit_dump(prog->len, image_size, pass, ctx.image);
 
-	bpf_flush_icache(header, (u8 *)header + (header->pages * PAGE_SIZE));
+	bpf_flush_icache(header, (u8 *)header + header->size);
 
 	if (!prog->is_func || extra_pass) {
 		bpf_jit_binary_lock_ro(header);
-- 
2.30.2

Re: [PATCH bpf-next 0/2] fix bpf_prog_pack build errors

From: patchwork-bot+netdevbpf@kernel.org
Date: 2022-02-09 05:34:49

Hello:

This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov [off-list ref]:

On Tue, 8 Feb 2022 14:05:07 -0800 you wrote:
Fix build errors reported by kernel test robot.

Song Liu (2):
  bpf: fix leftover header->pages in sparc and powerpc code.
  bpf: fix bpf_prog_pack build HPAGE_PMD_SIZE

 arch/powerpc/net/bpf_jit_comp.c  | 2 +-
 arch/sparc/net/bpf_jit_comp_64.c | 2 +-
 kernel/bpf/core.c                | 4 ++++
 3 files changed, 6 insertions(+), 2 deletions(-)

[...]
Here is the summary with links:
  - [bpf-next,1/2] bpf: fix leftover header->pages in sparc and powerpc code.
    https://git.kernel.org/bpf/bpf-next/c/0f350231b5ac
  - [bpf-next,2/2] bpf: fix bpf_prog_pack build HPAGE_PMD_SIZE
    https://git.kernel.org/bpf/bpf-next/c/c1b13a9451ab

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Re: [PATCH bpf-next 2/2] bpf: fix bpf_prog_pack build HPAGE_PMD_SIZE

From: Eric Dumazet <hidden>
Date: 2022-02-10 01:58:04

On 2/8/22 14:05, Song Liu wrote:
quoted hunk
Fix build with CONFIG_TRANSPARENT_HUGEPAGE=n with BPF_PROG_PACK_SIZE as
PAGE_SIZE.

Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
Reported-by: kernel test robot <redacted>
Signed-off-by: Song Liu <song@kernel.org>
---
  kernel/bpf/core.c | 4 ++++
  1 file changed, 4 insertions(+)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 306aa63fa58e..9519264ab1ee 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -814,7 +814,11 @@ int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
   * allocator. The prog_pack allocator uses HPAGE_PMD_SIZE page (2MB on x86)
   * to host BPF programs.
   */
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
  #define BPF_PROG_PACK_SIZE	HPAGE_PMD_SIZE
+#else
+#define BPF_PROG_PACK_SIZE	PAGE_SIZE
+#endif
  #define BPF_PROG_CHUNK_SHIFT	6
  #define BPF_PROG_CHUNK_SIZE	(1 << BPF_PROG_CHUNK_SHIFT)
  #define BPF_PROG_CHUNK_MASK	(~(BPF_PROG_CHUNK_SIZE - 1))
BTW, I do not understand with module_alloc(HPAGE_PMD_SIZE) would 
necessarily allocate a huge page.

I am pretty sure it does not on x86_64 and dual socket host (NUMA)

It seems you need to multiply this by num_online_nodes()  or change the 
way __vmalloc_node_range()

works, because it currently does:

     if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP)) {
         unsigned long size_per_node;

         /*
          * Try huge pages. Only try for PAGE_KERNEL allocations,
          * others like modules don't yet expect huge pages in
          * their allocations due to apply_to_page_range not
          * supporting them.
          */

         size_per_node = size;
         if (node == NUMA_NO_NODE)
<*>          size_per_node /= num_online_nodes();
         if (arch_vmap_pmd_supported(prot) && size_per_node >= PMD_SIZE)
             shift = PMD_SHIFT;
         else
             shift = arch_vmap_pte_supported_shift(size_per_node);



Re: [PATCH bpf-next 2/2] bpf: fix bpf_prog_pack build HPAGE_PMD_SIZE

From: Song Liu <hidden>
Date: 2022-02-10 05:59:59

Hi Eric, 
On Feb 9, 2022, at 5:13 PM, Eric Dumazet [off-list ref] wrote:


On 2/8/22 14:05, Song Liu wrote:
quoted
Fix build with CONFIG_TRANSPARENT_HUGEPAGE=n with BPF_PROG_PACK_SIZE as
PAGE_SIZE.

Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
Reported-by: kernel test robot <redacted>
Signed-off-by: Song Liu <song@kernel.org>
---
 kernel/bpf/core.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 306aa63fa58e..9519264ab1ee 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -814,7 +814,11 @@ int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
  * allocator. The prog_pack allocator uses HPAGE_PMD_SIZE page (2MB on x86)
  * to host BPF programs.
  */
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 #define BPF_PROG_PACK_SIZE	HPAGE_PMD_SIZE
+#else
+#define BPF_PROG_PACK_SIZE	PAGE_SIZE
+#endif
 #define BPF_PROG_CHUNK_SHIFT	6
 #define BPF_PROG_CHUNK_SIZE	(1 << BPF_PROG_CHUNK_SHIFT)
 #define BPF_PROG_CHUNK_MASK	(~(BPF_PROG_CHUNK_SIZE - 1))
BTW, I do not understand with module_alloc(HPAGE_PMD_SIZE) would necessarily allocate a huge page.

I am pretty sure it does not on x86_64 and dual socket host (NUMA)

It seems you need to multiply this by num_online_nodes()  or change the way __vmalloc_node_range()

works, because it currently does:

    if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP)) {
        unsigned long size_per_node;

        /*
         * Try huge pages. Only try for PAGE_KERNEL allocations,
         * others like modules don't yet expect huge pages in
         * their allocations due to apply_to_page_range not
         * supporting them.
         */

        size_per_node = size;
        if (node == NUMA_NO_NODE)
<*>          size_per_node /= num_online_nodes();
        if (arch_vmap_pmd_supported(prot) && size_per_node >= PMD_SIZE)
            shift = PMD_SHIFT;
        else
            shift = arch_vmap_pte_supported_shift(size_per_node);

Thanks for highlighting this issue! I will address this in a follow up commit. 

Regards,
Song
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help