Message ID | 20210124194909.453844-5-andreimatei1@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | bpf: allow variable-offset stack access | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for bpf-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | warning | 10 maintainers not CCed: shuah@kernel.org netdev@vger.kernel.org songliubraving@fb.com linux-kselftest@vger.kernel.org andrii@kernel.org daniel@iogearbox.net kpsingh@kernel.org john.fastabend@gmail.com kafai@fb.com yhs@fb.com |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 65 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
netdev/stable | success | Stable not CCed |
On Sun, Jan 24, 2021 at 11:54 AM Andrei Matei <andreimatei1@gmail.com> wrote: > > get_base_addr is generally useful for tests attaching uprobes. This > patch moves it from one particular test to test_progs.{h,c}. The > function will be used by a second test in the next patch. > > Signed-off-by: Andrei Matei <andreimatei1@gmail.com> > --- trace_helpers.{c,h} seem more appropriate as a destination > .../selftests/bpf/prog_tests/attach_probe.c | 21 ---------------- > tools/testing/selftests/bpf/test_progs.c | 25 +++++++++++++++++++ > tools/testing/selftests/bpf/test_progs.h | 1 + > 3 files changed, 26 insertions(+), 21 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c > index a0ee87c8e1ea..3bda8acbbafb 100644 > --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c > +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c > @@ -2,27 +2,6 @@ > #include <test_progs.h> > #include "test_attach_probe.skel.h" > [...]
diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c index a0ee87c8e1ea..3bda8acbbafb 100644 --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c @@ -2,27 +2,6 @@ #include <test_progs.h> #include "test_attach_probe.skel.h" -ssize_t get_base_addr() { - size_t start, offset; - char buf[256]; - FILE *f; - - f = fopen("/proc/self/maps", "r"); - if (!f) - return -errno; - - while (fscanf(f, "%zx-%*x %s %zx %*[^\n]\n", - &start, buf, &offset) == 3) { - if (strcmp(buf, "r-xp") == 0) { - fclose(f); - return start - offset; - } - } - - fclose(f); - return -EINVAL; -} - void test_attach_probe(void) { int duration = 0; diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index 213628ee721c..6d3354ae4034 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -423,6 +423,31 @@ static int load_bpf_testmod(void) return 0; } +/* find the address at which the executable section of the current program has + * been loaded. + */ +ssize_t get_base_addr(void) +{ + size_t start, offset; + char buf[256]; + FILE *f; + + f = fopen("/proc/self/maps", "r"); + if (!f) + return -errno; + + while (fscanf(f, "%zx-%*x %s %zx %*[^\n]\n", + &start, buf, &offset) == 3) { + if (strcmp(buf, "r-xp") == 0) { + fclose(f); + return start - offset; + } + } + + fclose(f); + return -EINVAL; +} + /* extern declarations for test funcs */ #define DEFINE_TEST(name) extern void test_##name(void); #include <prog_tests/tests.h> diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h index f7c2fd89d01a..7a1eafd7ae77 100644 --- a/tools/testing/selftests/bpf/test_progs.h +++ b/tools/testing/selftests/bpf/test_progs.h @@ -219,6 +219,7 @@ int compare_map_keys(int map1_fd, int map2_fd); int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len); int extract_build_id(char *build_id, size_t size); int kern_sync_rcu(void); +ssize_t get_base_addr(void); #ifdef __x86_64__ #define SYS_NANOSLEEP_KPROBE_NAME "__x64_sys_nanosleep"
get_base_addr is generally useful for tests attaching uprobes. This patch moves it from one particular test to test_progs.{h,c}. The function will be used by a second test in the next patch. Signed-off-by: Andrei Matei <andreimatei1@gmail.com> --- .../selftests/bpf/prog_tests/attach_probe.c | 21 ---------------- tools/testing/selftests/bpf/test_progs.c | 25 +++++++++++++++++++ tools/testing/selftests/bpf/test_progs.h | 1 + 3 files changed, 26 insertions(+), 21 deletions(-)