]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: restore behavior of bpf_map_update_elem
authorAlexei Starovoitov <ast@fb.com>
Fri, 5 Aug 2016 21:01:27 +0000 (14:01 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 7 Aug 2016 00:49:19 +0000 (20:49 -0400)
commitd9d2ccae8d6e8cc8afda52d5a9ec0a0d6faf1527
treede7e1b8094593fe8717b1392dbe103eeec55c6be
parent0678c9d292a4febf51c361cf50daccf32f0ff545
bpf: restore behavior of bpf_map_update_elem

The introduction of pre-allocated hash elements inadvertently broke
the behavior of bpf hash maps where users expected to call
bpf_map_update_elem() without considering that the map can be full.
Some programs do:
old_value = bpf_map_lookup_elem(map, key);
if (old_value) {
  ... prepare new_value on stack ...
  bpf_map_update_elem(map, key, new_value);
}
Before pre-alloc the update() for existing element would work even
in 'map full' condition. Restore this behavior.

The above program could have updated old_value in place instead of
update() which would be faster and most programs use that approach,
but sometimes the values are large and the programs use update()
helper to do atomic replacement of the element.
Note we cannot simply update element's value in-place like percpu
hash map does and have to allocate extra num_possible_cpu elements
and use this extra reserve when the map is full.

Fixes: 3e35e8593c2f ("bpf: pre-allocate hash map elements")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/hashtab.c