Commit graph

464 commits

Author SHA1 Message Date
Maciej Żenczykowski
aa295c8355 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
2020-06-17 10:44:19 +00:00
Maciej Żenczykowski
89515d979a Warn loudly and do not set bpf.progs_loaded property on critical bpf load failure.
Reasoning: critical load failures for netd bpf programs will just result
in unpredictable behaviour later on.  For example netd/systemserver
crash loops.

Test: builds
Bug: 150040815
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iefa01e60cd0a9a223e96411726a199bfb4857a5a
2020-06-15 08:01:50 +00:00
Maciej Żenczykowski
4ba8c1c1ac allow tagging a bpf .o as critical
This does not yet do anything with this information besides logging it.

Test: builds
  $ adb logcat -s -d LibBpfLoader:D | egrep Loading
  06-14 22:52:48.657   430   430 D LibBpfLoader: Loading critical for netd ELF object /system/etc/bpf/offload.o with license Apache 2.0
  06-14 22:52:48.682   430   430 D LibBpfLoader: Loading optional ELF object /system/etc/bpf/time_in_state.o with license GPL
  06-14 22:52:48.729   430   430 D LibBpfLoader: Loading critical for netd ELF object /system/etc/bpf/clatd.o with license Apache 2.0
  06-14 22:52:48.767   430   430 D LibBpfLoader: Loading critical for netd ELF object /system/etc/bpf/netd.o with license Apache 2.0
  06-14 22:53:26.052  2605  2605 D LibBpfLoader: Loading optional ELF object /data/local/tmp/32/kern.o with license Apache 2.0
  06-14 22:54:26.070  2605  2605 D LibBpfLoader: Loading optional ELF object /data/local/tmp/32/kern.o with license Apache 2.0
Bug: 150040815
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie07549528800d6d7c5ff7f12b859702113d7194e
2020-06-15 06:34:51 +00:00
Maciej Żenczykowski
567dc56b57 only set 'bpf.progs_loaded' property on eBPF capable devices...
... which also means waitForProgsLoaded() has to be a no-op on pre-bpf devices.

This is more consistent: it's weird to have bpf.progs_loaded set on a 4.4 device.

Test: builds, atest
Bug: 150040815
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iddabcf56c187ea518dd2e4d8db451b2f6902aa8e
2020-06-13 22:41:48 -07:00
Bob Badour
00d3a5292c Remove MODULE_LICENSE_APACHE2 from system/bpf am: 616c7cf8b0
Change-Id: I59e895d7db007788d36e609e9345fc77ac41c635
2020-05-05 00:24:55 +00:00
Bob Badour
616c7cf8b0 Remove MODULE_LICENSE_APACHE2 from system/bpf
Repositories containing third-party code need a METADATA and a
license_type. Repositories containing only first-party code no longer
need a MODULE_LICENSE_* file.

Bug: 68860345
Bug: 69058154
Bug: 151953481

Test: no code changes
Change-Id: I9abe7458b9bcbcce3217eaff3033116e3f0aeb44
2020-04-27 19:17:56 -07:00
Maciej Żenczykowski
9a3dbd00cb BpfMap.h - fix cert-oop54-cpp compiler warning am: 54a7e769ae
Change-Id: I8bc6b3265062d197fe4761ba069610d64c2603d0
2020-04-24 16:40:41 +00:00
Maciej Żenczykowski
54a7e769ae BpfMap.h - fix cert-oop54-cpp compiler warning
Fixes:
  system/bpf/libbpf_android/include/bpf/BpfMap.h:132:10: warning: operator=() does not handle self-assignment properly [cert-oop54-cpp]
      void operator=(const BpfMap<Key, Value>& other) {
           ^

Matches the self-assignment check from
  https://clang.llvm.org/extra/clang-tidy/checks/bugprone-unhandled-self-assignment.html

This isn't needed here, since the code was already correct, but
it does prevent a pointless newfd = dup(fd); close(fd); sequence.

Test: builds
Bug: 153035880
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia57f95d4ab180783c97db7e6f8d929f822c8958d
2020-04-24 08:15:00 -07:00
Maciej Żenczykowski
7867df4aa9 Merge "libbpf_android/Loader.cpp - fixes performance-inefficient-string-concatenation warning" am: 5206746831
Change-Id: Ib951ea746f4214d2de5d77c4d69099cef065c2b1
2020-04-24 07:26:22 +00:00
Maciej Żenczykowski
5206746831 Merge "libbpf_android/Loader.cpp - fixes performance-inefficient-string-concatenation warning" 2020-04-24 07:18:59 +00:00
Maciej Żenczykowski
3a2224fd42 Merge "change to ro.kernel.ebpf.supported property" am: fa1f620449
Change-Id: I47a6d30af20f06de70c8383265f343f1e3a0700a
2020-04-24 04:47:47 +00:00
Maciej Żenczykowski
fa1f620449 Merge "change to ro.kernel.ebpf.supported property" 2020-04-24 04:41:34 +00:00
Maciej Żenczykowski
39ab9d3ff7 libbpf_android/Loader - fixes performance-faster-string-find warning am: 428843de55
Change-Id: I296da6379e4da03247bb77651f48f2030f74787f
2020-04-24 04:38:34 +00:00
Maciej Żenczykowski
6c7871b8df libbpf_android/Loader.cpp - fixes performance-inefficient-string-concatenation warning
Fixes:
  system/bpf/libbpf_android/Loader.cpp:562:73: warning: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation]
          string progPinLoc = string(BPF_FS_PATH) + "prog_" + fname + "_" + name;
                                                                          ^

