Refactor function map_delete_elem() with a new helper bpf_map_delete_elem(), which will be used later for batched lookup_and_delete and delete operations. Signed-off-by: Yonghong Song <yhs@xxxxxx> --- kernel/bpf/syscall.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 3caa0ab3d30d..b8bba499df11 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -992,6 +992,25 @@ static int map_update_elem(union bpf_attr *attr) return err; } +static int bpf_map_delete_elem(struct bpf_map *map, void *key) +{ + int err; + + if (bpf_map_is_dev_bound(map)) + return bpf_map_offload_delete_elem(map, key); + + preempt_disable(); + __this_cpu_inc(bpf_prog_active); + rcu_read_lock(); + err = map->ops->map_delete_elem(map, key); + rcu_read_unlock(); + __this_cpu_dec(bpf_prog_active); + preempt_enable(); + maybe_wait_bpf_programs(map); + + return err; +} + #define BPF_MAP_DELETE_ELEM_LAST_FIELD key static int map_delete_elem(union bpf_attr *attr) @@ -1021,20 +1040,8 @@ static int map_delete_elem(union bpf_attr *attr) goto err_put; } - if (bpf_map_is_dev_bound(map)) { - err = bpf_map_offload_delete_elem(map, key); - goto out; - } + err = bpf_map_delete_elem(map, key); - preempt_disable(); - __this_cpu_inc(bpf_prog_active); - rcu_read_lock(); - err = map->ops->map_delete_elem(map, key); - rcu_read_unlock(); - __this_cpu_dec(bpf_prog_active); - preempt_enable(); - maybe_wait_bpf_programs(map); -out: kfree(key); err_put: fdput(f); -- 2.17.1