@@ -1062,7 +1062,7 @@ static struct bpf_map *prog_array_map_alloc(union bpf_attr *attr)
struct bpf_array_aux *aux;
struct bpf_map *map;
- aux = kzalloc(sizeof(*aux), GFP_KERNEL_ACCOUNT);
+ aux = kzalloc(sizeof(*aux), map_flags_no_charge(GFP_KERNEL, attr));
if (!aux)
return ERR_PTR(-ENOMEM);
@@ -582,11 +582,12 @@ int bpf_local_storage_map_alloc_check(union bpf_attr *attr)
struct bpf_local_storage_map *bpf_local_storage_map_alloc(union bpf_attr *attr)
{
+ gfp_t gfp_flags = map_flags_no_charge(GFP_USER | __GFP_NOWARN, attr);
struct bpf_local_storage_map *smap;
unsigned int i;
u32 nbuckets;
- smap = kzalloc(sizeof(*smap), GFP_USER | __GFP_NOWARN | __GFP_ACCOUNT);
+ smap = kzalloc(sizeof(*smap), gfp_flags);
if (!smap)
return ERR_PTR(-ENOMEM);
bpf_map_init_from_attr(&smap->map, attr);
@@ -597,7 +598,7 @@ struct bpf_local_storage_map *bpf_local_storage_map_alloc(union bpf_attr *attr)
smap->bucket_log = ilog2(nbuckets);
smap->buckets = kvcalloc(sizeof(*smap->buckets), nbuckets,
- GFP_USER | __GFP_NOWARN | __GFP_ACCOUNT);
+ map_flags_no_charge(GFP_USER | __GFP_NOWARN, attr));
if (!smap->buckets) {
kfree(smap);
return ERR_PTR(-ENOMEM);
@@ -99,7 +99,7 @@ static struct bpf_map *cpu_map_alloc(union bpf_attr *attr)
attr->map_flags & ~CPU_MAP_CREATE_FLAG_MASK)
return ERR_PTR(-EINVAL);
- cmap = kzalloc(sizeof(*cmap), GFP_USER | __GFP_ACCOUNT);
+ cmap = kzalloc(sizeof(*cmap), map_flags_no_charge(GFP_USER, attr));
if (!cmap)
return ERR_PTR(-ENOMEM);
@@ -160,7 +160,7 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
if (!capable(CAP_NET_ADMIN))
return ERR_PTR(-EPERM);
- dtab = kzalloc(sizeof(*dtab), GFP_USER | __GFP_ACCOUNT);
+ dtab = kzalloc(sizeof(*dtab), map_flags_no_charge(GFP_USER, attr));
if (!dtab)
return ERR_PTR(-ENOMEM);
@@ -474,7 +474,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
struct bpf_htab *htab;
int err, i;
- htab = kzalloc(sizeof(*htab), GFP_USER | __GFP_ACCOUNT);
+ htab = kzalloc(sizeof(*htab), map_flags_no_charge(GFP_USER, attr));
if (!htab)
return ERR_PTR(-ENOMEM);
@@ -313,7 +313,7 @@ static struct bpf_map *cgroup_storage_map_alloc(union bpf_attr *attr)
return ERR_PTR(-EINVAL);
map = kmalloc_node(sizeof(struct bpf_cgroup_storage_map),
- __GFP_ZERO | GFP_USER | __GFP_ACCOUNT, numa_node);
+ map_flags_no_charge(__GFP_ZERO | GFP_USER, attr), numa_node);
if (!map)
return ERR_PTR(-ENOMEM);
@@ -557,7 +557,7 @@ static struct bpf_map *trie_alloc(union bpf_attr *attr)
attr->value_size > LPM_VAL_SIZE_MAX)
return ERR_PTR(-EINVAL);
- trie = kzalloc(sizeof(*trie), GFP_USER | __GFP_NOWARN | __GFP_ACCOUNT);
+ trie = kzalloc(sizeof(*trie), map_flags_no_charge(GFP_USER | __GFP_NOWARN, attr));
if (!trie)
return ERR_PTR(-ENOMEM);
@@ -60,8 +60,8 @@ struct bpf_ringbuf_hdr {
static struct bpf_ringbuf *bpf_ringbuf_area_alloc(size_t data_sz, union bpf_attr *attr)
{
- const gfp_t flags = GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL |
- __GFP_NOWARN | __GFP_ZERO;
+ const gfp_t flags = map_flags_no_charge(__GFP_RETRY_MAYFAIL |
+ __GFP_NOWARN | __GFP_ZERO, attr);
int nr_meta_pages = RINGBUF_PGOFF + RINGBUF_POS_PAGES;
int nr_data_pages = data_sz >> PAGE_SHIFT;
int nr_pages = nr_meta_pages + nr_data_pages;
@@ -164,7 +164,7 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
return ERR_PTR(-E2BIG);
#endif
- rb_map = kzalloc(sizeof(*rb_map), GFP_USER | __GFP_ACCOUNT);
+ rb_map = kzalloc(sizeof(*rb_map), map_flags_no_charge(GFP_USER, attr));
if (!rb_map)
return ERR_PTR(-ENOMEM);
Some maps have their own ->map_alloc, in which the no charge should also be allowed. Signed-off-by: Yafang Shao <laoar.shao@gmail.com> --- kernel/bpf/arraymap.c | 2 +- kernel/bpf/bpf_local_storage.c | 5 +++-- kernel/bpf/cpumap.c | 2 +- kernel/bpf/devmap.c | 2 +- kernel/bpf/hashtab.c | 2 +- kernel/bpf/local_storage.c | 2 +- kernel/bpf/lpm_trie.c | 2 +- kernel/bpf/ringbuf.c | 6 +++--- 8 files changed, 12 insertions(+), 11 deletions(-)