blob: 14181dc6fcffee3bb654a87204dcbc1643d00d6b [file] [log] [blame]
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -07001# zygote-start is what officially starts netd (see //system/core/rootdir/init.rc)
2# However, on some hardware it's started from post-fs-data as well, which is just
3# a tad earlier. There's no benefit to that though, since on 4.9+ P+ devices netd
4# will just block until bpfloader finishes and sets the bpf.progs_loaded property.
5#
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -07006# It is important that we start bpfloader after:
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -07007# - /sys/fs/bpf is already mounted,
8# - apex (incl. rollback) is initialized (so that in the future we can load bpf
9# programs shipped as part of apex mainline modules)
10# - logd is ready for us to log stuff
11#
12# At the same time we want to be as early as possible to reduce races and thus
13# failures (before memory is fragmented, and cpu is busy running tons of other
14# stuff) and we absolutely want to be before netd and the system boot slot is
15# considered to have booted successfully.
16#
17on load_bpf_programs
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070018 exec_start bpfloader
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070019
Maciej Żenczykowskie36d77c2024-03-04 06:59:25 +000020service bpfloader /system/bin/netbpfload
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070021 # netbpfload will do network bpf loading, then execute /system/bin/bpfloader
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070022 capabilities CHOWN SYS_ADMIN NET_ADMIN
23 # The following group memberships are a workaround for lack of DAC_OVERRIDE
24 # and allow us to open (among other things) files that we created and are
25 # no longer root owned (due to CHOWN) but still have group read access to
26 # one of the following groups. This is not perfect, but a more correct
27 # solution requires significantly more effort to implement.
28 group root graphics network_stack net_admin net_bw_acct net_bw_stats net_raw system
29 user root
30 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070031 # Set RLIMIT_MEMLOCK to 1GiB for bpfloader
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070032 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070033 # Actually only 8MiB would be needed if bpfloader ran as its own uid.
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070034 #
35 # However, while the rlimit is per-thread, the accounting is system wide.
36 # So, for example, if the graphics stack has already allocated 10MiB of
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070037 # memlock data before bpfloader even gets a chance to run, it would fail
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070038 # if its memlock rlimit is only 8MiB - since there would be none left for it.
39 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070040 # bpfloader succeeding is critical to system health, since a failure will
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070041 # cause netd crashloop and thus system server crashloop... and the only
42 # recovery is a full kernel reboot.
43 #
44 # We've had issues where devices would sometimes (rarely) boot into
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070045 # a crashloop because bpfloader would occasionally lose a boot time
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070046 # race against the graphics stack's boot time locked memory allocation.
47 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070048 # Thus bpfloader's memlock has to be 8MB higher then the locked memory
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070049 # consumption of the root uid anywhere else in the system...
50 # But we don't know what that is for all possible devices...
51 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070052 # Ideally, we'd simply grant bpfloader the IPC_LOCK capability and it
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070053 # would simply ignore it's memlock rlimit... but it turns that this
54 # capability is not even checked by the kernel's bpf system call.
55 #
56 # As such we simply use 1GiB as a reasonable approximation of infinity.
57 #
58 rlimit memlock 1073741824 1073741824
59 oneshot
60 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070061 # How to debug bootloops caused by 'bpfloader-failed'.
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070062 #
63 # 1. On some lower RAM devices (like wembley) you may need to first enable developer mode
64 # (from the Settings app UI), and change the developer option "Logger buffer sizes"
65 # from the default (wembley: 64kB) to the maximum (1M) per log buffer.
66 # Otherwise buffer will overflow before you manage to dump it and you'll get useless logs.
67 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070068 # 2. comment out 'reboot_on_failure reboot,bpfloader-failed' below
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070069 # 3. rebuild/reflash/reboot
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070070 # 4. as the device is booting up capture bpfloader logs via:
71 # adb logcat -s 'bpfloader:*' 'LibBpfLoader:*' 'NetBpfLoad:*' 'NetBpfLoader:*'
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070072 #
73 # something like:
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070074 # $ adb reboot; sleep 1; adb wait-for-device; adb root; sleep 1; adb wait-for-device; adb logcat -s 'bpfloader:*' 'LibBpfLoader:*' 'NetBpfLoad:*' 'NetBpfLoader:*'
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070075 # will take care of capturing logs as early as possible
76 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070077 # 5. look through the logs from the kernel's bpf verifier that bpfloader dumps out,
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070078 # it usually makes sense to search back from the end and find the particular
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070079 # bpf verifier failure that caused bpfloader to terminate early with an error code.
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070080 # This will probably be something along the lines of 'too many jumps' or
81 # 'cannot prove return value is 0 or 1' or 'unsupported / unknown operation / helper',
82 # 'invalid bpf_context access', etc.
83 #
Maciej Żenczykowski7da54d92023-10-24 02:11:09 -070084 reboot_on_failure reboot,bpfloader-failed
Maciej Żenczykowski7db65c62023-10-19 16:51:15 -070085 # we're not really updatable, but want to be able to load bpf programs shipped in apexes
86 updatable