From: Pu Lehui <pulehui@huaweicloud.com>
To: bpf@vger.kernel.org, linux-riscv@lists.infradead.org,
netdev@vger.kernel.org
Cc: "Björn Töpel" <bjorn@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>, "Yonghong Song" <yhs@fb.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@google.com>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Conor Dooley" <conor@kernel.org>,
"Luke Nelson" <luke.r.nels@gmail.com>,
"Pu Lehui" <pulehui@huawei.com>,
"Pu Lehui" <pulehui@huaweicloud.com>
Subject: [PATCH bpf-next 2/4] riscv, bpf: Using kvcalloc to allocate cache buffer
Date: Tue, 19 Sep 2023 11:57:09 +0800 [thread overview]
Message-ID: <20230919035711.3297256-3-pulehui@huaweicloud.com> (raw)
In-Reply-To: <20230919035711.3297256-1-pulehui@huaweicloud.com>
From: Pu Lehui <pulehui@huawei.com>
It is unnecessary to allocate continuous physical memory for cache
buffer, and when ebpf program is too large, it may cause memory
allocation failure.
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
arch/riscv/net/bpf_jit_comp64.c | 4 ++--
arch/riscv/net/bpf_jit_core.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 8423f4ddf..57535cfe1 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -906,7 +906,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
}
if (fmod_ret->nr_links) {
- branches_off = kcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
+ branches_off = kvcalloc(fmod_ret->nr_links, sizeof(int), GFP_KERNEL);
if (!branches_off)
return -ENOMEM;
@@ -993,7 +993,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
ret = ctx->ninsns;
out:
- kfree(branches_off);
+ kvfree(branches_off);
return ret;
}
diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c
index dd00103a2..d9c82537d 100644
--- a/arch/riscv/net/bpf_jit_core.c
+++ b/arch/riscv/net/bpf_jit_core.c
@@ -78,7 +78,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
}
ctx->prog = prog;
- ctx->offset = kcalloc(prog->len, sizeof(int), GFP_KERNEL);
+ ctx->offset = kvcalloc(prog->len, sizeof(int), GFP_KERNEL);
if (!ctx->offset) {
prog = orig_prog;
goto out_offset;
@@ -170,7 +170,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
ctx->offset[i] = ninsns_rvoff(ctx->offset[i]);
bpf_prog_fill_jited_linfo(prog, ctx->offset);
out_offset:
- kfree(ctx->offset);
+ kvfree(ctx->offset);
kfree(jit_data);
prog->aux->jit_data = NULL;
}
--
2.25.1
next prev parent reply other threads:[~2023-09-19 3:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 3:57 [PATCH bpf-next 0/4] Mixing bpf2bpf and tailcalls for RV64 Pu Lehui
2023-09-19 3:57 ` [PATCH bpf-next 1/4] riscv, bpf: Remove redundant ctx->offset initialization Pu Lehui
2023-09-19 3:57 ` Pu Lehui [this message]
2023-09-19 3:57 ` [PATCH bpf-next 3/4] riscv, bpf: Add RV_TAILCALL_OFFSET macro to format tailcall offset Pu Lehui
2023-09-19 3:57 ` [PATCH bpf-next 4/4] riscv, bpf: Mixing bpf2bpf and tailcalls Pu Lehui
2023-09-19 10:04 ` Conor Dooley
2023-09-19 10:54 ` Conor Dooley
2023-09-19 11:23 ` Pu Lehui
2023-09-19 11:50 ` Conor Dooley
2023-09-19 12:01 ` Pu Lehui
2023-09-28 9:59 ` Björn Töpel
2023-09-28 10:39 ` Pu Lehui
2024-01-16 14:21 ` Pu Lehui
2024-01-30 8:29 ` Björn Töpel
2024-01-30 9:14 ` Pu Lehui
2024-01-30 13:28 ` Björn Töpel
2024-01-30 14:10 ` Pu Lehui
2024-01-30 16:03 ` Björn Töpel
2024-01-31 9:18 ` Pu Lehui
2024-01-30 3:26 ` Pu Lehui
2023-09-26 13:30 ` [PATCH bpf-next 0/4] Mixing bpf2bpf and tailcalls for RV64 Björn Töpel
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=20230919035711.3297256-3-pulehui@huaweicloud.com \
--to=pulehui@huaweicloud.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=conor@kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=luke.r.nels@gmail.com \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=palmer@dabbelt.com \
--cc=pulehui@huawei.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).