Commit graph

215 commits

Author SHA1 Message Date
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
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
7cbf4ac45a vmm_vhost: SET_DEVICE_STATE support
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>
2024-08-08 23:04:11 +00:00
Daniel Verkamp
5d028abd1c Ensure all packed structs are also repr(C)
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>
2024-08-05 17:59:28 +00:00
Frederick Mayle
b87c6eb0ee vmm_vhost: don't require files in recv_reply_with_files
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>
2024-07-24 02:04:36 +00:00
Frederick Mayle
fcf9a630e9 devices: vhost-user: align sleep/wake implementation with spec
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>
2024-07-17 01:00:11 +00:00
Alyssa Ross
34605332ed vhost_user: ignore unknown features from backend
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>
2024-07-16 04:08:29 +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
d1c8d49249 vmm_vhost: fix clippy::option_map_or_err_ok
.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>
2024-06-10 19:50:12 +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
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
18134c7283 devices: vhost-user: forbid packed virtqueues temporarily
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>
2024-03-27 02:50:13 +00:00
Daniel Verkamp
4e55a26ac9 vmm_vhost: remove leftover upstream config files
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>
2024-03-19 18:01:28 +00:00
Frederick Mayle
a53111b3a2 vmm_vhost: misc master/slave -> frontend/backend renaming
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>
2024-03-18 21:44:24 +00:00
Frederick Mayle
c4561c03b5 vmm_vhost: rename Master/SlaveReq -> Frontend/BackendReq
Bug: 233830719
Change-Id: If12e55b9ec9af4903f15fffe1ad48ddb150e52c8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5378014
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-03-18 21:15:56 +00:00
Frederick Mayle
ea572e18a9 vmm_vhost: simplify FrontendServer setup
Change-Id: I460d9a195df37cc0c757708cbe1588d85d8f854a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5369235
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-03-15 23:17:49 +00:00
Frederick Mayle
fc6b451f50 vmm_vhost: rename MasterReqHandler -> FrontendServer
Bug: 233830719
Change-Id: I87b1f4091957578d498d7536da3ae3be79970eac
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5373171
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-03-15 18:55:09 +00:00
Frederick Mayle
c15835df6b vmm_vhost: rename VhostUserMasterReqHandler -> Frontend
Bug: 233830719
Change-Id: I37ea260af7b22c59dbe45d55549c55e92849b726
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5373170
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-03-15 18:55:04 +00:00
Frederick Mayle
771969389b vmm_vhost: rename Slave -> FrontendClient
Bug: 233830719
Change-Id: If953a0eb266ec6f16d2687da3e1db58d3eea965b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5373169
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-03-15 18:54:58 +00:00
Frederick Mayle
18debe587f vmm_vhost: rename DummySlaveReqHandler -> TestBackend
Bug: 233830719
Change-Id: I7c1376e39ebaa2a9a33e8fb2a525272fc15efb40
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5373168
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-03-15 18:54:53 +00:00
Frederick Mayle
e4e322cbb2 vmm_vhost: rename SlaveReqHandler -> BackendServer
Bug: 233830719
Change-Id: I90fa12a2a157db16eabbb88757f2eb46c3e5c7cd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5373167
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-03-15 18:54:48 +00:00
Frederick Mayle
c3fe07493b vmm_vhost: rename VhostUserSlaveReqHandler -> Backend
Bug: 233830719
Change-Id: Ic2018f7d88ddaf18fcc0c59fdd01ec0b7dc40c4b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5373166
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-03-15 18:54:42 +00:00
Frederick Mayle
582ff93937 vmm_vhost: rename Master -> BackendClient
Bug: 233830719
Change-Id: I15473cc1feb435dc7af0de273c6060037cdf82d5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5373165
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-03-15 18:54:37 +00:00
Frederick Mayle
ba7bb48daf vmm_vhost: delete VhostUserFSSlaveMsg deadcode
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>
2024-03-14 23:13:00 +00:00
Daniel Verkamp
6fcc508f99 vmm_vhost: combine all sys modules into one
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>
2024-03-14 22:47:27 +00:00
Frederick Mayle
51b3e0367e vmm_vhost: delete non-standard FS_* message type support (unused)
Change-Id: I51278e0a0063d99795b97984b4a09b3aff59c824
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5372631
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-03-14 21:21:03 +00:00
Frederick Mayle
82557b0828 vmm_vhost: merge SlaveReqHelper into SlaveReqHandler
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>
2024-03-14 20:57:07 +00:00
Frederick Mayle
e428c4ba88 vmm_vhost: choose new ids for the non-standard messages types
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>
2024-03-14 20:30:47 +00:00
Daniel Verkamp
742791deef tree-wide: replace data_model::zerocopy_from_*()
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>
2024-03-13 18:03:24 +00:00
Kaiyi Li
c28067d1d9 Reformat comments
Test: presubmit
Change-Id: I39c261d9985989873b698213c5d8b653fc13757b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5299850
Auto-Submit: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-02-15 23:30:13 +00:00
Idan Raiter
fc7afc43b5 vmm_vhost: Support external mappings
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>
2024-02-08 20:54:45 +00:00
Rob Clark
2f9fe25b9c rutabaga_gfx: Query cachability from minigbm
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>
2024-02-01 21:34:17 +00:00
Idan Raiter
b21b7d650b vmm_vhost: Check for errors on vhost-user WAKE
Add analog of https://crrev.com/c/5247322 for WAKE.

