From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Anton Protopopov <aspsk@isovalent.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Quentin Monnet <qmo@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH v5 bpf-next 04/15] bpf, x86: add new map type: instructions array
Date: Fri, 3 Oct 2025 07:39:24 +0000 [thread overview]
Message-ID: <aN99rP7iS2O0kJMN@mail.gmail.com> (raw)
In-Reply-To: <7f2e28c4cee292fb6eb5785830d5e572b7bd59c2.camel@gmail.com>
On 25/10/02 05:50PM, Eduard Zingerman wrote:
> On Tue, 2025-09-30 at 12:51 +0000, Anton Protopopov wrote:
>
> Overall I think this patch is fine.
> We discussed this some time ago, but I can't find the previous discussion:
> would it be possible to make this map element a tuple of three elements
> (orig_off, xlated_off, jitted_off)?
> Visible to user as well.
See https://lore.kernel.org/bpf/8ff2059d38afbd49eccb4bb3fd5ba741fefc5b57.camel@gmail.com/
In short, this will make the map element to be of different size
from userspace and kernel (BPF) perspective.
(Userspace can build the orig_off -> xlated_off mapping easily, if needed,
just keep a copy of the map before the load.)
> [...]
>
> > diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
> > index 4c497e839526..cc06e6d57faa 100644
> > --- a/include/linux/bpf_verifier.h
> > +++ b/include/linux/bpf_verifier.h
>
> [...]
>
> > @@ -7645,4 +7646,14 @@ enum bpf_kfunc_flags {
> > BPF_F_PAD_ZEROS = (1ULL << 0),
> > };
> >
> > +/*
> > + * Values of a BPF_MAP_TYPE_INSN_ARRAY entry must be of this type.
> > + * On updates jitted_off must be equal to 0.
> > + */
> > +struct bpf_insn_array_value {
> > + __u32 jitted_off;
> > + __u32 xlated_off;
> > +};
>
> Could you please expand the comment a bit? Describe the meaning of
> the fields both before and after program load.
Sure.
> > +
> > +
> > #endif /* _UAPI__LINUX_BPF_H__ */
>
> [...]
>
> > @@ -0,0 +1,285 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/* Copyright (c) 2025 Isovalent */
> > +
> > +#include <linux/bpf.h>
> > +
> > +#define MAX_INSN_ARRAY_ENTRIES 256
>
> Hm, did not notice this before. We probably need an option limiting
> max number of jump table alternatives.
>
> Yonghong, wdyt?
This one comes from the fact I've mentioned in the other place: need
to optimize the lookup from jit (not it is brute force). Then this
limitation will go away.
But also curious, what LLVM thinks about this. Will it,
theoretically, create say 65K tables or so?
> [...]
>
> > +void bpf_insn_array_adjust_after_remove(struct bpf_map *map, u32 off, u32 len)
> > +{
> > + struct bpf_insn_array *insn_array = cast_insn_array(map);
> > + int i;
> > +
> > + for (i = 0; i < map->max_entries; i++) {
> > + if (insn_array->ptrs[i].user_value.xlated_off < off)
> > + continue;
> > + if (insn_array->ptrs[i].user_value.xlated_off == INSN_DELETED)
> > + continue;
> > + if (insn_array->ptrs[i].user_value.xlated_off >= off &&
> ^^^^^^
> Nit: this condition is redundant
True, thanks, will remove it.
>
> > + insn_array->ptrs[i].user_value.xlated_off < off + len)
> > + insn_array->ptrs[i].user_value.xlated_off = INSN_DELETED;
> > + else
> > + insn_array->ptrs[i].user_value.xlated_off -= len;
> > + }
> > +}
> > +
> > +void bpf_prog_update_insn_ptr(struct bpf_prog *prog,
> > + u32 xlated_off,
> > + u32 jitted_off,
> > + void *jitted_ip)
> > +{
> > + struct bpf_insn_array *insn_array;
> > + struct bpf_map *map;
> > + int i, j;
> > +
> > + for (i = 0; i < prog->aux->used_map_cnt; i++) {
> > + map = prog->aux->used_maps[i];
> > + if (!is_insn_array(map))
> > + continue;
> > +
> > + insn_array = cast_insn_array(map);
> > + for (j = 0; j < map->max_entries; j++) {
> > + if (insn_array->ptrs[j].user_value.xlated_off == xlated_off) {
>
> If this would check for `insn_array->ptrs[j].orig_xlated_off == xlated_off`
> there would be no need in `user_value.xlated_off = orig_xlated_off`
> in the `bpf_insn_array_init()`, right?
The copy of the original offset is kept inside the map for the
following reason. When the map is first loaded, it is frozen. Thus
user can't update it anymore. During load some of xlated_off are
changed (together with program code). If the program load fails, it
is common to reload it with a log buffer. If map was changed, it now
will point to incorrect instructions. So in this case the map should
be seen as the original one, and the orig_xlated_off is used to reset
it.
> > + insn_array->ips[j] = (long)jitted_ip;
> > + insn_array->ptrs[j].jitted_ip = jitted_ip;
> > + insn_array->ptrs[j].user_value.jitted_off = jitted_off;
> > + }
> > + }
> > + }
> > +}
>
> [...]
next prev parent reply other threads:[~2025-10-03 7:33 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 12:50 [PATCH v5 bpf-next 00/15] BPF indirect jumps Anton Protopopov
2025-09-30 12:50 ` [PATCH v5 bpf-next 01/15] bpf: fix the return value of push_stack Anton Protopopov
2025-09-30 12:50 ` [PATCH v5 bpf-next 02/15] bpf: save the start of functions in bpf_prog_aux Anton Protopopov
2025-10-01 21:53 ` Eduard Zingerman
2025-09-30 12:50 ` [PATCH v5 bpf-next 03/15] bpf: generalize and export map_get_next_key for arrays Anton Protopopov
2025-10-01 21:56 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 04/15] bpf, x86: add new map type: instructions array Anton Protopopov
2025-10-03 0:50 ` Eduard Zingerman
2025-10-03 7:39 ` Anton Protopopov [this message]
2025-10-03 8:48 ` Eduard Zingerman
2025-10-03 9:13 ` Anton Protopopov
2025-10-03 17:22 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 05/15] selftests/bpf: add selftests for new insn_array map Anton Protopopov
2025-10-03 1:16 ` Eduard Zingerman
2025-10-03 7:46 ` Anton Protopopov
2025-10-03 8:15 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 06/15] bpf: support instructions arrays with constants blinding Anton Protopopov
2025-10-03 17:38 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 07/15] selftests/bpf: test instructions arrays with blinding Anton Protopopov
2025-10-03 9:00 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 08/15] bpf, x86: allow indirect jumps to r8...r15 Anton Protopopov
2025-10-01 22:03 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 09/15] bpf: make bpf_insn_successors to return a pointer Anton Protopopov
2025-10-01 22:39 ` Eduard Zingerman
2025-10-01 23:49 ` Alexei Starovoitov
2025-10-02 8:19 ` Anton Protopopov
2025-10-02 16:07 ` Alexei Starovoitov
2025-10-02 8:16 ` Anton Protopopov
2025-10-02 19:35 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 10/15] bpf, x86: add support for indirect jumps Anton Protopopov
2025-10-02 0:15 ` Eduard Zingerman
2025-10-02 9:27 ` Anton Protopopov
2025-10-02 19:52 ` Eduard Zingerman
2025-10-03 7:04 ` Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 11/15] bpf: disasm: add support for BPF_JMP|BPF_JA|BPF_X Anton Protopopov
2025-10-02 0:18 ` Eduard Zingerman
2025-10-02 7:49 ` Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 12/15] libbpf: fix formatting of bpf_object__append_subprog_code Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 13/15] libbpf: support llvm-generated indirect jumps Anton Protopopov
2025-10-02 21:01 ` Eduard Zingerman
2025-10-03 7:19 ` Anton Protopopov
2025-10-15 15:32 ` Yonghong Song
2025-10-15 17:35 ` Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 14/15] bpftool: Recognize insn_array map type Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 15/15] selftests/bpf: add selftests for indirect jumps Anton Protopopov
2025-10-02 21:07 ` Eduard Zingerman
2025-10-03 7:22 ` Anton Protopopov
2025-10-03 7:29 ` Eduard Zingerman
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=aN99rP7iS2O0kJMN@mail.gmail.com \
--to=a.s.protopopov@gmail.com \
--cc=andrii@kernel.org \
--cc=aspsk@isovalent.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox