Commit graph

3772 commits

Author SHA1 Message Date
Kelvin Zhang
5cb1b0295e Add lz4 support for VABC
Add lz4 support in CowWriter/CowReader. Lz4 should offer faster
read/write performance but slightly larger COW sizes.

Download time: Reduced from 1264s to 825s (~35% faster)
Filesystem verification time: from 69s to 59s (~15% faster)
COW Size: 2.59GB to 3.21GB, (~25% regression)
Merge time: 37046ms to 27690ms (~25% faster)
Boot time: LZ4 is 2.7% faster

Overall, LZ4 offers faster read/write performance at the cost of 25%
space regression.

Test: th
Bug: 228478555
Change-Id: Ie521852fb3c9ff8a12e55b764c1eb1838f7b2181
2022-06-29 13:10:55 -07:00
Yi-Yo Chiang
01a7dcb240 first_stage_init: Optimize redundant vector copy
```
std::vector<std::string> v2;
for (auto&& e : get_temporary_v1()) { v2.push_back(e); }
```
^^^ This is constructing v2 from a temporary object, which is an
unnecessary manual clone. We should just let copy-elision do its thing:

```
// Give compiler the chance to optimize this with copy-elision...
auto v2 = get_temporary_v1();
```

Also `lp_names` appends an extra ',' at its end. Just use
android::base::Join() here.

Bug: 235111004
Test: Presubmit GSI boot test
Change-Id: Ibe8ce7a29b8521e789aa0a99f7f6d31f3f9c70e9
2022-06-27 16:19:37 +00:00
Eric Biggers
e5a9a70437 Merge "Rename fscrypt_is_native() to IsFbeEnabled()" 2022-06-22 18:24:38 +00:00
Florian Mayer
4effd2f901 Promote HWASan tests to presubmit.
They have been passing and do not show significant slowdown.

Change-Id: I3eba6ecb746160d75e9a2c9561bceb71a09117d3
2022-06-17 22:29:09 +00:00
Eric Biggers
893b1ae313 Rename fscrypt_is_native() to IsFbeEnabled()
Now that emulated FBE is no longer supported, there is no longer any
distinction between native FBE and emulated FBE.  There is just FBE.

Referring to FBE as "fscrypt" is also poor practice, as fscrypt (the
Linux kernel support for filesystem-level encryption) is just one part
of FBE, the Android feature.

Therefore, rename fscrypt_is_native() to IsFbeEnabled().

Bug: 232458753
Change-Id: Ib4dcdf799833b91d326b4b6f7120b0a3d4f4fc31
2022-06-15 18:52:39 +00:00
Treehugger Robot
a50d431830 Merge "Chmod for existing nodes which mode not the same as ueventd.rc" 2022-06-14 14:14:15 +00:00
Yi-Yo Chiang
70c53f5d52 Auto enable usb adb if booting with debug ramdisk
If booting with debug ramdisk (ro.force.debuggable is true), override
the persistent property "persist.sys.usb.config" to always enable adb.
This ensures a consistent debug experience. The developer can expect
that after debug ramdisk (debug boot image) is flashed,
1. Device is rootable with (adb root)
2. adb is enabled automatically
3. no-auth (if $ADB_VENDOR_KEYS is used)

Bug: 223517900
Test: 1. Flash & boot user build, verify device doesn't have usb
  debugging enabled.
  2. Reboot to bootloader and flash vendor_boot-debug.img.
  3. Boot and verify usb debugging is automatically enabled.
  4. Enter Developer Options and manually turn off usb debugging.
  5. Reboot and verify that usb debugging is automatically enabled.
Change-Id: I729e961d645f2dd521ead8ca30b5cb8eb1d9f909
2022-06-08 23:07:13 +08:00
Treehugger Robot
ac9b59ed5a Merge "Added libinit_headers to Android.bp" 2022-06-03 08:57:08 +00:00
Akilesh Kailash
4ffe8a3109 init: Set oom_score_adj to snapuserd process
When a process is started as a native service,
oom_score_adj is set to -1000 so that processes
are unkillable by lmkd.

During boot, snapuserd process is not started as a service;
hence, we need to set the oom_score_adj explicitly else in
the event of low memory situation, lmkd can kill the
process thereby device can never boot.

Bug: 234691483
Test: th and OTA on Pixel
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Ic2c85aa470522b4bc847a16b4f5cebfc528ed3cf
2022-06-02 20:49:03 +00:00
Thiébaud Weksteen
715ecbfb23 Merge "Add documentation on mkdir about seclabel" 2022-05-31 23:27:22 +00:00
Thiébaud Weksteen
cc2fb50f52 Add documentation on mkdir about seclabel
Test: n/a
Change-Id: Iab672b4755a259caacf495a6692afcb268b4205f
2022-05-31 14:47:13 +10:00
Kelvin Zhang
321d47639e Merge changes from topic "snapuserd_ramdisk"
* changes:
  Prefer generic ramdisk copy of snapuserd
  Install snapuserd.ramdisk with a separate path
2022-05-25 15:39:17 +00:00
Treehugger Robot
216b8b67fb Merge "Suppress most load_property_from_file logs" 2022-05-25 03:56:24 +00:00
Inseob Kim
946c972162 Suppress most load_property_from_file logs
Some partitions may not have build.prop files (and it's totally fine).
Rather than logging such failures as WARNING, load_property_from_file
now returns a Result<void> object so callers can manually log for
themselves.

Bug: 228389036
Test: boot and logcat
Change-Id: Ia4ad7eef34d572182a3f6e86547664ae31dfd29f
2022-05-25 09:47:08 +09:00
Jooyung Han
99fa346c35 init: Disable 'on' for non-Vendor APEXes
Mainline modules are not supposed to rely on 'on' action triggers in
their init scripts because events/properties are not guranteed to be
stable across many devices.

To reduce the potential risk of enabling 'on' for APEXes, for now, we
enable it for only Vendor APEXes.

When an init script in a non-Vendor APEX contains 'on' section, init
emits an error on parsing the script and skip the section.

For example, when init.rc in the ADBD APEX has 'on' section,
the following error is emitted on parsing the script.

  init: Parsing file /apex/com.android.adbd/etc/init.rc...
  init: /apex/com.android.adbd/etc/init.rc: 8: ParseSection() failed:
    'on' is supported for only Vendor APEXes.

Bug: 232543017
Test: see above
Change-Id: I6509c8d2c6b632369d215128f740f9ed78858605
2022-05-20 09:31:08 +00:00
Treehugger Robot
0ddcf6d2f1 Merge "init: log services requested restart" 2022-05-18 05:31:04 +00:00
Steven Moreland
61169c76dd init: log services requested restart
We have a case where a service is requested to be started and does
not appear to be running, but we see no indication that it is
actually starting. This log should be enough information to see
if init is in a bad state.

Bug: 232297944
Test: doesn't add too much spam
    ~/android/aosp/system/core/init :) adb logcat -d | grep "requested start" | wc -l
    42
Change-Id: Ic07f250c98b200b9e5b4432200c3668c6ca0ff35
2022-05-17 22:54:55 +00:00
Eric Biggers
48c05a6d03 init: remove unneeded special cases from FscryptInferAction
All the individual directories being treated specially by
FscryptInferAction() already have an explicit encryption action in the
corresponding mkdir commands.  The explicit action is the source of
truth, so the special cases in FscryptInferAction() are unnecessary.

Also, some of these cases were outdated.  For example, /data/app-staging
was changed from encryption=None to encryption=DeleteIfNecessary at some
point, but FscryptInferAction() was not updated.  This is causing the
warning "Inferred action different from explicit one" to be logged.

Additional "Inferred action different from explicit one" warnings are
logged due to subdirectories of /data/apex being explicitly encrypted.

Change FscryptInferAction() to only do what it needs to do: check
whether the directory is a top-level directory of /data or not.  Remove
the above-mentioned warning which is not useful.

Bug: 232554803
Change-Id: If6611d64107a19d242892c92dfea095577e193e5
2022-05-16 19:06:22 +00:00
Eric Biggers
6cb5a36f4c init: fix mkdir to reliably detect top-level /data directories
To determine the default encryption action, the mkdir command checks
whether the given path is a top-level directory of /data.  However, it
assumed a path without any duplicate slashes or trailing slash(es).

While everyone *should* be providing paths without unnecessary slashes,
it is not guaranteed, as paths with unnecessary slashes still work
correctly for all other parts of the mkdir command, including the
SELinux label lookup and the actual directory creation.  In particular,
the /data/fonts directory is being created using 'mkdir /data/fonts/'.

The effect is that the mkdir command thinks that /data/fonts/ is *not* a
top-level directory of /data, so it defaults to no encryption action.
Fortunately, the full command happens to use "encryption=Require", so we
dodged a bullet there, though the warning "Inferred action different
from explicit one" is still triggered.

There are a few approaches we could take here, including even just
fixing the /data/fonts/ command specifically, but I think the best
solution is to have mkdir clean its path at the very beginning.  This
retains the Linux path semantics that people expect, while avoiding
surprises in path processing afterwards.  This CL implements that.

Note, this CL intentionally changes the behavior of, and thus would
break, any existing cases where mkdir is used to create a top-level
/data directory using a path with unnecessary slashes and without using
an explicit encryption action.  There are no known cases where this
already occurs, however.  No cases exist in platform code, and vendor
init scripts shouldn't be creating top-level /data directories anyway.

Test: atest CtsInitTestCases
Test: Booted and verified that a trailing slash is no longer present in
      the log message "Verified that /data/fonts/ has the encryption
      policy ...".  Also verified that the message "Inferred action
      different ..." is no longer present just above it.
Bug: 232554803
Change-Id: Ie55c3ac1a2b1cf50632d54a1e565cb98c17b2a6a
2022-05-13 19:29:00 +00:00
Jooyung Han
ec76b5cb4e Merge changes from topics "action-in-apex-config", "apex-ready-event", "subcontext-for-vendor-apex"
* changes:
  Use subcontext for APEX configs from /{vendor, odm}
  add apex-ready event after post-fs-data
  APEX configs support 'on' as well
2022-05-13 01:47:40 +00:00
Eric Biggers
93a8fc215e Merge "Move creation of /data/user/0 and /data/media/obb to vold" 2022-05-12 18:41:21 +00:00
Jooyung Han
38e8e74550 Use subcontext for APEX configs from /{vendor, odm}
Instead of using config file path, use APEX's preinstalled path to
determine whether to use subcontext or not for APEX configs.

Bug: 232021354
Test: CtsInitTestCases, CtsBluetoothTestCases
Change-Id: Iba603f09602f0bec3113e2be3d15c62055c09e72
2022-05-12 13:37:19 +09:00
Jooyung Han
badb7de1a2 APEX configs support 'on' as well
APEX configs have supported only 'service' definitions. For those
services relying on 'on' trigger actions, we had to have separate config
files installed in read-only partitions (e.g. /system/etc/init).

This was suboptimal because even though APEXes are updatable, read-only
partitions are not.

Now, 'on' is supported in APEX configs. Putting 'on' trigger actions
near to service definitions makes APEX more self-contained.

'on' trigger actions loaded from APEX configs are not sticky. So, events
happens before loading APEX configs can't trigger actions. For example,
'post-fs-data' is where APEX configs are loaded for now, so 'on
post-fs-data' in APEX configs can't be triggerd.

Bug: 202731768
Test: atest CtsInitTestCases
Change-Id: I5a01d9c7c57b07955b829d6cc157e7f0c91166f9
2022-05-12 13:37:13 +09:00
Christopher Ferris
dbe14f2f73 Merge "Use new AndroidUnwinder object." 2022-05-12 03:35:34 +00:00
Christopher Ferris
d2bd6c5f13 Use new AndroidUnwinder object.
Replace libbacktrace with the new AndroidUnwinder object.

Bug: 120606663

Test: Ran unit tests.
Test: Added call of UnwindMainThreadStack() in DebugRebootLogging()
Test: and verified unwind data is logged properly.
Change-Id: Ia724f9485377d6d2c894283242a3c5653bf82768
2022-05-11 15:39:20 -07:00
Eric Biggers
ef9275223c Move creation of /data/user/0 and /data/media/obb to vold
To prevent bugs, directory creation and encryption should happen
together.  /data/user/0 (and its "alias" /data/data) is a per-user
encrypted directory; such directories can only be encrypted by vold.
Therefore, move its creation to vold as well.

