summaryrefslogtreecommitdiff
path: root/libbpf_android/Loader.cpp
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2020-06-16 17:02:48 -0700
committerMaciej Żenczykowski <maze@google.com>2020-06-17 10:44:19 +0000
commitaa295c835574952ff91f2c60183e5357d2664e9d (patch)
tree66b90c48c1eb2ddc1a73820f1ba4cb2a2c1825ea /libbpf_android/Loader.cpp
parent89515d979aa817546d5050027300a177b033002d (diff)
downloadbpf-aa295c835574952ff91f2c60183e5357d2664e9d.tar.gz
implement support for functions which may optionally fail to load
This is useful for critical functions with fallbacks, but may even be useful for non-critical functions, where a function in the middle of the file may fail to load, but you still want other (later) functions to be attempted. Critical applies to the entire .c file (or to be more correct to the entire resulting .o). Optional applies to a specific section of that .o (ie. a specific individual function). This new optional attribute is necessary to be able to declare a .c/.o file critical even if *some* of the individual functions might fail to load due to missing kernel patches. (Note: we currently have no way to specify a map as optional) Critical guarantees that all non-optional programs, and all maps, have been created, pinned, chowned, and chmoded successfully (or that they already existed). For an example of use see: system/netd/bpf_progs/offload.c (while at it also add retrieveProgram() and mapRetrieve{RW,RO,WO}() helpers to BpfUtils.h) Test: builds, atest, see paired netd change for extra details Bug: 150040815 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I50b292c061b05fc8f4b4b8574f128345c45c78db
Diffstat (limited to 'libbpf_android/Loader.cpp')
-rw-r--r--libbpf_android/Loader.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp
index 8f5318d..5a65c1b 100644
--- a/libbpf_android/Loader.cpp
+++ b/libbpf_android/Loader.cpp
@@ -564,8 +564,9 @@ static int loadCodeSections(const char* elfPath, vector<codeSection>& cs, const
progPinLoc += '_';
progPinLoc += name;
if (access(progPinLoc.c_str(), F_OK) == 0) {
- fd = bpf_obj_get(progPinLoc.c_str());
- ALOGD("New bpf prog load reusing prog %s, ret: %d\n", progPinLoc.c_str(), fd);
+ fd = retrieveProgram(progPinLoc.c_str());
+ ALOGD("New bpf prog load reusing prog %s, ret: %d (%s)\n", progPinLoc.c_str(), fd,
+ (fd < 0 ? std::strerror(errno) : "no error"));
reuse = true;
} else {
vector<char> log_buf(BPF_LOAD_LOG_SZ, 0);
@@ -579,9 +580,15 @@ static int loadCodeSections(const char* elfPath, vector<codeSection>& cs, const
if (fd < 0) {
std::vector<std::string> lines = android::base::Split(log_buf.data(), "\n");
- ALOGE("bpf_prog_load - BEGIN log_buf contents:");
- for (const auto& line : lines) ALOGE("%s", line.c_str());
- ALOGE("bpf_prog_load - END log_buf contents.");
+ ALOGW("bpf_prog_load - BEGIN log_buf contents:");
+ for (const auto& line : lines) ALOGW("%s", line.c_str());
+ ALOGW("bpf_prog_load - END log_buf contents.");
+
+ if (cs[i].prog_def->optional) {
+ ALOGW("failed program is marked optional - continuing...");
+ continue;
+ }
+ ALOGE("non-optional program failed to load.");
}
}