Test: builds
Bug: 153035880
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If56405273b4904e632a4b3a465b79eecae4c1446
2020-04-24 04:18:35 +00:00
Maciej Żenczykowski
428843de55 libbpf_android/Loader - fixes performance-faster-string-find warning
Fixes:
  system/bpf/libbpf_android/Loader.cpp:557:49: warning: 'find_last_of' called with a string literal consisting of a single character; consider using the more effective overload accepting a character [performance-faster-string-find]
          name = name.substr(0, name.find_last_of("$"));
                                                  ^~~
                                                  '$'

Test: builds
Bug: 153035880
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iea62a59380c155796a7fa2ac4ca3352f9236ba98
2020-04-24 04:18:00 +00:00
Maciej Żenczykowski
0335743c4a change to ro.kernel.ebpf.supported property
to match https://android-review.googlesource.com/c/platform/system/sepolicy/+/1292919

Test: builds
Bug: 151753987
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I43d9fd9c162edde6d7274bcc96049bf00278f056
2020-04-23 18:36:56 -07:00
Maciej Żenczykowski
2265e56d43 bpf loader - finish support for kernel version conditional loading am: 681f604b2e
Change-Id: I1e273f36eef7dd5a6e4c4426b26a4a629fdb3a23
2020-04-22 04:11:41 +00:00
Maciej Żenczykowski
681f604b2e bpf loader - finish support for kernel version conditional loading
bpf program section names must be unique to prevent programs from
appending to each other, so instead the bpf loader will strip
everything past the final $ symbol when actually pinning
the program into the filesystem.

While at it add a little bit more logging.

Example on aosp cuttlefish 5.4.30 virtual device:
  D LibBpfLoader: bpf_prog_load lib call for /system/etc/bpf/offload.o (schedcls_ingress_tether_ether) returned fd: 8 (no error)
  D LibBpfLoader: cs[1].name:schedcls_ingress_tether_rawip$stub min_kver:0 .max_kver:40e00 (kvers:5041e)
  D LibBpfLoader: cs[2].name:schedcls_ingress_tether_rawip$4_14 min_kver:40e00 .max_kver:ffffffff (kvers:5041e)
  D LibBpfLoader: bpf_prog_load lib call for /system/etc/bpf/offload.o (schedcls_ingress_tether_rawip$4_14) returned fd: 9 (no error)
  I bpfloader: Attempted load object: /system/etc/bpf/offload.o, ret: Success

  $ adb shell ls -l /sys/fs/bpf | egrep offload
  -rw-rw---- 1 root network_stack 0 2020-04-22 01:27 map_offload_tether_ingress_map
  -rw-rw---- 1 root network_stack 0 2020-04-22 01:27 map_offload_tether_stats_map
  -r--r----- 1 root root          0 2020-04-22 01:27 prog_offload_schedcls_ingress_tether_ether
  -r--r----- 1 root root          0 2020-04-22 01:27 prog_offload_schedcls_ingress_tether_rawip

Test: builds, atest, proper program loaded on 5.4.30 aosp cuttlefish
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id3fcb8e2a6b0087f704e77726e9961efc6145739
2020-04-21 18:29:58 -07:00
Xin Li
db1a43e3e7 DO NOT MERGE - Empty merge qt-qpr1-dev-plus-aosp into stag-aosp-master
Bug: 151763422
Change-Id: I58f6384e2295be6cbfe679f4570e471a7576aa1a
2020-04-09 17:51:26 -07:00
Tom Cherry
4e77502d99 Merge "Remove EXCLUDE_FS_CONFIG_STRUCTURES" am: c6ada47bc7 am: c02884a09f
Change-Id: I04969ee43d77a1d0f21b7cc274b39310fb66ba04
2020-04-03 15:17:26 +00:00
Tom Cherry
c02884a09f Merge "Remove EXCLUDE_FS_CONFIG_STRUCTURES" am: c6ada47bc7
Change-Id: Ia9140ff93a52dce2b16c186e8d296aa2ced47f6b
2020-04-03 14:49:35 +00:00
Tom Cherry
c6ada47bc7 Merge "Remove EXCLUDE_FS_CONFIG_STRUCTURES" 2020-04-03 14:36:58 +00:00
Maciej Żenczykowski
516b10f2b1 Increase BPF test memlock rlimit to 1GB to match the bpfloader. am: bd98c025bd am: fea034fa27
Change-Id: I557ebb6d86e94a3dd8074a6edd1e66785934f470
2020-03-31 12:12:38 +00:00
Maciej Żenczykowski
fea034fa27 Increase BPF test memlock rlimit to 1GB to match the bpfloader. am: bd98c025bd
Change-Id: Ia46c579214563b65320449d4329b20a4bc650dfb
2020-03-31 11:50:26 +00:00
Maciej Żenczykowski
bd98c025bd Increase BPF test memlock rlimit to 1GB to match the bpfloader.
Test: builds, atest
Bug: 152285563
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia283a66d38acfa3884463490a7a8c80560f5580d
2020-03-31 03:04:51 -07:00
Treehugger Robot
360212a788 Merge "add LICENSE() macro" am: 3a3870c6df am: d5ae9aa902
Change-Id: I232815547cf65f7eb0ae4c2a1d774f19dbca0989
2020-03-20 23:23:26 +00:00
Treehugger Robot
d5ae9aa902 Merge "add LICENSE() macro" am: 3a3870c6df
Change-Id: Ia9553164b8f2460bed5111da835505d8f4b1aedc
2020-03-20 23:07:41 +00:00
Treehugger Robot
3a3870c6df Merge "add LICENSE() macro" 2020-03-20 22:50:19 +00:00
Maciej Żenczykowski
78eca18c0a getBpfSupportLevel - check ro.product.kernel_has_ebpf first am: 3188138f3e am: 005bdcc687
Change-Id: Ic5f57678bf1aa1f36eb2f6b6b654c85ac4fd5160
2020-03-20 10:13:34 +00:00
Maciej Żenczykowski
2b47389a6e getBpfSupportLevel - make 4.14+ kernel trump ro.product.first_api_level am: 914c4b39c3 am: e6aa238ed9
Change-Id: I7edf111d71926df66e0210315d1d3f01caa62b31
2020-03-20 10:13:29 +00:00
Maciej Żenczykowski
005bdcc687 getBpfSupportLevel - check ro.product.kernel_has_ebpf first am: 3188138f3e
Change-Id: Ibe8476ea0c1f2a67940d66fbc2334b4ed2f811f9
2020-03-20 10:04:04 +00:00
Maciej Żenczykowski
e6aa238ed9 getBpfSupportLevel - make 4.14+ kernel trump ro.product.first_api_level am: 914c4b39c3
Change-Id: I3c3153318441a5db1676b290fcb92402d2b17a17
2020-03-20 10:03:14 +00:00
Maciej Żenczykowski
410ebe0c75 add LICENSE() macro
Test: builds
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I46db3e87e87b8237f4bbf53aa345826826ddb46d
2020-03-19 19:39:07 -07:00
Maciej Żenczykowski
3188138f3e getBpfSupportLevel - check ro.product.kernel_has_ebpf first
This allows a launched on Android O device but now running
a 4.9-P+ kernel to declare itself as ebpf capable.

This will eliminate a whole class of waivers.

Test: atest
Bug: 151753987
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4c860991abc252919283d6c17a5ff70915d14dd7
2020-03-18 23:36:08 -07:00
Maciej Żenczykowski
914c4b39c3 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
2020-03-18 23:36:01 -07:00
Xin Li
fc8e1e0a44 DO NOT MERGE - Empty merge qt-qpr1-dev-plus-aosp@6304901 into stag-aosp-master am: c6e1c4c4ab
Change-Id: I39e563818341b576fb752dc78c75a8579e744827
2020-03-19 04:22:48 +00:00
Xin Li
c6e1c4c4ab DO NOT MERGE - Empty merge qt-qpr1-dev-plus-aosp@6304901 into stag-aosp-master
Bug: 151763422
Change-Id: If06b1375d0198647e278a26c34091ece6f65b0ef
2020-03-18 19:40:56 -07:00
Automerger Merge Worker
426db71b13 BpfMap: Specify zero to be default map_flags in constructor am: 6161ff246f am: 5831cc9904
Change-Id: Ic8729cb77d8a072b2f653783d7f04269b85fe5c7
2020-03-06 01:04:05 +00:00
Automerger Merge Worker
5831cc9904 BpfMap: Specify zero to be default map_flags in constructor am: 6161ff246f
Change-Id: Idf811934440f7aca8ecfd380aeb7cafeef95cd83
2020-03-06 00:48:10 +00:00
Hungming Chen
6161ff246f BpfMap: Specify zero to be default map_flags in constructor
Bug: 149963652
Test: atest
Change-Id: I0a9311bdadffc0fda75f153b3e2617fb082d3ddb
2020-03-05 16:03:57 +08:00
Automerger Merge Worker
206478381d Merge "BpfMap: override copy assignment operator" am: 406e92d02c am: 222973a551
Change-Id: Iad9df45dfe8fbeeed81e626fef28b30dadae802c
2020-03-05 00:43:31 +00:00
Automerger Merge Worker
222973a551 Merge "BpfMap: override copy assignment operator" am: 406e92d02c
Change-Id: Id303ef95eee3c19e4e8640f8ca0ed92b14a8e7d0
2020-03-05 00:31:24 +00:00
Treehugger Robot
406e92d02c Merge "BpfMap: override copy assignment operator" 2020-03-05 00:14:49 +00:00
Hungming Chen
4008da93e8 BpfMap: override copy assignment operator
Test: build, atest
Bug: 149963652
Change-Id: I864ca00762a4e5c910454dd9dc023b74c67065d6
2020-03-04 23:11:28 +00:00
Tom Cherry
b2891eed16 Remove EXCLUDE_FS_CONFIG_STRUCTURES
This is no longer needed

Bug: 149785767
Test: build
Change-Id: Ic4c8f23dc5b9dbebfeee0820d007fd46919834b4
2020-03-04 13:42:06 -08:00
Automerger Merge Worker
2aa63dffd2 Merge "BpfMap - make clear() multithread safe" am: e9e8305a36 am: 6390c4b0be
Change-Id: I7c7e58dc78daa29fe7e52646977fc9e582b7c7d1
2020-02-20 13:27:03 +00:00
Automerger Merge Worker
6390c4b0be Merge "BpfMap - make clear() multithread safe" am: e9e8305a36
Change-Id: I28b535422944cff241f52fcf29351e52d09b66c7
2020-02-20 13:14:45 +00:00
Treehugger Robot
e9e8305a36 Merge "BpfMap - make clear() multithread safe" 2020-02-20 13:05:14 +00:00
Automerger Merge Worker
c59638c5c4 add support for marking ebpf programs as being only for some kernel versions am: 07375e26a3 am: fdc1c2ff8e
Change-Id: I670bb4bd205a61d6ef3d7a86b5f0173d1e26b3c5
2020-02-20 03:02:17 +00:00
Automerger Merge Worker
fdc1c2ff8e add support for marking ebpf programs as being only for some kernel versions am: 07375e26a3
Change-Id: Ia8b49d34c148f83f90a19625c095928de0b25dc8
2020-02-20 02:50:02 +00:00