Skip to content

Commit

Permalink
bpf: add memlock precharge check for cgroup_local_storage
Browse files Browse the repository at this point in the history
ANBZ: torvalds#26

commit ffc8b14 upstream

Cgroup local storage maps lack the memlock precharge check,
which is performed before the memory allocation for
most other bpf map types.

Let's add it in order to unify all map types.

Signed-off-by: Roman Gushchin <guro@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Qiao Ma <mqaio@linux.alibaba.com>
Acked-by: Tony Lu <tonylu@linux.alibaba.com>
  • Loading branch information
rgushchin authored and maqiao-mq committed Dec 10, 2021
1 parent 0b19de5 commit a4fdc7a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions kernel/bpf/local_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ static struct bpf_map *cgroup_storage_map_alloc(union bpf_attr *attr)
{
int numa_node = bpf_map_attr_numa_node(attr);
struct bpf_cgroup_storage_map *map;
u32 pages;
int ret;

if (attr->key_size != sizeof(struct bpf_cgroup_storage_key))
return ERR_PTR(-EINVAL);
Expand All @@ -210,13 +212,18 @@ static struct bpf_map *cgroup_storage_map_alloc(union bpf_attr *attr)
/* max_entries is not used and enforced to be 0 */
return ERR_PTR(-EINVAL);

pages = round_up(sizeof(struct bpf_cgroup_storage_map), PAGE_SIZE) >>
PAGE_SHIFT;
ret = bpf_map_precharge_memlock(pages);
if (ret < 0)
return ERR_PTR(ret);

map = kmalloc_node(sizeof(struct bpf_cgroup_storage_map),
__GFP_ZERO | GFP_USER, numa_node);
if (!map)
return ERR_PTR(-ENOMEM);

map->map.pages = round_up(sizeof(struct bpf_cgroup_storage_map),
PAGE_SIZE) >> PAGE_SHIFT;
map->map.pages = pages;

/* copy mandatory map attributes */
bpf_map_init_from_attr(&map->map, attr);
Expand Down

0 comments on commit a4fdc7a

Please sign in to comment.