From ae1a9ff2fad5d8123b2e9bb5352065cadd590481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Wed, 30 Jul 2025 17:30:45 -0700 Subject: [PATCH] bpf: switch prog 'pin_subdir' to 'pin_prefix' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit which simplifies NetBpfLoad logic Test: TreeHugger Flag: EXEMPT mainline Signed-off-by: Maciej Żenczykowski Change-Id: I610aa8374fe3c56262f76fe52edf8386c1a3ee12 --- bpf/loader/NetBpfLoad.cpp | 10 ++-------- bpf/progs/include/bpf_helpers.h | 2 +- bpf/progs/include/bpf_map_def.h | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index d4dc38d62e..1b7cb30d4e 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -1146,12 +1146,6 @@ static int validateProg(const borrowed_fd& fd, string& progPinLoc, return 0; } -static string buildProgPinLoc(const char pin_subdir[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE], - const string& objName, const string& name) { - // Format of pin location is /sys/fs/bpf/prog__ - return string(BPF_FS_PATH) + pin_subdir + "prog_" + objName + '_' + string(name); -} - static int loadCodeSections(const char* elfPath, vector& cs, const string& license, const unsigned int bpfloader_ver) { unsigned kvers = kernelVersion(); @@ -1194,7 +1188,7 @@ static int loadCodeSections(const char* elfPath, vector& cs, const name = name.substr(0, name.find_last_of('$')); bool reuse = false; - string progPinLoc = buildProgPinLoc(cs[i].prog_def->pin_subdir, objName, name); + string progPinLoc = string(cs[i].prog_def->pin_prefix) + name; if (access(progPinLoc.c_str(), F_OK) == 0) { fd.reset(retrieveProgram(progPinLoc.c_str())); ALOGD("New bpf prog load reusing prog %s, ret: %d (%s)", progPinLoc.c_str(), fd.get(), @@ -1390,7 +1384,7 @@ static int pinProgs(const char* const elfPath, const struct bpf_object * obj, string name = cs[i].name; name = name.substr(0, name.find_last_of('$')); - string progPinLoc = buildProgPinLoc(cs[i].prog_def->pin_subdir, objName, name); + string progPinLoc = string(cs[i].prog_def->pin_prefix) + name; if (access(progPinLoc.c_str(), F_OK) == 0) { // TODO: Skip loading lower priority program ALOGI("Higher priority program is already pinned, skip pinning %s", cs[i].name.c_str()); diff --git a/bpf/progs/include/bpf_helpers.h b/bpf/progs/include/bpf_helpers.h index abf0994db3..556aec386e 100644 --- a/bpf/progs/include/bpf_helpers.h +++ b/bpf/progs/include/bpf_helpers.h @@ -489,7 +489,7 @@ static int (*bpf_trace_printk)(const char* fmt, int fmt_size, ...) = (void*) BPF .bpfloader_min_ver = (min_loader), \ .bpfloader_max_ver = (max_loader), \ .create_location = CREATE_LOCATION(selinux), \ - .pin_subdir = pindir "/", \ + .pin_prefix = "/sys/fs/bpf/" pindir "/prog_" BPF_OBJ_NAME "_", \ }; \ SECTION(SECTION_NAME) \ int the_prog diff --git a/bpf/progs/include/bpf_map_def.h b/bpf/progs/include/bpf_map_def.h index 3034e496da..61463b4f21 100644 --- a/bpf/progs/include/bpf_map_def.h +++ b/bpf/progs/include/bpf_map_def.h @@ -168,7 +168,7 @@ struct bpf_prog_def { unsigned int bpfloader_max_ver; char create_location[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]; - char pin_subdir[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]; + char pin_prefix[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]; }; // This needs to be updated whenever the above structure definition is expanded.