Skip to content

Commit 3f6ccdf

Browse files
olsajiriborkmann
authored andcommitted
bpf: Move iterator functions into special init section
With upcoming changes to pahole [0], 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. [0] 5a22c2de79fb ("btf_encoder: Change functions check due to broken dwarf") Suggested-by: Yonghong Song <yhs@fb.com> Signed-off-by: Jiri Olsa <jolsa@redhat.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Song Liu <songliubraving@fb.com> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20201110154017.482352-1-jolsa@kernel.org
1 parent f16e631 commit 3f6ccdf

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

include/asm-generic/vmlinux.lds.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,21 @@
685685
.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \
686686
*(.BTF_ids) \
687687
}
688+
689+
/*
690+
* .init.bpf.preserve_type
691+
*
692+
* This section stores special BPF functions and marks them
693+
* with begin/end symbols pair for the sake of pahole tool.
694+
*/
695+
#define INIT_BPF_PRESERVE_TYPE \
696+
__init_bpf_preserve_type_begin = .; \
697+
*(.init.bpf.preserve_type) \
698+
__init_bpf_preserve_type_end = .; \
699+
MEM_DISCARD(init.bpf.preserve_type)
688700
#else
689701
#define BTF
702+
#define INIT_BPF_PRESERVE_TYPE
690703
#endif
691704

692705
/*
@@ -741,7 +754,8 @@
741754
#define INIT_TEXT \
742755
*(.init.text .init.text.*) \
743756
*(.text.startup) \
744-
MEM_DISCARD(init.text*)
757+
MEM_DISCARD(init.text*) \
758+
INIT_BPF_PRESERVE_TYPE
745759

746760
#define EXIT_DATA \
747761
*(.exit.data .exit.data.*) \

include/linux/bpf.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,10 +1276,20 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd);
12761276
int bpf_obj_pin_user(u32 ufd, const char __user *pathname);
12771277
int bpf_obj_get_user(const char __user *pathname, int flags);
12781278

1279+
/* In case we generate BTF data, we need to group all iterator
1280+
* functions into special init section, so pahole can track them.
1281+
* Otherwise pure __init section is enough.
1282+
*/
1283+
#ifdef CONFIG_DEBUG_INFO_BTF
1284+
#define __init_bpf_preserve_type __section(".init.bpf.preserve_type")
1285+
#else
1286+
#define __init_bpf_preserve_type __init
1287+
#endif
1288+
12791289
#define BPF_ITER_FUNC_PREFIX "bpf_iter_"
12801290
#define DEFINE_BPF_ITER_FUNC(target, args...) \
12811291
extern int bpf_iter_ ## target(args); \
1282-
int __init bpf_iter_ ## target(args) { return 0; }
1292+
int __init_bpf_preserve_type bpf_iter_ ## target(args) { return 0; }
12831293

12841294
struct bpf_iter_aux_info {
12851295
struct bpf_map *map;

0 commit comments

Comments
 (0)