Commit f043733f authored by Roman Gushchin's avatar Roman Gushchin Committed by Alexei Starovoitov

bpf: Eliminate rlimit-based memory accounting for bpf_struct_ops maps

Do not use rlimit-based memory accounting for bpf_struct_ops maps.
It has been replaced with the memcg-based memory accounting.
Signed-off-by: default avatarRoman Gushchin <guro@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20201201215900.3569844-20-guro@fb.com
parent 1bc59756
...@@ -548,12 +548,10 @@ static int bpf_struct_ops_map_alloc_check(union bpf_attr *attr) ...@@ -548,12 +548,10 @@ static int bpf_struct_ops_map_alloc_check(union bpf_attr *attr)
static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr) static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
{ {
const struct bpf_struct_ops *st_ops; const struct bpf_struct_ops *st_ops;
size_t map_total_size, st_map_size; size_t st_map_size;
struct bpf_struct_ops_map *st_map; struct bpf_struct_ops_map *st_map;
const struct btf_type *t, *vt; const struct btf_type *t, *vt;
struct bpf_map_memory mem;
struct bpf_map *map; struct bpf_map *map;
int err;
if (!bpf_capable()) if (!bpf_capable())
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
...@@ -573,20 +571,11 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr) ...@@ -573,20 +571,11 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
* struct bpf_struct_ops_tcp_congestions_ops * struct bpf_struct_ops_tcp_congestions_ops
*/ */
(vt->size - sizeof(struct bpf_struct_ops_value)); (vt->size - sizeof(struct bpf_struct_ops_value));
map_total_size = st_map_size +
/* uvalue */
sizeof(vt->size) +
/* struct bpf_progs **progs */
btf_type_vlen(t) * sizeof(struct bpf_prog *);
err = bpf_map_charge_init(&mem, map_total_size);
if (err < 0)
return ERR_PTR(err);
st_map = bpf_map_area_alloc(st_map_size, NUMA_NO_NODE); st_map = bpf_map_area_alloc(st_map_size, NUMA_NO_NODE);
if (!st_map) { if (!st_map)
bpf_map_charge_finish(&mem);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
}
st_map->st_ops = st_ops; st_map->st_ops = st_ops;
map = &st_map->map; map = &st_map->map;
...@@ -597,14 +586,12 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr) ...@@ -597,14 +586,12 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
st_map->image = bpf_jit_alloc_exec(PAGE_SIZE); st_map->image = bpf_jit_alloc_exec(PAGE_SIZE);
if (!st_map->uvalue || !st_map->progs || !st_map->image) { if (!st_map->uvalue || !st_map->progs || !st_map->image) {
bpf_struct_ops_map_free(map); bpf_struct_ops_map_free(map);
bpf_map_charge_finish(&mem);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
mutex_init(&st_map->lock); mutex_init(&st_map->lock);
set_vm_flush_reset_perms(st_map->image); set_vm_flush_reset_perms(st_map->image);
bpf_map_init_from_attr(map, attr); bpf_map_init_from_attr(map, attr);
bpf_map_charge_move(&map->memory, &mem);
return map; return map;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment