Commit graph android_packages_modules_Co.../staticlibs/native/bpf_headers
Message SHA1
NetBpfLoad: enable mainline on T+
Note:
   2 == BPFLOADER_S_VERSION
  19 == BPFLOADER_T_VERSION
  25 == BPFLOADER_OBJ_AT_VER_VERSION
  33 == BPFLOADER_IGNORED_ON_VERSION
  37 == BPFLOADER_U_VERSION [*]
  41 == BPFLOADER_V_VERSION [**]
and currently we have:
  42 == BPFLOADER_MAINLINE_VERSION
  43 == BPFLOADER_MAINLINE_T_VERSION
  44 == BPFLOADER_MAINLINE_U_VERSION
  45 == BPFLOADER_MAINLINE_V_VERSION

[*] udc-dev/udc-release are actually 38, as 37 was some earlier
    udc beta2 (2.1 ifirc), and beta3+ switched to 38

[**] 24Q{1,2}-release (ie. U QPR2+) are technically actually 41,
     but their platform bpfloader no longer even looks in /apex/com.android.tethering/etc/bpf/...
     so it doesn't really matter (although 24Q1's platform
     netbpfload still does, however that is obsoleted by
     this change)

Thus we need to (as minimum for NetBpfLoad):
  BPFLOADER_T_VERSION -> BPFLOADER_MAINLINE_T_VERSION
  BPFLOADER_IGNORED_ON_VERSION -> BPFLOADER_MAINLINE_U_VERSION
to cause these to load appropriately from mainline.

One would perhaps also expect (as minimum for NetBpfLoad):
  BPFLOADER_OBJ_AT_VERSION -> BPFLOADER_MAINLINE_U_VERSION
but (as maximum for platform bpfloader):
  BPFLOADER_OBJ_AT_VERSION -> BPFLOADER_MAINLINE_U_VERSION

