getBpfSupportLevel - make 4.14+ kernel trump ro.product.first_api_level
Devices launching with Android 'X' must have one of the following kernels:
O: 3.18 4.4 4.9
P: 4.4 4.9 4.14
Q: 4.9 4.14 4.19
R: 4.14 4.19 5.4
You can see this by looking at:
https://android.googlesource.com/kernel/configs/+/refs/heads/master
where the main directory is currently R (api level 30) and the subdirs for:
O (26), O-MR1 (27), P (28), and Q (29)
As such running a 'Y' kernel is proof of being at least Android 'X':
4.9 is O+
4.14 is P+
4.19 is Q+
5.4 is R+
And we know Android P VINTF has always required eBPF support from its
kernels. As such we can reorder the checks, to check kernel prior
to checking first_api_level.
This is *theoretically* a no-op.
But of course in practice it will actually fix a number of issues:
- Devices which launched on O with a 4.9 kernel but have been upgraded
to a 4.14-Q kernel and thus now support ebpf and don't support xt_qtaguid,
this will hopefully eliminate the need for test waivers...
- Devices during turn up where they're on a 4.19 kernel, targetting R,
and yet somehow still erroneously reporting a first_api_level of 26 (O),
this will hopefully eliminate some crash bugs.
Test: atest
Bug: 151753987
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7eaca016d0f77e5f320b499ac428987e23a6d184
diff --git a/libbpf_android/BpfUtils.cpp b/libbpf_android/BpfUtils.cpp
index c7c56d5..cf10449 100644
--- a/libbpf_android/BpfUtils.cpp
+++ b/libbpf_android/BpfUtils.cpp
@@ -117,9 +117,9 @@
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,6 +132,12 @@
}
static BpfLevel getUncachedBpfSupportLevel() {
+ 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;
+
uint64_t api_level = GetUintProperty<uint64_t>("ro.product.first_api_level", 0);
if (api_level == 0) {
ALOGE("Cannot determine initial API level of the device");
@@ -141,11 +147,6 @@
// 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;