]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpf: Lose const-ness of map in map_check_btf()
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Fri, 27 Feb 2026 22:48:02 +0000 (14:48 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 27 Feb 2026 23:39:00 +0000 (15:39 -0800)
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>
include/linux/bpf.h
include/linux/bpf_local_storage.h
kernel/bpf/arena.c
kernel/bpf/arraymap.c
kernel/bpf/bloom_filter.c
kernel/bpf/bpf_insn_array.c
kernel/bpf/bpf_local_storage.c
kernel/bpf/hashtab.c
kernel/bpf/local_storage.c
kernel/bpf/lpm_trie.c
kernel/bpf/syscall.c

index b78b53198a2ef99b0b3d110e75499b56d058096f..05b34a6355b0350fd2d52e27e972f7217e6f833a 100644 (file)
@@ -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);
index 85efa97725302cd39ddbd268e4340a7488d11be4..8157e8da61d40cb8cf218e3fccc2b052ed26928f 100644 (file)
@@ -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);
index 144f30e740e88ac544f2606de3c194f36ed4680b..f355cf1c1a1693c5ace9e444069c421506b0cc16 100644 (file)
@@ -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;
index 26763df6134a7a4b85cdeffbc2ec4350ecc17346..33de68c95ad8c156ba86f06738fc2e83240299b4 100644 (file)
@@ -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)
index 35e1ddca74d21067bc158436470138f0b2ad984c..b73336c976b7c3799798a4147bc3f7e2a776d99c 100644 (file)
@@ -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)
index c0286f25ca3c6173694ab5efa3cb79eb2c5faf07..a2f84afe6f7c65e7f88db46dce47297a89ab7634 100644 (file)
@@ -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)
index b28f07d3a0dbc51005b9441d165c14a4c37bb54d..2bf5ca5ae0dfd5ccdc3104ccd56b6810c65a16aa 100644 (file)
@@ -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)
index 582f0192b7e1388bd84e497939ea9aa63fc56b68..bc6bc8bb871d412443c0393ac2cf475b1ccef93e 100644 (file)
@@ -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);
index 1ccbf28b2ad9f1b200b96fbcdeca17c456fc2c7b..8fca0c64f7b1cdb7980f1fa53126e35c005ba574 100644 (file)
@@ -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)
index 1adeb4d3b8cf4a958d79091a27cde10421aaabbc..0f57608b385d43212b72c8e3bb866009245a109c 100644 (file)
@@ -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)
index 0378e83b40993e7b1f250459d766fa93ff248713..274039e36465dfe4d79f20c3bb39a77a104ad36b 100644 (file)
@@ -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)