Skip to content

Commit ae51772

Browse files
kkdwvdAlexei Starovoitov
authored andcommitted
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>
1 parent 1df97a7 commit ae51772

11 files changed

Lines changed: 15 additions & 16 deletions

File tree

include/linux/bpf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct bpf_map_ops {
124124
u32 (*map_fd_sys_lookup_elem)(void *ptr);
125125
void (*map_seq_show_elem)(struct bpf_map *map, void *key,
126126
struct seq_file *m);
127-
int (*map_check_btf)(const struct bpf_map *map,
127+
int (*map_check_btf)(struct bpf_map *map,
128128
const struct btf *btf,
129129
const struct btf_type *key_type,
130130
const struct btf_type *value_type);
@@ -656,7 +656,7 @@ static inline bool bpf_map_support_seq_show(const struct bpf_map *map)
656656
map->ops->map_seq_show_elem;
657657
}
658658

659-
int map_check_no_btf(const struct bpf_map *map,
659+
int map_check_no_btf(struct bpf_map *map,
660660
const struct btf *btf,
661661
const struct btf_type *key_type,
662662
const struct btf_type *value_type);

include/linux/bpf_local_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ u32 bpf_local_storage_destroy(struct bpf_local_storage *local_storage);
176176
void bpf_local_storage_map_free(struct bpf_map *map,
177177
struct bpf_local_storage_cache *cache);
178178

179-
int bpf_local_storage_map_check_btf(const struct bpf_map *map,
179+
int bpf_local_storage_map_check_btf(struct bpf_map *map,
180180
const struct btf *btf,
181181
const struct btf_type *key_type,
182182
const struct btf_type *value_type);

kernel/bpf/arena.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static long arena_map_update_elem(struct bpf_map *map, void *key,
303303
return -EOPNOTSUPP;
304304
}
305305

306-
static int arena_map_check_btf(const struct bpf_map *map, const struct btf *btf,
306+
static int arena_map_check_btf(struct bpf_map *map, const struct btf *btf,
307307
const struct btf_type *key_type, const struct btf_type *value_type)
308308
{
309309
return 0;

kernel/bpf/arraymap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ static void percpu_array_map_seq_show_elem(struct bpf_map *map, void *key,
548548
rcu_read_unlock();
549549
}
550550

551-
static int array_map_check_btf(const struct bpf_map *map,
551+
static int array_map_check_btf(struct bpf_map *map,
552552
const struct btf *btf,
553553
const struct btf_type *key_type,
554554
const struct btf_type *value_type)

kernel/bpf/bloom_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static long bloom_map_update_elem(struct bpf_map *map, void *key,
180180
return -EINVAL;
181181
}
182182

183-
static int bloom_map_check_btf(const struct bpf_map *map,
183+
static int bloom_map_check_btf(struct bpf_map *map,
184184
const struct btf *btf,
185185
const struct btf_type *key_type,
186186
const struct btf_type *value_type)

kernel/bpf/bpf_insn_array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static long insn_array_delete_elem(struct bpf_map *map, void *key)
9898
return -EINVAL;
9999
}
100100

101-
static int insn_array_check_btf(const struct bpf_map *map,
101+
static int insn_array_check_btf(struct bpf_map *map,
102102
const struct btf *btf,
103103
const struct btf_type *key_type,
104104
const struct btf_type *value_type)

kernel/bpf/bpf_local_storage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ int bpf_local_storage_map_alloc_check(union bpf_attr *attr)
797797
return 0;
798798
}
799799

800-
int bpf_local_storage_map_check_btf(const struct bpf_map *map,
800+
int bpf_local_storage_map_check_btf(struct bpf_map *map,
801801
const struct btf *btf,
802802
const struct btf_type *key_type,
803803
const struct btf_type *value_type)

kernel/bpf/hashtab.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,10 @@ static void htab_dtor_ctx_free(void *ctx)
496496
kfree(ctx);
497497
}
498498

499-
static int htab_set_dtor(const struct bpf_htab *htab, void (*dtor)(void *, void *))
499+
static int htab_set_dtor(struct bpf_htab *htab, void (*dtor)(void *, void *))
500500
{
501501
u32 key_size = htab->map.key_size;
502-
const struct bpf_mem_alloc *ma;
502+
struct bpf_mem_alloc *ma;
503503
struct htab_btf_record *hrec;
504504
int err;
505505

@@ -518,12 +518,11 @@ static int htab_set_dtor(const struct bpf_htab *htab, void (*dtor)(void *, void
518518
return err;
519519
}
520520
ma = htab_is_percpu(htab) ? &htab->pcpu_ma : &htab->ma;
521-
/* Kinda sad, but cast away const-ness since we change ma->dtor. */
522-
bpf_mem_alloc_set_dtor((struct bpf_mem_alloc *)ma, dtor, htab_dtor_ctx_free, hrec);
521+
bpf_mem_alloc_set_dtor(ma, dtor, htab_dtor_ctx_free, hrec);
523522
return 0;
524523
}
525524

526-
static int htab_map_check_btf(const struct bpf_map *map, const struct btf *btf,
525+
static int htab_map_check_btf(struct bpf_map *map, const struct btf *btf,
527526
const struct btf_type *key_type, const struct btf_type *value_type)
528527
{
529528
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);

kernel/bpf/local_storage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static long cgroup_storage_delete_elem(struct bpf_map *map, void *key)
364364
return -EINVAL;
365365
}
366366

367-
static int cgroup_storage_check_btf(const struct bpf_map *map,
367+
static int cgroup_storage_check_btf(struct bpf_map *map,
368368
const struct btf *btf,
369369
const struct btf_type *key_type,
370370
const struct btf_type *value_type)

kernel/bpf/lpm_trie.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key)
751751
return err;
752752
}
753753

754-
static int trie_check_btf(const struct bpf_map *map,
754+
static int trie_check_btf(struct bpf_map *map,
755755
const struct btf *btf,
756756
const struct btf_type *key_type,
757757
const struct btf_type *value_type)

0 commit comments

Comments
 (0)