Commit graph

226 commits

Author SHA1 Message Date
Keiichi Watanabe
621e719751 cargo: Deny compiler warnings
Fix exiting compiler warnings and enable "-Dwarnings" to reject code
emitting new warnings

BUG=b:181763000
TEST=CQ

Change-Id: I2ab69e861f0bf9dee8378ac1b33354c87a6a0c42
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4011747
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-11-08 16:53:48 +00:00
Shintaro Kawamura
985e575e66 base: unix: find active pages in a file
lseek(2) + SEEK_DATA/SEEK_HOLE is used to find active data in a file.
The api is also effective for memfd. snapshot feature uses to traverse
active pages in the memfd backed guest memory.

BUG=b:215093219
TEST=cargo test -p base unix::file::tests

Change-Id: I9f0eb46a568dadc94231ac437dec25c3478a7d37
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3993126
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-11-07 06:27:47 +00:00
Vikram Auradkar
afcaa35ab8 crosvm: Fix windows clippy warnings
BUG=b:257249038
TEST=CQ

Change-Id: Iffb53295fbe64b31b4f68e217f6b522e4231e61c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3993933
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-11-03 18:36:29 +00:00
Dennis Kempin
86034fd5fb base: Move clone_equality test to integration test
In non-privileged containers, comparing a file descriptor may not
work. So the test will not work in every runtime environment.

BUG=b:244623061
TEST=dev_container --podman --unprivileged tools/run_tests base:base

Change-Id: Ifa67e11db9694c36b47cd5ae88de9247284e1cdf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3999711
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-11-02 22:29:12 +00:00
Daniel Verkamp
11322f007d tree-wide: use LFS variants of libc functions
Use the off64_t versions of libc file functions.

There is no Rust libc crate equivalent of the C _FILE_OFFSET_BITS and
related defines, so we have to use the Linux-specific *64 variants
explicitly.

This extends the size of file offsets to 64 bits instead of 32 on
platforms with 32-bit userspace.

(It also fixes the recently introduced check for non-LFS functions in
ChromeOS - see b/201531268 for details.)

BUG=b:201531268
TEST=emerge-kevin crosvm
TEST=start Crostini on kevin

Change-Id: Ife42917c8896d4fa1ccd78051c2a0b7dd565b2b3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3979975
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-02 22:20:18 +00:00
Daniel Verkamp
3002df7872 base: windows: make Event wait() actually infinite
Refactor the Windows PlatformEvent wait and wait_timeout functions to
use an internal wrapper function that correctly handles waiting forever
by passing the INFINITE value to WaitForSingleObject.

Previously, the wait function used a Duration value of i64::MAX seconds,
which becomes 0xfffffc18 when converted to milliseconds and truncated to
a DWORD. This does not correspond to the INFINITE value (-1, 0xffffffff)
that the Win32 Wait* functions expect, so theoretically a wait() call
could have returned without the event being signaled.

BUG=b:231344063
TEST=tools/presubmit --all

Change-Id: If68c4b2518926c12e8caf6746ef4b0bb152be00d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3966485
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-11-01 21:03:05 +00:00
Daniel Verkamp
33078aac98 base: replace internal PlatformEvent uses with Event
We should use the public Event API wherever possible, even within the
base crate.

BUG=b:231344063
TEST=tools/presubmit --all

Change-Id: Ie4c8b2b82cf16299666998acb7b9b174c2bedc3b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3966484
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-11-01 20:59:29 +00:00
Daniel Verkamp
4cf9029b23 base: unix: use AsRawDescriptor in FileFlags and PlatformEvent
Use the cross-platform AsRawDescriptor rather than the unix-specific
AsRawFd. FileFlags and PlatformEvent are migrated simultaneously since
the FileFlags unit tests use PlatformEvent.

BUG=b:231344063
TEST=tools/presubmit --all
TEST=cargo test -p base -- --test-threads=1

Change-Id: I3653f7d50524bf459c6fb944b00dce90e9d4e659
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3966483
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-11-01 20:51:32 +00:00
Dennis Kempin
f8eb24052e Reformat all files with nightly
Run tools/fmt --nightly

BUG=None
TEST=None

