powerpc/bpf: populate extable entries only during the last pass
Subsystems (3)
Hari Bathini
maintainerPATCH 1/1 powerpc/bpf: populate extable entries only during the last pass
Since commit 85e031154c7c ("powerpc/bpf: Perform complete extra passes to update addresses"), two additional passes are performed to avoid space and CPU time wastage on powerpc. But these extra passes led to WARN_ON_ONCE() hits in bpf_add_extable_entry(). Fix it by not adding extable entries during the extra pass.
--- arch/powerpc/net/bpf_jit_comp32.c | 2 +- arch/powerpc/net/bpf_jit_comp64.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/net/bpf_jit_comp32.c +1 -1
@@ -977,7 +977,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *if (size !=BPF_DW && !fp->aux->verifier_zext)EMIT (PPC_RAW_LI (dst_reg_h,0 )); -if (BPF_MODE (code) ==BPF_PROBE_MEM ) { +if (BPF_MODE (code) ==BPF_PROBE_MEM && !extra_pass) {int insn_idx = ctx->idx -1 ;int jmp_off =4 ;
arch/powerpc/net/bpf_jit_comp64.c +1 -1
@@ -921,7 +921,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *if (size !=BPF_DW &&insn_is_zext (&insn[i +1 ])) addrs[++i] = ctx->idx *4 ; -if (BPF_MODE (code) ==BPF_PROBE_MEM ) { +if (BPF_MODE (code) ==BPF_PROBE_MEM && !extra_pass) { ret =bpf_add_extable_entry (fp, image, pass, ctx, ctx->idx -1 ,4 , dst_reg);if (ret)
Signature · 1 line
2.39.2
Le 06/04/2023 à 09:35, Hari Bathini a écrit :
Quoted 5 lines
Since commit
85e031154c7c("powerpc/bpf: Perform complete extra passes to update addresses"), two additional passes are performed to avoid space and CPU time wastage on powerpc. But these extra passes led toWARN_ON_ONCE()hits inbpf_add_extable_entry(). Fix it by not adding extable entries during the extra pass.
Are you sure this change is correct ?
During the extra pass the code can get shrinked or expanded (within the limits of the size of the preliminary pass). Shouldn't extable entries be populated during the last pass ?
Christophe
Quoted 34 lines
Fixes 85e031154c7c ("powerpc/bpf: Perform complete extra passes to update addresses")Signed-off-by Hari Bathini <[email protected]>--- arch/powerpc/net/bpf_jit_comp32.c | 2 +- arch/powerpc/net/bpf_jit_comp64.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/powerpc/net/bpf_jit_comp32.c +1
-1@@ -977,7 +977,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *if (size !=BPF_DW && !fp->aux->verifier_zext)EMIT (PPC_RAW_LI (dst_reg_h,0 )); -if (BPF_MODE (code) ==BPF_PROBE_MEM ) { +if (BPF_MODE (code) ==BPF_PROBE_MEM && !extra_pass) {int insn_idx = ctx->idx -1 ;int jmp_off =4 ;arch/powerpc/net/bpf_jit_comp64.c +1
-1@@ -921,7 +921,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *if (size !=BPF_DW &&insn_is_zext (&insn[i +1 ])) addrs[++i] = ctx->idx *4 ; -if (BPF_MODE (code) ==BPF_PROBE_MEM ) { +if (BPF_MODE (code) ==BPF_PROBE_MEM && !extra_pass) { ret =bpf_add_extable_entry (fp, image, pass, ctx, ctx->idx -1 ,4 , dst_reg);if (ret)
Hari Bathini
maintainerHello Christophe,
Thanks for the review.
Quoted 10 lines · Christophe Leroy
Le 06/04/2023 à 09:35, Hari Bathini a écrit :
Quoted 5 lines
Since commit
85e031154c7c("powerpc/bpf: Perform complete extra passes to update addresses"), two additional passes are performed to avoid space and CPU time wastage on powerpc. But these extra passes led toWARN_ON_ONCE()hits inbpf_add_extable_entry(). Fix it by not adding extable entries during the extra pass.Are you sure this change is correct ?
Actually, I was in two minds about that owing to commit 04c04205bc35 ("bpf powerpc: Remove extra_pass from bpf_jit_build_body()").
Quoted 3 lines
During the extra pass the code can get shrinked or expanded (within the limits of the size of the preliminary pass). Shouldn't extable entries be populated during the last pass ?
Unlikely, but the intention there was to eliminate a regression in case extra_pass ends up being 'false' always in any subsequent change.
- Hari
Quoted 34 lines
Quoted 34 lines
Fixes 85e031154c7c ("powerpc/bpf: Perform complete extra passes to update addresses")Signed-off-by Hari Bathini <[email protected]>--- arch/powerpc/net/bpf_jit_comp32.c | 2 +- arch/powerpc/net/bpf_jit_comp64.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/powerpc/net/bpf_jit_comp32.c +1
-1@@ -977,7 +977,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *if (size !=BPF_DW && !fp->aux->verifier_zext)EMIT (PPC_RAW_LI (dst_reg_h,0 )); -if (BPF_MODE (code) ==BPF_PROBE_MEM ) { +if (BPF_MODE (code) ==BPF_PROBE_MEM && !extra_pass) {int insn_idx = ctx->idx -1 ;int jmp_off =4 ;arch/powerpc/net/bpf_jit_comp64.c +1
-1@@ -921,7 +921,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *if (size !=BPF_DW &&insn_is_zext (&insn[i +1 ])) addrs[++i] = ctx->idx *4 ; -if (BPF_MODE (code) ==BPF_PROBE_MEM ) { +if (BPF_MODE (code) ==BPF_PROBE_MEM && !extra_pass) { ret =bpf_add_extable_entry (fp, image, pass, ctx, ctx->idx -1 ,4 , dst_reg);if (ret)
Quoted 14 lines · Hari Bathini
Hello Christophe,
Thanks for the review.
Quoted 9 lines · Christophe Leroy
Le 06/04/2023 à 09:35, Hari Bathini a écrit :
Quoted 5 lines
Since commit
85e031154c7c("powerpc/bpf: Perform complete extra passes to update addresses"), two additional passes are performed to avoid space and CPU time wastage on powerpc. But these extra passes led toWARN_ON_ONCE()hits inbpf_add_extable_entry(). Fix it by not adding extable entries during the extra pass.
Quoted 4 lines
Quoted 1 line
Are you sure this change is correct ?
Actually, I was in two minds about that owing to commit
04c04205bc35("bpf powerpc: Removeextra_passfrombpf_jit_build_body()").
Right, but Christophe's series adding complete passes during the extra_pass phase added 'extra_pass' parameter back to bpf_jit_build_body().
Quoted 7 lines
Quoted 4 lines
During the extra pass the code can get shrinked or expanded (within the limits of the size of the preliminary pass). Shouldn't extable entries be populated during the last pass ?
Unlikely, but the intention there was to eliminate a regression in case
extra_passends up being 'false' always in any subsequent change.
But, the current approach risks generating incorrect offsets in the extable. The main motivation for the extra pass is to generate more compact code, so there is a good chance that offsets are going to change (especially with bpf subprogs).
Quoted 19 lines
- Hari
Quoted 16 lines
Quoted 16 lines
Fixes 85e031154c7c ("powerpc/bpf: Perform complete extra passes to update addresses")Signed-off-by Hari Bathini <[email protected]>--- arch/powerpc/net/bpf_jit_comp32.c | 2 +- arch/powerpc/net/bpf_jit_comp64.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/powerpc/net/bpf_jit_comp32.c +0
-0@@ -977,7 +977,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *if (size !=BPF_DW && !fp->aux->verifier_zext)EMIT (PPC_RAW_LI (dst_reg_h,0 ));
Quoted 2 lines
Quoted 2 lines
arch/powerpc/net/bpf_jit_comp32.c int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * · line 980
Quoted 2 lines
arch/powerpc/net/bpf_jit_comp32.c +1
-1-if (BPF_MODE (code) ==BPF_PROBE_MEM ) { +if (BPF_MODE (code) ==BPF_PROBE_MEM && !extra_pass) {
It is probably better to pass 'extra_pass' into bpf_add_extable_entry() to keep all those checks together.
- Naveen
Hari Bathini
maintainerHi Naveen,
Quoted 43 lines · Naveen N. Rao
Quoted 14 lines · Hari Bathini
Hello Christophe,
Thanks for the review.
Quoted 9 lines · Christophe Leroy
Le 06/04/2023 à 09:35, Hari Bathini a écrit :
Quoted 5 lines
Since commit
85e031154c7c("powerpc/bpf: Perform complete extra passes to update addresses"), two additional passes are performed to avoid space and CPU time wastage on powerpc. But these extra passes led toWARN_ON_ONCE()hits inbpf_add_extable_entry(). Fix it by not adding extable entries during the extra pass.Quoted 4 lines
Quoted 1 line
Are you sure this change is correct ?
Actually, I was in two minds about that owing to commit
04c04205bc35("bpf powerpc: Removeextra_passfrombpf_jit_build_body()").Right, but Christophe's series adding complete passes during the
extra_passphase added 'extra_pass' parameter back tobpf_jit_build_body().Quoted 7 lines
Quoted 4 lines
During the extra pass the code can get shrinked or expanded (within the limits of the size of the preliminary pass). Shouldn't extable entries be populated during the last pass ?
Unlikely, but the intention there was to eliminate a regression in case
extra_passends up being 'false' always in any subsequent change.But, the current approach risks generating incorrect offsets in the extable. The main motivation for the extra pass is to generate more compact code, so there is a good chance that offsets are going to change (especially with bpf subprogs).
Quoted 11 lines
- Hari
Quoted 8 lines
Quoted 8 lines
Fixes 85e031154c7c ("powerpc/bpf: Perform complete extra passes to update addresses")Signed-off-by Hari Bathini <[email protected]>---
arch/powerpc/net/bpf_jit_comp32.c| 2 +-
arch/powerpc/net/bpf_jit_comp64.c| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines
Quoted 10 lines
Quoted 10 lines
arch/powerpc/net/bpf_jit_comp32.c int bpf_jit_build_body(struct bpf_prog *fp, u32 · line 980
Quoted 10 lines
arch/powerpc/net/bpf_jit_comp32.c +1
-1@@ -977,7 +977,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * if (size != BPF_DW && !fp->aux->verifier_zext) EMIT(PPC_RAW_LI(dst_reg_h, 0)); - if (BPF_MODE(code) == BPF_PROBE_MEM) { + if (BPF_MODE(code) == BPF_PROBE_MEM && !extra_pass) {It is probably better to pass '
extra_pass' intobpf_add_extable_entry()to keep all those checks together.
Thanks for the review and also the suggestion (offline) to reset index during extra pass, for my concern about possible regression. Posted v2.
- Hari