Besides closing the uncomfortably-large gap between the creation and
encryption of /data/user/0, this allows removing init's write access to
/data/user and similar directories (SELinux type system_userdir_file) to
prevent any such issues from being reintroduced in the future.

To also allow removing init's write access to /data/media (SELinux type
media_userdir_file), which also contains per-user encrypted directories,
also move the creation and encryption of /data/media/obb to vold.

Bug: 156305599
BYPASS_INCLUSIVE_LANGUAGE_REASON=Linux API ("slave" mount flag)
Change-Id: I7245251eeb56b345b6c7711482c0aa5848648edb
2022-05-11 21:50:35 +00:00
Kelvin Zhang
07c86bace1 Prefer generic ramdisk copy of snapuserd
Test: th
Bug: 219841787
Change-Id: I1319ff968dfa94fec2925b7d5febae32d824fe3a
2022-05-11 13:57:06 -07:00
Florian Mayer
6268f6ab7a Make sure all expected actions get run.
Change-Id: I2b390ffa394ccd6a50a4a5d8805ce5a580c369b9
2022-05-11 01:02:03 +00:00
Suren Baghdasaryan
af64077f83 init: Purge empty process groups on zygote restart
When system_server crashes or gets killed, it causes zygote to kill
itself, which in turn leads to killing all processes in the same
process group (all apps). This leaves empty process groups because
system_server is not there to remove them.
Purge empty process groups when init detects zygote death.

Bug: 228160715
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I0ce27eea28f8713e52033bbec2d5363a7b8ff5db
2022-04-29 17:17:51 +00:00
Devendra Singhi
1df957b9be Added libinit_headers to Android.bp
Test: Builds libint_headers
Bug: 218631398

Change-Id: Ia47d3c23cd4d4be7abc618ac1d2bf698f7761446
2022-04-26 09:51:59 +05:30
Jaegeuk Kim
4669f919a6 Merge "Shutdown f2fs to avoid fsck" 2022-04-25 16:42:48 +00:00
Jooyung Han
cee25aa926 Migrate compare-bootcharts.py to python3
Bug: 229983560
Test: system/core/init/compare-bootcharts.py \
          base-bootchart-dir exp-bootchart-dir
Change-Id: I72a3720cb3a80ef8d4fcb06fba8c8893ac08c930
2022-04-25 10:26:08 +09:00
Jooyung Han
7f8721b992 Unshare mount namespace in bootchart's thread
When bootchart is enabled its thread shares the mount namespace context
with the main thread. This prevents the main thread to switch the mount
namespace later with setns().

So, unshare() the mount namespace of the bootchart thread.

Bug: 229983560
Test: rebooted with bootcharting on/off
    enter_default_mount_ns should succeeded.
Change-Id: Idac0d0efcb4f7f7d8a7cbcebf8fa2fa29f104c35
2022-04-25 10:26:07 +09:00
Steven Moreland
d438ea723b Merge "ueventd: suggest move location for ueventd config" 2022-04-22 21:38:48 +00:00
Jaegeuk Kim
3e595d5e67 Shutdown f2fs to avoid fsck
Bug: 229406072
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: Id3b27219ab2a4655f1740829b0f03f027e66349d
2022-04-22 12:48:09 -07:00
Steven Moreland
2098314842 ueventd: suggest move location for ueventd config
Bug: 229650435
Test: N/A
Change-Id: I4645fd5a95b46ff40a0e8ee25130788ebfd01d72
2022-04-21 20:13:40 +00:00
zexin.hou
76cba8a16a Chmod for existing nodes which mode not the same as ueventd.rc
Change-Id: I5b0a918d4085b55daff5be1f4fc4496fabfb4cce
2022-04-19 14:40:56 +08:00
Akilesh Kailash
f86fca236f libsnapshot: Remove invalid snapshot metadata
If there are snapshot metadata persisting in /metadata/ota/snapshots,
remove them before applying a new update. Make sure that
the snapshots are indeed invalid before removing them.

On a sidenote, add a comment in init.cpp related to
b/223076262.

Bug: 228250473
Test: 1: Apply OTA in recovery through adb sideload
2: Reboot
3: Apply OTA OTA again through update_device.py
4: Re-run Full OTA updates just from update_device.py

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I116bbafae09042b9c391ccd58c102704571c214e
2022-04-16 16:43:35 +00:00
David Anderson
6776e645f1 Merge changes I16bd2d5e,I04e9bf73
* changes:
  DO NOT MERGE: Revert "init: Add more diagnostics for signalfd hangs."
  DO NOT MERGE: Revert "init: Add diagnostics for signalfd epoll failures."
2022-04-16 05:32:58 +00:00
David Anderson
fc90774ef2 DO NOT MERGE: Revert "init: Add diagnostics for signalfd epoll failures."
This reverts commit 0fa7c40c4c.

Reason for revert: Diagnostics no longer needed

Change-Id: I04e9bf73b89411f7092348f57bfe6eb7dfaa9fcb
2022-04-15 01:00:27 +00:00
David Anderson
9f1c919115 Add jiyong@ to OWNERS.
Change-Id: Iada34671296ebb7c1dc372638c91320bad6e7166
2022-04-07 19:15:01 -07:00
Treehugger Robot
02360a55b7 Merge "Clean up comments/logs" 2022-04-07 03:17:38 +00:00
Kelvin Zhang
f887e74588 Clean up comments/logs
Test: th
Change-Id: Ie63cfab7bf8d5d8e3e91695259cf62ab3ac17ee9
2022-04-06 14:02:13 -07:00
Suren Baghdasaryan
746ede9629 init: try converting writepid used with cgroups into task_profiles command
writepid usage to add a task to a cgroup was deprecated in favor of the
task_profile command. The reason is that writepid hardcodes cgroup path
and makes it hard to change it in the future, whereas task profiles
configure cgroup paths in one centralized place and are easy to change.
Log a warning when writepid is used with cgroups and try converting it
into a task_profiles command for well-known cgroups. If conversion is
not possible the writepid operation will still be attempted to avoid
breaking existing use cases and an error will be logged.

Bug: 191283136
Test: build and boot
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ie58393468ef7d92ab0ffb41e6f339e36d21f7478
2022-04-05 01:25:46 +00:00
Suren Baghdasaryan
1bd1746447 init: Treat failure to create a process group as fatal
During process startup, system creates a process group and places the
new process in it. If process group creation fails for some reason, the
new child process will stay in its parent's group. This poses danger
when the child is being frozen because the whole group is affected and
its parent is being frozen as well.
Fix this by treating group creation failure as a fatal error which would
prevent the app from starting.

Bug: 227395690
Test: fake group creation failure and confirm service failure to start
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I83261bef803751759c7fd709bf1ccd33ccad3a0b
2022-04-01 23:32:47 +00:00
David Anderson
ed1bca4b52 ueventd: Allow legacy paths in API version 32.
Bug: 226699360
Test: manual test
Change-Id: I2602eaa217a2b6cba8a5fb8acd6d5a8a9e3d405e
2022-03-29 17:50:01 -07:00
Daniel Norman
c015f7f96d Merge "Adds an init host lib for use in host_apex_verifier." 2022-03-29 23:56:15 +00:00
Treehugger Robot
a41f3812fd Merge "Load kernel modules in parallel" 2022-03-23 07:40:18 +00:00
Treehugger Robot
99c892e579 Merge "restorecon /dev/console at the second stage boot" 2022-03-23 04:29:53 +00:00
Inseob Kim
89d6913cf2 restorecon /dev/console at the second stage boot
It could be the case that /dev/console is created at the first stage
boot. ueventd doesn't have a permission to relabel from tmpfs to
console_device, so we should try restorecon /dev/console, together with
/dev.

Bug: 193118220
Test: atest MicrodroidHostTestCases
Change-Id: Ic538bc9214d3996fe7b37fa2224c1f0c6eb373d1
2022-03-22 21:51:07 +09:00