From: Yafang Shao <laoar.shao@gmail.com>
To: roman.gushchin@linux.dev, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, kafai@fb.com, songliubraving@fb.com,
yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org,
shuah@kernel.org
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCH 07/14] bpf: Allow no charge in map specific allocation
Date: Sat, 19 Mar 2022 17:30:29 +0000 [thread overview]
Message-ID: <20220319173036.23352-8-laoar.shao@gmail.com> (raw)
In-Reply-To: <20220319173036.23352-1-laoar.shao@gmail.com>
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(-)
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index e26aef906392..9df425ad769c 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -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);
diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index a92d3032fcde..b626546d384d 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -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);
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index 5a5b40e986ff..fd3b3f05e76a 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -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);
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 2857176c82bb..6aaa2e3ce795 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -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);
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 2c84045ff8e1..74696d8196a5 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -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);
diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
index 865766c240d6..741ab7cf3626 100644
--- a/kernel/bpf/local_storage.c
+++ b/kernel/bpf/local_storage.c
@@ -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);
diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c
index f42edf613624..9673f8e98c58 100644
--- a/kernel/bpf/lpm_trie.c
+++ b/kernel/bpf/lpm_trie.c
@@ -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);
diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
index a3b4d2a0a2c7..3db07cd0ab60 100644
--- a/kernel/bpf/ringbuf.c
+++ b/kernel/bpf/ringbuf.c
@@ -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);
--
2.17.1
next prev parent reply other threads:[~2022-03-19 17:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-19 17:30 [PATCH 00/14] bpf: Allow not to charge bpf memory Yafang Shao
2022-03-19 17:30 ` [PATCH 01/14] bpf: Introduce no charge flag for bpf map Yafang Shao
2022-03-19 17:30 ` [PATCH 02/14] bpf: Only sys admin can set no charge flag Yafang Shao
2022-03-19 17:30 ` [PATCH 03/14] bpf: Enable no charge in map _CREATE_FLAG_MASK Yafang Shao
2022-03-19 17:30 ` [PATCH 04/14] bpf: Introduce new parameter bpf_attr in bpf_map_area_alloc Yafang Shao
2022-03-19 17:30 ` [PATCH 05/14] bpf: Allow no charge " Yafang Shao
2022-03-19 17:30 ` [PATCH 06/14] bpf: Allow no charge for allocation not at map creation time Yafang Shao
2022-03-19 17:30 ` Yafang Shao [this message]
2022-03-19 17:30 ` [PATCH 08/14] bpf: Aggregate flags for BPF_PROG_LOAD command Yafang Shao
2022-03-19 17:30 ` [PATCH 09/14] bpf: Add no charge flag for bpf prog Yafang Shao
2022-03-19 17:30 ` [PATCH 10/14] bpf: Only sys admin can set " Yafang Shao
2022-03-19 17:30 ` [PATCH 11/14] bpf: Set __GFP_ACCOUNT at the callsite of bpf_prog_alloc Yafang Shao
2022-03-19 17:30 ` [PATCH 12/14] bpf: Allow no charge for bpf prog Yafang Shao
2022-03-19 17:30 ` [PATCH 13/14] bpf: selftests: Add test case for BPF_F_NO_CHARTE Yafang Shao
2022-03-19 17:30 ` [PATCH 14/14] bpf: selftests: Add test case for BPF_F_PROG_NO_CHARGE Yafang Shao
2022-03-21 22:52 ` [PATCH 00/14] bpf: Allow not to charge bpf memory Roman Gushchin
2022-03-22 16:10 ` Yafang Shao
2022-03-22 19:10 ` Roman Gushchin
2022-03-23 1:37 ` Yafang Shao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220319173036.23352-8-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=roman.gushchin@linux.dev \
--cc=shuah@kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox