Commit 0d2c4f96 authored by Roman Gushchin's avatar Roman Gushchin Committed by Alexei Starovoitov

bpf: Eliminate rlimit-based memory accounting for sockmap and sockhash maps

Do not use rlimit-based memory accounting for sockmap and sockhash 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-29-guro@fb.com
parent abbdd081
...@@ -27,8 +27,6 @@ struct bpf_stab { ...@@ -27,8 +27,6 @@ struct bpf_stab {
static struct bpf_map *sock_map_alloc(union bpf_attr *attr) static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
{ {
struct bpf_stab *stab; struct bpf_stab *stab;
u64 cost;
int err;
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
...@@ -46,22 +44,15 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr) ...@@ -46,22 +44,15 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
bpf_map_init_from_attr(&stab->map, attr); bpf_map_init_from_attr(&stab->map, attr);
raw_spin_lock_init(&stab->lock); raw_spin_lock_init(&stab->lock);
/* Make sure page count doesn't overflow. */
cost = (u64) stab->map.max_entries * sizeof(struct sock *);
err = bpf_map_charge_init(&stab->map.memory, cost);
if (err)
goto free_stab;
stab->sks = bpf_map_area_alloc(stab->map.max_entries * stab->sks = bpf_map_area_alloc(stab->map.max_entries *
sizeof(struct sock *), sizeof(struct sock *),
stab->map.numa_node); stab->map.numa_node);
if (stab->sks) if (!stab->sks) {
return &stab->map;
err = -ENOMEM;
bpf_map_charge_finish(&stab->map.memory);
free_stab:
kfree(stab); kfree(stab);
return ERR_PTR(err); return ERR_PTR(-ENOMEM);
}
return &stab->map;
} }
int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *prog) int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *prog)
...@@ -1104,7 +1095,6 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr) ...@@ -1104,7 +1095,6 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
{ {
struct bpf_shtab *htab; struct bpf_shtab *htab;
int i, err; int i, err;
u64 cost;
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
...@@ -1132,21 +1122,10 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr) ...@@ -1132,21 +1122,10 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
goto free_htab; goto free_htab;
} }
cost = (u64) htab->buckets_num * sizeof(struct bpf_shtab_bucket) +
(u64) htab->elem_size * htab->map.max_entries;
if (cost >= U32_MAX - PAGE_SIZE) {
err = -EINVAL;
goto free_htab;
}
err = bpf_map_charge_init(&htab->map.memory, cost);
if (err)
goto free_htab;
htab->buckets = bpf_map_area_alloc(htab->buckets_num * htab->buckets = bpf_map_area_alloc(htab->buckets_num *
sizeof(struct bpf_shtab_bucket), sizeof(struct bpf_shtab_bucket),
htab->map.numa_node); htab->map.numa_node);
if (!htab->buckets) { if (!htab->buckets) {
bpf_map_charge_finish(&htab->map.memory);
err = -ENOMEM; err = -ENOMEM;
goto free_htab; goto free_htab;
} }
......
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