From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: Yonghong Song <yhs@fb.com>, Song Liu <songliubraving@fb.com>,
dwarves@vger.kernel.org, bpf@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andriin@fb.com>, Hao Luo <haoluo@google.com>,
"Frank Ch. Eigler" <fche@redhat.com>,
Mark Wielaard <mjw@redhat.com>
Subject: Re: [PATCH 1/3] bpf: Move iterator functions into special init section
Date: Mon, 9 Nov 2020 15:05:00 -0300 [thread overview]
Message-ID: <20201109180500.GC340169@kernel.org> (raw)
In-Reply-To: <20201106222512.52454-2-jolsa@kernel.org>
Em Fri, Nov 06, 2020 at 11:25:10PM +0100, Jiri Olsa escreveu:
> With upcoming changes to pahole, that change the way how and
> which kernel functions are stored in BTF data, we need a way
> to recognize iterator functions.
>
> Iterator functions need to be in BTF data, but have no real
> body and are currently placed in .init.text section, so they
> are freed after kernel init and are filtered out of BTF data
> because of that.
>
> The solution is to place these functions under new section:
> .init.bpf.preserve_type
>
> And add 2 new symbols to mark that area:
> __init_bpf_preserve_type_begin
> __init_bpf_preserve_type_end
>
> The code in pahole responsible for picking up the functions will
> be able to recognize functions from this section and add them to
> the BTF data and filter out all other .init.text functions.
This isn't applying on torvalds/master:
[acme@five linux]$ patch -p1 < /wb/1.patch
patching file include/asm-generic/vmlinux.lds.h
Hunk #2 succeeded at 754 (offset 1 line).
patching file include/linux/bpf.h
Hunk #1 succeeded at 1276 (offset -1 lines).
patching file include/linux/init.h
Hunk #1 FAILED at 52.
1 out of 1 hunk FAILED -- saving rejects to file include/linux/init.h.rej
[acme@five linux]$
[acme@five linux]$ cat include/linux/init.h.rej
--- include/linux/init.h
+++ include/linux/init.h
@@ -52,6 +52,7 @@
#define __initconst __section(.init.rodata)
#define __exitdata __section(.exit.data)
#define __exit_call __used __section(.exitcall.exit)
+#define __init_bpf_preserve_type __section(.init.bpf.preserve_type)
/*
* modpost check for section mismatches during the kernel build.
[acme@five linux]$
I'm fixing it up by hand to try together with pahole's patches.
- Arnaldo
> Suggested-by: Yonghong Song <yhs@fb.com>
> Acked-by: Song Liu <songliubraving@fb.com>
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> ---
> include/asm-generic/vmlinux.lds.h | 16 +++++++++++++++-
> include/linux/bpf.h | 8 +++++++-
> include/linux/init.h | 1 +
> 3 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index cd14444bf600..e18e1030dabf 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -685,8 +685,21 @@
> .BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \
> *(.BTF_ids) \
> }
> +
> +/*
> + * .init.bpf.preserve_type
> + *
> + * This section store special BPF function and marks them
> + * with begin/end symbols pair for the sake of pahole tool.
> + */
> +#define INIT_BPF_PRESERVE_TYPE \
> + __init_bpf_preserve_type_begin = .; \
> + *(.init.bpf.preserve_type) \
> + __init_bpf_preserve_type_end = .; \
> + MEM_DISCARD(init.bpf.preserve_type)
> #else
> #define BTF
> +#define INIT_BPF_PRESERVE_TYPE
> #endif
>
> /*
> @@ -740,7 +753,8 @@
> #define INIT_TEXT \
> *(.init.text .init.text.*) \
> *(.text.startup) \
> - MEM_DISCARD(init.text*)
> + MEM_DISCARD(init.text*) \
> + INIT_BPF_PRESERVE_TYPE
>
> #define EXIT_DATA \
> *(.exit.data .exit.data.*) \
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 73d5381a5d5c..894f66c7703e 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1277,10 +1277,16 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd);
> int bpf_obj_pin_user(u32 ufd, const char __user *pathname);
> int bpf_obj_get_user(const char __user *pathname, int flags);
>
> +#ifdef CONFIG_DEBUG_INFO_BTF
> +#define BPF_INIT __init_bpf_preserve_type
> +#else
> +#define BPF_INIT __init
> +#endif
> +
> #define BPF_ITER_FUNC_PREFIX "bpf_iter_"
> #define DEFINE_BPF_ITER_FUNC(target, args...) \
> extern int bpf_iter_ ## target(args); \
> - int __init bpf_iter_ ## target(args) { return 0; }
> + int BPF_INIT bpf_iter_ ## target(args) { return 0; }
>
> struct bpf_iter_aux_info {
> struct bpf_map *map;
> diff --git a/include/linux/init.h b/include/linux/init.h
> index 212fc9e2f691..133462863711 100644
> --- a/include/linux/init.h
> +++ b/include/linux/init.h
> @@ -52,6 +52,7 @@
> #define __initconst __section(.init.rodata)
> #define __exitdata __section(.exit.data)
> #define __exit_call __used __section(.exitcall.exit)
> +#define __init_bpf_preserve_type __section(.init.bpf.preserve_type)
>
> /*
> * modpost check for section mismatches during the kernel build.
> --
> 2.26.2
>
--
- Arnaldo
next prev parent reply other threads:[~2020-11-09 18:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-06 22:25 [PATCHv4 0/3] pahole/kernel: Workaround dwarf bug for function encoding Jiri Olsa
2020-11-06 22:25 ` [PATCH 1/3] bpf: Move iterator functions into special init section Jiri Olsa
2020-11-09 18:05 ` Arnaldo Carvalho de Melo [this message]
2020-11-09 18:06 ` Arnaldo Carvalho de Melo
2020-11-09 18:10 ` Arnaldo Carvalho de Melo
2020-11-09 18:49 ` Jiri Olsa
2020-11-06 22:25 ` [PATCH 2/3] btf_encoder: Move find_all_percpu_vars in generic collect_symbols Jiri Olsa
2020-11-06 22:25 ` [PATCH 3/3] btf_encoder: Change functions check due to broken dwarf Jiri Olsa
2020-11-11 19:59 ` Andrii Nakryiko
2020-11-11 20:19 ` Jiri Olsa
2020-11-11 20:26 ` Andrii Nakryiko
2020-11-11 20:49 ` Jiri Olsa
2020-11-11 20:31 ` Jiri Olsa
2020-11-11 20:36 ` Andrii Nakryiko
2020-11-12 0:36 ` Arnaldo Carvalho de Melo
2020-11-06 22:56 ` [PATCHv4 0/3] pahole/kernel: Workaround dwarf bug for function encoding Andrii Nakryiko
2020-11-09 17:29 ` Arnaldo Carvalho de Melo
2020-11-09 19:11 ` Arnaldo Carvalho de Melo
-- strict thread matches above, loose matches on Subject: below --
2020-11-04 21:59 [PATCHv3 " Jiri Olsa
2020-11-04 21:59 ` [PATCH 1/3] bpf: Move iterator functions into special init section Jiri Olsa
2020-11-05 1:01 ` Song Liu
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=20201109180500.GC340169@kernel.org \
--to=acme@kernel.org \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=fche@redhat.com \
--cc=haoluo@google.com \
--cc=jolsa@kernel.org \
--cc=mjw@redhat.com \
--cc=songliubraving@fb.com \
--cc=yhs@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).