s390/bpf: Fix 64-bit subtraction of the -0x80000000 constant

The JIT uses agfi for subtracting constants, but -(-0x80000000) cannot
be represented as a 32-bit signed binary integer. Fix by using algfi in
this particular case.

Reported-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
Fixes: 0546231057 ("s390/bpf: Add s390x eBPF JIT compiler backend")
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
This commit is contained in:
Ilya Leoshkevich 2021-09-07 13:41:16 +02:00 коммит произвёл Vasily Gorbik
Родитель 1511df6f5e
Коммит 6e61dc9da0
1 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -794,8 +794,13 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
case BPF_ALU64 | BPF_SUB | BPF_K: /* dst = dst - imm */ case BPF_ALU64 | BPF_SUB | BPF_K: /* dst = dst - imm */
if (!imm) if (!imm)
break; break;
if (imm == -0x80000000) {
/* algfi %dst,0x80000000 */
EMIT6_IMM(0xc20a0000, dst_reg, 0x80000000);
} else {
/* agfi %dst,-imm */ /* agfi %dst,-imm */
EMIT6_IMM(0xc2080000, dst_reg, -imm); EMIT6_IMM(0xc2080000, dst_reg, -imm);
}
break; break;
/* /*
* BPF_MUL * BPF_MUL