summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-03-22 07:13:41 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-03-22 07:13:41 +0000
commit1c293f6fce930339ab9ef6210aa0e322ab078707 (patch)
tree6cc2891bb8e3b4802e964ac9aa9171431e8c770a
parentadc24280e35d9d6d32583e4f8d0c01cdf683cf33 (diff)
parent58d4c09a59d0c4abe15695fcf011820351c2fc29 (diff)
downloadplatform_system_bpf-1c293f6fce930339ab9ef6210aa0e322ab078707.tar.gz
platform_system_bpf-1c293f6fce930339ab9ef6210aa0e322ab078707.tar.bz2
platform_system_bpf-1c293f6fce930339ab9ef6210aa0e322ab078707.zip
Snap for 6321095 from 58d4c09a59d0c4abe15695fcf011820351c2fc29 to mainline-release
Change-Id: I2f92d95378fb6b6c4494bf9043a6b107808eca6b
-rw-r--r--libbpf_android/BpfUtils.cpp24
-rw-r--r--progs/include/bpf_helpers.h3
2 files changed, 17 insertions, 10 deletions
diff --git a/libbpf_android/BpfUtils.cpp b/libbpf_android/BpfUtils.cpp
index c7c56d5..2b96f95 100644
--- a/libbpf_android/BpfUtils.cpp
+++ b/libbpf_android/BpfUtils.cpp
@@ -39,7 +39,6 @@
#include <log/log.h>
#include <processgroup/processgroup.h>
-using android::base::GetUintProperty;
using android::base::unique_fd;
// The buffer size for the buffer that records program loading logs, needs to be large enough for
@@ -117,9 +116,9 @@ unsigned kernelVersion() {
std::string BpfLevelToString(BpfLevel bpfLevel) {
switch (bpfLevel) {
case BpfLevel::NONE:
- return "None [pre-4.9]";
+ return "None [pre-4.9 or pre-P]";
case BpfLevel::BASIC_4_9:
- return "Basic [4.9]";
+ return "Basic [4.9 P+]";
case BpfLevel::EXTENDED_4_14:
return "Extended [4.14]";
case BpfLevel::EXTENDED_4_19:
@@ -132,20 +131,25 @@ std::string BpfLevelToString(BpfLevel bpfLevel) {
}
static BpfLevel getUncachedBpfSupportLevel() {
- uint64_t api_level = GetUintProperty<uint64_t>("ro.product.first_api_level", 0);
+ unsigned kver = kernelVersion();
+
+ if (kver >= KVER(5, 4, 0)) return BpfLevel::EXTENDED_5_4;
+ if (kver >= KVER(4, 19, 0)) return BpfLevel::EXTENDED_4_19;
+ if (kver >= KVER(4, 14, 0)) return BpfLevel::EXTENDED_4_14;
+
+ // Override for devices launched with O but now on a 4.9-P+ kernel.
+ bool has_ebpf = base::GetBoolProperty("ro.product.kernel_has_ebpf", false);
+ if (has_ebpf) return BpfLevel::BASIC_4_9;
+
+ uint64_t api_level = base::GetUintProperty<uint64_t>("ro.product.first_api_level", 0);
if (api_level == 0) {
ALOGE("Cannot determine initial API level of the device");
- api_level = GetUintProperty<uint64_t>("ro.build.version.sdk", 0);
+ api_level = base::GetUintProperty<uint64_t>("ro.build.version.sdk", 0);
}
// Check if the device is shipped originally with android P.
if (api_level < MINIMUM_API_REQUIRED) return BpfLevel::NONE;
- unsigned kver = kernelVersion();
-
- if (kver >= KVER(5, 4, 0)) return BpfLevel::EXTENDED_5_4;
- if (kver >= KVER(4, 19, 0)) return BpfLevel::EXTENDED_4_19;
- if (kver >= KVER(4, 14, 0)) return BpfLevel::EXTENDED_4_14;
if (kver >= KVER(4, 9, 0)) return BpfLevel::BASIC_4_9;
return BpfLevel::NONE;
diff --git a/progs/include/bpf_helpers.h b/progs/include/bpf_helpers.h
index 09c3373..8ff155f 100644
--- a/progs/include/bpf_helpers.h
+++ b/progs/include/bpf_helpers.h
@@ -9,6 +9,9 @@
/* place things in different elf sections */
#define SEC(NAME) __attribute__((section(NAME), used))
+/* Example use: LICENSE("GPL"); or LICENSE("Apache 2.0"); */
+#define LICENSE(NAME) char _license[] SEC("license") = (NAME)
+
/*
* Helper functions called from eBPF programs written in C. These are
* implemented in the kernel sources.