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>
... 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>