bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Quentin Monnet <quentin@isovalent.com>
To: "Mauricio Vásquez" <mauricio@kinvolk.io>,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Rafael David Tinoco <rafaeldtinoco@gmail.com>,
	Lorenzo Fontana <lorenzo.fontana@elastic.co>,
	Leonardo Di Donato <leonardo.didonato@elastic.co>
Subject: Re: [PATCH bpf-next v5 1/9] libbpf: Implement changes needed for BTFGen in bpftool
Date: Tue, 1 Feb 2022 20:57:38 +0000	[thread overview]
Message-ID: <1b081b16-d91e-01fd-9154-7845782e8715@isovalent.com> (raw)
In-Reply-To: <20220128223312.1253169-2-mauricio@kinvolk.io>

2022-01-28 17:33 UTC-0500 ~ Mauricio Vásquez <mauricio@kinvolk.io>
> 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ásquez <mauricio@kinvolk.io>
> Signed-off-by: Rafael David Tinoco <rafael.tinoco@aquasec.com>
> Signed-off-by: Lorenzo Fontana <lorenzo.fontana@elastic.co>
> Signed-off-by: Leonardo Di Donato <leonardo.didonato@elastic.co>

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?

> ---
>  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_program *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 = 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 = hashmap__new(bpf_core_hash_fn, bpf_core_equal_fn, NULL);
> +	cand_cache = bpf_core_create_cand_cache();
>  	if (IS_ERR(cand_cache)) {
>  		err = 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 = 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_internal.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.

  reply	other threads:[~2022-02-01 20:57 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-28 22:33 [PATCH bpf-next v5 0/9] libbpf: Implement BTFGen Mauricio Vásquez
2022-01-28 22:33 ` [PATCH bpf-next v5 1/9] libbpf: Implement changes needed for BTFGen in bpftool Mauricio Vásquez
2022-02-01 20:57   ` Quentin Monnet [this message]
2022-02-03 16:08     ` Mauricio Vásquez Bernal
2022-02-02 18:54   ` Andrii Nakryiko
2022-02-02 19:02     ` Andrii Nakryiko
2022-02-03 16:09     ` Mauricio Vásquez Bernal
2022-01-28 22:33 ` [PATCH bpf-next v5 2/9] bpftool: Add gen min_core_btf command Mauricio Vásquez
2022-02-02 17:58   ` Andrii Nakryiko
2022-02-03 16:07     ` Mauricio Vásquez Bernal
2022-02-03 17:21       ` Andrii Nakryiko
2022-01-28 22:33 ` [PATCH bpf-next v5 3/9] bpftool: Implement btf_save_raw() Mauricio Vásquez
2022-02-02 18:48   ` Andrii Nakryiko
2022-02-03 16:07     ` Mauricio Vásquez Bernal
2022-02-03 17:23       ` Andrii Nakryiko
2022-01-28 22:33 ` [PATCH bpf-next v5 4/9] bpftool: Add struct definitions and helpers for BTFGen Mauricio Vásquez
2022-02-02 18:54   ` Andrii Nakryiko
2022-02-03 16:08     ` Mauricio Vásquez Bernal
2022-02-03 17:24       ` Andrii Nakryiko
2022-01-28 22:33 ` [PATCH bpf-next v5 5/9] bpftool: Implement btfgen() Mauricio Vásquez
2022-02-01 20:57   ` Quentin Monnet
2022-02-03 19:10     ` Mauricio Vásquez Bernal
2022-02-02 19:14   ` Andrii Nakryiko
2022-02-03 16:09     ` Mauricio Vásquez Bernal
2022-01-28 22:33 ` [PATCH bpf-next v5 6/9] bpftool: Implement relocations recording for BTFGen Mauricio Vásquez
2022-02-02 19:31   ` Andrii Nakryiko
2022-02-03 16:40     ` Mauricio Vásquez Bernal
2022-02-03 17:30       ` Andrii Nakryiko
2022-02-04  6:20         ` Rafael David Tinoco
2022-02-04 18:41           ` Andrii Nakryiko
2022-02-02 22:55   ` Andrii Nakryiko
2022-02-04 19:44     ` Mauricio Vásquez Bernal
2022-01-28 22:33 ` [PATCH bpf-next v5 7/9] bpftool: Implement btfgen_get_btf() Mauricio Vásquez
2022-02-02 19:36   ` Andrii Nakryiko
2022-02-03 16:10     ` Mauricio Vásquez Bernal
2022-02-03 17:31       ` Andrii Nakryiko
2022-01-28 22:33 ` [PATCH bpf-next v5 8/9] bpftool: gen min_core_btf explanation and examples Mauricio Vásquez
2022-02-01 20:57   ` Quentin Monnet
2022-01-28 22:33 ` [PATCH bpf-next v5 9/9] selftest/bpf: Implement tests for bpftool gen min_core_btf Mauricio Vásquez
2022-01-28 23:23   ` Mauricio Vásquez Bernal
2022-02-01 20:58     ` Quentin Monnet
2022-02-02 19:50     ` Andrii Nakryiko
2022-02-03 21:17       ` Mauricio Vásquez Bernal
2022-02-04 20:05         ` Andrii Nakryiko
2022-02-01 20:57   ` Quentin Monnet

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=1b081b16-d91e-01fd-9154-7845782e8715@isovalent.com \
    --to=quentin@isovalent.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=leonardo.didonato@elastic.co \
    --cc=lorenzo.fontana@elastic.co \
    --cc=mauricio@kinvolk.io \
    --cc=netdev@vger.kernel.org \
    --cc=rafaeldtinoco@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;
as well as URLs for NNTP newsgroup(s).