Skip to content

Commit 46dd3d7

Browse files
lukenelsborkmann
authored andcommitted
bpf, riscv: Enable zext optimization for more RV64G ALU ops
Commit 66d0d5a ("riscv: bpf: eliminate zero extension code-gen") added the new zero-extension optimization for some BPF ALU operations. Since then, bugs in the JIT that have been fixed in the bpf tree require this optimization to be added to other operations: commit 1e692f0 ("bpf, riscv: clear high 32 bits for ALU32 add/sub/neg/lsh/rsh/arsh"), and commit fe121ee ("bpf, riscv: clear target register high 32-bits for and/or/xor on ALU32"). Now that these have been merged to bpf-next, the zext optimization can be enabled for the fixed operations. Signed-off-by: Luke Nelson <[email protected]> Cc: Song Liu <[email protected]> Cc: Jiong Wang <[email protected]> Cc: Xi Wang <[email protected]> Acked-by: Björn Töpel <[email protected]> Acked-by: Jiong Wang <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent aa52bcb commit 46dd3d7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

arch/riscv/net/bpf_jit_comp.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -757,31 +757,31 @@ static int emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
757757
case BPF_ALU | BPF_ADD | BPF_X:
758758
case BPF_ALU64 | BPF_ADD | BPF_X:
759759
emit(is64 ? rv_add(rd, rd, rs) : rv_addw(rd, rd, rs), ctx);
760-
if (!is64)
760+
if (!is64 && !aux->verifier_zext)
761761
emit_zext_32(rd, ctx);
762762
break;
763763
case BPF_ALU | BPF_SUB | BPF_X:
764764
case BPF_ALU64 | BPF_SUB | BPF_X:
765765
emit(is64 ? rv_sub(rd, rd, rs) : rv_subw(rd, rd, rs), ctx);
766-
if (!is64)
766+
if (!is64 && !aux->verifier_zext)
767767
emit_zext_32(rd, ctx);
768768
break;
769769
case BPF_ALU | BPF_AND | BPF_X:
770770
case BPF_ALU64 | BPF_AND | BPF_X:
771771
emit(rv_and(rd, rd, rs), ctx);
772-
if (!is64)
772+
if (!is64 && !aux->verifier_zext)
773773
emit_zext_32(rd, ctx);
774774
break;
775775
case BPF_ALU | BPF_OR | BPF_X:
776776
case BPF_ALU64 | BPF_OR | BPF_X:
777777
emit(rv_or(rd, rd, rs), ctx);
778-
if (!is64)
778+
if (!is64 && !aux->verifier_zext)
779779
emit_zext_32(rd, ctx);
780780
break;
781781
case BPF_ALU | BPF_XOR | BPF_X:
782782
case BPF_ALU64 | BPF_XOR | BPF_X:
783783
emit(rv_xor(rd, rd, rs), ctx);
784-
if (!is64)
784+
if (!is64 && !aux->verifier_zext)
785785
emit_zext_32(rd, ctx);
786786
break;
787787
case BPF_ALU | BPF_MUL | BPF_X:
@@ -811,13 +811,13 @@ static int emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
811811
case BPF_ALU | BPF_RSH | BPF_X:
812812
case BPF_ALU64 | BPF_RSH | BPF_X:
813813
emit(is64 ? rv_srl(rd, rd, rs) : rv_srlw(rd, rd, rs), ctx);
814-
if (!is64)
814+
if (!is64 && !aux->verifier_zext)
815815
emit_zext_32(rd, ctx);
816816
break;
817817
case BPF_ALU | BPF_ARSH | BPF_X:
818818
case BPF_ALU64 | BPF_ARSH | BPF_X:
819819
emit(is64 ? rv_sra(rd, rd, rs) : rv_sraw(rd, rd, rs), ctx);
820-
if (!is64)
820+
if (!is64 && !aux->verifier_zext)
821821
emit_zext_32(rd, ctx);
822822
break;
823823

@@ -826,7 +826,7 @@ static int emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
826826
case BPF_ALU64 | BPF_NEG:
827827
emit(is64 ? rv_sub(rd, RV_REG_ZERO, rd) :
828828
rv_subw(rd, RV_REG_ZERO, rd), ctx);
829-
if (!is64)
829+
if (!is64 && !aux->verifier_zext)
830830
emit_zext_32(rd, ctx);
831831
break;
832832

0 commit comments

Comments
 (0)