s390/bpf,jit: fix 32 bit divisions, use unsigned divide instructions

The s390 bpf jit compiler emits the signed divide instructions "dr" and "d"
for unsigned divisions.
This can cause problems: the dividend will be zero extended to a 64 bit value
and the divisor is the 32 bit signed value as specified A or X accumulator,
even though A and X are supposed to be treated as unsigned values.

The divide instrunctions will generate an exception if the result cannot be
expressed with a 32 bit signed value.
This is the case if e.g. the dividend is 0xffffffff and the divisor either 1
or also 0xffffffff (signed: -1).

To avoid all these issues simply use unsigned divide instructions.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Heiko Carstens and committed by David S. Miller 3af57f78 75b99dbd

Changed files
+8 -8
arch
s390
+8 -8
arch/s390/net/bpf_jit_comp.c
··· 368 368 EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); 369 369 /* lhi %r4,0 */ 370 370 EMIT4(0xa7480000); 371 - /* dr %r4,%r12 */ 372 - EMIT2(0x1d4c); 371 + /* dlr %r4,%r12 */ 372 + EMIT4(0xb997004c); 373 373 break; 374 374 case BPF_S_ALU_DIV_K: /* A /= K */ 375 375 if (K == 1) 376 376 break; 377 377 /* lhi %r4,0 */ 378 378 EMIT4(0xa7480000); 379 - /* d %r4,<d(K)>(%r13) */ 380 - EMIT4_DISP(0x5d40d000, EMIT_CONST(K)); 379 + /* dl %r4,<d(K)>(%r13) */ 380 + EMIT6_DISP(0xe340d000, 0x0097, EMIT_CONST(K)); 381 381 break; 382 382 case BPF_S_ALU_MOD_X: /* A %= X */ 383 383 jit->seen |= SEEN_XREG | SEEN_RET0; ··· 387 387 EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); 388 388 /* lhi %r4,0 */ 389 389 EMIT4(0xa7480000); 390 - /* dr %r4,%r12 */ 391 - EMIT2(0x1d4c); 390 + /* dlr %r4,%r12 */ 391 + EMIT4(0xb997004c); 392 392 /* lr %r5,%r4 */ 393 393 EMIT2(0x1854); 394 394 break; ··· 400 400 } 401 401 /* lhi %r4,0 */ 402 402 EMIT4(0xa7480000); 403 - /* d %r4,<d(K)>(%r13) */ 404 - EMIT4_DISP(0x5d40d000, EMIT_CONST(K)); 403 + /* dl %r4,<d(K)>(%r13) */ 404 + EMIT6_DISP(0xe340d000, 0x0097, EMIT_CONST(K)); 405 405 /* lr %r5,%r4 */ 406 406 EMIT2(0x1854); 407 407 break;