Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Kumar Kartikeya Dwivedi and committed by
Alexei Starovoitov
ae51772b 1df97a74

+15 -16
+2 -2
include/linux/bpf.h
··· 124 124 u32 (*map_fd_sys_lookup_elem)(void *ptr); 125 125 void (*map_seq_show_elem)(struct bpf_map *map, void *key, 126 126 struct seq_file *m); 127 - int (*map_check_btf)(const struct bpf_map *map, 127 + int (*map_check_btf)(struct bpf_map *map, 128 128 const struct btf *btf, 129 129 const struct btf_type *key_type, 130 130 const struct btf_type *value_type); ··· 656 656 map->ops->map_seq_show_elem; 657 657 } 658 658 659 - int map_check_no_btf(const struct bpf_map *map, 659 + int map_check_no_btf(struct bpf_map *map, 660 660 const struct btf *btf, 661 661 const struct btf_type *key_type, 662 662 const struct btf_type *value_type);
+1 -1
include/linux/bpf_local_storage.h
··· 176 176 void bpf_local_storage_map_free(struct bpf_map *map, 177 177 struct bpf_local_storage_cache *cache); 178 178 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, 180 180 const struct btf *btf, 181 181 const struct btf_type *key_type, 182 182 const struct btf_type *value_type);
+1 -1
kernel/bpf/arena.c
··· 303 303 return -EOPNOTSUPP; 304 304 } 305 305 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, 307 307 const struct btf_type *key_type, const struct btf_type *value_type) 308 308 { 309 309 return 0;
+1 -1
kernel/bpf/arraymap.c
··· 548 548 rcu_read_unlock(); 549 549 } 550 550 551 - static int array_map_check_btf(const struct bpf_map *map, 551 + static int array_map_check_btf(struct bpf_map *map, 552 552 const struct btf *btf, 553 553 const struct btf_type *key_type, 554 554 const struct btf_type *value_type)
+1 -1
kernel/bpf/bloom_filter.c
··· 180 180 return -EINVAL; 181 181 } 182 182 183 - static int bloom_map_check_btf(const struct bpf_map *map, 183 + static int bloom_map_check_btf(struct bpf_map *map, 184 184 const struct btf *btf, 185 185 const struct btf_type *key_type, 186 186 const struct btf_type *value_type)
+1 -1
kernel/bpf/bpf_insn_array.c
··· 98 98 return -EINVAL; 99 99 } 100 100 101 - static int insn_array_check_btf(const struct bpf_map *map, 101 + static int insn_array_check_btf(struct bpf_map *map, 102 102 const struct btf *btf, 103 103 const struct btf_type *key_type, 104 104 const struct btf_type *value_type)
+1 -1
kernel/bpf/bpf_local_storage.c
··· 797 797 return 0; 798 798 } 799 799 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, 801 801 const struct btf *btf, 802 802 const struct btf_type *key_type, 803 803 const struct btf_type *value_type)
+4 -5
kernel/bpf/hashtab.c
··· 496 496 kfree(ctx); 497 497 } 498 498 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 *)) 500 500 { 501 501 u32 key_size = htab->map.key_size; 502 - const struct bpf_mem_alloc *ma; 502 + struct bpf_mem_alloc *ma; 503 503 struct htab_btf_record *hrec; 504 504 int err; 505 505 ··· 518 518 return err; 519 519 } 520 520 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); 523 522 return 0; 524 523 } 525 524 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, 527 526 const struct btf_type *key_type, const struct btf_type *value_type) 528 527 { 529 528 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
+1 -1
kernel/bpf/local_storage.c
··· 364 364 return -EINVAL; 365 365 } 366 366 367 - static int cgroup_storage_check_btf(const struct bpf_map *map, 367 + static int cgroup_storage_check_btf(struct bpf_map *map, 368 368 const struct btf *btf, 369 369 const struct btf_type *key_type, 370 370 const struct btf_type *value_type)
+1 -1
kernel/bpf/lpm_trie.c
··· 751 751 return err; 752 752 } 753 753 754 - static int trie_check_btf(const struct bpf_map *map, 754 + static int trie_check_btf(struct bpf_map *map, 755 755 const struct btf *btf, 756 756 const struct btf_type *key_type, 757 757 const struct btf_type *value_type)
+1 -1
kernel/bpf/syscall.c
··· 1234 1234 } 1235 1235 EXPORT_SYMBOL_GPL(bpf_obj_name_cpy); 1236 1236 1237 - int map_check_no_btf(const struct bpf_map *map, 1237 + int map_check_no_btf(struct bpf_map *map, 1238 1238 const struct btf *btf, 1239 1239 const struct btf_type *key_type, 1240 1240 const struct btf_type *value_type)