Commit graph

503 commits

Author SHA1 Message Date
Daniel Verkamp
fbb8137c0a Windows clippy fixes for Rust 1.81
Add the minimal allow(dead_code) and feature declarations to allow the
clippy checks to pass for Windows with Rust 1.81.

BUG=b:365852007
TEST=tools/presubmit clippy_mingw64

Change-Id: I9ab776b07d8e9e14fe380d9b5ef1fa332788ff63
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6013080
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-11-13 00:07:11 +00:00
Jason Macnak
9bd5e72cdf rutabaga_gfx: Make fence state snapshot-able with serde json
... by serializing/deserializing the map as a series of kv pairs
to avoid `key must be a string` errors with JSON.

Bug: b/369615058
Test: cvd start --enable_virtiofs=false
Test: cvd snapshot_take --snapshot_path=/tmp/snapshot1
Test: cvd create --snapshot_path=/tmp/snapshot1
Change-Id: I037e8e3659b52fa2983712425381431a0bebab87
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5917178
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2024-10-25 20:20:17 +00:00
Jiyong Park
0d73150cfe Add --name option to the run command
It is used to optionally set the name of the VM. It can be useful when
there are multiple crosvm processes running and we want to distinguish
them. This is especially a must in Android which uses process name for
the resource attribution purpose.

BUG=b/375094126
TEST=tools/dev_container tools/presubmit

Change-Id: Id4af3b8f2b216ad3239a4467a0c30a4630d44a73
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5955889
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jiyong Park <jiyong@google.com>
2024-10-24 01:37:48 +00:00
Keiichi Watanabe
6327cc1cae base: Add call_with_extended_max_files()
Add a utility function `base::call_with_extended_max_files()` that executes
a given callback with extended file counts and restore the original file limit.

This utility will be used by the following CL for pmem-ext2.

BUG=b:329359333
TEST=presubmit

Change-Id: Id85781e4e4cd5542d4da630eb48779947b098490
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5872164
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2024-09-19 01:22:11 +00:00
Keiichi Watanabe
56ada36fc0 base: Make max_open_files() return both soft and hard limits
Make base::max_open_files() return the rlimit64 struct intead of
its rlim_max field.
This will be helpful when changing the soft limit in the following
CL.

BUG=b:329359333
TEST=presubmit

Change-Id: I2738c325f4f1ed19ae021e0b8a50a6a1592c5592
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5872162
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-09-19 01:22:00 +00:00
Daniel Verkamp
d6976ef66b Fix byte_char_slices clippy warnings
BUG=b:365852007

Change-Id: I18bfdcc077cc871ea98e9d6deed5514a6e7d2aa5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5852613
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-09-17 19:49:53 +00:00
Yuan Yao
6547cd1661 vmm_host: Make VhostUserStream blocking
The VhostUserStream is set to non_blocking before running handler now.
However, the VhostUserStream is created from connection sockets, so it
does not call accept and handle error. This CL removes the line setting
VhostUserSteam to non_blocking.

Also, this CL fixes several incorrect comments.

BUG=b:365458565
TEST=run manual test

Change-Id: I7803fc4c277559f98be4f0bd93b2bb77564ef93c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5838947
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
2024-09-11 02:02:51 +00:00
Daniel Verkamp
c2ebaa19e4 Fix bad indentation in Markdown around lists
Some doc comments were being incorrectly interpreted due to missing
indentation (for intentional line contintuations) or line breaks (for
new lines that were intended to be separate paragraphs).

Clippy warns about these as of Rust 1.80:
<https://rust-lang.github.io/rust-clippy/master/index.html#/doc_lazy_continuation>

Fix them along with some other nearby minor formatting cleanups.

TEST=tools/cargo-doc
TEST=tools/clippy # with rust-toolchain 1.80

Change-Id: Ice0b7cc3bd75d9ab08c10107a13f95ca9f87a0a3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5758934
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-09-10 02:05:59 +00:00
Daniel Verkamp
9329c55dca base: impl Write for VolatileSlice
Add an implementation of std::io::Write for VolatileSlice that mirrors
the standard slice Write implementation:
<https://doc.rust-lang.org/std/primitive.slice.html#impl-Write-for-%26mut+%5Bu8%5D>

This allows more ergonomic writing to guest memory.

Change-Id: I4bfc84920d33c379b9986ffc0232e5787613e93a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5842392
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-09-09 21:40:46 +00:00
Frederick Mayle
80536f4aaf base: periodic_logger: fix bad timer usage
Waiting on a `WaitContext` isn't enough, the timer must be ack'd. I
suspect this code has only been used on Windows, where the ack
technically isn't needed.

Change-Id: Ia53714a4f94f83310decf45888c9314e4631da5a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825224
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-03 18:16:19 +00:00
Yuan Yao
c32a063c84 vmm_host: support creating VhostUserStream from socket fd
The vhost-user backend currently supports socket creation solely from
UDS paths. To accommodate scenarios requiring the passing of connected
sockets via file descriptors, this change introduces the VhostUserStream
structure implementing VhostUserConnection. The VhostUserStream
constructs directly from a raw file descriptor, dup fd and establishing
a UnixStream for communication.

This change adds a 'fd' option to the vhost-user-fs backend device. This
allows the vhost-user socket to be created either by providing a UDS
path (using the 'socket' option) or by using a raw file descriptor
(using the new 'fd' option).

TEST=tools/dev_container tools/presubmit
BUG=b:361212225

Change-Id: I4912f697b5b9d24c7b0b2281a113047831c844df
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5796596
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
2024-09-03 10:53:02 +00:00
Frederick Mayle
72deb6d840 base: linux: fix Timer::mark_waited deadlock
If `mark_waited` was called in an event loop to ack the timer, but
another thread was concurrently disabling the timer, then a deadlock
could occur. Despite the code being written as if the timer is in
NONBLOCK mode and even stating it in the implementation, it seems as if
that has never been the case.

Change-Id: I75b80a2ab7a5b13f2c48035199aa18313012419a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825218
Reviewed-by: David Dai <davidai@google.com>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-08-29 16:13:05 +00:00
Frederick Mayle
28c3524b9b base: enable the timer unit tests
Instead of checking for an error range of elapsed time, just make sure
the lower bound was reached. No code using this should be written
expecting a tight upper bound.

Change-Id: Iffb31bf4c621a3dd91b7904d096dc92713be76c6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825217
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-08-29 15:59:32 +00:00
Jiyong Park
5465236314 Let UnixSeqpacketListener convert into OwnedFd
BUG=b:243500154
TEST=tools/dev_container tools/presubmit

Change-Id: Ibb8502eccd9b43f3b7d4339ad5672cf9029e28b0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5796023
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Andrew Walbran <qwandor@google.com>
2024-08-21 15:47:40 +00:00
Keiichi Watanabe
c7a790d1cf base: tube: unix: Add methods to send/recieve 32+ FDs
On Unix, Tube::send()/recv() limits the numbers of FDs that can
be sent to avoid additional memory allocation CMSG buffers.

We add new methods Tube::{send,recv}_with_num_fds() to allow
sending/receiving more FDs by specifying the number.

BUG=b:329359333
TEST=CQ

Change-Id: I1a919afb0e98725f9315fdd6717efb060b313044
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5675764
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-08-09 06:02:04 +00:00
Frederick Mayle
c9628cf0da base: windows: named_pipes: implement std::io::Read EOF correctly
std::io::Read should return Ok(0) on EOF so that callers can read all of
the data of a variable length stream.

The fix is implemented in PipeConnection::read_internal, so it will
affect more than just the std::io::Read users of Pipe and likely cause
some breakages, but we decided that making them inconsistent would be
too confusing.

I also added a test for std::io::Write, but didn't not change its
behavior. The stdlib docs aren't clear if there are similar expectations
for writes and methods like write_all ought to work as expected with the
currently implementation.

BUG=b:301269927

