From 667dfa97e6be3cb37884ae43e29b118c6ecfa13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Wed, 30 Jul 2025 17:26:15 -0700 Subject: [PATCH] bpf: switch map '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: I3600cf45ae14a20801b5beca0aa9e79bb3052c57 --- bpf/loader/NetBpfLoad.cpp | 11 ++--------- bpf/progs/include/bpf_helpers.h | 2 +- bpf/progs/include/bpf_map_def.h | 8 ++------ 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 4c2df43d8c..d4dc38d62e 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -880,13 +880,6 @@ static enum bpf_map_type sanitizeMapType(enum bpf_map_type type) { return type; } -static string buildMapPinLoc(const char pin_subdir[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE], - const string& objName, const string& mapName) { - // Format of pin location is /sys/fs/bpf/map__ - // Note: refers to the extension-less basename of the .o file (without @ suffix). - return string(BPF_FS_PATH) + pin_subdir + "map_" + objName + "_" + mapName; -} - static int createMaps(const char* elfPath, ifstream& elfFile, vector& mapFds, const unsigned int bpfloader_ver) { int ret; @@ -967,7 +960,7 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector& if (max_entries < page_size) max_entries = page_size; } - string mapPinLoc = buildMapPinLoc(md[i].pin_subdir, objName, mapNames[i]); + string mapPinLoc = string(md[i].pin_prefix) + mapNames[i]; unique_fd fd; int saved_errno; @@ -1368,7 +1361,7 @@ static int pinMaps(const char* const elfPath, const struct bpf_object* obj, // This map was skipped if (!bpf_map__autocreate(m)) continue; - string mapPinLoc = buildMapPinLoc(md[i].pin_subdir, objName, mapNames[i]); + string mapPinLoc = string(md[i].pin_prefix) + mapNames[i]; if (access(mapPinLoc.c_str(), F_OK) == 0) { ALOGE("Reusing map is not supported: %s", mapNames[i].c_str()); return -1; diff --git a/bpf/progs/include/bpf_helpers.h b/bpf/progs/include/bpf_helpers.h index 53daa7470e..abf0994db3 100644 --- a/bpf/progs/include/bpf_helpers.h +++ b/bpf/progs/include/bpf_helpers.h @@ -260,7 +260,7 @@ static int (*bpf_sk_storage_delete_unsafe) (const void* sk_storage, .min_kver = (minkver).kver, \ .max_kver = (maxkver).kver, \ .create_location = CREATE_LOCATION(selinux), \ - .pin_subdir = pindir "/", \ + .pin_prefix = "/sys/fs/bpf/" pindir "/map_" BPF_OBJ_NAME "_", \ }; #define __uint(name, val) int (*name)[val] diff --git a/bpf/progs/include/bpf_map_def.h b/bpf/progs/include/bpf_map_def.h index 8b998f9bbc..3034e496da 100644 --- a/bpf/progs/include/bpf_map_def.h +++ b/bpf/progs/include/bpf_map_def.h @@ -141,13 +141,9 @@ struct bpf_map_def { unsigned int min_kver; unsigned int max_kver; - // These are fixed length strings, padded with null bytes - // - // overrides default selinux context (which is based on pin subdir) + // These are fixed length ASCIIZ strings, padded with null bytes char create_location[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]; - // - // overrides default prefix (which is based on .o location) - 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.