mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
bpf: Remove __bpf_local_storage_map_alloc
[ Upstream commit 62827d612a ]
bpf_local_storage_map_alloc() is the only caller of
__bpf_local_storage_map_alloc(). The remaining logic in
bpf_local_storage_map_alloc() is only a one liner setting
the smap->cache_idx.
Remove __bpf_local_storage_map_alloc() to simplify code.
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20230308065936.1550103-4-martin.lau@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Stable-dep-of: af253aef183a ("bpf: fix order of args in call to bpf_map_kvcalloc")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
902219ed3f
commit
d71bed34bc
@@ -552,40 +552,6 @@ int bpf_local_storage_map_alloc_check(union bpf_attr *attr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bpf_local_storage_map *__bpf_local_storage_map_alloc(union bpf_attr *attr)
|
|
||||||
{
|
|
||||||
struct bpf_local_storage_map *smap;
|
|
||||||
unsigned int i;
|
|
||||||
u32 nbuckets;
|
|
||||||
|
|
||||||
smap = bpf_map_area_alloc(sizeof(*smap), NUMA_NO_NODE);
|
|
||||||
if (!smap)
|
|
||||||
return ERR_PTR(-ENOMEM);
|
|
||||||
bpf_map_init_from_attr(&smap->map, attr);
|
|
||||||
|
|
||||||
nbuckets = roundup_pow_of_two(num_possible_cpus());
|
|
||||||
/* Use at least 2 buckets, select_bucket() is undefined behavior with 1 bucket */
|
|
||||||
nbuckets = max_t(u32, 2, nbuckets);
|
|
||||||
smap->bucket_log = ilog2(nbuckets);
|
|
||||||
|
|
||||||
smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
|
|
||||||
nbuckets, GFP_USER | __GFP_NOWARN);
|
|
||||||
if (!smap->buckets) {
|
|
||||||
bpf_map_area_free(smap);
|
|
||||||
return ERR_PTR(-ENOMEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < nbuckets; i++) {
|
|
||||||
INIT_HLIST_HEAD(&smap->buckets[i].list);
|
|
||||||
raw_spin_lock_init(&smap->buckets[i].lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
smap->elem_size = offsetof(struct bpf_local_storage_elem,
|
|
||||||
sdata.data[attr->value_size]);
|
|
||||||
|
|
||||||
return smap;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_local_storage_map_check_btf(const struct bpf_map *map,
|
int bpf_local_storage_map_check_btf(const struct bpf_map *map,
|
||||||
const struct btf *btf,
|
const struct btf *btf,
|
||||||
const struct btf_type *key_type,
|
const struct btf_type *key_type,
|
||||||
@@ -641,10 +607,33 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
|
|||||||
struct bpf_local_storage_cache *cache)
|
struct bpf_local_storage_cache *cache)
|
||||||
{
|
{
|
||||||
struct bpf_local_storage_map *smap;
|
struct bpf_local_storage_map *smap;
|
||||||
|
unsigned int i;
|
||||||
|
u32 nbuckets;
|
||||||
|
|
||||||
smap = __bpf_local_storage_map_alloc(attr);
|
smap = bpf_map_area_alloc(sizeof(*smap), NUMA_NO_NODE);
|
||||||
if (IS_ERR(smap))
|
if (!smap)
|
||||||
return ERR_CAST(smap);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
bpf_map_init_from_attr(&smap->map, attr);
|
||||||
|
|
||||||
|
nbuckets = roundup_pow_of_two(num_possible_cpus());
|
||||||
|
/* Use at least 2 buckets, select_bucket() is undefined behavior with 1 bucket */
|
||||||
|
nbuckets = max_t(u32, 2, nbuckets);
|
||||||
|
smap->bucket_log = ilog2(nbuckets);
|
||||||
|
|
||||||
|
smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
|
||||||
|
nbuckets, GFP_USER | __GFP_NOWARN);
|
||||||
|
if (!smap->buckets) {
|
||||||
|
bpf_map_area_free(smap);
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < nbuckets; i++) {
|
||||||
|
INIT_HLIST_HEAD(&smap->buckets[i].list);
|
||||||
|
raw_spin_lock_init(&smap->buckets[i].lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
smap->elem_size = offsetof(struct bpf_local_storage_elem,
|
||||||
|
sdata.data[attr->value_size]);
|
||||||
|
|
||||||
smap->cache_idx = bpf_local_storage_cache_idx_get(cache);
|
smap->cache_idx = bpf_local_storage_cache_idx_get(cache);
|
||||||
return &smap->map;
|
return &smap->map;
|
||||||
|
|||||||
Reference in New Issue
Block a user