From: Anton Protopopov <a.s.protopopov@gmail.com>
To: bot+bpf-ci@kernel.org
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
aspsk@isovalent.com, daniel@iogearbox.net, eddyz87@gmail.com,
qmo@kernel.org, yonghong.song@linux.dev, martin.lau@kernel.org,
clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCH v10 bpf-next 08/11] libbpf: support llvm-generated indirect jumps
Date: Sun, 2 Nov 2025 21:38:53 +0000 [thread overview]
Message-ID: <aQfPbc97GSajDCcc@mail.gmail.com> (raw)
In-Reply-To: <311fb2ea7bc0de371449e98951bf8366aa8b30be8c50c8c549e2501fc9095878@mail.kernel.org>
On 25/11/02 09:13PM, bot+bpf-ci@kernel.org wrote:
>
> ```
> commit b44690c09995d34f7665c7d687b359d41a6ab79f
> Author: Anton Protopopov <a.s.protopopov@gmail.com>
>
> libbpf: support llvm-generated indirect jumps
>
> This commit adds support for LLVM-generated indirect jumps in BPF v4
> instruction set. It handles jump table metadata from the .jumptables
> ELF section and creates BPF_MAP_TYPE_INSN_ARRAY maps for them.
>
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index fbe74686c..ed14090a9 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
>
> [ ... ]
>
> > @@ -6144,6 +6192,157 @@ static void poison_kfunc_call(struct bpf_program *prog, int relo_idx,
> > insn->imm = POISON_CALL_KFUNC_BASE + ext_idx;
> > }
> >
> > +static int find_jt_map(struct bpf_object *obj, struct bpf_program *prog, int sym_off)
> > +{
>
> [ ... ]
>
> > +static int create_jt_map(struct bpf_object *obj, struct bpf_program *prog, struct reloc_desc *relo)
> > +{
> > + const __u32 jt_entry_size = 8;
> > + int sym_off = relo->sym_off;
> > + int jt_size = relo->sym_size;
> > + __u32 max_entries = jt_size / jt_entry_size;
> > + __u32 value_size = sizeof(struct bpf_insn_array_value);
> > + struct bpf_insn_array_value val = {};
> > + int subprog_idx;
> > + int map_fd, err;
> > + __u64 insn_off;
> > + __u64 *jt;
> > + __u32 i;
> > +
> > + map_fd = find_jt_map(obj, prog, sym_off);
> > + if (map_fd >= 0)
> > + return map_fd;
> > +
> > + if (sym_off % jt_entry_size) {
> > + pr_warn("map '.jumptables': jumptable start %d should be multiple of %u\n",
> > + sym_off, jt_entry_size);
> > + return -EINVAL;
> > + }
> > +
> > + if (jt_size % jt_entry_size) {
> > + pr_warn("map '.jumptables': jumptable size %d should be multiple of %u\n",
> > + jt_size, jt_entry_size);
> > + return -EINVAL;
> > + }
> > +
> > + map_fd = bpf_map_create(BPF_MAP_TYPE_INSN_ARRAY, ".jumptables",
> > + 4, value_size, max_entries, NULL);
> > + if (map_fd < 0)
> > + return map_fd;
> > +
> > + if (!obj->jumptables_data) {
> > + pr_warn("map '.jumptables': ELF file is missing jump table data\n");
> > + err = -EINVAL;
> > + goto err_close;
> > + }
> > + if (sym_off + jt_size > obj->jumptables_data_sz) {
> > + pr_warn("map '.jumptables': jumptables_data size is %zd, trying to access %d\n",
> > + obj->jumptables_data_sz, sym_off + jt_size);
> > + err = -EINVAL;
> > + goto err_close;
> > + }
> > +
> > + subprog_idx = -1; /* main program */
> > + if (relo->insn_idx < 0 || relo->insn_idx >= prog->insns_cnt) {
> > + pr_warn("map '.jumptables': invalid instruction index %d\n", relo->insn_idx);
> > + err = -EINVAL;
> > + goto err_close;
> > + }
> > + if (prog->subprogs)
> > + subprog_idx = find_subprog_idx(prog, relo->insn_idx);
> > +
> > + jt = (__u64 *)(obj->jumptables_data + sym_off);
> > + for (i = 0; i < max_entries; i++) {
> > + /*
> > + * The offset should be made to be relative to the beginning of
> > + * the main function, not the subfunction.
> > + */
> > + insn_off = jt[i]/sizeof(struct bpf_insn);
> > + if (subprog_idx >= 0) {
> > + insn_off -= prog->subprogs[subprog_idx].sec_insn_off;
> > + insn_off += prog->subprogs[subprog_idx].sub_insn_off;
> > + } else {
> > + insn_off -= prog->sec_insn_off;
> > + }
> > +
> > + /*
> > + * LLVM-generated jump tables contain u64 records, however
> > + * should contain values that fit in u32.
> > + */
> > + if (insn_off > UINT32_MAX) {
> > + pr_warn("map '.jumptables': invalid jump table value 0x%llx at offset %d\n",
> > + (long long)jt[i], sym_off + i);
> ^^^^^^^^^^^^
>
> Does this error message print the correct offset? Since jt is a pointer
> to __u64, the array access jt[i] is at byte offset "sym_off + i * 8",
> not "sym_off + i". All the other error messages in create_jt_map report
> byte offsets and sizes (sym_off, jt_size, sym_off + jt_size), so this
> one should probably be "sym_off + i * jt_entry_size" for consistency.
Is there a way to run this AI as part of any PR to
kernel-patches/bpf, not only those coming from the mailing list?
Maybe for a selected commit?
Also, how deterministinc it is? Will it generate different comments
for a given patch for different runs?
> > + err = -EINVAL;
> > + goto err_close;
> > + }
> > +
> > + val.orig_off = insn_off;
> > + err = bpf_map_update_elem(map_fd, &i, &val, 0);
> > + if (err)
> > + goto err_close;
> > + }
> > +
> > + err = bpf_map_freeze(map_fd);
> > + if (err)
> > + goto err_close;
> > +
> > + err = add_jt_map(obj, prog, sym_off, map_fd);
> > + if (err)
> > + goto err_close;
> > +
> > + return map_fd;
> > +
> > +err_close:
> > + close(map_fd);
> > + return err;
> > +}
>
> [ ... ]
>
>
> ```
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> In-Reply-To-Subject: `libbpf: support llvm-generated indirect jumps`
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/19018051915
next prev parent reply other threads:[~2025-11-02 21:32 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-02 20:57 [PATCH v10 bpf-next 00/11] BPF indirect jumps Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 01/11] bpf, x86: add new map type: instructions array Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 02/11] selftests/bpf: add selftests for new insn_array map Anton Protopopov
2025-11-04 2:10 ` Alexei Starovoitov
2025-11-04 13:52 ` Anton Protopopov
2025-11-04 16:49 ` Alexei Starovoitov
2025-11-05 6:35 ` Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 03/11] bpf: support instructions arrays with constants blinding Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 04/11] selftests/bpf: test instructions arrays with blinding Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 05/11] bpf, x86: allow indirect jumps to r8...r15 Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 06/11] bpf, x86: add support for indirect jumps Anton Protopopov
2025-11-02 21:20 ` bot+bpf-ci
2025-11-02 22:00 ` Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 07/11] bpf: disasm: add support for BPF_JMP|BPF_JA|BPF_X Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 08/11] libbpf: support llvm-generated indirect jumps Anton Protopopov
2025-11-02 21:13 ` bot+bpf-ci
2025-11-02 21:36 ` Anton Protopopov
2025-11-02 21:38 ` Anton Protopopov [this message]
2025-11-03 0:32 ` Ihor Solodrai
2025-11-03 0:58 ` Chris Mason
2025-11-03 8:29 ` Anton Protopopov
2025-11-03 8:21 ` Anton Protopopov
2025-11-04 1:15 ` Eduard Zingerman
2025-11-04 1:30 ` Eduard Zingerman
2025-11-04 5:26 ` Yonghong Song
2025-11-04 18:31 ` Eduard Zingerman
2025-11-05 8:12 ` Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 09/11] bpftool: Recognize insn_array map type Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 10/11] selftests/bpf: add new verifier_gotox test Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 11/11] selftests/bpf: add C-level selftests for indirect jumps Anton Protopopov
2025-11-03 20:45 ` Eduard Zingerman
2025-11-05 7:26 ` Anton Protopopov
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=aQfPbc97GSajDCcc@mail.gmail.com \
--to=a.s.protopopov@gmail.com \
--cc=andrii@kernel.org \
--cc=aspsk@isovalent.com \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=martin.lau@kernel.org \
--cc=qmo@kernel.org \
--cc=yonghong.song@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.