dwarves.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Martin KaFai Lau <kafai@fb.com>, Jiri Olsa <jolsa@kernel.org>
Cc: dwarves@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	bpf <bpf@vger.kernel.org>, Kernel Team <kernel-team@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH dwarves] btf: Generate btf for functions in the .BTF_ids section
Date: Mon, 26 Apr 2021 16:26:11 -0700	[thread overview]
Message-ID: <CAEf4BzY16ziMkOMdNGNjQOmiACF3E5nFn2LhtUUQbo-y-AP7Tg@mail.gmail.com> (raw)
In-Reply-To: <20210423213728.3538141-1-kafai@fb.com>

On Fri, Apr 23, 2021 at 2:37 PM Martin KaFai Lau <kafai@fb.com> wrote:
>
> BTF is currently generated for functions that are in ftrace list
> or extern.
>
> A recent use case also needs BTF generated for functions included in
> allowlist.  In particular, the kernel
> commit e78aea8b2170 ("bpf: tcp: Put some tcp cong functions in allowlist for bpf-tcp-cc")
> allows bpf program to directly call a few tcp cc kernel functions.  Those
> functions are specified under an ELF section .BTF_ids.  The symbols
> in this ELF section is like __BTF_ID__func__<kernel_func>__[digit]+.
> For example, __BTF_ID__func__cubictcp_init__1.  Those kernel
> functions are currently allowed only if CONFIG_DYNAMIC_FTRACE is
> set to ensure they are in the ftrace list but this kconfig dependency
> is unnecessary.
>
> pahole can generate BTF for those kernel functions if it knows they
> are in the allowlist.  This patch is to capture those symbols
> in the .BTF_ids section and generate BTF for them.
>
> Cc: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>
> ---

I wonder if we just record all functions how bad that would be. Jiri,
do you remember from the time you were experimenting with static
functions how much more functions we'd be recording if we didn't do
ftrace filtering?

>  btf_encoder.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++---
>  libbtf.c      |  10 ++++
>  libbtf.h      |   2 +
>  3 files changed, 142 insertions(+), 6 deletions(-)
>
> diff --git a/btf_encoder.c b/btf_encoder.c
> index 80e896961d4e..48c183915ddd 100644
> --- a/btf_encoder.c
> +++ b/btf_encoder.c
> @@ -106,6 +106,121 @@ static int collect_function(struct btf_elf *btfe, GElf_Sym *sym,
>         return 0;
>  }
>
> +#define BTF_ID_FUNC_PREFIX "__BTF_ID__func__"
> +#define BTF_ID_FUNC_PREFIX_LEN (sizeof(BTF_ID_FUNC_PREFIX) - 1)
> +
> +static char **listed_functions;
> +static int listed_functions_alloc;
> +static int listed_functions_cnt;

maybe just use struct btf as a container of strings, which is what you
need here? You can do btf__add_str() and btf__find_str(), which are
both fast and memory-efficient, and you won't have to manage all the
memory and do sorting, etc, etc.

[...]

  reply	other threads:[~2021-04-26 23:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 21:37 [PATCH dwarves] btf: Generate btf for functions in the .BTF_ids section Martin KaFai Lau
2021-04-26 23:26 ` Andrii Nakryiko [this message]
2021-04-27 11:38   ` Jiri Olsa
2021-04-27 12:34     ` Arnaldo Carvalho de Melo
2021-04-27 12:43       ` Jiri Olsa
2021-04-27 20:38       ` Andrii Nakryiko
2021-04-28 13:10         ` Arnaldo Carvalho de Melo
2021-04-28 19:45           ` Andrii Nakryiko
2021-04-28 22:05             ` Arnaldo Carvalho de Melo
2021-05-01  0:16     ` Martin KaFai Lau
2021-05-01 22:23       ` Jiri Olsa
2021-04-27 11:42 ` Jiri Olsa
2021-04-27 18:20   ` Martin KaFai Lau

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=CAEf4BzY16ziMkOMdNGNjQOmiACF3E5nFn2LhtUUQbo-y-AP7Tg@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=acme@kernel.org \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.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).