From: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
kkd@meta.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v2 3/6] bpf: Make find_linfo widely available
Date: Wed, 8 Apr 2026 16:46:50 +0100 [thread overview]
Message-ID: <02c440cc-6ecc-45d9-97ab-16730a15fc80@gmail.com> (raw)
In-Reply-To: <20260408021359.3786905-4-memxor@gmail.com>
On 4/8/26 3:13 AM, Kumar Kartikeya Dwivedi wrote:
> Move find_linfo() as bpf_find_linfo() into core.c to allow for its use
> in the verifier in subsequent patches.
>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---
> include/linux/bpf.h | 1 +
> kernel/bpf/core.c | 37 +++++++++++++++++++++++++++++++++++++
> kernel/bpf/log.c | 43 +------------------------------------------
> 3 files changed, 39 insertions(+), 42 deletions(-)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index d8fb9d61f5ce..0136a108d083 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -3945,6 +3945,7 @@ static inline bool bpf_is_subprog(const struct bpf_prog *prog)
> return prog->aux->func_idx != 0;
> }
>
> +const struct bpf_line_info *bpf_find_linfo(const struct bpf_prog *prog, u32 insn_off);
> void bpf_get_linfo_file_line(struct btf *btf, const struct bpf_line_info *linfo,
> const char **filep, const char **linep, int *nump);
> int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char **filep,
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index ada76f997177..066b86e7233c 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -3335,6 +3335,43 @@ void bpf_get_linfo_file_line(struct btf *btf, const struct bpf_line_info *linfo,
> *nump = BPF_LINE_INFO_LINE_NUM(linfo->line_col);
> }
>
> +const struct bpf_line_info *bpf_find_linfo(const struct bpf_prog *prog, u32 insn_off)
> +{
> + const struct bpf_line_info *linfo;
> + u32 nr_linfo;
> + int l, r, m;
> +
> + nr_linfo = prog->aux->nr_linfo;
> + if (!nr_linfo || insn_off >= prog->len)
> + return NULL;
> +
> + linfo = prog->aux->linfo;
> + /* Loop invariant: linfo[l].insn_off <= insns_off.
If you are touching these lines, it's worth updating to kernel style
comments.
other than that the change looks straightforward, just moving a function
from one place to another + minor change of the arguments and rename.
Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
> + * linfo[0].insn_off == 0 which always satisfies above condition.
> + * Binary search is searching for rightmost linfo entry that satisfies
> + * the above invariant, giving us the desired record that covers given
> + * instruction offset.
> + */
> + l = 0;
> + r = nr_linfo - 1;
> + while (l < r) {
> + /* (r - l + 1) / 2 means we break a tie to the right, so if:
> + * l=1, r=2, linfo[l].insn_off <= insn_off, linfo[r].insn_off > insn_off,
> + * then m=2, we see that linfo[m].insn_off > insn_off, and so
> + * r becomes 1 and we exit the loop with correct l==1.
> + * If the tie was broken to the left, m=1 would end us up in
> + * an endless loop where l and m stay at 1 and r stays at 2.
> + */
> + m = l + (r - l + 1) / 2;
> + if (linfo[m].insn_off <= insn_off)
> + l = m;
> + else
> + r = m - 1;
> + }
> +
> + return &linfo[l];
> +}
> +
> int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char **filep,
> const char **linep, int *nump)
> {
> diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c
> index c67fbbbd5768..48931d4e5a68 100644
> --- a/kernel/bpf/log.c
> +++ b/kernel/bpf/log.c
> @@ -327,47 +327,6 @@ __printf(2, 3) void bpf_log(struct bpf_verifier_log *log,
> }
> EXPORT_SYMBOL_GPL(bpf_log);
>
> -static const struct bpf_line_info *
> -find_linfo(const struct bpf_verifier_env *env, u32 insn_off)
> -{
> - const struct bpf_line_info *linfo;
> - const struct bpf_prog *prog;
> - u32 nr_linfo;
> - int l, r, m;
> -
> - prog = env->prog;
> - nr_linfo = prog->aux->nr_linfo;
> -
> - if (!nr_linfo || insn_off >= prog->len)
> - return NULL;
> -
> - linfo = prog->aux->linfo;
> - /* Loop invariant: linfo[l].insn_off <= insns_off.
> - * linfo[0].insn_off == 0 which always satisfies above condition.
> - * Binary search is searching for rightmost linfo entry that satisfies
> - * the above invariant, giving us the desired record that covers given
> - * instruction offset.
> - */
> - l = 0;
> - r = nr_linfo - 1;
> - while (l < r) {
> - /* (r - l + 1) / 2 means we break a tie to the right, so if:
> - * l=1, r=2, linfo[l].insn_off <= insn_off, linfo[r].insn_off > insn_off,
> - * then m=2, we see that linfo[m].insn_off > insn_off, and so
> - * r becomes 1 and we exit the loop with correct l==1.
> - * If the tie was broken to the left, m=1 would end us up in
> - * an endless loop where l and m stay at 1 and r stays at 2.
> - */
> - m = l + (r - l + 1) / 2;
> - if (linfo[m].insn_off <= insn_off)
> - l = m;
> - else
> - r = m - 1;
> - }
> -
> - return &linfo[l];
> -}
> -
> static const char *ltrim(const char *s)
> {
> while (isspace(*s))
> @@ -388,7 +347,7 @@ __printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env,
> return;
>
> prev_linfo = env->prev_linfo;
> - linfo = find_linfo(env, insn_off);
> + linfo = bpf_find_linfo(env->prog, insn_off);
> if (!linfo || linfo == prev_linfo)
> return;
>
next prev parent reply other threads:[~2026-04-08 15:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 2:13 [PATCH bpf-next v2 0/6] Add support to emit verifier warnings Kumar Kartikeya Dwivedi
2026-04-08 2:13 ` [PATCH bpf-next v2 1/6] bpf: Add support for verifier warning messages Kumar Kartikeya Dwivedi
2026-04-08 8:46 ` sun jian
2026-04-08 2:13 ` [PATCH bpf-next v2 2/6] bpf: Extract bpf_get_linfo_file_line Kumar Kartikeya Dwivedi
2026-04-08 2:13 ` [PATCH bpf-next v2 3/6] bpf: Make find_linfo widely available Kumar Kartikeya Dwivedi
2026-04-08 15:46 ` Mykyta Yatsenko [this message]
2026-04-08 2:13 ` [PATCH bpf-next v2 4/6] bpf: Use KF_DEPRECATED to emit verifier warnings Kumar Kartikeya Dwivedi
2026-04-08 2:13 ` [PATCH bpf-next v2 5/6] bpf: Add __bpf_kfunc_replacement() annotation Kumar Kartikeya Dwivedi
2026-04-08 2:13 ` [PATCH bpf-next v2 6/6] libbpf: Flush verifier warning messages by default Kumar Kartikeya Dwivedi
2026-04-08 2:21 ` Kumar Kartikeya Dwivedi
2026-04-08 14:55 ` [PATCH bpf-next v2 0/6] Add support to emit verifier warnings Leon Hwang
2026-04-08 15:30 ` Leon Hwang
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=02c440cc-6ecc-45d9-97ab-16730a15fc80@gmail.com \
--to=mykyta.yatsenko5@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.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