@@ -9432,11 +9432,7 @@ static int validate_map_op(const struct bpf_map *map, size_t key_sz,
if (!check_value_sz)
return 0;
- switch (map->def.type) {
- case BPF_MAP_TYPE_PERCPU_ARRAY:
- case BPF_MAP_TYPE_PERCPU_HASH:
- case BPF_MAP_TYPE_LRU_PERCPU_HASH:
- case BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE: {
+ if (is_percpu_bpf_map_type(map->def.type)) {
int num_cpu = libbpf_num_possible_cpus();
size_t elem_sz = roundup(map->def.value_size, 8);
@@ -9445,15 +9441,12 @@ static int validate_map_op(const struct bpf_map *map, size_t key_sz,
map->name, value_sz, num_cpu, elem_sz, num_cpu * elem_sz);
return -EINVAL;
}
- break;
- }
- default:
+ } else {
if (map->def.value_size != value_sz) {
pr_warn("map '%s': unexpected value size %zu provided, expected %u\n",
map->name, value_sz, map->def.value_size);
return -EINVAL;
}
- break;
}
return 0;
}
@@ -577,4 +577,12 @@ static inline bool is_pow_of_2(size_t x)
#define PROG_LOAD_ATTEMPTS 5
int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size, int attempts);
+static inline bool is_percpu_bpf_map_type(__u32 type)
+{
+ return type == BPF_MAP_TYPE_PERCPU_HASH ||
+ type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
+ type == BPF_MAP_TYPE_PERCPU_ARRAY ||
+ type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE;
+}
+
#endif /* __LIBBPF_LIBBPF_INTERNAL_H */
This will be useful for unpoisoning map values for Memory Sanitizer. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- tools/lib/bpf/libbpf.c | 11 ++--------- tools/lib/bpf/libbpf_internal.h | 8 ++++++++ 2 files changed, 10 insertions(+), 9 deletions(-)