Change-Id: I808993cdad722a4e95b28800e5681035f254e637
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5768033
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-08-08 23:01:13 +00:00
David Dai
8932366b94 Allow users to specify custom cpu frequencies for vCPUs
Add an option to allow users to specify custom cpu frequencies
rather than obtaining frequencies from the host. This is
useful for emulating cores that have different performance
points from the host.

Bug=b:284367589
Test: tools/presubmit
Change-Id: I9508a7b20d6d2db16babb9e43d912fd891f41b2e
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5709094
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-07-24 17:19:04 +00:00
Frederick Mayle
8b54fe99b8 base: fix missing import on musl builds
Change-Id: Ia7035dbd807bc7c2ab5323d698e6a25d270b1e79
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5698366
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Frederick Mayle <fmayle@google.com>
2024-07-12 15:33:04 +00:00
Daniel Verkamp
dc310d7cb6 Replace ::max_value() with ::MAX
The max_value() function is considered to be a "legacy numeric constant"
now, and future clippy versions will warn about it:

<https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants>

BUG=None
TEST=tools/clippy # with rust-toolchain = "1.79"

Change-Id: I72a333dc4aa1f48cf71744c848f050097a7e7f55
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5690374
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-07-09 23:26:03 +00:00
Dennis Kempin
33d5aa219a Enable clippy for android code
This change enables clippy builds of android specific code.

Doing so without adding the full Android SDK into our container
is a bit hacky. The CL https://crrev.com/c/5671653 adds env variables
to the minijail build.rs to allow us to skip building the library, and
generate bindings for linux instead of android.

This allow us to build all non-gpu related features of the
android build. It will not link, but it will run clippy.

This CL fixes various clippy issues that come up in this new
configuration

BUG=b:349907813
TEST=tools/clippy -p android
TEST=tools/presubmit clippy_android

Change-Id: I1f51d383051bbeeeff55d716feb7b56c3e24588b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5672567
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2024-07-09 20:43:44 +00:00
Daniel Verkamp
9269aee61f devices: vhost-user: use safe SharedMemory to SafeDescriptor conversion
Replace an unsafe block with the equivalent safe From<SharedMemory> for
SafeDescriptor implementation.

This was also the only use of IntoRawDescriptor for SharedMemory, so it
can be removed.

BUG=b:242953353
TEST=tools/dev_container tools/presubmit

Change-Id: I9004b3d9b1b20f5c22dcbfdc6ea1fb9fdc4b419b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5669342
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-07-03 17:40:03 +00:00
Daniel Verkamp
64841ed4dc base: simplify SharedMemory::try_clone()
Use the SafeDescriptor try_clone() function rather than reimplementing
it in a roundabout way.

BUG=b:242953353
TEST=tools/dev_container tools/presubmit

Change-Id: Ic75ba06073eb964706b32701f0ed0184a6148bcf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5671239
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-07-03 17:34:07 +00:00
Daniel Verkamp
43ff80a026 base: windows: pass &File to set_sparse_file()
This is only ever called with a File, so replace the AsRawDescriptor
parameter to simplify it and prevent accidentally calling it with the
wrong type (as mentioned by the comment, it must be a File anyway).

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: I08a87211f74983caeabe812448be4984e6f68cea
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5666315
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-07-01 17:27:19 +00:00
David Dai
9d47f021d3 linux: mod: Use u64 when normalizing capacity
For systems where CPU frequencies can exceed 4GHz(linux reports
frequency in khz, but muliplying it by SCHED_SCALE_CAPACITY or 1024 can
overflow u32). Use u64 to calculate normalized capacities instead.

BUG=b:348152361
TEST=tools/presubmit
Change-Id: Ica4ea2ea0dd15d2917d28581a929ead4a5681d2f
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5664534
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-06-27 20:17:22 +00:00
Daniel Verkamp
4f7b7de714 base: remove get_filesystem_type()
This was used in a single informational log statement when opening a
disk image, which was added for debugging an issue and is no longer
needed. It was also only ever implemented for Linux and not other
platforms.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: Id77244a883b6bb4b90ee1a909fa305ab4193c17e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5656451
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-25 22:24:10 +00:00
Daniel Verkamp
b06d296a1b base: define ioctls as consts rather than functions
For ioctl numbers that do not require any parameters, make ioctl_io_nr
and related macros generate a constant rather than a function with no
parameters. This makes the code that uses these constants more idiomatic
and also allows using the constants in match statements (see an example
in virtio/fs/passthrough.rs).

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: Id52817528d770c5dbbe2ce7928c9f31a15c83d83
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5648647
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-25 19:17:21 +00:00
Daniel Verkamp
e38524847d Windows clippy fixes for Rust 1.77
BUG=b:344974550
TEST=tools/presubmit clippy_mingw64

Change-Id: I1a4c8a59cb0618ed40ebe04129be359dfee5c5e4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5627831
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-13 01:07:13 +00:00
Daniel Verkamp
df8168ad25 Remove unused pub re-exports
Fixes new clippy warnings about dead code.

BUG=b:344974550
TEST=tools/clippy

Change-Id: If5dc935542db3f39e918845b5864c46dad4a902c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5604661
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-10 19:39:54 +00:00
Frederick Mayle
7ec3293ab4 base_tokio: tokio compatible Event and Tube types
BUG=b:338274203

Change-Id: I6fbce1386c2c086d7a53a706018d959f4fadfada
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507771
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-06-06 23:30:20 +00:00
Daniel Verkamp
75a3c8ab2e base: fix clippy::multiple_bound_locations lint
Merge the `where` clause bounds into the ones in the generic type
definitions. This is also more consistent with the other functions in
this file.

BUG=b:344974550
TEST=tools/clippy

Change-Id: Ie4d33ae0c204dab6279607aa0b181768b42c75eb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5599145
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-06 17:38:46 +00:00
Daniel Verkamp
7599eeddbb base: move fork_process to jail crate
This API directly depends on Minijail, so it does not make sense for it
to be in the base crate that should be cross platform. Move it into the
jail crate, which already wraps other Linux-specific Minijail
functionality.

If we need to add a fork API that works on all unix platforms (including
non-Linux), that could be re-added in base, but for now, this is only
needed for Linux.

This removes the `base` crate's dependency on minijail, as well as the
special case test harness (which is moved to `jail` instead).

Change-Id: Iabefff03ab18222b71b82571bd815d5f028236c8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5556681
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-05-22 21:21:59 +00:00
Daniel Verkamp
52b8e42869 Cargo.toml: avoid "*" versions for external crates
Ensure that every Cargo.toml dependency on a third-party crates.io crate
specifies at least a major version, or a minor version for 0.x crates,
to ensure that if a new major version is published, it cannot cause API
breaks.

The versions are selected to match the ones already in Cargo.lock, so
this should have no functional change, but it will help prevent new "*"
versions from being introduced via copy-and-paste.

For rationale, see the Cargo FAQ:
<https://doc.rust-lang.org/cargo/faq.html#can-libraries-use--as-a-version-for-their-dependencies>

`minijail`, `audio_streams`, and `cras` are left as "*" for now, since
they have unusual situations (imported from a submodule and/or replaced
at build time with ebuild magic).

BUG=None
TEST=tools/dev_container tools/presubmit
TEST=verify Cargo.lock is unchanged

Change-Id: Ifa18199f812f01d2d10bfb4146b3353c1a76527c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5555656
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-22 01:01:42 +00:00
Hung Nguyen
070a316a8b devices: pmem: Add new virtual swap options
The new options will allow a virtio-pmem to be created based on an
anonymous memory mapping, and can be paged out at the specified
interval. The created virtio-pmem device can be used as a swap area in
the guest, where the guest swapped out memory will be paged out to the
host swap area.

Design doc: go/arcvm-virtual-swap-impl

BUG=b:329310285
TEST=./tools/dev_container ./tools/presubmit
TEST=tested seccomp policy with armv7-unknown-linux-gnueabihf and
aarch64-unknown-linux-gnu targets running on 32 bit (hana) and 64 bit
(kukui) ARM devices
TEST=crosvm run with new pmem options

Change-Id: Icd261bf94ba9c8168b9274b8e56fe352f153b9e6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5529961
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Hung Nguyen <hungmn@google.com>
2024-05-17 17:45:43 +00:00
Frederick Mayle
bd32973373 base: windows: expose Tube's ReadNotifier and CloseNotifier Events
Those traits use RawDescriptor, which isn't useable directly in Windows
and so the users have to assume it is an Event undernearth and coerce it
back, usually using `EventAsync::clone_raw_without_reset`.

BUG=b:338274203

Change-Id: I2fbaa38e58cbd1ee154078f8d74e33c4dc61f0b9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5539776
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-16 16:49:05 +00:00
Frederick Mayle
1503bd5640 base: linux: event: handle EINTR and short reads/writes
I haven't seen these happen in practice, but the code was technically
wrong, as pointed out in
https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507771/comment/5f1d7aff_5419cde5/

BUG=b:338274203

Change-Id: I3449abe47fb4679c37e0eb3f41bca8c32546b4d0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5537837
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-15 19:34:21 +00:00
Frederick Mayle
784ed62943 base: move cros_async's WaitForHandle into base
This functionality will also be used by a pure Tokio library for crosvm.

The API is now a single async function and is named to match the
underlying Windows API. The unit tests have been rewritten to not
require an async executor and should have a bit more test coverage.

BUG=b:338274203

Change-Id: Iff65ca088c74ce5c5ce396fdf7dcd9f1550ea545
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5536313
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-05-14 17:34:54 +00:00
Shalini Sengupta
6b26ac8f4b base: Add serialize/deserialize for Descriptor.
Valid use case for base::Descriptor lists 'You need to serialize a
['RawDescriptor'].

BUG=b:337051928
TEST=tested downstream


Change-Id: Iaf27c4b5ed99c59d6e5d83b11ff76fe858e5c0d7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5511662
Reviewed-by: Idan Raiter <idanr@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Shalini Sengupta <shalinisen@google.com>
2024-05-07 23:07:39 +00:00
Daniel Verkamp
92665a611f Cargo.toml: move tempfile to dev-dependencies
The tempfile crate is only used in tests, so it does not need to be in
the main [dependencies] section of any of our first-party crates.

Also fix a couple of [dev_dependencies] instances to the officially
documented [dev-dependencies] name for consistency.

BUG=None
TEST=cargo tree

Change-Id: I1dcb6be10c302baec4e8ebe6f72480f76e4e3760
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5521511
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-07 20:00:48 +00:00
Frederick Mayle
44a84f4360 base: windows: support Sync usage of StreamChannel
I want the async tube types to be `Sync` and they wrap `StreamChannel`
(via `Tube`). It is important for async types to be `Sync` so that they
can be freely used in spawned futures.

BUG=b:338274203

Change-Id: I76d7ff1f4001a7aa71ace929dc5b4c9f25acad0b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507772
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-05-02 19:32:36 +00:00
Frederick Mayle
f909e42679 base: don't require &mut for File{Sync,Allocate} methods
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: I7db283cb946508daf8fd7bd8cf9397aa7f97a478
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507757
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-02 19:32:26 +00:00
Frederick Mayle
5381cc2b66 base: don't require &mut for WriteZeroesAt methods
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: Iff684f5a25b0f488b006e05eebe913f92f404a2b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507756
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-02 19:32:21 +00:00
Frederick Mayle
8515568a51 base: don't require &mut for FileReadWriteAtVolatile methods
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: I810b537e971bf007b6b34f0cbc605f2b3943a763
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507754
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-05-02 19:32:17 +00:00
Frederick Mayle
1cbaa32809 base: delete PunchHoleMut trait
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: I995cf646a66909b9b146b9a7c0ff7d5a8348acd7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507755
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-02 19:32:09 +00:00
David Dai
a4ddf90735 Revert "aarch64: Use cpu_capacity to determine clustering instead"
This reverts commit b7e72de084.

Reason for revert: It turns out some devices intentionally flattens out their cpu-map topology to improve scheduling behavior. Revert back to using package id to determine clustering info.

Original change's description:
> aarch64: Use cpu_capacity to determine clustering instead
>
> Some systems do not populate cpu-map information and
> use other ways of grouping CPUs in a frequency/topology
> domain instead. Use normalized cpu_capacity information
> to determine clustering instead.
>
> BUG=b:326170473
> Test=./tools/presubmit
> Change-Id: If4ba7d224338798fcf2c0ffbaa91547dc2f2e16d
> Signed-off-by: David Dai <davidai@google.com>
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5319790
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>

Bug: b:335130218
Change-Id: I1a601e65a79aacb68c1244127420b2e395f12d5d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5467699
Commit-Queue: David Dai <davidai@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-04-25 16:22:01 +00:00
A. Cody Schuffelen
706b28b357 base: Separate TimerTrait::reset into 2 functions
See prior comment thread:

https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5454793/6..9//COMMIT_MSG#b12

`TimerTrait::reset` offers a very similar API to the `timerfd_settime`
system call, but in practice is almost used to set either a one-shot
timer, or a repeating timer with an initial timeout the same as the
repeating timeout.

`kqueue`'s timer functionality only supports the cases that are actually
used in practice. This change aligns the API with the way it is used,
and makes the distinction between the behavior of the arguments more
obvious.

Test: tools/presubmit
Test: cargo test -p base timer -- --ignored
Bug: 335486579
Change-Id: I1873ab9cccaf7a4b988431839964b1c253f76a34
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5463100
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-04-18 09:23:31 +00:00
Cody Schuffelen
1846ca7ec0 base: Implement base::TimerTrait on MacOS
This has two outstanding issues:

- `timerfd`'s timer repeats only after a delay, while kqueue either
  starts a one-shot timer or a repeating timer.
- `clock_getres` seems overly optimistic. It claims microsecond
  precision, while I've seen `timer::tests::one_shot` and
  `timer::tests::one_shot_cloned` return too late by up to 5
  milliseconds. Therefore these tests still fail.

`kevent64_s` is used to give larger values in the `data` field, making
it safer to always use nanosecond precision in the kqueue timer. (Using
coarser precisions doesn't seem to help the tests pass anyway.)

Test: `cargo test -p base timer -- --ignored` (still fails)
Bug: b/309020556
Change-Id: I789a0fb853b083c0466016d5a3338479dabd8b08
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5454793
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-04-16 23:34:00 +00:00
Cody Schuffelen
f1fbbc811e base: Separate macos kqueue code into its own file
Bug: b/309020556
Test: cargo test -p base
Change-Id: I7e4063e3f293f85da0abe2627ea156601ed26240
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5454792
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-04-16 23:03:14 +00:00
Frederick Mayle
128e591037 base: fix musl build
musl doesn't appear to provide _SC_LEVEL1_DCACHE_LINESIZE, neither in
its C headers nor in the `libc` crate.

BUG=b:332584046
TEST=built in AOSP against musl target

Change-Id: I3c79435ff43f85a64e55dd86d231ab3d61522214
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5455211
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
2024-04-15 22:56:58 +00:00
David Stevens
d4d9fad2ee base: Round up when calculating cache flush count
When dividing target length by the cache line size, round up to make
sure we flush the entire target region.

BUG=b:316402315
TEST=tast run asurada arc.Boot.vm

Change-Id: I66938bb51e1ce58f17e4bb28ec7b8f1e14a4fc6d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5437515
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2024-04-09 05:51:42 +00:00
David Stevens
c552254625 metrics: Remove MetricsRequest from vendor API
Instead of deserializing from the metrics tube in the generic
MetricsController code, we can directly pass the readable tube to the
vendor RequestHandler implementation. This allows us to shrink the size
of the vendor metrics API by removing RequestHandler.

This change also makes MetricsController use RecvTubes instead of Tubes.

BUG=b:332466813
TEST=./tools/dev_container ./tools/presubmit all

Change-Id: Ia1507d5e1c0cdd346d165c968184e9d2bd70314e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5400362
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-04-09 01:43:33 +00:00