Change-Id: Iaccfc5fe141c512f4b508c699f89686a4552bf96
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3988327
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-10-31 21:33:33 +00:00
Dennis Kempin
b896b869e4 base: Extract integration tests
The extracted tests rely on access to system devices
or global state that prevent them from being run in parallel
or in restricted environments.

As an integration test they will be executed separately and
single threaded.

Updates the test runner to ensure integration tests are actually
run single threaded as intended.

BUG=b:244623061
TEST=./tools/run_tests base:\* --repeat 100 -p x86_64/mingw64/aarch64

Change-Id: I4267b9f79055208aca86796d902da251816bcada
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3971025
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-10-24 22:49:29 +00:00
Daniel Verkamp
c433c9e796 base: remove Windows EventExt::new_with_manual_reset()
Replace the single new_with_manual_reset() call, which passed false to
create an auto-reset event, with a call to the more descriptive
new_auto_reset() function.

This allows the new_with_manual_reset() API to be removed.

BUG=b:231344063
TEST=tools/presubmit --all

Change-Id: I51d1fcbab161d10539c44689b31e2d86ad9e1527
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3966482
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-10-20 21:15:41 +00:00
Daniel Verkamp
a364040b4b base: fix WaitContext doc tests
BUG=b:231344063
TEST=cargo test -p base -- --test-threads=1

Change-Id: Icf4dc6228eadb41aacbb49844089b1cadb6c5b5e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3966481
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-10-20 21:10:14 +00:00
Daniel Verkamp
28d0f67858 base: event: add Event::reset() API
This allows resetting an Event without waiting on it. Windows already
had this functionality in its EventExt, and we can provide an equivalent
implementation for eventfd on Linux, so promote this function to the
cross-platform Event type.

BUG=b:231344063
TEST=tools/presubmit --all

Change-Id: I6dba3cb2e0b2d702e8a3f0dacf5c25c1dd044a13
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3966480
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-10-20 21:04:14 +00:00
Frederick Mayle
3d4b4809ba base: cross platform Event API
Trying to reconcile the difference between the linux and windows
implementations.

Code relying on the eventfd count must now use the linux specific
`EventExt` interface.

BUG=b:231344063
TEST=presubmits

Change-Id: I14eb50f7a02d766a00f27aca388823309633e193
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864030
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-10-19 20:17:42 +00:00
Daniel Verkamp
4b6c33d346 base: windows: error if CPU >= 64 in set_cpu_affinity
The loop that generates the CPU affinity mask uses a shift by the CPU
index to generate a u64, so if the shift count is 64 or greater, it will
shift past the end of the u64 and panic when overflow checks are enabled
(which we enable by default in release builds in Cargo.toml).

Add a bounds check so set_cpu_affinity() will return an error rather
than causing a panic in this case.

BUG=None
TEST=run tests via wine on 72 logical core machine

Change-Id: I2ac4a0602b2c014aeca4939ec2882926cdfe2c29
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3935523
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-10-14 20:04:46 +00:00
Sebastian Ene
b5edcab20b devices: vmwdt: Add watchdog reset reboot reason
When we detect a VCPU stall we propagate the watchdog reboot error code
to the event tube. The newly added error code WATCHDOG_REBOOT = 36 is
returned from the crovm process.

Bug: 245900797
Test: manual testing, build and Virtualization apk on a device
Signed-off-by: Sebastian Ene <sebastianene@google.com>
Change-Id: Ib1ce97de911784b33d130d40536be26813edc3d7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3936647
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-12 06:34:58 +00:00
Keir Fraser
47cf9446ac base: net: Ignore path of a UnixSeqpacketListener passed by descriptor
The path does not belong to crosvm and should not, for example, be
revealed to UnlinkUnixSeqpacketListener which would try to remove it.

TEST=cargo test, added a new unit test
BUG=b:251742702

Change-Id: I6e81623b76d62961c774010e1dafcf73ffca6471
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3941684
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keir Fraser <keirf@google.com>
2022-10-11 06:54:07 +00:00
Alexandre Courbot
7186bc7bb8 base: event: remove obsolete comments to fix cargo doc
The platform event types are now private, and their methods are exposed
through the base Event type, so remove that comment that triggers a
warning with `cargo doc`.

TEST=`cargo doc` does not warn about this line.

Change-Id: I4577a194582dddaa2536541247807fc4cd1eea06
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3932438
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-10-05 01:39:19 +00:00
Frederick Mayle
d5f37f2982 base: rename platform specific event types to PlatformEvent
This isn't necessary, but it does aid readbility in my opinion.

BUG=b:231344063
TEST=cargo build && ./tools/dev_container ./tools/run_tests --target=host --build-target=mingw64 --build-only

Change-Id: Id486d66773a15f1a544f717aab508d5006be3553
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864026
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2022-10-04 18:29:21 +00:00
Keir Fraser
88674cade9 base: net: Validate descriptor passed to UnixSeqpacketListener
The existing file descriptor must refer to a listening socket.

TEST=cargo test, added a new unit test
BUG=b:238931628

Change-Id: Ia6bd5d6d30af69fb4b5fa00865f5528f19f569d9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3932714
Commit-Queue: Keir Fraser <keirf@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-04 06:53:48 +00:00
Hikaru Nishida
129c75ccea base: unix: Add a wrapper for getppid
BUG=b:215093219
TEST=None

Change-Id: I89d6d163af5fd97ad36fb294e12a0729b1391035
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3865218
Commit-Queue: Hikaru Nishida <hikalium@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-10-04 03:28:02 +00:00
Colin Downs-Razouk
e0de18a6a5 base: timer: handle 0 interval explicitly
Make it official that setting a Timer's interval to 0 is the same as
setting it to None, meaning it will not be periodic. Fixed the windows
timer to behave this way again, and updated Timer docstring.

Also updated APIC timer to use None for interval which is clearer.

Bug: b:248612697
Test: tested with UserspaceIrqChip in dynamic tick mode
Change-Id: I57713c3ace345a8c64b9219a8e60f36c54a9481c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3925006
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2022-09-30 16:50:22 +00:00
Keir Fraser
ba9c9e2e1e crosvm: Accept existing control socket file descriptor via command line
An existing file descriptor is specified by a path of the form
/proc/self/fd/<fd>. In this case crosvm will use this existing
listener socket directly, rather than trying to create a fresh one at
the specified path location.

This is useful for sandboxing crosvm in an environment in which it is
unable to create new filesystem entries.

BUG=b:238931628
TEST=Tested downstream

Change-Id: Ic6b24196bbe01960aedfe3f00ec69fd799e6ba91
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3928022
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keir Fraser <keirf@google.com>
2022-09-30 08:51:01 +00:00
Colin Downs-Razouk
27bdb64e4d base: windows: timer: fix interval < 1ms
Windows' SetWaitableTimer function takes a period argument that is in
milliseconds. If it's set to 0 then the timer will not be periodic. If
the reset function is called with a period that is <1ms but not None, we
should set the period to 1ms which is the best we can do.

Bug: b:248612697
Test: ran kernel with HZ=1000 on Windows, verified PIT works

Change-Id: Ie908205a455c818bad5b246da54b504eb9ce7b27
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3926198
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2022-09-28 21:17:41 +00:00
Frederick Mayle
1c3ba38583 base: don't export platform specific Event types
TEST=cargo build && ./tools/dev_container ./tools/run_tests --target=host --build-target=mingw64 --build-only
BUG=b:231344063

Change-Id: I125f4b200abdc6758bae93d98c590c2139fe915b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864025
Auto-Submit: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-21 21:35:48 +00:00
Dennis Kempin
7cd928d985 Remove ChromeOS only PR_SET_CORE_SCHED
This feature is only available on ChromeOS and should live in
the downstream ChromeOS repository.

Note: This change should be reverted with the next ChromeOS merge.

BUG=b:244618505
TEST=None

Change-Id: I33d4e6c5feb4178ebf7cd946ea654dbd20291653
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3907532
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-21 20:51:16 +00:00
Ryan Neph
bf6e7d9060 rutabaga_gfx: unmap from gpu thread for virglrenderer
Virglrenderer must not unmap from any thread other than the virtio-gpu
thread because virglrenderer is not thread-safe and EGL requires that
only one thread own a context concurrently.

For the VirglRenderer RutabagaComponent, we can unmap directly from the
virtio-gpu thread. In fact, we can greatly simplify the use of
ExternalMapping if we eliminate the associated map/unmap callbacks for
all RutabagaComponents.

Now VirtioGpu is responsible for ensuring that the map/unmap occurs and
is registered/unregistered. Also, the shared `map_request:
Arc<Mutex<ExternalMapping>>` spanning the KVM and virtio-gpu threads is
no longer necessary.

BUG=b:244626679
TEST=OpenGL and Vulkan gameplay with sandboxing disabled
TEST=OpenGL and Vulkan gameplay on ChromeOS with sandboxing

Change-Id: I4acaf4aabff3891536ca0439221cfbd021dba123
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3888602
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Ryan Neph <ryanneph@google.com>
2022-09-16 17:29:37 +00:00
Dennis Kempin
1dab58a2cf Update all copyright headers to match new style
This search/replace updates all copyright notices to drop the
"All rights reserved", Use "ChromiumOS" instead of "Chromium OS"
and drops the trailing dots.

This fulfills the request from legal and unifies our notices.

./tools/health-check has been updated to only accept this style.

BUG=b:246579983
TEST=./tools/health-check

Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-09-13 18:41:29 +00:00
Vikram Auradkar
644251cec0 crosvm: fold windows-only proto-tube-hack into kiwi
Makes proto-tube the default behavior when kiwi is enabled.

BUG=b:244666222
TEST=tested downstream

Change-Id: I4281dec4dc201ff981662498dae932b514c34050
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3881729
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Tested-by: Vikram Auradkar <auradkar@google.com>
2022-09-08 19:04:26 +00:00
Daniel Verkamp
b75f65855c base: netlink: remove unused family_name_query variable
Remove the _bytes_read variable, since it is not needed. It was also
misnamed since we are writing, not reading, data.

Fixes a Rust 1.62 clippy lint:

  error: this let-binding has unit value

BUG=b:243677117
TEST=tools/clippy # with Rust 1.62

Change-Id: I53f7b675f8e95c94ab127e500127a9153166a906
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3854968
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-01 18:45:50 +00:00
Frederick Mayle
96d8e77926 base: dedup EventReadResult
TEST=cargo build
BUG=b:231344063

Change-Id: I461d5dda013fe69322ef51144d7a28824a607553
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3863923
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Auto-Submit: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Tested-by: Frederick Mayle <fmayle@google.com>
2022-08-31 21:29:08 +00:00
Christian Blichmann
ab3e298e4e base: Simplify sched.rs a bit
Behavior should be exactly the same.
- Use `CpuSet::new()` directly instead of duplicating its code
- Use the `syscall!()` macro for error handling

TEST=./tools/presubmit
BUG=None

Change-Id: I371e9a113914db7ffdecbf4bf8770be157368569
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3858174
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Christian Blichmann <cblichmann@google.com>
Reviewed-by: Christian Blichmann <cblichmann@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-08-29 08:42:19 +00:00
Vikram Auradkar
5d264785c8 crosvm: resync with downstream after running clippy
BUG=b:243099012
TEST=presubmit

Change-Id: Ia910932344c58979c6735776797139e3a1ee9428
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3846056
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: Vikram Auradkar <auradkar@google.com>
2022-08-25 20:45:12 +00:00
Daniel Verkamp
bf449563d8 tree-wide: reformat with nightly rustfmt
BUG=None
TEST=tools/fmt --nightly

Change-Id: I9e1985546b364835e252df04dab2c9ecb192047c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3852316
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-23 23:33:58 +00:00
Daniel Verkamp
4a6942dd33 base: syslog: make platform syslog init non-fatal
If we can't create a PlatformSyslog instance (for example, if /dev/log
is not available on a minimal Linux system without a traditional init),
warn the user and continue executing instead of failing.

BUG=b:242103548
TEST=Run crosvm inside minimal VM with no init

Change-Id: I4d81da396125331ef7ad335e57b37645b6546980
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3842814
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-08-22 21:05:18 +00:00
Daniel Verkamp
fd0b2ecdaa base: linux: store syslog fd in a OnceCell
Ensure that openlog_and_get_socket() is only called once by storing its
result in a OnceCell. This fixes logging initialization when the syslog
State structure was constructed more than once, causing the log fd to be
invalidated and breaking sandboxed startup.

BUG=b:242103548
TEST=Start crosvm on Linux with sandbox enabled (default mode)

Change-Id: I663a7e918b81f4c23415a28cfcc2c72f6b4a51d8
Fixes: 7dbdc73063 ("base & src: allow multiple log inits.")
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3842813
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-08-20 00:43:56 +00:00
Noah Gold
7dbdc73063 base & src: allow multiple log inits.
With the migration to env_logger, we lost the ability to initialize
logging multiple times. This meant that we had to wait until we had
parsed CLI args and knew exactly what we wanted our logging spec to be,
which meant that it would sometimes be too late to log startup errors.
This CL modifies the logging facade to be modifiable on the fly, albeit
with some restrictions, to obviate the problem.

The syslog API has been modified as follows:

syslog::early_init: initializes stderr logging, can be called only once
per process. Called as the first function in main.

syslog::init/init_with: can be called after early_init to modify the
parameters used by the logging system. Can be called only once per
process. Will be called roughly after argument parsing or bootstrapping
is complete.

The fundamental change to enable this was in the logging facade. Now,
the facade passes all logging operations to a static, mutex protected
struct. This way, the facade never changes, but we can modify the
struct whenever we wish.

BUG=b:242103548
TEST=tested downstream

Change-Id: I76bc1bb275c81a69aadc7f03a80b94c297f47781
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3834294
Commit-Queue: Noah Gold <nkgold@google.com>
Tested-by: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-19 22:16:46 +00:00
Paramjit Oberoi
91113e63af Panic handler that passes info to crash reporter via memfds.
Crashes of rust executables have a generic signature since the user
crash collector is not able to compute a reasonable signature for them.
This custom panic hook allows passing a signature derived from PanicInfo
to the crash collector.

BUG=b:234093439
TEST=See crrev.com/c/3834930 and crrev.com/c/3836804

Change-Id: Ida7f655d3a2463e8a42602d8e32588195a0ce36b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3842808
Commit-Queue: Paramjit Oberoi <psoberoi@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Paramjit Oberoi <psoberoi@google.com>
2022-08-19 19:35:05 +00:00
Clarissa Garvey
926d0063d8 base/src: Migrate Unix Tube to use StreamChannel
This CL migrates Tube from directly using a UnixSeqpacket to instead use
a StreamChannel backed by UnixSeqpackets. This CL also migrates users of
the old Tube::new(UnixSeqpacket) function to its renamed counterpart.
Tests are added for new functionality.

This CL enforces that the StreamChannel used by the Tube is backed by a
UnixSeqpacket because the reading and writing behavior of a UnixStream
is different, and it cannot guarantee the same multi-process
concurrent-writers behavior that a UnixSeqpacket can. This is because
the UnixStream does not send data as packets and the size cannot be
queried, so two underlyig writes are required for each Tube write: one
to send a header indicating message size, and one for the actual content
of the sent data. These can be interleaved during concurrent writes,
causing corruption of the Tube's data.

This CL makes the Windows and Unix API closer to each other, with some
differences remaining or added, including Tube::new_from_unix_seqpacket
existing in Unix but necessarily not Windows.

This migration (Tube from UnixSeqpacket to Stream) is intended to move
the Unix Tube API closer to the Windows API, with the eventual goal of
creating a platform-agnostic API for Tube.

Bug: b:231641496
Change-Id: I2422e76b7efa5a20bc40a8d194f5f8390dc71438
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3818253
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: Clarissa Garvey <clarissagarvey@chromium.org>
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
2022-08-15 23:15:12 +00:00
Clarissa Garvey
92acafb14c base/src: Prepare Unix StreamChannel for Tube use
This CL is one of two CLs in a series that migrate the Unix Tube from
using UnixSeqpackets directly to instead use StreamChannels backed by
UnixSeqpackets. This CL adds some pass-through functions to
StreamChannel that are needed by Tube in the follow-up CL, as well as
a new function to create a StreamChannel directly from a UnixSeqpacket.
Additionally, a test is added for the new constructor-like function.

This migration (Tube from UnixSeqpacket to Stream) is intended to move
the Unix Tube API closer to the Windows API, with the eventual goal of
creating a platform-agnostic API for Tube.

Bug: b:231641496
Change-Id: I8d7da6a0e64d38d8f9833ae8e62ec7a2c4cfda5c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3818249
Tested-by: Clarissa Garvey <clarissagarvey@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-08-15 23:15:12 +00:00
Frederick Mayle
878318b80a base: use tempfile in syslog_file test
The test isn't unix specific anymore, so we ought to move it to
base/src/syslog.rs, however, when moved, it fails with an "Illegal Seek"
error when run in the presubmit (but not in `cargo test`). The cause is
unclear.

BUG=b:228881485
TEST=./tools/dev_container ./tools/presubmit

Change-Id: I76e6595007a3b59f6bbd5a4afae42f911686f3e3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3817974
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Frederick Mayle <fmayle@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-08 21:41:50 +00:00
Clarissa Garvey
61a46f7275 base/src: Add tests to Unix Tube
This CL adds tests for Unix Tube: a test for the platform-specific
Tube::new function, and a serialization/deserialization test that
existed previously in Windows and now is shared between platforms.

Bug: b:231641496
Change-Id: Iabbc15f847b995affd0bfd5b304fd70d34b171b5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3794509
Tested-by: Clarissa Garvey <clarissagarvey@chromium.org>
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-08-04 20:49:01 +00:00
Vikram Auradkar
ea807a07a6 devices: Enable net device on windows
This introduces slirp support. On windows, net is enabled only if slirp
is enabled.

BUG=b:213149155
TEST=presubmit

Change-Id: I77f0121ab4545350345c4f42f67b51186279c44c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3787269
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-08-04 17:01:01 +00:00
Daniel Verkamp
a00ad77d21 devices: cmos: use chrono crate to get time
We already depend on chrono elsewhere, so we might as well use it rather
than rolling our own unsafe wrapper around gmtime_r.

BUG=None
TEST=tools/presubmit --all

Change-Id: I46e4a75ca74f8a02875814f6cb21031db58e1e3a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3795009
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-08-03 18:19:31 +00:00
Frederick Mayle
b59b108930 base: syslog: Fix android build
bionic (the android libc) doesn't have shm_open or shm_unlink.

TEST=presubmit
BUG=b:228881485

Change-Id: Ic0df86387a1110835b1e53a68d249fa3d55803ab
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3803896
Reviewed-by: Devin Moore <devinmoore@google.com>
Auto-Submit: Frederick Mayle <fmayle@google.com>
Tested-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-08-02 18:30:40 +00:00
Daniel Verkamp
600ad38ff8 Remove redundant {self} imports
- Remove trailing ::{self} on all use statements
- Remove any resulting single-level use statements (e.g. use libc;)
- Reformat with `tools/fmt --nightly`

BUG=b:239937122
TEST=tools/dev_container tools/presubmit --all

Change-Id: I8afd1b0458ca6d08d9b41a24583f7d4148597ccb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3798973
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-08-01 21:27:54 +00:00
Clarissa Garvey
00be3d5180 base/src: Add Unix StreamChannel Message test
Prior to this CL, the StreamChannel in base/src/sys/unix had no tests
for FramingMode::Message. This CL adds a test for that framing mode.

Bug: b:231641496
Change-Id: I75e13709d558258eca838c3190aaf0237e39513b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3793688
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
Tested-by: Clarissa Garvey <clarissagarvey@chromium.org>
2022-08-01 19:01:44 +00:00
David Manouchehri
4b3db6786c base: Allow memory to be merged with KSM on Linux.
By default, KSM is disabled by the kernel. This is harmless if KSM
is disabled, and only causes merging if the user manually enabled
the feature on their kernel. If enabled, significant memory saving
can occur, at the cost of CPU cycles and a reduction in privacy.

Bug: 1346340
Change-Id: I838cdda97ea8d335b1953dd6775311958069898c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3780870
Reviewed-by: David Manouchehri <david@davidmanouchehri.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-08-01 18:04:43 +00:00
Vikram Auradkar
5e4ce1db39 base: RecvTube impl ReadNotifier
Closing one of the deltas in base crate.

BUG=b:213146388
TEST=presubmit

Change-Id: Ibac36d1ad9b1b6387ec74e8b59ccb38319903655
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3793691
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-07-29 17:49:31 +00:00
Dennis Kempin
4fea399df9 Reformat imports
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.

Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.

BUG=b:239937122
TEST=CQ

Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-28 00:15:50 +00:00