However, since the goal is actually for those to load via mainline on T+,
(with the 'old' version of the .o's loading on S via platform bpfloader)
thus one actually needs (as minimum for NetBpfLoad):
  BPFLOADER_OBJ_AT_VERSION -> BPFLOADER_MAINLINE_T_VERSION
and (as maximum for platform bpfloader):
  BPFLOADER_OBJ_AT_VERSION -> BPFLOADER_T_VERSION

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4b688692ffca0db7ead20cefd9e7e892ca92c70a

Maciej Żenczykowski   commited 2024-03-19 21:33:55 +00:00
11141da623
NetBpfLoad: chose bpfloader version at runtime based on Android OS
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iee55d9c6f828f05d4096dff2e874abc6c41eadeb

Maciej Żenczykowski   commited 2024-03-18 15:02:53 -07:00
65f7022461
Eliminate spurious COMPILE_FOR_BPFLOADER_VERSION macro
and make platform bpf.o's target V's platform bpfloader.

Note that all mainline shipped bpf.o's already manually
specify BPFLOADER_MIN_VER.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I67b73969def24e1e169c70c5fb1a402bf6e8cabc

Maciej Żenczykowski   commited 2024-03-15 18:14:16 +00:00
0de80f1a9f
add #define BPFLOADER_MAINLINE_VERSION 42u
See: //packages/modules/Connectivity/netbpfload/loader.cpp
  // This is Network BpfLoader v0.42
  #define BPFLOADER_VERSION_MAJOR 0u
  #define BPFLOADER_VERSION_MINOR 42u

Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ieeed6d402de06d3f01e151c2c9ee44270c53323c

Maciej Żenczykowski   commited 2024-03-12 06:31:36 +00:00
84aa9ea83a
bpf_helpers: add #defines for next 2 LTS KVERs
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iac303578071ff5dd3848f63c7497180d7694874b

Maciej Żenczykowski   commited 2024-03-10 22:11:54 +00:00
978b3f2d9b
[DON'T BLOCK] Test ownership migration rules
This CL is created as a best effort to migrate test targets
to the new android ownership model. If you find incorrect or unnecessary
attribution in this CL, please create a separate CL to fix that.

For more details please refer to the link below,
<add g3 doc link>

Bug: 304529413
Test: N/A
Change-Id: I243f17b3f0ad7af9ffa15ca242456e36688733f5
Merged-In: I243f17b3f0ad7af9ffa15ca242456e36688733f5

Aditya Choudhary   commited 2024-01-31 12:34:50 +00:00
01b5ede2b2
Add missing libc++ includes
Bug: 175635923
Test: m MODULES-IN-packages-modules-Connectivity
Change-Id: I94dafe991ccd73450671ea68eaf65b787dc1d0fa

Tomasz Wasilczyk   commited 2024-01-09 11:01:22 -08:00
661ec166c7
BpfRingBuf.h - implement wait()
Test: TreeHugger, atest BpfRingbufTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2696077caf4de27dd64e4af1c45a13844ed186c9

Maciej Żenczykowski   commited 2023-11-11 00:59:42 +00:00
ddb0ab8c61
BpfRingBuf.h - implement isEmpty()
Test: TreeHugger, atest BpfRingbufTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I23020869ab665c029c3219b1b39c3749be6e6992

Maciej Żenczykowski   commited 2023-11-09 19:13:40 +00:00
0b99c961bb
BpfMap.h - simplify error returns
Returning the number of the file descriptor isn't actually useful since
it doesn't really tell you anything once the program has terminated.
(most logs we look at are long after the fact)

However, it does involve a fair bit of string processing to generate
the errors.  This is particularly an issue for things we constantly
call and sometimes expect to fail.  For example it is normal for
getNextKey() to fail with ENOENT at the end of iteration...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib94037440b5fcaa34cc8aa01b165431efabeb377

Maciej Żenczykowski   commited 2023-11-08 18:36:42 -08:00
0ad252e03c
type safety for kernel version
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If05c0c5383dceeb65964143f5574d2ee1a484907

Maciej Żenczykowski   commited 2023-10-06 15:54:38 -07:00
3a64568abb
type safety for bool ignore_on_{eng,user,userdebug}
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia85e16d1a7f8d1b21e4ce4c306db6bbea06138e0

Maciej Żenczykowski   commited 2023-10-06 14:57:12 -07:00
6dec6e9374
type safety for bool optional
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6f10395ca6f1c73f3513031f561fdf1b1dedf451

Maciej Żenczykowski   commited 2023-10-06 14:48:43 -07:00
f2466ef4bb
type safety for bool shared
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4883eab734f47522fec718f0709475f7e6dd0a53

Maciej Żenczykowski   commited 2023-10-06 14:46:11 -07:00
a262bd3d1e
move PRIVATE/SHARED/MANDATORY/OPTIONAL/{LOAD,IGNORE}_ON_* into core headers
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7053ab46e73b763f64f36baf5e7ab64b62421045

Maciej Żenczykowski   commited 2023-10-06 14:25:41 -07:00
10da6d4e61
BpfClassic.h - add missing commas
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ife32fa36808de13c5f37ace497395dcc381ca336

Maciej Żenczykowski   commited 2023-10-06 13:50:13 -07:00
1e32277fff
more classic bpf macros
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5c7fd55301cd5aa44502f8481923c86bc49ea914

Maciej Żenczykowski   commited 2023-10-04 22:41:21 +00:00
d5bf2061f3
BpfClassic.h - more helpers
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie0eb8895c2d887b71ba886735ad106c1118ebeac

Maciej Żenczykowski   commited 2023-10-02 20:03:41 +00:00
73df7414f1
rename BPF2_REJECT_IF_ANY_BITS_SET -> BPF2_REJECT_IF_ANY_MASKED_BITS_SET
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I54a189f0f7b73917aa3fd049fe2eca387aaca250

Maciej Żenczykowski   authored and   Patrick Rohr   commited 2023-10-02 16:09:05 +00:00
b900201ffe
reverse BpfMap & BpfMapRO inheritence to make sense
Bug: 235590615
Bug: 235907076
Bug: 286003437
Test: TreeHugger, m droid gpuservice_unittest libtimeinstate_test bpf_benchmark bpf_module_test libbpf_load_test && mma
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I020a898fe8b257040a100f146654d4a04b19f843

Maciej Żenczykowski   commited 2023-09-29 00:44:33 +00:00
7e2f53e762
use different log.h header file
Test: TreeHugger
Bug: 299653233
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1e5c7bfc86d2ad61c0bad3b5ef2add94b4ce1481

Maciej Żenczykowski   commited 2023-09-21 22:11:43 +00:00
601d9f8b65
Merge "BpfMap.h - hide getMap()" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-08-22 00:32:09 +00:00
1ef814da95
BpfMap.h - hide getMap()
This leaks (what should be) an internal only fd.

There's still multiple uses of getMap() left in:
  common/native/bpf_headers/BpfMapTest.cpp

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I87a36f3f935ba9148ae4456fc6bf14b0e04f6038

Maciej Żenczykowski   commited 2023-08-21 19:53:04 +00:00
12c0ea929c
Merge "BpfMap.h - add 3 using statements" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-08-21 17:20:17 +00:00
ef136ebfa1
BpfMap.h - add 3 using statements
in particular base::Result is needlessly verbose

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ide0de9acec79b9aeeaff7ec92270304907bd10d4

Maciej Żenczykowski   commited 2023-08-20 23:33:46 +00:00
eb1eb69f86
BpfMap - slightly simplify isEmpty()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9b93224ec2d4ff717d5e39c3ad50e63ac73f5f7c

Maciej Żenczykowski   commited 2023-08-20 12:03:26 +00:00
910cf4da9b
BpfClassic - add three more macros
Example use case:
  BPF_LOAD_SKB_PROTOCOL,
  BPF2_ACCEPT_IF_EQUAL(ETH_P_ARP),
  BPF2_REJECT_IF_NOT_EQUAL(ETH_P_IP),
  BPF_LOAD_IPV4_BE16(frag_off),
  BPF2_REJECT_IF_ANY_BITS_SET(IP_MF | IP_OFFMASK),
  BPF_ACCEPT,
which is a sample program which accepts ARP plus non-fragmented IPv4.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibe6f9f7941f11bc7b767a092d3d108fa0291f360

Maciej Żenczykowski   commited 2023-07-22 14:32:47 +00:00
2cd8b69005
enforce bpf ring buffer size is a power of two
While at it enforce a min/max of 4 kiB and 256 MiB.

A bpf ringbuffer must be an integer multiple of page size
(which is at least 4kiB), so 4kB is forced.

256 MiB upper limit is probably higher than it should be,
but it's really only here to avoid the u32/s32 conversion
mess that happens for 2+ GiB.

Test: TreeHugger
Bug: 279819914
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2216d2273b0956a86c4222dd6ecf7293e0bafd41

Maciej Żenczykowski   commited 2023-06-17 11:26:21 +00:00
f1416b5494
add macro to disable BTF on user builds
Bug: 286369326
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6a705ae99a12fb8464730dab1119f4ce2ef3f974

Maciej Żenczykowski   commited 2023-06-09 06:06:36 +00:00
8837bf21a5
force map key/value sizes < 1024/65536 bytes to match BpfMap.java
Test: TreeHugger
Bug: 286154283
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I31fb48aa032e22a83e3e9f0ac8d7f2b3253e995e

Maciej Żenczykowski   commited 2023-06-07 06:59:40 +00:00
5bec8b44a9
KernelUtils.h - better static assert messages for impossible conditions
per Lorenzo's request during cherrypick to udc-dev on
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/libs/net/+/23391171

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib19f5b3b63a6978ac5a72b2be08a2f0ba6cdd712

Maciej Żenczykowski   commited 2023-05-25 12:30:52 +00:00
2129040ae4
KernelUtils.h: explicitly do not support x32
x86 has 2 obvious ABIs:
32-bit registers/pointers/system calls (i386/i486/i586/i686)
64-bit registers/pointers/system calls (amd64 / x86_64)

but there also exists a third:
the memory optimizing hybrid 'x32' which uses 64-bit registers,
with 32-bit pointers, and 64-bit system calls (with minor tweaks).

(there is also technically an aarch64/arm64-ilp32 ABI mirroring x32)

Note: It would probably be trivial to add support if we wanted to.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I82138c5bafbc3bd37cad98eeb79441701d94c386

Maciej Żenczykowski   commited 2023-05-21 02:33:55 +00:00
4782ab1b9e
Merge "bpfloader: ignore_on_(arch) support"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-05-20 01:04:21 +00:00
1c4ba307f4
KernelUtils.h - add describeArch()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0ae4b5fd8cf9baf04b738743d9e52f94a35aaf21

Maciej Żenczykowski   commited 2023-05-20 00:45:27 +00:00
2998627ddd
bpfloader: ignore_on_(arch) support
Test: TreeHugger
Bug: 283523051
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I73768a67b50bb82ebb13e20c6ba6425e1e4236c7

Maciej Żenczykowski   commited 2023-05-19 20:59:40 +00:00
6d3224e286
Merge "KernelUtils.h - add arch query helpers"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-05-19 07:32:57 +00:00
8273756bcc
bpf_headers: Make bpf_headers available to libsysutils
So KernelUtils.h can be used in NetlinkEvent.cpp.

Test: builds
Change-Id: If7a6a28e735ee19dc6b7a72330a97a8a01bcecd5

Patrick Rohr   commited 2023-05-18 14:39:14 -07:00
93312c998e
BpfRingbuf: Clean up memory access
Consumer pos is only written to by userspace (except for
initialization), so reading from it does not require a memory barrier.

This change also moves producer pos to be acquired before anything else
and marks start_ptr as volatile, so it is only read once.

Test: atest BpfRingbufTest
Change-Id: I228578ef4b42c1732646f0ae928b9a0aa2445304

Patrick Rohr   commited 2023-05-18 14:08:37 -07:00
85a86cb908
BpfRingbuf: Add support for 32 bit kernels
This change adds support for 32 bit kernels by capping mProducerPos to
4 bytes. mConsumerPos (which is written to by userspace) continues to
use 8 bytes. (This can be done because an entire page is allocated for
mConsumerPos to control access permissions). In a 32 bit kernel, that
means that the top order bits are just ignored. In addition, comparisons
in userspace only use the bottom 4 bytes to be bitness agnostic.

Test: atest BpfRingbufTest
Change-Id: I7fe6d9000a151512785f1aa2a53fa97d31967d19

Patrick Rohr   commited 2023-05-18 14:08:37 -07:00
52954ff505
KernelUtils.h - add arch query helpers
see bionic/docs/defines.md:
http://cs/h/android/platform/superproject/+/master:bionic/docs/defines.md?l=57

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I818da16ad4dd1837ef3cdcc552557119eafaf6af

Maciej Żenczykowski   commited 2023-05-18 17:17:29 +00:00
5b2bcc508a
Merge "BpfRingbuf: support 32 bit userspace"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-05-18 17:08:15 +00:00
0d6edeef83
Merge "bpf_headers: add kernel bitness utility functions to KernelUtils"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-05-18 00:28:51 +00:00
cee4bd691e
Merge "bpf: Copy comment about bpffs labelling into bpf_helpers.h"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-05-17 22:40:57 +00:00
7d2b91e7a3
BpfRingbuf: support 32 bit userspace
Both consumer and producer position are wrapped in an std::atomic and
extended to uint64_t to enforce atomic access.

See resulting assembly instructions for aosp_cf_x86_phone-userdebug:

frameworks/libs/net/common/native/bpf_headers/include/bpf/BpfRingbuf.h:212
  2d:   8b 41 18                mov    0x18(%ecx),%eax
external/libcxx/include/atomic:926 (discriminator 4)
  30:   f3 0f 7e 00             movq   (%eax),%xmm0

This will not work on a 32 bit kernel (so we might want to explicitly
check for that in the test).

Test: atest BpfRingbufTest
Change-Id: I7fec435cbe49d392363d05f7e702d82ecacb9e91

Patrick Rohr   commited 2023-05-17 15:39:38 -07:00
311f8b325e
bpf: Copy comment about bpffs labelling into bpf_helpers.h
I found this comment in aosp/2103424 helpful in figuring out the correct
selinux domain for a newly added map.

Test: documentation only change
Change-Id: I96c06ff33605c8ed3f2ae6e8810bbcdc8e66b51b

Patrick Rohr   authored and   Maciej Żenczykowski   commited 2023-05-17 22:38:22 +00:00
2f5c1159cc
bpf_headers: add kernel bitness utility functions to KernelUtils
These were copied from
system/core/libsysutils/src/NetlinkEvent.cpp and the following changes
were applied:
- Mark isUserspace64bit as constexpr.
- Added __unused annotations
- Fixed a typo (s/meaningul/meaningful)

Test: TH
Change-Id: Ia0b8e6e02daca7e9b69f337a494d88eb1beffc22

Patrick Rohr   commited 2023-05-17 12:52:56 -07:00
432291a334
bpf_headers: rename KernelVersion.h to KernelUtils.h
Test: TH
Change-Id: Ifacc159c19a8fcb64b571295b945fb9fca82496a

Patrick Rohr   commited 2023-05-17 11:43:02 -07:00
66452f566b
Merge "Remove mentions of bploader versions between S and T"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-04-27 19:37:36 +00:00
bc89547ed3
Merge "Bump the default bpfloader version for platform code."
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-04-27 19:17:59 +00:00
82b6bd25f3
Remove mentions of bploader versions between S and T
(they're only of historical interest at this point)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0e52efda62626091c3023c5fd3622ffcdcd00ee1

Maciej Żenczykowski   commited 2023-04-26 23:17:07 +00:00
9ee26f72eb