OSDN Git Service

bpf: check illegal usage of XADD insn return value
authorYonghong Song <yhs@fb.com>
Thu, 20 Sep 2018 22:24:27 +0000 (22:24 +0000)
committerYonghong Song <yhs@fb.com>
Thu, 20 Sep 2018 22:24:27 +0000 (22:24 +0000)
commit8135e49e9b65827e4bbcb8801e327aea29c6dfc2
tree780dee77d42edba7efc17f2190eb8a7a0adbc68f
parent10d1aafc7825dd3b6ad733686afa3789d93d74c8
bpf: check illegal usage of XADD insn return value

Currently, BPF has XADD (locked add) insn support and the
asm looks like:
  lock *(u32 *)(r1 + 0) += r2
  lock *(u64 *)(r1 + 0) += r2
The instruction itself does not have a return value.

At the source code level, users often use
  __sync_fetch_and_add()
which eventually translates to XADD. The return value of
__sync_fetch_and_add() is supposed to be the old value
in the xadd memory location. Since BPF::XADD insn does not
support such a return value, this patch added a PreEmit
phase to check such a usage. If such an illegal usage
pattern is detected, a fatal error will be reported like
  line 4: Invalid usage of the XADD return value
if compiled with -g, or
  Invalid usage of the XADD return value
if compiled without -g.

Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342692 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/BPF/BPF.h
lib/Target/BPF/BPFMIChecking.cpp [new file with mode: 0644]
lib/Target/BPF/BPFTargetMachine.cpp
lib/Target/BPF/CMakeLists.txt
test/CodeGen/BPF/xadd.ll [new file with mode: 0644]