diff options
author | Yafang Shao <laoar.shao@gmail.com> | 2023-03-05 12:46:15 +0000 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2023-03-07 09:33:43 -0800 |
commit | 6b4a6ea2c62d34272d64161d43a19c02355576e2 (patch) | |
tree | 33e31263163cc0d003c2942de91b147606a60e38 /kernel/bpf | |
parent | 9629363cd05642fe43aded44938adec067ad1da3 (diff) | |
download | linux-stable-6b4a6ea2c62d34272d64161d43a19c02355576e2.tar.gz linux-stable-6b4a6ea2c62d34272d64161d43a19c02355576e2.tar.bz2 linux-stable-6b4a6ea2c62d34272d64161d43a19c02355576e2.zip |
bpf: enforce all maps having memory usage callback
We have implemented memory usage callback for all maps, and we enforce
any newly added map having a callback as well. We check this callback at
map creation time. If it doesn't have the callback, we will return
EINVAL.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Link: https://lore.kernel.org/r/20230305124615.12358-19-laoar.shao@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf')
-rw-r--r-- | kernel/bpf/syscall.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 053409d951d2..f406dfa13792 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -129,6 +129,8 @@ static struct bpf_map *find_and_alloc_map(union bpf_attr *attr) } if (attr->map_ifindex) ops = &bpf_map_offload_ops; + if (!ops->map_mem_usage) + return ERR_PTR(-EINVAL); map = ops->map_alloc(attr); if (IS_ERR(map)) return map; @@ -775,13 +777,7 @@ static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f) /* Show the memory usage of a bpf map */ static u64 bpf_map_memory_usage(const struct bpf_map *map) { - unsigned long size; - - if (map->ops->map_mem_usage) - return map->ops->map_mem_usage(map); - - size = round_up(map->key_size + bpf_map_value_size(map), 8); - return round_up(map->max_entries * size, PAGE_SIZE); + return map->ops->map_mem_usage(map); } static void bpf_map_show_fdinfo(struct seq_file *m, struct file *filp) |