Skip to content

Commit 3de5589

Browse files
iii-iAlexei Starovoitov
authored andcommitted
s390/bpf: Implement BPF_MOV | BPF_X with sign-extension
Implement the cpuv4 register-to-register move with sign extension. It is distinguished from the normal moves by non-zero values in insn->off, which determine the source size. s390x has instructions to deal with all of them: lbr, lhr, lgbr, lghr and lgfr. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Link: https://lore.kernel.org/r/20230919101336.2223655-5-iii@linux.ibm.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 9873ce2 commit 3de5589

1 file changed

Lines changed: 40 additions & 8 deletions

File tree

arch/s390/net/bpf_jit_comp.c

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -795,15 +795,47 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
795795
/*
796796
* BPF_MOV
797797
*/
798-
case BPF_ALU | BPF_MOV | BPF_X: /* dst = (u32) src */
799-
/* llgfr %dst,%src */
800-
EMIT4(0xb9160000, dst_reg, src_reg);
801-
if (insn_is_zext(&insn[1]))
802-
insn_count = 2;
798+
case BPF_ALU | BPF_MOV | BPF_X:
799+
switch (insn->off) {
800+
case 0: /* DST = (u32) SRC */
801+
/* llgfr %dst,%src */
802+
EMIT4(0xb9160000, dst_reg, src_reg);
803+
if (insn_is_zext(&insn[1]))
804+
insn_count = 2;
805+
break;
806+
case 8: /* DST = (u32)(s8) SRC */
807+
/* lbr %dst,%src */
808+
EMIT4(0xb9260000, dst_reg, src_reg);
809+
/* llgfr %dst,%dst */
810+
EMIT4(0xb9160000, dst_reg, dst_reg);
811+
break;
812+
case 16: /* DST = (u32)(s16) SRC */
813+
/* lhr %dst,%src */
814+
EMIT4(0xb9270000, dst_reg, src_reg);
815+
/* llgfr %dst,%dst */
816+
EMIT4(0xb9160000, dst_reg, dst_reg);
817+
break;
818+
}
803819
break;
804-
case BPF_ALU64 | BPF_MOV | BPF_X: /* dst = src */
805-
/* lgr %dst,%src */
806-
EMIT4(0xb9040000, dst_reg, src_reg);
820+
case BPF_ALU64 | BPF_MOV | BPF_X:
821+
switch (insn->off) {
822+
case 0: /* DST = SRC */
823+
/* lgr %dst,%src */
824+
EMIT4(0xb9040000, dst_reg, src_reg);
825+
break;
826+
case 8: /* DST = (s8) SRC */
827+
/* lgbr %dst,%src */
828+
EMIT4(0xb9060000, dst_reg, src_reg);
829+
break;
830+
case 16: /* DST = (s16) SRC */
831+
/* lghr %dst,%src */
832+
EMIT4(0xb9070000, dst_reg, src_reg);
833+
break;
834+
case 32: /* DST = (s32) SRC */
835+
/* lgfr %dst,%src */
836+
EMIT4(0xb9140000, dst_reg, src_reg);
837+
break;
838+
}
807839
break;
808840
case BPF_ALU | BPF_MOV | BPF_K: /* dst = (u32) imm */
809841
/* llilf %dst,imm */

0 commit comments

Comments
 (0)