create_pair() and create_client_pair() can be implemented in a
platform-independent way now.
Change-Id: I294b504a9875417c9f12ddaed448746d81aa4dfb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5876620
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
The vmm_vhost::Connection type is now used consistently to represent a
vhost-user connection in the places that previously used a SystemStream
(which is either UnixStream or Tube depending on the platform).
This cleans up the vmm_vhost public API and also keeps more of the
internal vhost-user implementation encapsulated inside the vmm_vhost
library.
The conversion to Connection for unix has also been improved to
propagate the error via TryFrom instead of From, resolving a TODO
comment.
Change-Id: Ib02d300a04304242f7be7e1661c0213c25c7a4f1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5874103
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@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>
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>
This replaces the custom SNAPSHOT/RESTORE vhost-user extensions with the
new SET_DEVICE_STATE_FD and CHECK_DEVICE_STATE vhost-user methods.
For now, we keep the custom message types around as a fallback to allow
for a smoother migration for non-crosvm users (there is only one I know
of, so it shouldn't take long).
BUG=b:301269927
Change-Id: Ib3d1d232fdfc92e605c372e778e78d84395704fe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5735713
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Using #[repr(packed)] alone does not guarantee that the struct fields
will stay in the specified order, and as of a change in Rust 1.80, the
compiler will actually reorder such structs in practice in some cases:
<https://github.com/rust-lang/rust/pull/125360/>
Add "C" to all structs that were previously #[repr(packed)] alone, since
these are all trying to match an externally-defined layout where order
matters. None of these would get reordered in practice today, even with
the Rust 1.80 change, but this ensures they will always stay consistent.
Change-Id: I397fd0bd531a34e0f1726afb830bcd7fcc6a2f05
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5758933
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
All of the callers check the number of files and error appropriately
already. Later, I'm going to add a new message type where the FD in the
reply is optional and this check would cause issues.
BUG=b:301269927
Change-Id: I22366134edb0680caea2566f3c49cf8b9b522c38
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5735712
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Takaya Saeki <takayas@chromium.org>
See the diffs in snapshot_extensions.md for an overview of the changes.
Originally, crosvm's virtio and vhost-user frameworks diverged in their
snapshot-restore implementations. Virtio devices returned ownership of
their queues back to VirtioPciDevice, but vhost-user devices kept
ownership in the backend process. Replacing SLEEP with GET_VRING_BASE
has a side effect of bringing the two into alignment. If you look at
this commit in isolation, you might wonder why we ever went with the
other approach. The reason is that there were a large number of misc
bugs and code organization issue in the way that have been fixed since,
for example, it wasn't possible to restart the vhost-user frontend
worker to rewire the IPC for interrupts, instead we rewired them inside
the backend. Another example: the frontend and backend were not
correctly communicating the current vring base to each other, they
always passed zero.
There is no vhost-user feature bit to indicate if the backend supports
the "suspended device state", so, for devices without support, we no
longer can fail when putting the device to sleep. Instead, we only fail
when we try to snapshot or restore.
Bug: 301269927
Change-Id: I5aaac864e36a2dffe078d7c8f8abff29365a02c0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5394172
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
virtiofsd 1.11.0 added support for VHOST_USER_PROTOCOL_F_DEVICE_STATE.
Upgrading virtiofsd meant that the latest released version of Cloud
Hypervisor (39.0) was no longer able to communicate with it, because
rather than just ignoring the unsupported feature, it got an
unrecoverable "invalid message" error. This demonstrates that it's
better for frontends to just ignore offers of unsupported features.
If the backend requires some feature, it'll get a chance to know that
when we send VHOST_USER_SET_PROTOCOL_FEATURES anyway.
Signed-off-by: Alyssa Ross <hi@alyssa.is>
(cherry picked from upstream commit 7554d06ff4dbf3c4d7e5c6ac7cb02f83387eac27)
[crosvm exhibits the same problem as Cloud Hypervisor.]
Change-Id: I85c14c4205afaa2763d4505476abbcb4436536a5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5708608
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@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>
.map_or(..., Ok) can be replaced with the simpler .ok_or(...)
BUG=b:344974550
TEST=tools/clippy
Change-Id: I6bd50845e06b228e3c16a29fa15af1b1f5ffb68a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5609072
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
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 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>
VHOST_USER_SET_VRING_BASE and VHOST_USER_GET_VRING_BASE have different
request/response formats if packed queues have been negotiated and we
don't support that yet. Forbid it for now in the vhost-user frontend and
backend to keep people from tripping on it.
Bug: 331466964
Change-Id: I7a064ab0d4677cec465baa444c308c84d87e00b2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5397650
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
The .cargo/config file enables a workaround for a problem we don't have,
and the .github and .buildkite configs aren't necessary for us either.
Change-Id: Idf816ac8ad4a90bbc37c4cdd1e759590a29ae33e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5372380
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
This covers everything remaining in the `devices` and `vmm_vhost` crates
that are easy to find with grep.
BUG=b:233830719
Change-Id: I47a741ef9d54ff19213ded45b207b71777ac4ef1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5378015
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
The VhostUserMsgValidator impl for VhostUserShmemMapMsg was using the
wrong flags struct. It was technically OK because they were identical.
Change-Id: Ie99aca48efd85f443e905599d16f0e22e515de5e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5372375
Auto-Submit: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
vmm_vhost has sys modules out the wazoo. Flatten them into a single sys.
Change-Id: If5d8720947ce0f4aea0afa244360ac4b9256d33a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5372374
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
SlaveReqHelper was basically just a set of private methods for
SlaveReqHandler. The methods and fields are moved into SlaveReqHandler
without any real code changes.
Change-Id: I250f030a9613e655babaf9dc16855f0447e88b36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5372626
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Backend message ID 42 has been taken by VHOST_USER_SET_DEVICE_STATE_FD
and frontend message ID 6 has been taken by
VHOST_USER_BACKEND_SHARED_OBJECT_ADD.
Using large numbers to avoid future conflicts.
The only known user of the sleep/wake/snapshot/restore message types
outside of the crosvm repo is in AOSP and it can be updated as part of
the next crosvm merge. Usage of the other's is less clear.
BUG=b:301269927
Change-Id: I4ba272563117b65a3dd9aa4e936f164e863cafbc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5369109
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Use zerocopy functions directly instead. This is a step toward replacing
our data_model crate with standard crates.io functionality where
possible.
BUG=b:312312646
TEST=tools/dev_container tools/presubmit
Change-Id: I9717edce6fe2b4ca53ad9043db61de2e9bc55b78
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5046345
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
In this chain we will add support for running the GPU vhost-user backend
in single-process mode. This means external mappings from Gfxstream will
need to be able to pass through the vhost-user protocol. This change
mirrors the addition of GPU_MAP when we needed Vulkan mappings.
In any other configuration this likely cannot be used because the
pointer here needs to be in the context of the VMM.
BUG=b:323416803
TEST=run GPU downstream
Change-Id: I686bc0d3e07c478e707c225abc10264cf0bbca2e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5263218
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Idan Raiter <idanr@google.com>
Drop the hack hard-coding cachability based on driver name, and replace
with querying from minigbm. This allows other drivers to use cached
minigbm/gralloc allocated buffers in cases where it is beneficial (such
as with sw encoders)
BUG=b:239718180, b:306548532
TEST=cts-tradefed run cts -m CtsVideoTestCases -t android.video.cts.VideoEncoderDecoderTest#testAvcGoog0Perf0320x0240
no artifact in Camera FOV Calibration of CtsVerifier on rex
Change-Id: I854e2f00b993310716f64a3c568ed8c6f2665469
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3780218
Reviewed-by: Dawn Han <dawnhan@google.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chia-I Wu <olv@google.com>
If a device fails to sleep we never handle it and continue snapshotting.
This causes a corrupt snapshot to be made with silent failure on boot.
I noticed this for the vhost-user GPU, whenever there is a failure to
recover the queue, this failure was not preventing the snapshot.
BUG=b:300501737
TEST=snapshotted downstream and checked error prevents snapshot
Change-Id: I7573805c37ba9bb66495ff2f256e706a33907361
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5247322
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Idan Raiter <idanr@google.com>
The stubbed-out VhostUserMsgHeader for the FS_MAP reply was specifying a
length of 256 bytes (VhostUserFSSlaveMsg), but the reply actually only
contains 8 bytes (u64). This didn't matter previously because the
Connection::recv_message() code ignored the header's size field, but
this will change in an upcoming commit. Without this fix, the recv would
hang waiting for the additional data that would never come.
BUG=None
TEST=(cd third_party/vmm_vhost; cargo test)
Change-Id: I54df0af9ae88d8bea9fb815a433ff4fc96f2d4d8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5124497
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This seems to have been copy-pasted from somewhere else without changing
the debug_struct() argument.
Change-Id: I5bb57eca4ec18d808bc2b8dced224f4bbd098a0f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5124495
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
This makes it possible to share the same tests between platforms instead
of having two near-duplicate sets of tests to update for each API
change.
Additionally, the tests now exercise the message-oriented APIs that are
actually used in the vhost-user handler, rather than the test-only
send_slice() and recv_into_buf() APIs, which can be removed.
Change-Id: I8242f99fd8eda3907b8de744634d81477ebb858d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5121280
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Make the connection API provide a send_message() API instead of
send_iovec(). This moves the responsibility for ensuring all data of a
message is sent into the platform-specific code (SocketConnection and
TubeConnection), which can now use different approaches.
The send_iovec_all() function is moved into the socket code, and the
socket implementation of send_message() now sends all of the data in a
single sendmsg() call. This is acceptable now, since the
Windows-specific requirement for splitting the header and data into
separate sends does not apply to the unix-only socket code.
The tube code now relies on the Tube::send() function to ensure all data
is delivered, removing the send_iovec_all() retry loop from Windows
entirely.
BUG=b:273574299
Change-Id: I9652e4ee3e95bb9ecf700dac93b0d5b806469ab2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5075018
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Handle the Vec allocation and resizing internally in ScmSocket instead
of making each caller deal with it.
This also prevents file descriptor leaks since the fds are immediately
wrapped in SafeDescriptor, which will close them if dropped, rather than
the previous API which used un-owned RawDescriptors.
Change-Id: Icb44bd744ea18bbdfc63f816b4b992f320a36823
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5075016
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
The send and recv functions are renamed and refactored to provide
consistent API:
- send_with_fds()/recv_with_fds() accept plain non-iovec &[u8]/&mut[u8]
- send_vectored_with_fds()/recv_vectored_with_fds() accept iovecs
AsIobufs is implemented for &[IoSlice], so a separate `_bufs` entry
point is not needed.
The `with_fd` (singular) function was only used in one place, in a unit
test, which can be adjusted to call `with_fds` instead.
As a semi-related cleanup, raw_sendmsg() and raw_recvmsg() now take
&[iovec] directly rather than AsIobuf, which matches the raw libc API
more closely and avoids the need for the functions to be generic.
Change-Id: Id4ed18d96a01c6622b2c7bc459e95cb2fa499069
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5075015
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
No implementors used `VhostUserSlaveReqHandler` directly, so it is
merged with `VhostUserSlaveReqHandlerMut`. The locking would have been
moved into `SlaveReqHandler`, however, the handler only processes one
request at a time, so no locking is actually necessary.
Change-Id: Iaa8896b09d2d1eb393c2eed794c295183cc5e099
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5076928
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Now that the trait methods accept `&mut self`, there is no need for an
internal mutex.
Change-Id: Idb626317100e9d5ec421a114d6c93a74c3c7ba54
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5076927
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Only `Slave` implemented `VhostUserMasterReqHandler` direcly and it was
internally using a mutex to guard everything just as done by
`VhostUserMasterReqHandlerMut` implicitly. To simplify things, the trait
now only supports `&mut self` methods and users of the trait need to add
a mutex themselves as needed.
There are two users of `VhostUserMasterReqHandler`:
1. `VhostBackendReqConnection`: Uses an `Arc` for memory management and
so does need the lock to get a `&mut`. Added a `Mutex` directly to
it (effectively at the same level of granularity as before).
2. `MasterReqHandler`: Already has a `&mut` (it can only process one
request at a time) and so doesn't need a lock.
`Slave` no longer needs a lock internally. That will be cleaned up in a
separate CL.
Change-Id: Icf8edd40087b68e7d2b55a0569ffde1afde6bfcf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5076926
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
It only handles bytes and FDs now.
Change-Id: Ie28ee94c04d9fcd34b9803581ff0e0f087555fce
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5073072
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>