mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 03:24:45 +01:00
bpf: Lose const-ness of map in map_check_btf()
BPF hash map may now use the map_check_btf() callback to decide whether to set a dtor on its bpf_mem_alloc or not. Unlike C++ where members can opt out of const-ness using mutable, we must lose the const qualifier on the callback such that we can avoid the ugly cast. Make the change and adjust all existing users, and lose the comment in hashtab.c. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20260227224806.646888-3-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
1df97a7453
commit
ae51772b1e
11 changed files with 15 additions and 16 deletions
|
|
@ -124,7 +124,7 @@ struct bpf_map_ops {
|
|||
u32 (*map_fd_sys_lookup_elem)(void *ptr);
|
||||
void (*map_seq_show_elem)(struct bpf_map *map, void *key,
|
||||
struct seq_file *m);
|
||||
int (*map_check_btf)(const struct bpf_map *map,
|
||||
int (*map_check_btf)(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type);
|
||||
|
|
@ -656,7 +656,7 @@ static inline bool bpf_map_support_seq_show(const struct bpf_map *map)
|
|||
map->ops->map_seq_show_elem;
|
||||
}
|
||||
|
||||
int map_check_no_btf(const struct bpf_map *map,
|
||||
int map_check_no_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type);
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ u32 bpf_local_storage_destroy(struct bpf_local_storage *local_storage);
|
|||
void bpf_local_storage_map_free(struct bpf_map *map,
|
||||
struct bpf_local_storage_cache *cache);
|
||||
|
||||
int bpf_local_storage_map_check_btf(const struct bpf_map *map,
|
||||
int bpf_local_storage_map_check_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type);
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ static long arena_map_update_elem(struct bpf_map *map, void *key,
|
|||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static int arena_map_check_btf(const struct bpf_map *map, const struct btf *btf,
|
||||
static int arena_map_check_btf(struct bpf_map *map, const struct btf *btf,
|
||||
const struct btf_type *key_type, const struct btf_type *value_type)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -548,7 +548,7 @@ static void percpu_array_map_seq_show_elem(struct bpf_map *map, void *key,
|
|||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
static int array_map_check_btf(const struct bpf_map *map,
|
||||
static int array_map_check_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type)
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ static long bloom_map_update_elem(struct bpf_map *map, void *key,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int bloom_map_check_btf(const struct bpf_map *map,
|
||||
static int bloom_map_check_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type)
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ static long insn_array_delete_elem(struct bpf_map *map, void *key)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int insn_array_check_btf(const struct bpf_map *map,
|
||||
static int insn_array_check_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type)
|
||||
|
|
|
|||
|
|
@ -797,7 +797,7 @@ int bpf_local_storage_map_alloc_check(union bpf_attr *attr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int bpf_local_storage_map_check_btf(const struct bpf_map *map,
|
||||
int bpf_local_storage_map_check_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type)
|
||||
|
|
|
|||
|
|
@ -496,10 +496,10 @@ static void htab_dtor_ctx_free(void *ctx)
|
|||
kfree(ctx);
|
||||
}
|
||||
|
||||
static int htab_set_dtor(const struct bpf_htab *htab, void (*dtor)(void *, void *))
|
||||
static int htab_set_dtor(struct bpf_htab *htab, void (*dtor)(void *, void *))
|
||||
{
|
||||
u32 key_size = htab->map.key_size;
|
||||
const struct bpf_mem_alloc *ma;
|
||||
struct bpf_mem_alloc *ma;
|
||||
struct htab_btf_record *hrec;
|
||||
int err;
|
||||
|
||||
|
|
@ -518,12 +518,11 @@ static int htab_set_dtor(const struct bpf_htab *htab, void (*dtor)(void *, void
|
|||
return err;
|
||||
}
|
||||
ma = htab_is_percpu(htab) ? &htab->pcpu_ma : &htab->ma;
|
||||
/* Kinda sad, but cast away const-ness since we change ma->dtor. */
|
||||
bpf_mem_alloc_set_dtor((struct bpf_mem_alloc *)ma, dtor, htab_dtor_ctx_free, hrec);
|
||||
bpf_mem_alloc_set_dtor(ma, dtor, htab_dtor_ctx_free, hrec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int htab_map_check_btf(const struct bpf_map *map, const struct btf *btf,
|
||||
static int htab_map_check_btf(struct bpf_map *map, const struct btf *btf,
|
||||
const struct btf_type *key_type, const struct btf_type *value_type)
|
||||
{
|
||||
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ static long cgroup_storage_delete_elem(struct bpf_map *map, void *key)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int cgroup_storage_check_btf(const struct bpf_map *map,
|
||||
static int cgroup_storage_check_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type)
|
||||
|
|
|
|||
|
|
@ -751,7 +751,7 @@ free_stack:
|
|||
return err;
|
||||
}
|
||||
|
||||
static int trie_check_btf(const struct bpf_map *map,
|
||||
static int trie_check_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type)
|
||||
|
|
|
|||
|
|
@ -1234,7 +1234,7 @@ int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(bpf_obj_name_cpy);
|
||||
|
||||
int map_check_no_btf(const struct bpf_map *map,
|
||||
int map_check_no_btf(struct bpf_map *map,
|
||||
const struct btf *btf,
|
||||
const struct btf_type *key_type,
|
||||
const struct btf_type *value_type)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue