[PATCH bpf-next v6 3/7] riscv, bpf: Using kvzalloc_objs to allocate cache buffer
Pu Lehui
pulehui at huaweicloud.com
Tue Jul 7 23:44:32 PDT 2026
From: Pu Lehui <pulehui at 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.
Acked-by: Björn Töpel <bjorn at kernel.org>
Signed-off-by: Pu Lehui <pulehui at huawei.com>
---
arch/riscv/net/bpf_jit_comp64.c | 4 ++--
arch/riscv/net/bpf_jit_core.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 406e774b4ac3..2f06752fb036 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1195,7 +1195,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
}
if (fmod_ret->nr_nodes) {
- branches_off = kzalloc_objs(int, fmod_ret->nr_nodes);
+ branches_off = kvzalloc_objs(int, fmod_ret->nr_nodes);
if (!branches_off)
return -ENOMEM;
@@ -1300,7 +1300,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 7cce19118619..cbfcd287ea16 100644
--- a/arch/riscv/net/bpf_jit_core.c
+++ b/arch/riscv/net/bpf_jit_core.c
@@ -72,7 +72,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
ctx->arena_vm_start = bpf_arena_get_kern_vm_start(prog->aux->arena);
ctx->user_vm_start = bpf_arena_get_user_vm_start(prog->aux->arena);
ctx->prog = prog;
- ctx->offset = kzalloc_objs(int, prog->len);
+ ctx->offset = kvzalloc_objs(int, prog->len);
if (!ctx->offset)
goto out_offset;
@@ -170,7 +170,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
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;
}
@@ -234,7 +234,7 @@ void bpf_jit_free(struct bpf_prog *prog)
*/
if (jit_data) {
bpf_jit_binary_pack_finalize(jit_data->ro_header, jit_data->header);
- kfree(jit_data->ctx.offset);
+ kvfree(jit_data->ctx.offset);
kfree(jit_data);
}
hdr = bpf_jit_binary_pack_hdr(prog);
--
2.34.1
More information about the linux-riscv
mailing list