bpf: Add missed maybe_wait_bpf_programs() for htab of maps
authorHou Tao <houtao1@huawei.com>
Fri, 8 Dec 2023 10:23:51 +0000 (18:23 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 10 Dec 2023 02:12:34 +0000 (18:12 -0800)
When doing batched lookup and deletion operations on htab of maps,
maybe_wait_bpf_programs() is needed to ensure all programs don't use the
inner map after the bpf syscall returns.

Instead of adding the wait in __htab_map_lookup_and_delete_batch(),
adding the wait in bpf_map_do_batch() and also removing the calling of
maybe_wait_bpf_programs() from generic_map_{delete,update}_batch().

Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20231208102355.2628918-4-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/syscall.c

index 07e671431987546165cd2dbf31803b38e9b6bdb1..2e6ef361da1cc677f35240c437d3c6a134bdbe93 100644 (file)
@@ -1758,7 +1758,6 @@ int generic_map_delete_batch(struct bpf_map *map,
 
        kvfree(key);
 
-       maybe_wait_bpf_programs(map);
        return err;
 }
 
@@ -1817,7 +1816,6 @@ int generic_map_update_batch(struct bpf_map *map, struct file *map_file,
        kvfree(value);
        kvfree(key);
 
-       maybe_wait_bpf_programs(map);
        return err;
 }
 
@@ -5031,8 +5029,10 @@ static int bpf_map_do_batch(const union bpf_attr *attr,
        else
                BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr);
 err_put:
-       if (has_write)
+       if (has_write) {
+               maybe_wait_bpf_programs(map);
                bpf_map_write_active_dec(map);
+       }
        fdput(f);
        return err;
 }