From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 2/6] riscv, bpf: Using kvzalloc_objs to allocate cache buffer
Date: Tue, 07 Jul 2026 14:29:07 +0000 [thread overview]
Message-ID: <20260707142908.466981F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707142219.2871758-3-pulehui@huaweicloud.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing `kvfree(jit_data->ctx.offset)` in `bpf_jit_free` causes a memory leak of the JIT context offsets when JIT compilation aborts during subprogram processing.
--
--- Patch [2]: [PATCH bpf-next v5 2/6] riscv, bpf: Using kvzalloc_objs to allocate cache buffer ---
commit a49923246dc7e8b492561a3a183fc88dc6914fa1
Author: Pu Lehui <pulehui@huawei.com>
riscv, bpf: Using kvzalloc_objs to allocate cache buffer
It is unnecessary to allocate continuous physical memory for cache
buffer, and when ebpf program is too large, it may cause memory
allocation failure.
> diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c
> index ce3bd3762e08c..367ae923ea40c 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);
[Severity: High]
This is a pre-existing issue, but does this leak the ctx->offset array if JIT
compilation aborts during subprogram processing?
For subprograms during the first pass (!prog->is_func || extra_pass is false),
bpf_int_jit_compile() returns early, keeping ctx->offset alive for the
subsequent extra pass.
If a later subprogram fails JIT compilation, the BPF core aborts and calls
bpf_jit_free() to clean up the first subprogram:
arch/riscv/net/bpf_jit_core.c:bpf_jit_free() {
...
if (jit_data) {
bpf_jit_binary_pack_finalize(jit_data->ro_header, jit_data->header);
kfree(jit_data);
}
...
}
It appears jit_data->ctx.offset is not freed during this cleanup, which could
lead to a memory leak.
> if (!ctx->offset)
> goto out_offset;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707142219.2871758-1-pulehui@huaweicloud.com?part=2
next prev parent reply other threads:[~2026-07-07 14:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 14:22 [PATCH bpf-next v5 0/6] Mixing bpf2bpf and tailcalls for RV64 Pu Lehui
2026-07-07 14:22 ` [PATCH bpf-next v5 1/6] bpf: Extract the is_struct_ops_tramp helper Pu Lehui
2026-07-07 14:22 ` [PATCH bpf-next v5 2/6] riscv, bpf: Using kvzalloc_objs to allocate cache buffer Pu Lehui
2026-07-07 14:29 ` sashiko-bot [this message]
2026-07-08 2:57 ` Pu Lehui
2026-07-07 14:22 ` [PATCH bpf-next v5 3/6] riscv, bpf: Fix kernel stack corruption in tailcall with CFI Pu Lehui
2026-07-07 14:22 ` [PATCH bpf-next v5 4/6] riscv, bpf: Add RV_TAILCALL_OFFSET macro to format tailcall offset Pu Lehui
2026-07-07 14:22 ` [PATCH bpf-next v5 5/6] riscv, bpf: Mixing bpf2bpf and tailcalls Pu Lehui
2026-07-07 14:49 ` sashiko-bot
2026-07-08 2:39 ` Pu Lehui
2026-07-07 14:22 ` [PATCH bpf-next v5 6/6] selftests/bpf: Remove tailcalls tests from DENYLIST.riscv64 Pu Lehui
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=20260707142908.466981F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=pulehui@huaweicloud.com \
--cc=sashiko-reviews@lists.linux.dev \
/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