]> 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)
commit6db839d57c37108d86cce96c3ca293154846933f
treede7e1b8094593fe8717b1392dbe103eeec55c6be
parent5d6fd1947c58dd3ffb65e71b6b753f87f3b6f38e
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: ad97dd3b1903 ("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