linux-stable/tools
Daniel Borkmann d8eca5bbb2 bpf: implement lookup-free direct value access for maps
This generic extension to BPF maps allows for directly loading
an address residing inside a BPF map value as a single BPF
ldimm64 instruction!

The idea is similar to what BPF_PSEUDO_MAP_FD does today, which
is a special src_reg flag for ldimm64 instruction that indicates
that inside the first part of the double insns's imm field is a
file descriptor which the verifier then replaces as a full 64bit
address of the map into both imm parts. For the newly added
BPF_PSEUDO_MAP_VALUE src_reg flag, the idea is the following:
the first part of the double insns's imm field is again a file
descriptor corresponding to the map, and the second part of the
imm field is an offset into the value. The verifier will then
replace both imm parts with an address that points into the BPF
map value at the given value offset for maps that support this
operation. Currently supported is array map with single entry.
It is possible to support more than just single map element by
reusing both 16bit off fields of the insns as a map index, so
full array map lookup could be expressed that way. It hasn't
been implemented here due to lack of concrete use case, but
could easily be done so in future in a compatible way, since
both off fields right now have to be 0 and would correctly
denote a map index 0.

The BPF_PSEUDO_MAP_VALUE is a distinct flag as otherwise with
BPF_PSEUDO_MAP_FD we could not differ offset 0 between load of
map pointer versus load of map's value at offset 0, and changing
BPF_PSEUDO_MAP_FD's encoding into off by one to differ between
regular map pointer and map value pointer would add unnecessary
complexity and increases barrier for debugability thus less
suitable. Using the second part of the imm field as an offset
into the value does /not/ come with limitations since maximum
possible value size is in u32 universe anyway.

This optimization allows for efficiently retrieving an address
to a map value memory area without having to issue a helper call
which needs to prepare registers according to calling convention,
etc, without needing the extra NULL test, and without having to
add the offset in an additional instruction to the value base
pointer. The verifier then treats the destination register as
PTR_TO_MAP_VALUE with constant reg->off from the user passed
offset from the second imm field, and guarantees that this is
within bounds of the map value. Any subsequent operations are
normally treated as typical map value handling without anything
extra needed from verification side.

The two map operations for direct value access have been added to
array map for now. In future other types could be supported as
well depending on the use case. The main use case for this commit
is to allow for BPF loader support for global variables that
reside in .data/.rodata/.bss sections such that we can directly
load the address of them with minimal additional infrastructure
required. Loader support has been added in subsequent commits for
libbpf library.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-04-09 17:05:46 -07:00
..
accounting
arch tools headers uapi: Sync copy of asm-generic/unistd.h with the kernel sources 2019-03-11 16:13:04 -03:00
bpf bpf: implement lookup-free direct value access for maps 2019-04-09 17:05:46 -07:00
build perf build: Check what binutils's 'disassembler()' signature to use 2019-03-20 16:42:10 -03:00
cgroup
crypto
debugging
firewire
firmware tools/firmware/ihex2fw: Replace explicit alignment with ALIGN 2019-01-22 10:23:18 +01:00
gpio
hv
iio Merge 5.0-rc6 into staging-next 2019-02-11 09:25:01 +01:00
include Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-03-27 17:37:58 -07:00
io_uring io_uring: add a few test tools 2019-03-06 13:00:16 -07:00
kvm/kvm_stat
laptop
leds
lib libbpf: Ignore -Wformat-nonliteral warning 2019-04-06 23:13:54 -07:00
memory-model
nfsd
objtool objtool: Move objtool_file struct off the stack 2019-03-21 12:02:19 +01:00
pci
pcmcia
perf perf/core improvements and fixes: 2019-03-22 22:51:21 +01:00
power tools/power turbostat: return the exit status of a command 2019-03-19 16:51:16 +01:00
scripts
spi
testing selftests/bpf: Test unbounded var_off stack access 2019-04-05 16:50:08 +02:00
thermal/tmon
time
usb
virtio
vm tools/vm/slabinfo: clean up usage menu debug items 2019-03-05 21:07:20 -08:00
wmi
Makefile