From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79C35C433EF for ; Thu, 3 Feb 2022 16:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244652AbiBCQJJ (ORCPT ); Thu, 3 Feb 2022 11:09:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232684AbiBCQJJ (ORCPT ); Thu, 3 Feb 2022 11:09:09 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74D05C061714 for ; Thu, 3 Feb 2022 08:09:08 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id o12so6906508lfg.12 for ; Thu, 03 Feb 2022 08:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kinvolk.io; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=tm8cOIT2RMZaJvCrGE0aS5CTgwdbaLEWFyz2wA6Ms38=; b=RyMW/3GHR2o2+f8EqylzL45XxO4v0B0ZN7L++cNfNgpuRHLNofoGzAObNz1W7tqmr1 7z+GYvGdxxHJYSrw+XqK3+pEgcinA2WF4rjhd2Hx9CJxIHFL+49V58iv41whs94Z6W7t v7SnyW+TejWEdWRqYAd7x0bg+PfgCIRMfiMik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=tm8cOIT2RMZaJvCrGE0aS5CTgwdbaLEWFyz2wA6Ms38=; b=B6MGVqh6sWyvjqoOj+/tyuhVfdZQEJjmJLwFv5J25xUY/+27BCs4VpT+A9TPO3iUQj t+Sf+v80GIp02SegmhXsnn5/I+K8lfQlXUY76kW7152ANZGCGU/CcipCGwJ8oUu+dQvA 7uhMdEj+py8PT2a4bzRUhkvawfNpxf0An/APKSH+2ZLrJhO5LzhPah9cJssGl9KpoN+3 JU6+1Jw8DuU8NHm/Af8A5yp/rAdZmebsF7RzkBP5JWZLsPY5zZYJnDYEEEZcKVXsmdi4 TING56XW0eowf1fA2HolP1gSWlh6aRbIplWq7v5udTIjtBmnl8gs0xkQmt7s78kBpKk6 /d8A== X-Gm-Message-State: AOAM533v2zO34GWiAR2OV341SzUUqMcYgEqbmTGnjBn8GhXrDjJ8venY P0PtA0KrrEQdULAFddN2yYPzPdRmWYZAcb8cMWFwKQ== X-Google-Smtp-Source: ABdhPJzMI72HU1BhGh9dw/LdYDt4Lq0FUOT+bi6/i42p2vNBn+DoEGNIGxSCaHgKcGjC2fY+QIcYrjE3MlvDYxwuji8= X-Received: by 2002:a05:6512:3045:: with SMTP id b5mr18823790lfb.346.1643904546685; Thu, 03 Feb 2022 08:09:06 -0800 (PST) MIME-Version: 1.0 References: <20220128223312.1253169-1-mauricio@kinvolk.io> <20220128223312.1253169-2-mauricio@kinvolk.io> <1b081b16-d91e-01fd-9154-7845782e8715@isovalent.com> In-Reply-To: <1b081b16-d91e-01fd-9154-7845782e8715@isovalent.com> From: =?UTF-8?Q?Mauricio_V=C3=A1squez_Bernal?= Date: Thu, 3 Feb 2022 11:08:55 -0500 Message-ID: Subject: Re: [PATCH bpf-next v5 1/9] libbpf: Implement changes needed for BTFGen in bpftool To: Quentin Monnet Cc: Networking , bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Rafael David Tinoco , Lorenzo Fontana , Leonardo Di Donato Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Tue, Feb 1, 2022 at 3:57 PM Quentin Monnet wrote= : > > 2022-01-28 17:33 UTC-0500 ~ Mauricio V=C3=A1squez > > This commit extends libbpf with the features that are needed to > > implement BTFGen: > > > > - Implement bpf_core_create_cand_cache() and bpf_core_free_cand_cache() > > to handle candidates cache. > > - Expose bpf_core_add_cands() and bpf_core_free_cands to handle > > candidates list. > > - Expose bpf_core_calc_relo_insn() to bpftool. > > > > Signed-off-by: Mauricio V=C3=A1squez > > Signed-off-by: Rafael David Tinoco > > Signed-off-by: Lorenzo Fontana > > Signed-off-by: Leonardo Di Donato > > Hi, note that the patchset (or at least, this patch) does not apply > cleanly. Can you please double-check that it is based on bpf-next? I missed one commit on this submission... > > --- > > tools/lib/bpf/libbpf.c | 44 ++++++++++++++++++++++----------- > > tools/lib/bpf/libbpf_internal.h | 12 +++++++++ > > 2 files changed, 41 insertions(+), 15 deletions(-) > > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > > index 12771f71a6e7..61384d219e28 100644 > > --- a/tools/lib/bpf/libbpf.c > > +++ b/tools/lib/bpf/libbpf.c > > @@ -5195,18 +5195,18 @@ size_t bpf_core_essential_name_len(const char *= name) > > return n; > > } > > > > -static void bpf_core_free_cands(struct bpf_core_cand_list *cands) > > +void bpf_core_free_cands(struct bpf_core_cand_list *cands) > > { > > free(cands->cands); > > free(cands); > > } > > > > -static int bpf_core_add_cands(struct bpf_core_cand *local_cand, > > - size_t local_essent_len, > > - const struct btf *targ_btf, > > - const char *targ_btf_name, > > - int targ_start_id, > > - struct bpf_core_cand_list *cands) > > +int bpf_core_add_cands(struct bpf_core_cand *local_cand, > > + size_t local_essent_len, > > + const struct btf *targ_btf, > > + const char *targ_btf_name, > > + int targ_start_id, > > + struct bpf_core_cand_list *cands) > > { > > struct bpf_core_cand *new_cands, *cand; > > const struct btf_type *t, *local_t; > > @@ -5577,6 +5577,25 @@ static int bpf_core_resolve_relo(struct bpf_prog= ram *prog, > > targ_res); > > } > > > > +struct hashmap *bpf_core_create_cand_cache(void) > > +{ > > + return hashmap__new(bpf_core_hash_fn, bpf_core_equal_fn, NULL); > > +} > > + > > +void bpf_core_free_cand_cache(struct hashmap *cand_cache) > > +{ > > + struct hashmap_entry *entry; > > + int i; > > + > > + if (IS_ERR_OR_NULL(cand_cache)) > > + return; > > + > > + hashmap__for_each_entry(cand_cache, entry, i) { > > + bpf_core_free_cands(entry->value); > > + } > > + hashmap__free(cand_cache); > > +} > > + > > static int > > bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf= _path) > > { > > @@ -5584,7 +5603,6 @@ bpf_object__relocate_core(struct bpf_object *obj,= const char *targ_btf_path) > > struct bpf_core_relo_res targ_res; > > const struct bpf_core_relo *rec; > > const struct btf_ext_info *seg; > > - struct hashmap_entry *entry; > > struct hashmap *cand_cache =3D NULL; > > struct bpf_program *prog; > > struct bpf_insn *insn; > > @@ -5603,7 +5621,7 @@ bpf_object__relocate_core(struct bpf_object *obj,= const char *targ_btf_path) > > } > > } > > > > - cand_cache =3D hashmap__new(bpf_core_hash_fn, bpf_core_equal_fn, = NULL); > > + cand_cache =3D bpf_core_create_cand_cache(); > > if (IS_ERR(cand_cache)) { > > err =3D PTR_ERR(cand_cache); > > goto out; > > @@ -5694,12 +5712,8 @@ bpf_object__relocate_core(struct bpf_object *obj= , const char *targ_btf_path) > > btf__free(obj->btf_vmlinux_override); > > obj->btf_vmlinux_override =3D NULL; > > > > - if (!IS_ERR_OR_NULL(cand_cache)) { > > - hashmap__for_each_entry(cand_cache, entry, i) { > > - bpf_core_free_cands(entry->value); > > - } > > - hashmap__free(cand_cache); > > - } > > + bpf_core_free_cand_cache(cand_cache); > > + > > return err; > > } > > > > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_int= ernal.h > > index bc86b82e90d1..686a5654262b 100644 > > --- a/tools/lib/bpf/libbpf_internal.h > > +++ b/tools/lib/bpf/libbpf_internal.h > > @@ -529,4 +529,16 @@ static inline int ensure_good_fd(int fd) > > return fd; > > } > > > > +struct hashmap; > > + > > +struct hashmap *bpf_core_create_cand_cache(void); > > +void bpf_core_free_cand_cache(struct hashmap *cand_cache); > > +int bpf_core_add_cands(struct bpf_core_cand *local_cand, > > + size_t local_essent_len, > > + const struct btf *targ_btf, > > + const char *targ_btf_name, > > + int targ_start_id, > > + struct bpf_core_cand_list *cands); > > +void bpf_core_free_cands(struct bpf_core_cand_list *cands); > > I wonder if these might deserve a comment to mention that they are > exposed for bpftool? I fear someone might attempt to clean it up and > remove the unused exports otherwise. I added a comment there.