From af617ca0aa133404cbb8d4c8cf4403e55d9ddf27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Fri, 20 May 2022 16:44:06 -0700 Subject: [PATCH] ease debugging - print pinned bpf prog & map ids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit combined with content of /proc/${pid}/fd/${fd} and /proc/${pid}/fdinfo/${fd} this allows figuring out which programs/maps a process continues to have open See: adbz logcat -d | egrep '(map|prog) .* id' adbz root adbz_bpf_progs_and_maps Bug: 230880517 Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: I66c7fa12d079257486569105368bf1eea2d3ab0c (cherry picked from commit 57412c2a27a53be306b5c389babfb3a47090ab88) Merged-In: I66c7fa12d079257486569105368bf1eea2d3ab0c --- libbpf_android/Loader.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp index b2f15cc..5f2bc70 100644 --- a/libbpf_android/Loader.cpp +++ b/libbpf_android/Loader.cpp @@ -30,9 +30,9 @@ #include #include -// This is BpfLoader v0.13 +// This is BpfLoader v0.14 #define BPFLOADER_VERSION_MAJOR 0u -#define BPFLOADER_VERSION_MINOR 13u +#define BPFLOADER_VERSION_MINOR 14u #define BPFLOADER_VERSION ((BPFLOADER_VERSION_MAJOR << 16) | BPFLOADER_VERSION_MINOR) #include "bpf/BpfUtils.h" @@ -713,6 +713,15 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector& if (ret) return -errno; } + struct bpf_map_info map_info = {}; + __u32 map_info_len = sizeof(map_info); + int rv = bpf_obj_get_info_by_fd(fd, &map_info, &map_info_len); + if (rv) { + ALOGE("bpf_obj_get_info_by_fd failed, ret: %d [%d]\n", rv, errno); + } else { + ALOGI("map %s id %d\n", mapPinLoc.c_str(), map_info.id); + } + mapFds.push_back(std::move(fd)); } @@ -890,6 +899,15 @@ static int loadCodeSections(const char* elfPath, vector& cs, const } } + struct bpf_prog_info prog_info = {}; + __u32 prog_info_len = sizeof(prog_info); + int rv = bpf_obj_get_info_by_fd(fd, &prog_info, &prog_info_len); + if (rv) { + ALOGE("bpf_obj_get_info_by_fd failed, ret: %d [%d]\n", rv, errno); + } else { + ALOGI("prog %s id %d\n", progPinLoc.c_str(), prog_info.id); + } + cs[i].prog_fd.reset(fd); }