nfp: bpf: support u32 divide using reciprocal_div.h
authorJiong Wang <jiong.wang@netronome.com>
Fri, 6 Jul 2018 22:13:22 +0000 (15:13 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 6 Jul 2018 23:45:31 +0000 (01:45 +0200)
commit2a952b03d1a011e2e7ddc9ca59cbb21df7dc3525
tree65fec3490f3538a15d1f35a89a806aec9cbe495b
parentd3d23fdb4688de4421e94227c95b1d54b233f432
nfp: bpf: support u32 divide using reciprocal_div.h

NFP doesn't have integer divide instruction, this patch use reciprocal
algorithm (the basic one, reciprocal_div) to emulate it.

For each u32 divide, we would need 11 instructions to finish the operation.

  7 (for multiplication) + 4 (various ALUs) = 11

Given NFP only supports multiplication no bigger than u32, we'd require
divisor and dividend no bigger than that as well.

Also eBPF doesn't support signed divide and has enforced this on C language
level by failing compilation. However LLVM assembler hasn't enforced this,
so it is possible for negative constant to leak in as a BPF_K operand
through assembly code, we reject such cases as well.

Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
drivers/net/ethernet/netronome/nfp/bpf/jit.c
drivers/net/ethernet/netronome/nfp/bpf/main.h
drivers/net/ethernet/netronome/nfp/bpf/verifier.c