[automerger skipped] bpfloader: remove btf support am: 74e9d0a4f8 -s ours

am skip reason: Merged-In I258a9437aedb10d1fa7e91e1a7f22fd8cb99a4a2 with SHA-1 b44e287ed0 is already in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/bpf/+/24991388

Change-Id: I0367e21574190631f398d8155974a533e02f5036
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/OWNERS b/OWNERS
index e58fb39..f37daeb 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,2 +1,2 @@
 set noparent
-file:platform/system/bpf:master:/OWNERS_bpf
+file:platform/system/bpf:main:/OWNERS_bpf
diff --git a/bpfloader/Android.bp b/bpfloader/Android.bp
index 09a5d3d..2ddf463 100644
--- a/bpfloader/Android.bp
+++ b/bpfloader/Android.bp
@@ -36,16 +36,13 @@
     ],
     sanitize: {
         integer_overflow: true,
-        memtag_heap: true,
     },
 
     header_libs: ["bpf_headers"],
     shared_libs: [
-        "libcutils",
-        "libbpf_android",
         "libbase",
+        "libbpf_android",
         "liblog",
-        "libnetdutils",
     ],
     srcs: [
         "BpfLoader.cpp",
diff --git a/bpfloader/BpfLoader.cpp b/bpfloader/BpfLoader.cpp
index e53669a..d476a48 100644
--- a/bpfloader/BpfLoader.cpp
+++ b/bpfloader/BpfLoader.cpp
@@ -46,8 +46,6 @@
 #include <android-base/unique_fd.h>
 #include <libbpf_android.h>
 #include <log/log.h>
-#include <netdutils/Misc.h>
-#include <netdutils/Slice.h>
 #include "BpfSyscallWrappers.h"
 #include "bpf/BpfUtils.h"
 
@@ -251,6 +249,35 @@
     (void)argc;
     android::base::InitLogging(argv, &android::base::KernelLogger);
 
+    if (!android::bpf::isAtLeastKernelVersion(4, 19, 0)) {
+        ALOGE("Android U QPR2 requires kernel 4.19.");
+        return 1;
+    }
+
+    if (android::bpf::isUserspace32bit() && android::bpf::isAtLeastKernelVersion(6, 2, 0)) {
+        /* Android 14/U should only launch on 64-bit kernels
+         *   T launches on 5.10/5.15
+         *   U launches on 5.15/6.1
+         * So >=5.16 implies isKernel64Bit()
+         *
+         * We thus added a test to V VTS which requires 5.16+ devices to use 64-bit kernels.
+         *
+         * Starting with Android V, which is the first to support a post 6.1 Linux Kernel,
+         * we also require 64-bit userspace.
+         *
+         * There are various known issues with 32-bit userspace talking to various
+         * kernel interfaces (especially CAP_NET_ADMIN ones) on a 64-bit kernel.
+         * Some of these have userspace or kernel workarounds/hacks.
+         * Some of them don't...
+         * We're going to be removing the hacks.
+         *
+         * Additionally the 32-bit kernel jit support is poor,
+         * and 32-bit userspace on 64-bit kernel bpf ringbuffer compatibility is broken.
+         */
+        ALOGE("64-bit userspace required on 6.2+ kernels.");
+        return 1;
+    }
+
     // Ensure we can determine the Android build type.
     if (!android::bpf::isEng() && !android::bpf::isUser() && !android::bpf::isUserdebug()) {
         ALOGE("Failed to determine the build type: got %s, want 'eng', 'user', or 'userdebug'",
@@ -270,14 +297,12 @@
     //  kernel does not have CONFIG_BPF_JIT=y)
     // BPF_JIT is required by R VINTF (which means 4.14/4.19/5.4 kernels),
     // but 4.14/4.19 were released with P & Q, and only 5.4 is new in R+.
-    if (writeProcSysFile("/proc/sys/net/core/bpf_jit_enable", "1\n") &&
-        android::bpf::isAtLeastKernelVersion(5, 4, 0)) return 1;
+    if (writeProcSysFile("/proc/sys/net/core/bpf_jit_enable", "1\n")) return 1;
 
     // Enable JIT kallsyms export for privileged users only
     // (Note: this (open) will fail with ENOENT 'No such file or directory' if
     //  kernel does not have CONFIG_HAVE_EBPF_JIT=y)
-    if (writeProcSysFile("/proc/sys/net/core/bpf_jit_kallsyms", "1\n") &&
-        android::bpf::isAtLeastKernelVersion(5, 4, 0)) return 1;
+    if (writeProcSysFile("/proc/sys/net/core/bpf_jit_kallsyms", "1\n")) return 1;
 
     // Create all the pin subdirectories
     // (this must be done first to allow selinux_context and pin_subdir functionality,
diff --git a/libbpf_android/Android.bp b/libbpf_android/Android.bp
index d8272cc..52fb043 100644
--- a/libbpf_android/Android.bp
+++ b/libbpf_android/Android.bp
@@ -39,7 +39,6 @@
 
     shared_libs: [
         "libbase",
-        "libcutils",
         "libutils",
         "liblog",
     ],
diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp
index d817614..e817a59 100644
--- a/libbpf_android/Loader.cpp
+++ b/libbpf_android/Loader.cpp
@@ -59,9 +59,9 @@
 
 #include <android-base/cmsg.h>
 #include <android-base/file.h>
+#include <android-base/properties.h>
 #include <android-base/strings.h>
 #include <android-base/unique_fd.h>
-#include <cutils/properties.h>
 
 #define BPF_FS_PATH "/sys/fs/bpf/"
 
@@ -79,17 +79,11 @@
 using std::string;
 using std::vector;
 
-static std::string getBuildTypeInternal() {
-    char value[PROPERTY_VALUE_MAX] = {};
-    (void)property_get("ro.build.type", value, "unknown");  // ignore length
-    return value;
-}
-
 namespace android {
 namespace bpf {
 
 const std::string& getBuildType() {
-    static std::string t = getBuildTypeInternal();
+    static std::string t = android::base::GetProperty("ro.build.type", "unknown");
     return t;
 }
 
diff --git a/progs/bpfRingbufProg.c b/progs/bpfRingbufProg.c
index cbf9104..dec1615 100644
--- a/progs/bpfRingbufProg.c
+++ b/progs/bpfRingbufProg.c
@@ -21,8 +21,9 @@
 #define TEST_RINGBUF_MAGIC_NUM 12345
 
 // This ring buffer is for testing purposes only.
-DEFINE_BPF_RINGBUF_EXT(test_ringbuf, __u64, 4096, AID_ROOT, AID_ROOT, 0660, "", "", false,
-                       BPFLOADER_MIN_VER, BPFLOADER_MAX_VER, false, false, false);
+DEFINE_BPF_RINGBUF_EXT(test_ringbuf, __u64, 4096, AID_ROOT, AID_ROOT, 0660, "", "", PRIVATE,
+                       BPFLOADER_MIN_VER, BPFLOADER_MAX_VER,
+                       LOAD_ON_ENG, LOAD_ON_USER, LOAD_ON_USERDEBUG);
 
 // This program is for test purposes only - it should never be attached to a
 // socket, only executed manually with BPF_PROG_RUN.