hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/arch/sparc/net/bpf_jit_comp_64.c
....@@ -791,7 +791,7 @@
791791 }
792792
793793 /* Just skip the save instruction and the ctx register move. */
794
-#define BPF_TAILCALL_PROLOGUE_SKIP 16
794
+#define BPF_TAILCALL_PROLOGUE_SKIP 32
795795 #define BPF_TAILCALL_CNT_SP_OFF (STACK_BIAS + 128)
796796
797797 static void build_prologue(struct jit_ctx *ctx)
....@@ -824,9 +824,15 @@
824824 const u8 vfp = bpf2sparc[BPF_REG_FP];
825825
826826 emit(ADD | IMMED | RS1(FP) | S13(STACK_BIAS) | RD(vfp), ctx);
827
+ } else {
828
+ emit_nop(ctx);
827829 }
828830
829831 emit_reg_move(I0, O0, ctx);
832
+ emit_reg_move(I1, O1, ctx);
833
+ emit_reg_move(I2, O2, ctx);
834
+ emit_reg_move(I3, O3, ctx);
835
+ emit_reg_move(I4, O4, ctx);
830836 /* If you add anything here, adjust BPF_TAILCALL_PROLOGUE_SKIP above. */
831837 }
832838
....@@ -902,6 +908,8 @@
902908 /* dst = src */
903909 case BPF_ALU | BPF_MOV | BPF_X:
904910 emit_alu3_K(SRL, src, 0, dst, ctx);
911
+ if (insn_is_zext(&insn[1]))
912
+ return 1;
905913 break;
906914 case BPF_ALU64 | BPF_MOV | BPF_X:
907915 emit_reg_move(src, dst, ctx);
....@@ -936,6 +944,8 @@
936944 case BPF_ALU | BPF_DIV | BPF_X:
937945 emit_write_y(G0, ctx);
938946 emit_alu(DIV, src, dst, ctx);
947
+ if (insn_is_zext(&insn[1]))
948
+ return 1;
939949 break;
940950 case BPF_ALU64 | BPF_DIV | BPF_X:
941951 emit_alu(UDIVX, src, dst, ctx);
....@@ -969,6 +979,8 @@
969979 break;
970980 case BPF_ALU | BPF_RSH | BPF_X:
971981 emit_alu(SRL, src, dst, ctx);
982
+ if (insn_is_zext(&insn[1]))
983
+ return 1;
972984 break;
973985 case BPF_ALU64 | BPF_RSH | BPF_X:
974986 emit_alu(SRLX, src, dst, ctx);
....@@ -991,9 +1003,12 @@
9911003 case 16:
9921004 emit_alu_K(SLL, dst, 16, ctx);
9931005 emit_alu_K(SRL, dst, 16, ctx);
1006
+ if (insn_is_zext(&insn[1]))
1007
+ return 1;
9941008 break;
9951009 case 32:
996
- emit_alu_K(SRL, dst, 0, ctx);
1010
+ if (!ctx->prog->aux->verifier_zext)
1011
+ emit_alu_K(SRL, dst, 0, ctx);
9971012 break;
9981013 case 64:
9991014 /* nop */
....@@ -1015,6 +1030,8 @@
10151030 emit_alu3_K(AND, dst, 0xff, dst, ctx);
10161031 emit_alu3_K(SLL, tmp, 8, tmp, ctx);
10171032 emit_alu(OR, tmp, dst, ctx);
1033
+ if (insn_is_zext(&insn[1]))
1034
+ return 1;
10181035 break;
10191036
10201037 case 32:
....@@ -1031,6 +1048,8 @@
10311048 emit_alu3_K(AND, dst, 0xff, dst, ctx); /* dst = dst & 0xff */
10321049 emit_alu3_K(SLL, dst, 24, dst, ctx); /* dst = dst << 24 */
10331050 emit_alu(OR, tmp, dst, ctx); /* dst = dst | tmp */
1051
+ if (insn_is_zext(&insn[1]))
1052
+ return 1;
10341053 break;
10351054
10361055 case 64:
....@@ -1044,6 +1063,8 @@
10441063 /* dst = imm */
10451064 case BPF_ALU | BPF_MOV | BPF_K:
10461065 emit_loadimm32(imm, dst, ctx);
1066
+ if (insn_is_zext(&insn[1]))
1067
+ return 1;
10471068 break;
10481069 case BPF_ALU64 | BPF_MOV | BPF_K:
10491070 emit_loadimm_sext(imm, dst, ctx);
....@@ -1126,6 +1147,8 @@
11261147 break;
11271148 case BPF_ALU | BPF_RSH | BPF_K:
11281149 emit_alu_K(SRL, dst, imm, ctx);
1150
+ if (insn_is_zext(&insn[1]))
1151
+ return 1;
11291152 break;
11301153 case BPF_ALU64 | BPF_RSH | BPF_K:
11311154 emit_alu_K(SRLX, dst, imm, ctx);
....@@ -1138,7 +1161,8 @@
11381161 break;
11391162
11401163 do_alu32_trunc:
1141
- if (BPF_CLASS(code) == BPF_ALU)
1164
+ if (BPF_CLASS(code) == BPF_ALU &&
1165
+ !ctx->prog->aux->verifier_zext)
11421166 emit_alu_K(SRL, dst, 0, ctx);
11431167 break;
11441168
....@@ -1259,6 +1283,8 @@
12591283 rs2 = RS2(tmp);
12601284 }
12611285 emit(opcode | RS1(src) | rs2 | RD(dst), ctx);
1286
+ if (opcode != LD64 && insn_is_zext(&insn[1]))
1287
+ return 1;
12621288 break;
12631289 }
12641290 /* speculation barrier */
....@@ -1429,6 +1455,11 @@
14291455 *ptr++ = 0x91d02005; /* ta 5 */
14301456 }
14311457
1458
+bool bpf_jit_needs_zext(void)
1459
+{
1460
+ return true;
1461
+}
1462
+
14321463 struct sparc64_jit_data {
14331464 struct bpf_binary_header *header;
14341465 u8 *image;
....@@ -1572,6 +1603,7 @@
15721603 prog->jited_len = image_size;
15731604
15741605 if (!prog->is_func || extra_pass) {
1606
+ bpf_prog_fill_jited_linfo(prog, ctx.offset);
15751607 out_off:
15761608 kfree(ctx.offset);
15771609 kfree(jit_data);