Messages in this thread | | | Date | Mon, 12 Mar 2018 11:44:57 -0700 | From | Alexei Starovoitov <> | Subject | Re: [PATCH 11/13] perf bpf: Add helper header files |
| |
On Mon, Mar 12, 2018 at 10:43:11AM +0100, Jiri Olsa wrote: > diff --git a/tools/perf/util/bpf-userapi.h b/tools/perf/util/bpf-userapi.h > new file mode 100644 > index 000000000000..63f2b4c13a5c > --- /dev/null > +++ b/tools/perf/util/bpf-userapi.h > @@ -0,0 +1,11 @@ > +#ifndef __BPF_USERAPI_H > +#define __BPF_USERAPI_H > + > +enum { > + BPF_FUNC_USER_START = 10000, > + BPF_FUNC_USER_print = BPF_FUNC_USER_START, > + BPF_FUNC_USER_bpf_map_get_next_key, > + BPF_FUNC_USER_bpf_map_lookup_elem, > +}; > + > +#endif /* __BPF_USERFUNCS_H */ > diff --git a/tools/perf/util/bpf-userfuncs.h b/tools/perf/util/bpf-userfuncs.h > new file mode 100644 > index 000000000000..e920420237ee > --- /dev/null > +++ b/tools/perf/util/bpf-userfuncs.h > @@ -0,0 +1,19 @@ > +#ifndef __BPF_USERFUNCS_H > +#define __BPF_USERFUNCS_H > + > +#include <bpf-userapi.h> > + > +static int (*bpfu_print)(const char *fmt, ...) = > + (void *) BPF_FUNC_USER_print; > +static int (*bpfu_map_get_next_key)(void *map, void *key, void *value) = > + (void *) BPF_FUNC_USER_bpf_map_get_next_key; > +static int (*bpfu_map_lookup_elem)(void *map, void *key, void *value) = > + (void *) BPF_FUNC_USER_bpf_map_lookup_elem; > + > +#define print(fmt, ...) \ > +({ \ > + char ____fmt[] = fmt; \ > + bpfu_print(____fmt, ##__VA_ARGS__); \ > +})
since there is no verifier for this user space bpf interpreter there is no need to restrict what BEGIN/END progs can do and can call. llvm will happily compile any C code into bpf instructions. With little bit of elf magic it's possible to let it call any libc function instead of only 3 above. perf loader will see bpf_call into normal printf, memcpy, memcmp, etc then during the loading need to associate symbol with actual address of these functions inside perf binary and let call_cb do the call. I think this way begin/end will be much more powerful and useful. Potentially allowing some of the bcc scripts to be written this way.
| |