WSL2-Linux-Kernel/tools/testing/selftests
Alexei Starovoitov 8c290e60fa bpf: fix hashmap extra_elems logic
In both kmalloc and prealloc mode the bpf_map_update_elem() is using
per-cpu extra_elems to do atomic update when the map is full.
There are two issues with it. The logic can be misused, since it allows
max_entries+num_cpus elements to be present in the map. And alloc_extra_elems()
at map creation time can fail percpu alloc for large map values with a warn:
WARNING: CPU: 3 PID: 2752 at ../mm/percpu.c:892 pcpu_alloc+0x119/0xa60
illegal size (32824) or align (8) for percpu allocation

The fixes for both of these issues are different for kmalloc and prealloc modes.
For prealloc mode allocate extra num_possible_cpus elements and store
their pointers into extra_elems array instead of actual elements.
Hence we can use these hidden(spare) elements not only when the map is full
but during bpf_map_update_elem() that replaces existing element too.
That also improves performance, since pcpu_freelist_pop/push is avoided.
Unfortunately this approach cannot be used for kmalloc mode which needs
to kfree elements after rcu grace period. Therefore switch it back to normal
kmalloc even when full and old element exists like it was prior to
commit 6c90598174 ("bpf: pre-allocate hash map elements").

Add tests to check for over max_entries and large map values.

Reported-by: Dave Jones <davej@codemonkey.org.uk>
Fixes: 6c90598174 ("bpf: pre-allocate hash map elements")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-03-22 14:12:18 -07:00
..
bpf bpf: fix hashmap extra_elems logic 2017-03-22 14:12:18 -07:00
breakpoints
capabilities
cpu-hotplug
cpufreq selftest: cpufreq: Add special tests 2017-01-19 10:32:27 -07:00
drivers/gpu
efivarfs
exec
filesystems
firmware driver core patches for 4.11-rc1 2017-02-22 11:44:32 -08:00
ftrace
futex selftests/futex: Add headers to makefile dependencies 2017-01-19 10:30:21 -07:00
gpio
ia64
intel_pstate selftests/intel_pstate: Update makefile to match new style 2017-01-19 10:30:40 -07:00
ipc
kcmp
lib
locking
media_tests
membarrier
memfd
memory-hotplug
mount
mqueue
net linux-kselftest-4.11-rc1 2017-02-25 15:32:53 -08:00
networking/timestamping
nsfs
ntb
powerpc selftests/powerpc: Replace stxvx and lxvx with stxvd2x/lxvd2x 2017-03-09 13:58:00 +11:00
prctl
pstore
ptp
ptrace
rcutorture Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2017-02-20 13:23:30 -08:00
seccomp
sigaltstack tools/testing/selftests/sigaltstack/sas.c: improve output of sigaltstack testcase 2017-02-27 18:43:45 -08:00
size
splice selftest for default_file_splice_read() infoleak 2017-02-18 22:07:24 -05:00
static_keys
sync
sysctl
timers
user
vDSO
vm userfaultfd: selftest: vm: allow to build in vm/ directory 2017-03-09 17:01:10 -08:00
watchdog
x86 Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2017-03-07 14:47:24 -08:00
zram
.gitignore
Makefile Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2017-03-03 21:44:35 -08:00
gen_kselftest_tar.sh
kselftest.h
kselftest_install.sh
lib.mk selftests: lib.mk Fix individual test builds 2017-03-02 07:53:01 -07:00