BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Emil Tsalapatis" <emil@etsalapatis.com>
Cc: bpf@vger.kernel.org
Subject: Re: [RESEND PATCH bpf-next v6 5/7] bpf: Directly store kfunc desc index in instruction off field
Date: Fri, 02 Oct 2026 11:06:37 +0000	[thread overview]
Message-ID: <20261002110638.65E041F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261002105218.6171-6-emil@etsalapatis.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] bpf: JIT compilation fails for kfuncs emitted in prologues
--

commit ba562be891ad9f52f9742001cfab2a791d6aefb8
Author: Emil Tsalapatis <emil@etsalapatis.com>

bpf: Directly store kfunc desc index in instruction off field
    
This patch modifies the verifier to store the kfunc descriptor index directly
in the instruction's off field. It removes the need to sort the descriptor
table twice, simplifying subsequent function specialization patches.

> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> index 37cf130ebb57b..cb7219ff68bd1 100644
> --- a/kernel/bpf/fixups.c
> +++ b/kernel/bpf/fixups.c

[ ... ]

>  const struct btf_func_model *
>  bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
>  			 const struct bpf_insn *insn)
>  {
[ ... ]
>  	tab = prog->aux->kfunc_tab;
> -	res = bsearch(&desc, tab->descs, tab->nr_descs,
> -		      sizeof(tab->descs[0]), kfunc_desc_cmp_by_imm_off);
> -
> -	return res ? &res->func_model : NULL;
> -}
[ ... ]
> +	if (insn->off < 0 || insn->off >= tab->nr_descs)
> +		return NULL;
>  
> +	res = &tab->descs[insn->off];
>  	if (bpf_jit_supports_far_kfunc_call()) {
> +		if (res->func_id != insn->imm)
> +			return NULL;

[Severity: Medium]
Will this lead to a JIT failure for kfuncs emitted in prologues or
epilogues?

When bpf_convert_ctx_accesses() calls gen_prologue(), it can emit a kfunc
call where insn->off is 0. This is then processed by add_kfunc_in_insns(),
which calls bpf_add_kfunc_call() to register the kfunc:

kernel/bpf/fixups.c:add_kfunc_in_insns() {
	...
	for (i = 0; i < cnt; i++, insn++) {
		if (bpf_pseudo_kfunc_call(insn)) {
			ret = bpf_add_kfunc_call(env, insn->imm, insn->off);
			if (ret < 0)
				return ret;
		}
	}
	...
}

However, add_kfunc_in_insns() does not update insn->off to the descriptor
index returned by bpf_add_kfunc_call().

Later, when the JIT compiler calls bpf_jit_find_kfunc_model() and uses
insn->off (which is still 0) to fetch the descriptor, could it fetch the
wrong descriptor and abort the compilation due to a func_id mismatch?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261002105218.6171-1-emil@etsalapatis.com?part=5

  reply	other threads:[~2026-10-02 11:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 10:52 [RESEND PATCH bpf-next v6 0/7] Make sleepable arena paths use sleepable alloc_pages Emil Tsalapatis
2026-10-02 10:52 ` [RESEND PATCH bpf-next v6 1/7] bpf: Use an llist for page allocations Emil Tsalapatis
2026-10-02 10:52 ` [RESEND PATCH bpf-next v6 2/7] bpf: Add sleepable argument to bpf_alloc_pages() Emil Tsalapatis
2026-10-02 10:52 ` [RESEND PATCH bpf-next v6 3/7] bpf: Add sleepable arena page allocation path Emil Tsalapatis
2026-10-02 10:52 ` [RESEND PATCH bpf-next v6 4/7] selftests/bpf: Test large allocations for both sleepable/nonsleepable arena users Emil Tsalapatis
2026-10-02 10:52 ` [RESEND PATCH bpf-next v6 5/7] bpf: Directly store kfunc desc index in instruction off field Emil Tsalapatis
2026-10-02 11:06   ` sashiko-bot [this message]
2026-10-02 11:47   ` bot+bpf-ci
2026-10-02 10:52 ` [RESEND PATCH bpf-next v6 6/7] bpf: Support per-call-site kfunc specialization Emil Tsalapatis
2026-10-02 10:52 ` [RESEND PATCH bpf-next v6 7/7] selftests/bpf: Test per-call site function specialization Emil Tsalapatis
2026-10-02 13:10 ` [RESEND PATCH bpf-next v6 0/7] Make sleepable arena paths use sleepable alloc_pages patchwork-bot+netdevbpf

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=20261002110638.65E041F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=emil@etsalapatis.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