[PATCH] D70372: [InstCombine] Disable insertRangeTest() optimization for BPF target

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 17 20:43:52 PST 2019


yonghong-song created this revision.
yonghong-song added reviewers: ast, spatel, rnk, greened.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

The LLVM generated BPF byte codes need go through kernel
verifier before being allowed to execute in kernel.

Kernel verifier

  https://github.com/torvalds/linux/blob/master/kernel/bpf/verifier.c

performs path sensitive analysis to verify safety of the program.
The verification is done during bpf program loading time, and 
typically right before the program starts to run.

Since verifier is executed in kernel space and it runs during program
loading time, there is a great effort to avoid introducing complexity
and running time overhead for it. Sometime, in order to add analysis
to verifier, user code hacking is conducted to workaround the issue.

Related to this patch, the following kernel patch is a workaround
for code generated by LLVM instcombine insertRangeTest().

  https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=b7a0d65d80a0c5034b366392624397a0915b7556
  
     107:       w1 = w0
     108:       w1 += -1
     109:       if w1 > 6 goto -24 <LBB0_5>
     110:       w0 += w8

Basically since verifier does not record and propagate copy state
for performance and memory reasons. Register "w0" value range
will become conservative and later on may cause verification failure.

Another example is

  https://lore.kernel.org/netdev/871019a0-71f8-c26d-0ae8-c7fd8c8867fc@fb.com/

People has to come up with weird ways to workaround this issue.
To improve user space usability, this patch proposed to disable
insertRangeTest() for bpf target. All other targets are not 
affected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70372

Files:
  llvm/include/llvm/Analysis/TargetTransformInfo.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Target/BPF/BPFTargetMachine.cpp
  llvm/lib/Target/BPF/BPFTargetMachine.h
  llvm/lib/Target/BPF/BPFTargetTransformInfo.h
  llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/BPF/no-insert-range-test.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70372.229742.patch
Type: text/x-patch
Size: 11924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191118/e18c8266/attachment-0001.bin>


More information about the llvm-commits mailing list