From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:42:35
The kbuild test robot reported compile issue on x86 in one of
the following patches that adds <linux/kallsyms.h> include into
<linux/bpf.h>, which is picked up by init_32.c object.
The problem is that <linux/kallsyms.h> defines global function
is_kernel_text which colides with the static function of the
same name defined in init_32.c:
$ make ARCH=i386
...
>> arch/x86/mm/init_32.c:241:19: error: redefinition of 'is_kernel_text'
static inline int is_kernel_text(unsigned long addr)
^~~~~~~~~~~~~~
In file included from include/linux/bpf.h:21:0,
from include/linux/bpf-cgroup.h:5,
from include/linux/cgroup-defs.h:22,
from include/linux/cgroup.h:28,
from include/linux/hugetlb.h:9,
from arch/x86/mm/init_32.c:18:
include/linux/kallsyms.h:31:19: note: previous definition of 'is_kernel_text' was here
static inline int is_kernel_text(unsigned long addr)
Renaming the init_32.c is_kernel_text function to __is_kernel_text.
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Reported-by: kbuild test robot <redacted>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
arch/x86/mm/init_32.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:42:36
From: Björn Töpel <redacted>
Adding bpf_trampoline_ name prefix for DECLARE_BPF_DISPATCHER,
so all the dispatchers have the common name prefix.
And also a small '_' cleanup for bpf_dispatcher_nopfunc function
name.
Signed-off-by: Björn Töpel <redacted>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 21 +++++++++++----------
include/linux/filter.h | 7 +++----
net/core/filter.c | 5 ++---
3 files changed, 16 insertions(+), 17 deletions(-)
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:42:44
Adding 'struct bpf_ksym' object that will carry the
kallsym information for bpf symbol. Adding the start
and end address to begin with. It will be used by
bpf_prog, bpf_trampoline, bpf_dispatcher.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 6 ++++++
kernel/bpf/core.c | 26 +++++++++++---------------
2 files changed, 17 insertions(+), 15 deletions(-)
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:42:44
Adding name to 'struct bpf_ksym' object to carry the name
of the symbol for bpf_prog, bpf_trampoline, bpf_dispatcher.
The current benefit is that name is now generated only when
the symbol is added to the list, so we don't need to generate
it every time it's accessed.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 2 ++
include/linux/filter.h | 6 ------
kernel/bpf/core.c | 8 +++++---
kernel/events/core.c | 4 ++--
4 files changed, 9 insertions(+), 11 deletions(-)
@@ -681,7 +683,7 @@ const char *__bpf_address_lookup(unsigned long addr, unsigned long *size,unsignedlongsymbol_start=prog->aux->ksym.start;unsignedlongsymbol_end=prog->aux->ksym.end;-bpf_get_prog_name(prog,sym);+strncpy(sym,prog->aux->ksym.name,KSYM_NAME_LEN);ret=sym;if(size)
@@ -738,7 +740,7 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,if(it++!=symnum)continue;-bpf_get_prog_name(aux->prog,sym);+strncpy(sym,aux->ksym.name,KSYM_NAME_LEN);*value=(unsignedlong)aux->prog->bpf_func;*type=BPF_SYM_ELF_TYPE;
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:42:47
Adding lnode list node to 'struct bpf_ksym' object,
so the symbol itself can be chained and used in other
objects like bpf_trampoline and bpf_dispatcher.
Changing iterator to bpf_ksym in bpf_get_kallsym.
This patch also changes the address used for bpf_prog
displayed in /proc/kallsyms. Now it's the address of
the whole bpf_prog region, not the address of the entry
function. I think it make more sense for /proc/kallsyms
to describe all the place used by bpf_prog. We can easily
change it in future if needed.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 2 +-
kernel/bpf/core.c | 22 +++++++++++-----------
2 files changed, 12 insertions(+), 12 deletions(-)
@@ -728,7 +728,7 @@ const struct exception_table_entry *search_bpf_extables(unsigned long addr)intbpf_get_kallsym(unsignedintsymnum,unsignedlong*value,char*type,char*sym){-structbpf_prog_aux*aux;+structbpf_ksym*ksym;unsignedintit=0;intret=-ERANGE;
@@ -736,13 +736,13 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,returnret;rcu_read_lock();-list_for_each_entry_rcu(aux,&bpf_kallsyms,ksym_lnode){+list_for_each_entry_rcu(ksym,&bpf_kallsyms,lnode){if(it++!=symnum)continue;-strncpy(sym,aux->ksym.name,KSYM_NAME_LEN);+strncpy(sym,ksym->name,KSYM_NAME_LEN);-*value=(unsignedlong)aux->prog->bpf_func;+*value=ksym->start;*type=BPF_SYM_ELF_TYPE;ret=0;
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:42:50
The bpf_tree is used both for kallsyms iterations and searching
for exception tables of bpf programs, which is needed only for
bpf programs.
Adding bpf_kallsyms_tree that will hold symbols for all bpf_prog,
bpf_trampoline and bpf_dispatcher objects and keeping bpf_tree
only for bpf_prog objects exception tables search to keep it fast.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 1 +
kernel/bpf/core.c | 60 ++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 55 insertions(+), 6 deletions(-)
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:42:52
Moving bpf_tree add/del from bpf_prog_ksym_node_add/del,
because it will be used (and renamed) in following patches
for bpf_ksym objects. The bpf_tree is specific for bpf_prog
objects.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/bpf/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:43:01
When bpf_prog is removed from kallsyms it's on the way
out to be removed, so we don't care about lnode state.
However the bpf_ksym_del will be used also by bpf_trampoline
and bpf_dispatcher objects, which stay allocated even when
they are not in kallsyms list, hence the lnode re-init.
The list_del_rcu commentary states that we need to call
synchronize_rcu, before we can change/re-init the list_head
pointers.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/bpf/core.c | 7 +++++++
1 file changed, 7 insertions(+)
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:43:02
Adding bpf_ksym_add/del functions as locked version
for __bpf_ksym_add/del. It will be used in following
patches for bpf_trampoline and bpf_dispatcher.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 3 +++
kernel/bpf/core.c | 14 ++++++++++++++
2 files changed, 17 insertions(+)
@@ -573,6 +573,9 @@ struct bpf_image {#define BPF_IMAGE_SIZE (PAGE_SIZE - sizeof(struct bpf_image))boolis_bpf_image_address(unsignedlongaddress);void*bpf_image_alloc(void);+/* Called only from code, so there's no need for stubs. */+voidbpf_ksym_add(structbpf_ksym*ksym);+voidbpf_ksym_del(structbpf_ksym*ksym);#elsestaticinlinestructbpf_trampoline*bpf_trampoline_lookup(u64key){
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:43:06
Renaming bpf_tree to bpf_progs_tree and bpf_tree_ops
to bpf_progs_tree_ops to better capture the usage of
the tree, which is used for the bpf_prog objects only
for exception tables search.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/bpf/core.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:43:09
Adding trampolines to kallsyms. It's displayed as
bpf_trampoline_<ID> [bpf]
where ID is the BTF id of the trampoline function.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 2 ++
kernel/bpf/trampoline.c | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
@@ -502,6 +502,7 @@ struct bpf_trampoline {/* Executable image of trampoline */void*image;u64selector;+structbpf_ksymksym;};#define BPF_DISPATCHER_MAX 48 /* Fits in 2048B */
@@ -573,6 +574,7 @@ struct bpf_image {#define BPF_IMAGE_SIZE (PAGE_SIZE - sizeof(struct bpf_image))boolis_bpf_image_address(unsignedlongaddress);void*bpf_image_alloc(void);+voidbpf_image_ksym_add(void*data,structbpf_ksym*ksym);/* Called only from code, so there's no need for stubs. */voidbpf_ksym_add(structbpf_ksym*ksym);voidbpf_ksym_del(structbpf_ksym*ksym);
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:43:13
Adding dispatchers to kallsyms. It's displayed as
bpf_dispatcher_<NAME>
where NAME is the name of dispatcher.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 19 ++++++++++++-------
kernel/bpf/dispatcher.c | 6 ++++++
2 files changed, 18 insertions(+), 7 deletions(-)
From: Jiri Olsa <jolsa@kernel.org> Date: 2020-02-08 15:43:15
Currently we don't sort bpf_kallsyms and display symbols
in proc/kallsyms as they come in via __bpf_ksym_add.
Using the latch tree to get the next bpf_ksym object
and insert the new symbol ahead of it.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/bpf/core.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
From: Björn Töpel <hidden> Date: 2020-02-10 15:51:21
On Sat, 8 Feb 2020 at 16:42, Jiri Olsa [off-list ref] wrote:
hi,
this patchset adds trampoline and dispatcher objects
to be visible in /proc/kallsyms. The last patch also
adds sorting for all bpf objects in /proc/kallsyms.
Thanks for working on this!
I'm probably missing something with my perf setup; I've applied your
patches, and everything seem to work fine from an kallsyms
perspective:
# grep bpf_dispatcher_xdp /proc/kallsyms
...
ffffffffc0511000 t bpf_dispatcher_xdp [bpf]
However, when I run
# perf top
I still see the undecorated one:
0.90% [unknown] [k] 0xffffffffc0511037
Any ideas?
Björn
From: Jiri Olsa <hidden> Date: 2020-02-10 16:18:08
On Mon, Feb 10, 2020 at 04:51:08PM +0100, Björn Töpel wrote:
On Sat, 8 Feb 2020 at 16:42, Jiri Olsa [off-list ref] wrote:
quoted
hi,
this patchset adds trampoline and dispatcher objects
to be visible in /proc/kallsyms. The last patch also
adds sorting for all bpf objects in /proc/kallsyms.
Thanks for working on this!
I'm probably missing something with my perf setup; I've applied your
patches, and everything seem to work fine from an kallsyms
perspective:
# grep bpf_dispatcher_xdp /proc/kallsyms
...
ffffffffc0511000 t bpf_dispatcher_xdp [bpf]
However, when I run
# perf top
I still see the undecorated one:
0.90% [unknown] [k] 0xffffffffc0511037
Any ideas?
yea strange.. it should be picked up from /proc/kallsyms as
fallback if there's no other source, I'll check on that
(might be the problem with perf depending on address going
only higher in /proc/kallsyms, while bpf symbols are at the
end and start over from the lowest bpf address)
anyway, in perf we enumerate bpf_progs via the perf events
PERF_BPF_EVENT_PROG_LOAD,PERF_BPF_EVENT_PROG_UNLOAD interface
together with PERF_RECORD_KSYMBOL_TYPE_BPF events
we might need to add something like:
PERF_RECORD_KSYMBOL_TYPE_BPF_TRAMPOLINE
PERF_RECORD_KSYMBOL_TYPE_BPF_DISPATCHER
to notify about the area, I'll check on that
however the /proc/kallsyms fallback should work in any
case.. thanks for report ;-)
jirka
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted hunk
The bpf_tree is used both for kallsyms iterations and searching
for exception tables of bpf programs, which is needed only for
bpf programs.
Adding bpf_kallsyms_tree that will hold symbols for all bpf_prog,
bpf_trampoline and bpf_dispatcher objects and keeping bpf_tree
only for bpf_prog objects exception tables search to keep it fast.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 1 +
kernel/bpf/core.c | 60 ++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 55 insertions(+), 6 deletions(-)
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
When bpf_prog is removed from kallsyms it's on the way
out to be removed, so we don't care about lnode state.
However the bpf_ksym_del will be used also by bpf_trampoline
and bpf_dispatcher objects, which stay allocated even when
they are not in kallsyms list, hence the lnode re-init.
The list_del_rcu commentary states that we need to call
synchronize_rcu, before we can change/re-init the list_head
pointers.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
Wouldn't it make more sense to have patches 7 though 10 as a one
patch? It's a generalization of ksym from being bpf_prog-specific to
be more general (which this initialization fix is part of, arguably).
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted hunk
Adding trampolines to kallsyms. It's displayed as
bpf_trampoline_<ID> [bpf]
where ID is the BTF id of the trampoline function.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 2 ++
kernel/bpf/trampoline.c | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
@@ -502,6 +502,7 @@ struct bpf_trampoline {/* Executable image of trampoline */void*image;u64selector;+structbpf_ksymksym;};#define BPF_DISPATCHER_MAX 48 /* Fits in 2048B */
@@ -573,6 +574,7 @@ struct bpf_image {#define BPF_IMAGE_SIZE (PAGE_SIZE - sizeof(struct bpf_image))boolis_bpf_image_address(unsignedlongaddress);void*bpf_image_alloc(void);+voidbpf_image_ksym_add(void*data,structbpf_ksym*ksym);/* Called only from code, so there's no need for stubs. */voidbpf_ksym_add(structbpf_ksym*ksym);voidbpf_ksym_del(structbpf_ksym*ksym);
@@ -311,6 +330,8 @@ int bpf_trampoline_link_prog(struct bpf_prog *prog) if (err) { hlist_del(&prog->aux->tramp_hlist); tr->progs_cnt[kind]--;+ } else if (cnt == 0) {+ bpf_trampoline_kallsyms_add(tr);
You didn't handle BPF_TRAMP_REPLACE case above.
Also this if (err) { ... } else if (cnt == 0) { } pattern is a bit
convoluted. How about:
if (err) {
... whatever ...
goto out;
}
if (cnt == 0) { ... }
quoted hunk
}
out:
mutex_unlock(&tr->mutex);
@@ -336,6 +357,8 @@ int bpf_trampoline_unlink_prog(struct bpf_prog *prog) } hlist_del(&prog->aux->tramp_hlist); tr->progs_cnt[kind]--;+ if (!(tr->progs_cnt[BPF_TRAMP_FENTRY] + tr->progs_cnt[BPF_TRAMP_FEXIT]))+ bpf_ksym_del(&tr->ksym);
same, BPF_TRAMP_REPLACE case. I'd also introduce cnt for consistency
with bpf_trampoline_link_prog?
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted hunk
Adding dispatchers to kallsyms. It's displayed as
bpf_dispatcher_<NAME>
where NAME is the name of dispatcher.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 19 ++++++++++++-------
kernel/bpf/dispatcher.c | 6 ++++++
2 files changed, 18 insertions(+), 7 deletions(-)
On slightly unrelated note: seems like bpf_dispatcher_update won't
propagate any lower-level errors back, which seems pretty bad as a
bunch of stuff can go wrong.
Björn, was it a conscious decision or this just slipped through the cracks?
Jiri, reason I started looking at this was twofold:
1. you add/remove symbol before dispatcher is updated, which is
different order from BPF trampoline updates. I think updating symbols
after successful update makes more sense, no?
2. I was wondering if bpf_dispatcher_update() could return 0/1 (and <0
on error, of course), depending on whether dispatcher is present or
not. Though I'm not hard set on this.
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
Currently we don't sort bpf_kallsyms and display symbols
in proc/kallsyms as they come in via __bpf_ksym_add.
Using the latch tree to get the next bpf_ksym object
and insert the new symbol ahead of it.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
From: Arnaldo Carvalho de Melo <hidden> Date: 2020-02-11 19:14:00
Em Sat, Feb 08, 2020 at 04:41:55PM +0100, Jiri Olsa escreveu:
hi,
this patchset adds trampoline and dispatcher objects
to be visible in /proc/kallsyms. The last patch also
adds sorting for all bpf objects in /proc/kallsyms.
This will allow those to appear in profiles, right? That would be
interesting to explicitely state, i.e. the _why_ of this patch, not just
the _what_.
Thanks,
- Arnaldo
$ sudo cat /proc/kallsyms | tail -20
...
ffffffffa050f000 t bpf_prog_5a2b06eab81b8f51 [bpf]
ffffffffa0511000 t bpf_prog_6deef7357e7b4530 [bpf]
ffffffffa0542000 t bpf_trampoline_13832 [bpf]
ffffffffa0548000 t bpf_prog_96f1b5bf4e4cc6dc_mutex_lock [bpf]
ffffffffa0572000 t bpf_prog_d1c63e29ad82c4ab_bpf_prog1 [bpf]
ffffffffa0585000 t bpf_prog_e314084d332a5338__dissect [bpf]
ffffffffa0587000 t bpf_prog_59785a79eac7e5d2_mutex_unlock [bpf]
ffffffffa0589000 t bpf_prog_d0db6e0cac050163_mutex_lock [bpf]
ffffffffa058d000 t bpf_prog_d8f047721e4d8321_bpf_prog2 [bpf]
ffffffffa05df000 t bpf_trampoline_25637 [bpf]
ffffffffa05e3000 t bpf_prog_d8f047721e4d8321_bpf_prog2 [bpf]
ffffffffa05e5000 t bpf_prog_3b185187f1855c4c [bpf]
ffffffffa05e7000 t bpf_prog_d8f047721e4d8321_bpf_prog2 [bpf]
ffffffffa05eb000 t bpf_prog_93cebb259dd5c4b2_do_sys_open [bpf]
ffffffffa0677000 t bpf_dispatcher_xdp [bpf]
thanks,
jirka
---
Björn Töpel (1):
bpf: Add bpf_trampoline_ name prefix for DECLARE_BPF_DISPATCHER
Jiri Olsa (13):
x86/mm: Rename is_kernel_text to __is_kernel_text
bpf: Add struct bpf_ksym
bpf: Add name to struct bpf_ksym
bpf: Add lnode list node to struct bpf_ksym
bpf: Add bpf_kallsyms_tree tree
bpf: Move bpf_tree add/del from bpf_prog_ksym_node_add/del
bpf: Separate kallsyms add/del functions
bpf: Add bpf_ksym_add/del functions
bpf: Re-initialize lnode in bpf_ksym_del
bpf: Rename bpf_tree to bpf_progs_tree
bpf: Add trampolines to kallsyms
bpf: Add dispatchers to kallsyms
bpf: Sort bpf kallsyms symbols
arch/x86/mm/init_32.c | 14 ++++++----
include/linux/bpf.h | 54 ++++++++++++++++++++++++++------------
include/linux/filter.h | 13 +++-------
kernel/bpf/core.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
kernel/bpf/dispatcher.c | 6 +++++
kernel/bpf/trampoline.c | 23 ++++++++++++++++
kernel/events/core.c | 4 +--
net/core/filter.c | 5 ++--
8 files changed, 219 insertions(+), 82 deletions(-)
From: Arnaldo Carvalho de Melo <hidden> Date: 2020-02-11 19:32:32
Em Mon, Feb 10, 2020 at 05:17:51PM +0100, Jiri Olsa escreveu:
On Mon, Feb 10, 2020 at 04:51:08PM +0100, Björn Töpel wrote:
quoted
On Sat, 8 Feb 2020 at 16:42, Jiri Olsa [off-list ref] wrote:
quoted
this patchset adds trampoline and dispatcher objects
to be visible in /proc/kallsyms. The last patch also
adds sorting for all bpf objects in /proc/kallsyms.
quoted
Thanks for working on this!
quoted
I'm probably missing something with my perf setup; I've applied your
patches, and everything seem to work fine from an kallsyms
perspective:
quoted
# grep bpf_dispatcher_xdp /proc/kallsyms
...
ffffffffc0511000 t bpf_dispatcher_xdp [bpf]
However, when I run
# perf top
I still see the undecorated one:
0.90% [unknown] [k] 0xffffffffc0511037
Any ideas?
yea strange.. it should be picked up from /proc/kallsyms as
fallback if there's no other source, I'll check on that
(might be the problem with perf depending on address going
only higher in /proc/kallsyms, while bpf symbols are at the
end and start over from the lowest bpf address)
anyway, in perf we enumerate bpf_progs via the perf events
PERF_BPF_EVENT_PROG_LOAD,PERF_BPF_EVENT_PROG_UNLOAD interface
together with PERF_RECORD_KSYMBOL_TYPE_BPF events
we might need to add something like:
PERF_RECORD_KSYMBOL_TYPE_BPF_TRAMPOLINE
PERF_RECORD_KSYMBOL_TYPE_BPF_DISPATCHER
to notify about the area, I'll check on that
however the /proc/kallsyms fallback should work in any
case.. thanks for report ;-)
We should by now move kallsyms to be the preferred source of symbols,
not vmlinux, right?
Perhaps what is happening is:
[root@quaco ~]# strace -f -e open,openat -o /tmp/bla perf top
[root@quaco ~]# grep vmlinux /tmp/bla
11013 openat(AT_FDCWD, "vmlinux", O_RDONLY) = -1 ENOENT (No such file or directory)
11013 openat(AT_FDCWD, "/boot/vmlinux", O_RDONLY) = -1 ENOENT (No such file or directory)
11013 openat(AT_FDCWD, "/boot/vmlinux-5.5.0+", O_RDONLY) = -1 ENOENT (No such file or directory)
11013 openat(AT_FDCWD, "/usr/lib/debug/boot/vmlinux-5.5.0+", O_RDONLY) = -1 ENOENT (No such file or directory)
11013 openat(AT_FDCWD, "/lib/modules/5.5.0+/build/vmlinux", O_RDONLY) = 152
[root@quaco ~]#
I.e. it is using vmlinux for resolving symbols and he should try with:
[root@quaco ~]# strace -f -e open,openat -o /tmp/bla perf top --ignore-vmlinux
[root@quaco ~]# perf top -h vmlinux
Usage: perf top [<options>]
-k, --vmlinux <file> vmlinux pathname
--ignore-vmlinux don't load vmlinux even if found
[root@quaco ~]# grep vmlinux /tmp/bla
[root@quaco ~]#
Historically vmlinux was preferred because it contains function sizes,
but with all these out of the blue symbols, we need to prefer starting
with /proc/kallsyms and, as we do now, continue getting updates via
PERF_RECORD_KSYMBOL.
Humm, but then trampolines don't generate that, right? Or does it? If it
doesn't, then we will know about just the trampolines in place when the
record/top session starts, reparsing /proc/kallsyms periodically seems
excessive?
- Arnaldo
From: Jiri Olsa <hidden> Date: 2020-02-12 10:44:50
On Tue, Feb 11, 2020 at 10:28:50AM -0800, Andrii Nakryiko wrote:
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted
When bpf_prog is removed from kallsyms it's on the way
out to be removed, so we don't care about lnode state.
However the bpf_ksym_del will be used also by bpf_trampoline
and bpf_dispatcher objects, which stay allocated even when
they are not in kallsyms list, hence the lnode re-init.
The list_del_rcu commentary states that we need to call
synchronize_rcu, before we can change/re-init the list_head
pointers.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
Wouldn't it make more sense to have patches 7 though 10 as a one
patch? It's a generalization of ksym from being bpf_prog-specific to
be more general (which this initialization fix is part of, arguably).
it was my initial change ;-) but then I realized I have to explain
several things in the changelog, and that's usually the sign that
you need to split the patch.. also I think now it's easier for review
and backporting
so I prefer it split like this, but if you guys want to squash it
together, I'll do it ;-)
jirka
From: Jiri Olsa <hidden> Date: 2020-02-12 10:47:00
On Tue, Feb 11, 2020 at 04:13:47PM -0300, Arnaldo Carvalho de Melo wrote:
Em Sat, Feb 08, 2020 at 04:41:55PM +0100, Jiri Olsa escreveu:
quoted
hi,
this patchset adds trampoline and dispatcher objects
to be visible in /proc/kallsyms. The last patch also
adds sorting for all bpf objects in /proc/kallsyms.
This will allow those to appear in profiles, right? That would be
yea, one would think so.. but as you saw in the other email
there are still some issues ;-)
interesting to explicitely state, i.e. the _why_ of this patch, not just
the _what_.
I guess another reason would be accountability of the kernel space,
so that everything with the symbol would appear in /proc/kallsyms
jirka
Thanks,
- Arnaldo
quoted
$ sudo cat /proc/kallsyms | tail -20
...
ffffffffa050f000 t bpf_prog_5a2b06eab81b8f51 [bpf]
ffffffffa0511000 t bpf_prog_6deef7357e7b4530 [bpf]
ffffffffa0542000 t bpf_trampoline_13832 [bpf]
ffffffffa0548000 t bpf_prog_96f1b5bf4e4cc6dc_mutex_lock [bpf]
ffffffffa0572000 t bpf_prog_d1c63e29ad82c4ab_bpf_prog1 [bpf]
ffffffffa0585000 t bpf_prog_e314084d332a5338__dissect [bpf]
ffffffffa0587000 t bpf_prog_59785a79eac7e5d2_mutex_unlock [bpf]
ffffffffa0589000 t bpf_prog_d0db6e0cac050163_mutex_lock [bpf]
ffffffffa058d000 t bpf_prog_d8f047721e4d8321_bpf_prog2 [bpf]
ffffffffa05df000 t bpf_trampoline_25637 [bpf]
ffffffffa05e3000 t bpf_prog_d8f047721e4d8321_bpf_prog2 [bpf]
ffffffffa05e5000 t bpf_prog_3b185187f1855c4c [bpf]
ffffffffa05e7000 t bpf_prog_d8f047721e4d8321_bpf_prog2 [bpf]
ffffffffa05eb000 t bpf_prog_93cebb259dd5c4b2_do_sys_open [bpf]
ffffffffa0677000 t bpf_dispatcher_xdp [bpf]
thanks,
jirka
---
Björn Töpel (1):
bpf: Add bpf_trampoline_ name prefix for DECLARE_BPF_DISPATCHER
Jiri Olsa (13):
x86/mm: Rename is_kernel_text to __is_kernel_text
bpf: Add struct bpf_ksym
bpf: Add name to struct bpf_ksym
bpf: Add lnode list node to struct bpf_ksym
bpf: Add bpf_kallsyms_tree tree
bpf: Move bpf_tree add/del from bpf_prog_ksym_node_add/del
bpf: Separate kallsyms add/del functions
bpf: Add bpf_ksym_add/del functions
bpf: Re-initialize lnode in bpf_ksym_del
bpf: Rename bpf_tree to bpf_progs_tree
bpf: Add trampolines to kallsyms
bpf: Add dispatchers to kallsyms
bpf: Sort bpf kallsyms symbols
arch/x86/mm/init_32.c | 14 ++++++----
include/linux/bpf.h | 54 ++++++++++++++++++++++++++------------
include/linux/filter.h | 13 +++-------
kernel/bpf/core.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
kernel/bpf/dispatcher.c | 6 +++++
kernel/bpf/trampoline.c | 23 ++++++++++++++++
kernel/events/core.c | 4 +--
net/core/filter.c | 5 ++--
8 files changed, 219 insertions(+), 82 deletions(-)
From: Jiri Olsa <hidden> Date: 2020-02-12 10:49:50
On Tue, Feb 11, 2020 at 10:21:10AM -0800, Andrii Nakryiko wrote:
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted
The bpf_tree is used both for kallsyms iterations and searching
for exception tables of bpf programs, which is needed only for
bpf programs.
Adding bpf_kallsyms_tree that will hold symbols for all bpf_prog,
bpf_trampoline and bpf_dispatcher objects and keeping bpf_tree
only for bpf_prog objects exception tables search to keep it fast.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 1 +
kernel/bpf/core.c | 60 ++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 55 insertions(+), 6 deletions(-)
From: Jiri Olsa <hidden> Date: 2020-02-12 10:53:06
On Tue, Feb 11, 2020 at 11:03:23AM -0800, Andrii Nakryiko wrote:
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted
Adding dispatchers to kallsyms. It's displayed as
bpf_dispatcher_<NAME>
where NAME is the name of dispatcher.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 19 ++++++++++++-------
kernel/bpf/dispatcher.c | 6 ++++++
2 files changed, 18 insertions(+), 7 deletions(-)
On slightly unrelated note: seems like bpf_dispatcher_update won't
propagate any lower-level errors back, which seems pretty bad as a
bunch of stuff can go wrong.
Björn, was it a conscious decision or this just slipped through the cracks?
Jiri, reason I started looking at this was twofold:
1. you add/remove symbol before dispatcher is updated, which is
different order from BPF trampoline updates. I think updating symbols
after successful update makes more sense, no?
right, I guess I did not care, because there's no error returned
from bpf_dispatcher_update as you pointed out.. I'll check if we
can add that and add/del symbols afterwards
2. I was wondering if bpf_dispatcher_update() could return 0/1 (and <0
on error, of course), depending on whether dispatcher is present or
not. Though I'm not hard set on this.
yes, that might be a way.. I'll check
thanks,
jirka
From: Jiri Olsa <hidden> Date: 2020-02-12 11:10:13
On Tue, Feb 11, 2020 at 10:51:27AM -0800, Andrii Nakryiko wrote:
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted
Adding trampolines to kallsyms. It's displayed as
bpf_trampoline_<ID> [bpf]
where ID is the BTF id of the trampoline function.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 2 ++
kernel/bpf/trampoline.c | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
@@ -502,6 +502,7 @@ struct bpf_trampoline {/* Executable image of trampoline */void*image;u64selector;+structbpf_ksymksym;};#define BPF_DISPATCHER_MAX 48 /* Fits in 2048B */
@@ -573,6 +574,7 @@ struct bpf_image {#define BPF_IMAGE_SIZE (PAGE_SIZE - sizeof(struct bpf_image))boolis_bpf_image_address(unsignedlongaddress);void*bpf_image_alloc(void);+voidbpf_image_ksym_add(void*data,structbpf_ksym*ksym);/* Called only from code, so there's no need for stubs. */voidbpf_ksym_add(structbpf_ksym*ksym);voidbpf_ksym_del(structbpf_ksym*ksym);
@@ -96,6 +96,15 @@ bool is_bpf_image_address(unsigned long addr)returnret;}+voidbpf_image_ksym_add(void*data,structbpf_ksym*ksym)+{+structbpf_image*image=container_of(data,structbpf_image,data);++ksym->start=(unsignedlong)image;+ksym->end=ksym->start+PAGE_SIZE;
this seems wrong, use BPF_IMAGE_SIZE instead of PAGE_SIZE?
BPF_IMAGE_SIZE is the size of the data portion of the image,
which is PAGE_SIZE - sizeof(struct bpf_image)
here we want to account the whole size = data + tree node (struct bpf_image)
@@ -311,6 +330,8 @@ int bpf_trampoline_link_prog(struct bpf_prog *prog) if (err) { hlist_del(&prog->aux->tramp_hlist); tr->progs_cnt[kind]--;+ } else if (cnt == 0) {+ bpf_trampoline_kallsyms_add(tr);
You didn't handle BPF_TRAMP_REPLACE case above.
ugh, right.. will add
Also this if (err) { ... } else if (cnt == 0) { } pattern is a bit
convoluted. How about:
if (err) {
... whatever ...
goto out;
}
if (cnt == 0) { ... }
yep, that's better
quoted
}
out:
mutex_unlock(&tr->mutex);
@@ -336,6 +357,8 @@ int bpf_trampoline_unlink_prog(struct bpf_prog *prog) } hlist_del(&prog->aux->tramp_hlist); tr->progs_cnt[kind]--;+ if (!(tr->progs_cnt[BPF_TRAMP_FENTRY] + tr->progs_cnt[BPF_TRAMP_FEXIT]))+ bpf_ksym_del(&tr->ksym);
same, BPF_TRAMP_REPLACE case. I'd also introduce cnt for consistency
with bpf_trampoline_link_prog?
From: Jiri Olsa <hidden> Date: 2020-02-12 11:13:59
On Tue, Feb 11, 2020 at 04:32:23PM -0300, Arnaldo Carvalho de Melo wrote:
Em Mon, Feb 10, 2020 at 05:17:51PM +0100, Jiri Olsa escreveu:
quoted
On Mon, Feb 10, 2020 at 04:51:08PM +0100, Björn Töpel wrote:
quoted
On Sat, 8 Feb 2020 at 16:42, Jiri Olsa [off-list ref] wrote:
quoted
this patchset adds trampoline and dispatcher objects
to be visible in /proc/kallsyms. The last patch also
adds sorting for all bpf objects in /proc/kallsyms.
quoted
quoted
Thanks for working on this!
quoted
quoted
I'm probably missing something with my perf setup; I've applied your
patches, and everything seem to work fine from an kallsyms
perspective:
quoted
quoted
# grep bpf_dispatcher_xdp /proc/kallsyms
...
ffffffffc0511000 t bpf_dispatcher_xdp [bpf]
However, when I run
# perf top
I still see the undecorated one:
0.90% [unknown] [k] 0xffffffffc0511037
Any ideas?
quoted
yea strange.. it should be picked up from /proc/kallsyms as
fallback if there's no other source, I'll check on that
(might be the problem with perf depending on address going
only higher in /proc/kallsyms, while bpf symbols are at the
end and start over from the lowest bpf address)
anyway, in perf we enumerate bpf_progs via the perf events
PERF_BPF_EVENT_PROG_LOAD,PERF_BPF_EVENT_PROG_UNLOAD interface
together with PERF_RECORD_KSYMBOL_TYPE_BPF events
we might need to add something like:
PERF_RECORD_KSYMBOL_TYPE_BPF_TRAMPOLINE
PERF_RECORD_KSYMBOL_TYPE_BPF_DISPATCHER
to notify about the area, I'll check on that
however the /proc/kallsyms fallback should work in any
case.. thanks for report ;-)
We should by now move kallsyms to be the preferred source of symbols,
not vmlinux, right?
Perhaps what is happening is:
[root@quaco ~]# strace -f -e open,openat -o /tmp/bla perf top
[root@quaco ~]# grep vmlinux /tmp/bla
11013 openat(AT_FDCWD, "vmlinux", O_RDONLY) = -1 ENOENT (No such file or directory)
11013 openat(AT_FDCWD, "/boot/vmlinux", O_RDONLY) = -1 ENOENT (No such file or directory)
11013 openat(AT_FDCWD, "/boot/vmlinux-5.5.0+", O_RDONLY) = -1 ENOENT (No such file or directory)
11013 openat(AT_FDCWD, "/usr/lib/debug/boot/vmlinux-5.5.0+", O_RDONLY) = -1 ENOENT (No such file or directory)
11013 openat(AT_FDCWD, "/lib/modules/5.5.0+/build/vmlinux", O_RDONLY) = 152
[root@quaco ~]#
I.e. it is using vmlinux for resolving symbols and he should try with:
[root@quaco ~]# strace -f -e open,openat -o /tmp/bla perf top --ignore-vmlinux
[root@quaco ~]# perf top -h vmlinux
Usage: perf top [<options>]
-k, --vmlinux <file> vmlinux pathname
--ignore-vmlinux don't load vmlinux even if found
[root@quaco ~]# grep vmlinux /tmp/bla
[root@quaco ~]#
Historically vmlinux was preferred because it contains function sizes,
but with all these out of the blue symbols, we need to prefer starting
with /proc/kallsyms and, as we do now, continue getting updates via
PERF_RECORD_KSYMBOL.
Humm, but then trampolines don't generate that, right? Or does it? If it
doesn't, then we will know about just the trampolines in place when the
record/top session starts, reparsing /proc/kallsyms periodically seems
excessive?
I plan to extend the KSYMBOL interface to contain trampolines/dispatcher
data, plus we could do some inteligent fallback to /proc/kallsyms in case
vmlinux won't have anything
jirka
From: Arnaldo Carvalho de Melo <hidden> Date: 2020-02-12 13:31:34
Em Wed, Feb 12, 2020 at 12:13:46PM +0100, Jiri Olsa escreveu:
On Tue, Feb 11, 2020 at 04:32:23PM -0300, Arnaldo Carvalho de Melo wrote:
quoted
Historically vmlinux was preferred because it contains function sizes,
but with all these out of the blue symbols, we need to prefer starting
with /proc/kallsyms and, as we do now, continue getting updates via
PERF_RECORD_KSYMBOL.
quoted
Humm, but then trampolines don't generate that, right? Or does it? If it
doesn't, then we will know about just the trampolines in place when the
record/top session starts, reparsing /proc/kallsyms periodically seems
excessive?
I plan to extend the KSYMBOL interface to contain trampolines/dispatcher
data,
That seems like the sensible, without looking too much at all the
details, to do, yes.
plus we could do some inteligent fallback to /proc/kallsyms in case
vmlinux won't have anything
At this point what would be the good reason to prefer vmlinux instead of
going straight to using /proc/kallsyms?
We have support for taking a snapshot of it at 'perf top' start, i.e.
right at the point we need to resolve a kernel symbol, then we get
PERF_RECORD_KSYMBOL for things that gets in place after that.
And as well we save it to the build-id cache so that later, at 'perf
report/script' time we can resolve kernel symbols, etc.
vmlinux is just what is in there right before boot, after that, for
quite some time, _lots_ of stuff happens :-)
- Arnaldo
On Wed, Feb 12, 2020 at 3:10 AM Jiri Olsa [off-list ref] wrote:
On Tue, Feb 11, 2020 at 10:51:27AM -0800, Andrii Nakryiko wrote:
quoted
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted
Adding trampolines to kallsyms. It's displayed as
bpf_trampoline_<ID> [bpf]
where ID is the BTF id of the trampoline function.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 2 ++
kernel/bpf/trampoline.c | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
@@ -502,6 +502,7 @@ struct bpf_trampoline {/* Executable image of trampoline */void*image;u64selector;+structbpf_ksymksym;};#define BPF_DISPATCHER_MAX 48 /* Fits in 2048B */
@@ -573,6 +574,7 @@ struct bpf_image {#define BPF_IMAGE_SIZE (PAGE_SIZE - sizeof(struct bpf_image))boolis_bpf_image_address(unsignedlongaddress);void*bpf_image_alloc(void);+voidbpf_image_ksym_add(void*data,structbpf_ksym*ksym);/* Called only from code, so there's no need for stubs. */voidbpf_ksym_add(structbpf_ksym*ksym);voidbpf_ksym_del(structbpf_ksym*ksym);
@@ -96,6 +96,15 @@ bool is_bpf_image_address(unsigned long addr)returnret;}+voidbpf_image_ksym_add(void*data,structbpf_ksym*ksym)+{+structbpf_image*image=container_of(data,structbpf_image,data);++ksym->start=(unsignedlong)image;+ksym->end=ksym->start+PAGE_SIZE;
this seems wrong, use BPF_IMAGE_SIZE instead of PAGE_SIZE?
BPF_IMAGE_SIZE is the size of the data portion of the image,
which is PAGE_SIZE - sizeof(struct bpf_image)
here we want to account the whole size = data + tree node (struct bpf_image)
Why? Seems like the main use case for this is resolve IP to symbol
(function, dispatcher, trampoline, bpf program, etc). For this
purpose, you only need part of trampoline actually containing
executable code?
Also, for bpf_dispatcher in later patch, you are not including struct
bpf_dispatcher itself, you only include image, so if the idea is to
include all the code and supporting data structures, that already
failed for bpf_dispatcher (and can't even work for that case, due to
dispatcher and image not being part of the same blob of memory, so
you'll need two symbols).
So I guess it would be good to be clear on why we include these
symbols and not mix data and executable parts.
why the 32-bit truncation? also, wouldn't it be more trivial as (u32)tr->key?
tr->key can have the target prog id in upper 32 bits,
True, but not clear why it's bad? It's not a security concern, because
those IDs are already exposed (you can dump them from bpftool). On the
other hand, by cutting out part of key, you make symbols potentially
ambiguous, with different trampolines marked with the same name in
kallsyms, which is just going to be confusing to users/tools.
@@ -311,6 +330,8 @@ int bpf_trampoline_link_prog(struct bpf_prog *prog) if (err) { hlist_del(&prog->aux->tramp_hlist); tr->progs_cnt[kind]--;+ } else if (cnt == 0) {+ bpf_trampoline_kallsyms_add(tr);
You didn't handle BPF_TRAMP_REPLACE case above.
ugh, right.. will add
quoted
Also this if (err) { ... } else if (cnt == 0) { } pattern is a bit
convoluted. How about:
if (err) {
... whatever ...
goto out;
}
if (cnt == 0) { ... }
yep, that's better
quoted
quoted
}
out:
mutex_unlock(&tr->mutex);
@@ -336,6 +357,8 @@ int bpf_trampoline_unlink_prog(struct bpf_prog *prog) } hlist_del(&prog->aux->tramp_hlist); tr->progs_cnt[kind]--;+ if (!(tr->progs_cnt[BPF_TRAMP_FENTRY] + tr->progs_cnt[BPF_TRAMP_FEXIT]))+ bpf_ksym_del(&tr->ksym);
same, BPF_TRAMP_REPLACE case. I'd also introduce cnt for consistency
with bpf_trampoline_link_prog?
From: Jiri Olsa <hidden> Date: 2020-02-12 22:40:53
On Wed, Feb 12, 2020 at 10:31:25AM -0300, Arnaldo Carvalho de Melo wrote:
Em Wed, Feb 12, 2020 at 12:13:46PM +0100, Jiri Olsa escreveu:
quoted
On Tue, Feb 11, 2020 at 04:32:23PM -0300, Arnaldo Carvalho de Melo wrote:
quoted
Historically vmlinux was preferred because it contains function sizes,
but with all these out of the blue symbols, we need to prefer starting
with /proc/kallsyms and, as we do now, continue getting updates via
PERF_RECORD_KSYMBOL.
quoted
quoted
Humm, but then trampolines don't generate that, right? Or does it? If it
doesn't, then we will know about just the trampolines in place when the
record/top session starts, reparsing /proc/kallsyms periodically seems
excessive?
quoted
I plan to extend the KSYMBOL interface to contain trampolines/dispatcher
data,
That seems like the sensible, without looking too much at all the
details, to do, yes.
quoted
plus we could do some inteligent fallback to /proc/kallsyms in case
vmlinux won't have anything
At this point what would be the good reason to prefer vmlinux instead of
going straight to using /proc/kallsyms?
symbol (with sizes) and code for dwarf unwind, processor trace
jirka
We have support for taking a snapshot of it at 'perf top' start, i.e.
right at the point we need to resolve a kernel symbol, then we get
PERF_RECORD_KSYMBOL for things that gets in place after that.
And as well we save it to the build-id cache so that later, at 'perf
report/script' time we can resolve kernel symbols, etc.
vmlinux is just what is in there right before boot, after that, for
quite some time, _lots_ of stuff happens :-)
- Arnaldo
From: Jiri Olsa <hidden> Date: 2020-02-12 22:58:36
On Wed, Feb 12, 2020 at 08:33:49AM -0800, Andrii Nakryiko wrote:
On Wed, Feb 12, 2020 at 3:10 AM Jiri Olsa [off-list ref] wrote:
quoted
On Tue, Feb 11, 2020 at 10:51:27AM -0800, Andrii Nakryiko wrote:
quoted
On Sat, Feb 8, 2020 at 7:43 AM Jiri Olsa [off-list ref] wrote:
quoted
Adding trampolines to kallsyms. It's displayed as
bpf_trampoline_<ID> [bpf]
where ID is the BTF id of the trampoline function.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 2 ++
kernel/bpf/trampoline.c | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
@@ -502,6 +502,7 @@ struct bpf_trampoline {/* Executable image of trampoline */void*image;u64selector;+structbpf_ksymksym;};#define BPF_DISPATCHER_MAX 48 /* Fits in 2048B */
@@ -573,6 +574,7 @@ struct bpf_image {#define BPF_IMAGE_SIZE (PAGE_SIZE - sizeof(struct bpf_image))boolis_bpf_image_address(unsignedlongaddress);void*bpf_image_alloc(void);+voidbpf_image_ksym_add(void*data,structbpf_ksym*ksym);/* Called only from code, so there's no need for stubs. */voidbpf_ksym_add(structbpf_ksym*ksym);voidbpf_ksym_del(structbpf_ksym*ksym);
@@ -96,6 +96,15 @@ bool is_bpf_image_address(unsigned long addr)returnret;}+voidbpf_image_ksym_add(void*data,structbpf_ksym*ksym)+{+structbpf_image*image=container_of(data,structbpf_image,data);++ksym->start=(unsignedlong)image;+ksym->end=ksym->start+PAGE_SIZE;
this seems wrong, use BPF_IMAGE_SIZE instead of PAGE_SIZE?
BPF_IMAGE_SIZE is the size of the data portion of the image,
which is PAGE_SIZE - sizeof(struct bpf_image)
here we want to account the whole size = data + tree node (struct bpf_image)
Why? Seems like the main use case for this is resolve IP to symbol
(function, dispatcher, trampoline, bpf program, etc). For this
purpose, you only need part of trampoline actually containing
executable code?
right, executable code is enough for perf to resolve the symbol
Also, for bpf_dispatcher in later patch, you are not including struct
bpf_dispatcher itself, you only include image, so if the idea is to
include all the code and supporting data structures, that already
failed for bpf_dispatcher (and can't even work for that case, due to
dispatcher and image not being part of the same blob of memory, so
you'll need two symbols).
So I guess it would be good to be clear on why we include these
symbols and not mix data and executable parts.
ok it should be only the executable part then, there's more
on the data side that wasn't included and we don't need it
thanks,
jirka
why the 32-bit truncation? also, wouldn't it be more trivial as (u32)tr->key?
tr->key can have the target prog id in upper 32 bits,
True, but not clear why it's bad? It's not a security concern, because
those IDs are already exposed (you can dump them from bpftool). On the
other hand, by cutting out part of key, you make symbols potentially
ambiguous, with different trampolines marked with the same name in
kallsyms, which is just going to be confusing to users/tools.
ugh ok, I did not see the target bpf program case clearly,
will include the whole tr->key
thanks,
jirka
From: Jiri Olsa <hidden> Date: 2020-02-13 16:23:58
On Mon, Feb 10, 2020 at 04:51:08PM +0100, Björn Töpel wrote:
On Sat, 8 Feb 2020 at 16:42, Jiri Olsa [off-list ref] wrote:
quoted
hi,
this patchset adds trampoline and dispatcher objects
to be visible in /proc/kallsyms. The last patch also
adds sorting for all bpf objects in /proc/kallsyms.
Thanks for working on this!
I'm probably missing something with my perf setup; I've applied your
patches, and everything seem to work fine from an kallsyms
perspective:
# grep bpf_dispatcher_xdp /proc/kallsyms
...
ffffffffc0511000 t bpf_dispatcher_xdp [bpf]
However, when I run
# perf top
I still see the undecorated one:
0.90% [unknown] [k] 0xffffffffc0511037
Any ideas?
heya,
the code is little rusty and needs some fixing :-\
with the patch below on top of Arnaldo's perf/urgent branch,
there's one workaround for now:
# perf record --vmlinux /proc/kallsyms
^C[ perf record: Woken up 0 times to write data ]
[ perf record: Captured and wrote 18.954 MB perf.data (348693 samples) ]
# perf report --kallsyms /proc/kallsyms | grep bpf_trampoline_13795
0.01% sched-messaging kallsyms [k] bpf_trampoline_13795
0.00% perf kallsyms [k] bpf_trampoline_13795
0.00% :47547 kallsyms [k] bpf_trampoline_13795
0.00% :47546 kallsyms [k] bpf_trampoline_13795
0.00% :47544 kallsyms [k] bpf_trampoline_13795
with recent kcore/vmlinux changes we neglected kallsyms fallback,
I'm preparing changes that will detect and use it automaticaly
jirka
---