On Thu, Nov 11, 2021 at 9:02 PM Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote: > > From: Alexei Starovoitov <ast@xxxxxxxxxx> > > Given BPF program's BTF perform a linear search through kernel BTFs for > a possible candidate. > Then wire the result into bpf_core_apply_relo_insn(). > > Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> > --- > kernel/bpf/btf.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 137 insertions(+), 1 deletion(-) > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > index efb7fa2f81a2..aeb591579282 100644 > --- a/kernel/bpf/btf.c > +++ b/kernel/bpf/btf.c > @@ -25,6 +25,7 @@ > #include <linux/kobject.h> > #include <linux/sysfs.h> > #include <net/sock.h> > +#include "../tools/lib/bpf/relo_core.h" > > /* BTF (BPF Type Format) is the meta data format which describes > * the data types of BPF program/map. Hence, it basically focus > @@ -6440,9 +6441,144 @@ size_t bpf_core_essential_name_len(const char *name) > return n; > } > > +static void bpf_core_free_cands(struct bpf_core_cand_list *cands) > +{ > + if (!cands) > + return; > + kfree(cands->cands); > + kfree(cands); indentation is off? > +} > + > +static int bpf_core_add_cands(struct bpf_verifier_log *log, > + struct bpf_core_cand *local_cand, and here? > + size_t local_essent_len, > + const struct btf *targ_btf, > + int targ_start_id, > + struct bpf_core_cand_list *cands) > +{ > + struct bpf_core_cand *new_cands, *cand; > + const struct btf_type *t; > + const char *targ_name; > + size_t targ_essent_len; > + int n, i; > + [...] > int bpf_core_relo_apply(struct bpf_verifier_log *log, const struct btf *btf, > const struct bpf_core_relo *relo, int relo_idx, > void *insn) > { > - return -EOPNOTSUPP; > + struct bpf_core_cand_list *cands = NULL; > + int err; > + > + if (relo->kind != BPF_CORE_TYPE_ID_LOCAL) { > + cands = bpf_core_find_cands(log, btf, relo->type_id); > + if (IS_ERR(cands)) { > + bpf_log(log, "target candidate search failed for %d\n", > + relo->type_id); > + return PTR_ERR(cands); some indentation issues here as well > + } > + } > + err = bpf_core_apply_relo_insn((void *)log, insn, relo->insn_off / 8, > + relo, relo_idx, btf, cands); > + bpf_core_free_cands(cands); Why did you decide to not persist the candidate list? It is a significant slowdown even on moderately large BPF programs, as you are linearly re-searching vmlinux BTF multiple times for the same root type. > + return err; > } > -- > 2.30.2 >