BUG=b:300501737
TEST=snapshotted downstream and resumed

Change-Id: I4567867e14b9eb045c46df8394bb564a8eb2b800
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5252007
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Idan Raiter <idanr@google.com>
2024-01-31 21:47:22 +00:00
Idan Raiter
48d18bb1f5 vmm_vhost: Check for errors on vhost-user SLEEP
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>
2024-01-31 20:50:35 +00:00
Daniel Verkamp
fe82628b0b vmm_vhost: fix reply hdr size in FS_MAP tests
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>
2023-12-15 19:39:24 +00:00
Daniel Verkamp
2f83b50899 vmm_vhost: replace unsafe with AsBytes usage
Change-Id: I49eb66cebba5d3b948fdc64d00c725ecd17ff85e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5124496
Commit-Queue: Frederick Mayle <fmayle@google.com>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-12-15 01:35:09 +00:00
Daniel Verkamp
9ef0e3fd38 vmm_vhost: fix VhostUserMsgHeader debug struct name
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>
2023-12-15 01:28:42 +00:00
Daniel Verkamp
6eb32df285 vmm_vhost: replace Option<Vec<File>> with Vec<File>
Change-Id: I42c27d016d2e09c81964421b47dfc4ddf6f2b448
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5121281
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-12-14 23:35:51 +00:00
Daniel Verkamp
5ed7528ef9 vmm_vhost: replace socket/Tube tests with Connection tests
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>
2023-12-14 23:35:51 +00:00
Vikram Auradkar
2768f223ee clippy: enforce safety block comments
BUG=b:316174930
TEST=none

Change-Id: I5c7811b2c548155aa003e4b71a54bbc16e2f2588
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5120567
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-12-14 18:21:54 +00:00
Daniel Verkamp
2a417a0b1b vmm_vhost: change Connection send API to send_message()
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>
2023-12-06 20:37:20 +00:00
Daniel Verkamp
a0aad9eb0f base: unix: return Vec<SafeDecriptor> from recv_with_fds()
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>
2023-12-01 02:11:32 +00:00
Daniel Verkamp
aec2b91fa3 base: unix: rework ScmSocket send/recv functions
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>
2023-12-01 01:11:48 +00:00
Frederick Mayle
7166a22943 vmm_vhost: eliminate locking in SlaveReqHandler and merge traits
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>
2023-11-30 23:42:32 +00:00
Frederick Mayle
c9c8daa8b1 vmm_vhost: simplify Slave
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>
2023-11-30 23:42:32 +00:00
Frederick Mayle
1ff6199db8 vmm_vhost: eliminate locking in MasterReqHandler and merge traits
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>
2023-11-30 23:42:32 +00:00
Frederick Mayle
2db5f6e4c0 vmm_vhost: remove type parameter from PlatformConnection
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>
2023-11-29 19:11:59 +00:00
Frederick Mayle
e71368498f vmm_vhost: simplify backend request connection creation
The connection type is no longer polymorphic, so there is no need to
thread the file descriptors through an existing connection instance.

The SAFETY comment isn't very satifying, but at least it is closer to
the code that makes the assumption now.

Change-Id: I2b040c2d56c17bddec856fa91da15b9b8cdd62eb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5069045
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-11-29 18:51:27 +00:00
Dennis Kempin
73aed77b49 Run rustfmt on whole codebase with nightly enabled
Nigthly is enabled as part of https://crrev.com/c/4950268
This change contains the formatting changes resulting from the switch.

BUG=b:302055317
TEST=dev_container presubmit format --no-delta

Change-Id: Idaf2b8bae2e09c624b19d9cd3dd5fc8e4d099b3c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5067088
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-11-29 18:41:29 +00:00
Frederick Mayle
862d4709c9 vmm_vhost: rename Endpoint to Connection
Change-Id: If7e8a845a50d09c5ee2bdfe1e807121d835b1431
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5068400
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-11-29 00:02:34 +00:00