llvm-project/llvm/test/CodeGen/BPF
Yonghong Song 9276ef05c8 bpf: generate better lowering code for certain select/setcc instructions
Currently, for code like below,
===
  inner_map = bpf_map_lookup_elem(outer_map, &port_key);
  if (!inner_map) {
    inner_map = &fallback_map;
  }
===
the compiler generates (pseudo) code like the below:
===
  I1: r1 = bpf_map_lookup_elem(outer_map, &port_key);
  I2: r2 = 0
  I3: if (r1 == r2)
  I4:   r6 = &fallback_map
  I5: ...
===

During kernel verification process, After I1, r1 holds a state
map_ptr_or_null. If I3 condition is not taken
(path [I1, I2, I3, I5]), supposedly r1 should become map_ptr.
Unfortunately, kernel does not recognize this pattern
and r1 remains map_ptr_or_null at insn I5. This will cause
verificaiton failure later on.

Kernel, however, is able to recognize pattern "if (r1 == 0)"
properly and give a map_ptr state to r1 in the above case.

LLVM here generates suboptimal code which causes kernel verification
failure. This patch fixes the issue by changing BPF insn pattern
matching and lowering to generate proper codes if the righthand
parameter of the above condition is a constant. A test case
is also added.

Signed-off-by: Yonghong Song <yhs@fb.com>
llvm-svn: 308080
2017-07-15 05:41:42 +00:00
..
alu8.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
atomics.ll [bpf] add BPF disassembler 2016-11-20 02:25:00 +00:00
basictest.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
byval.ll
cc_args.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
cc_args_be.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
cc_ret.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
cmp.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
dwarfdump.ll [bpf] fix a bug which causes incorrect big endian reloc fixup 2017-05-05 18:05:00 +00:00
ex1.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
fi_ri.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
intrinsics.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
lit.local.cfg
load.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
loops.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
many_args1.ll
many_args2.ll
mem_offset.ll [bpf] Fix memory offset check for loads and stores 2017-04-13 22:24:13 +00:00
mem_offset_be.ll [bpf] add bigendian support to disassembler 2017-04-28 16:51:01 +00:00
objdump_atomics.ll [bpf] add BPF disassembler 2016-11-20 02:25:00 +00:00
objdump_intrinsics.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
objdump_trivial.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
reloc.ll [bpf] add relocation support 2017-05-03 17:30:56 +00:00
remove_truncate_1.ll bpf: remove unnecessary truncate operation 2017-06-29 15:18:54 +00:00
remove_truncate_2.ll bpf: remove unnecessary truncate operation 2017-06-29 15:18:54 +00:00
rodata_1.ll bpf: avoid load from read-only sections 2017-06-16 15:41:16 +00:00
rodata_2.ll bpf: avoid load from read-only sections 2017-06-16 15:41:16 +00:00
rodata_3.ll bpf: avoid load from read-only sections 2017-06-16 15:41:16 +00:00
rodata_4.ll bpf: avoid load from read-only sections 2017-06-16 15:41:16 +00:00
sanity.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
sdiv_error.ll
select_ri.ll bpf: generate better lowering code for certain select/setcc instructions 2017-07-15 05:41:42 +00:00
setcc.ll bpf: generate better lowering code for certain select/setcc instructions 2017-07-15 05:41:42 +00:00
shifts.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
sockex2.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
struct_ret1.ll
struct_ret2.ll
undef.ll Rewrite areNonVolatileConsecutiveLoads to use BaseIndexOffset 2017-07-05 01:21:23 +00:00
vararg1.ll
warn-call.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
warn-stack.ll Add address space mangling to lifetime intrinsics 2017-04-10 20:18:21 +00:00