Commit graph

2971 commits

Author SHA1 Message Date
Daniel Verkamp
96afbc3dd6 vmm_vhost: replace SystemStream with Connection in pub API
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>
2024-09-19 21:19:33 +00:00
Richard Zhang
adb8234a12 Revert "gpu: Add parameter for a custom cursor file"
This reverts commit 2744e5fef6.

Reason for revert: This cmd line param is no longer being used

BUG=b:364906315

Original change's description:
> gpu: Add parameter for a custom cursor file
>
> This will be used to display a custom mouse cursor for Surfaces. This CL
> won't change any functionality
>
> BUG=b:362814745
> TEST=builds and presubmits
>
> Change-Id: If4e5a41bdaa92fecf680aa09fe8e2ca154946d07
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825087
> Reviewed-by: Noah Gold <nkgold@google.com>
> Commit-Queue: Richard Zhang <rizhang@google.com>
> Reviewed-by: Pujun Lun <lunpujun@google.com>

Bug: b:362814745
Change-Id: Ib975f92e96e3adb07e1fa27d1a5e6c870e76881a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5876365
Commit-Queue: Richard Zhang <rizhang@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-09-19 19:20:09 +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
934322f32e devices: vhost-user: remove keep_rds from VhostUserListener::new()
Most callers don't want this functionality, and the ones that do can
easily handle it themselves.

Change-Id: I93cf7fe0237428256b10ff72e87cfd888d5fdd1d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5871724
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-09-18 19:39:24 +00:00
Daniel Verkamp
126a2818d2 devices: vhost-user: unify VhostUserListener constructors
The VhostUserListener new() and new_socket() are identical; replace all
of them with new(). The "socket" name was left over from the VVU
cleanup; in the current code, VhostUserListener always listens on a unix
domain socket.

Change-Id: I51b1beeb1c17431e08708e70dc252b78c77e747d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5871723
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-09-18 19:39:18 +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
Daniel Verkamp
bd52961574 devices: virtio_gpu: simplify remove_displays()
Iterate over the Vec of display_ids directly, rather than converting
them into a BTreeSet first, and use a regular `for` loop rather than
`try_for_each()`.

Additionally, the `scanouts.get_mut()` looked up the scanout once, then
the `scanouts.remove()` looked it up again; `remove()` returns the
removed item, so the `get_mut()` lookup can be avoided entirely.

Also avoids a clippy manual_inspect lint in Rust 1.81.

BUG=b:365852007

Change-Id: If0bf16c0d886315a8d81bcb072ff873dd132e062
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5852612
Reviewed-by: Jason Macnak <natsu@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-09-11 21:19:23 +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
Frederick Mayle
5921c375cc disk: add option to disable file locking
The recent changes to make crosvm lock nested disk files is running
afoul of Android Virtualization Framework's SELinux policies. The file
locking doesn't add much value in that environement because all the
shared files are read-only, so add an opt-out for locking to buy us time
to re-engineer the policies.

BUG=b:330911976

Change-Id: I0b35732978e946a2331507d6061729d53955a8d3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5849284
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-10 22:07:48 +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
Frederick Mayle
6cde4e3b9e disk: consolidate disk file opening logic
The disk crate is now responsible for opening the file and handling
options like OVERLAPPED and O_DIRECT.

O_DIRECT is now applied to all nested disk files. For now, OVERLAPPED
contiues to only apply to the root disk file.

BUG=b:330911976
BUG=b:190435784

Change-Id: Ib46a965c0589bf1c1e8e4ae5f0c81747530eff98
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5842394
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:39:03 +00:00
Frederick Mayle
6b965beb80 disk: use flock on nested disk files
flock is called on the root disk file to make sure nothing is
concurrently modifying a disk (which would appear to the guest as disk
corruption). This CL extends that functionality to all of the nested
files of composite and qcow2 disks.

BUG=b:330911976

Change-Id: I4489222943c3530255ffc52aba5a11aa4bc82f9a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5840920
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:37:08 +00:00
Frederick Mayle
2b9ea3f859 disk: pass more disk options to nested DiskFiles
No behavior difference intended. This is prep work to treat nested
DiskFiles consistently, e.g. using flock for them.

BUG=b:330911976

Change-Id: Id887ca21a9d5d186ba4dc77280c1ce4bfec8b319
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5840918
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:29:41 +00:00
Dorinda Bassey
5204e5db2d virtio-gpu: Respect offset parameter in TransferToHost2d command
Modify Transfer3D::new_2d to accept an offset argument, ensuring
it is correctly initialized.
This change ensures the offset is no longer ignored during 2D
transfers to the host, hence it addresses potential issues
that could arise with data transfer alignment.

Change-Id: I83a7436e825e1fa6e44fb46d921dd84a799baa93
Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/5785895
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
(cherry picked from commit a3ec3b77dbcfa44defd91775c6ecfc5af605d42c)

Reason for cherry-pick: CL was initially merged to `chromeos` branch by
mistake; never made it to `main` branch.

BUG=None
Test=builds

Change-Id: Ic7f720e59c6f43b3477e891f6da91acc23cde0fb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5838083
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-09-05 21:40:07 +00:00
Frederick Mayle
b94ed073cd devices: serial: windows: fix bad timer usage
Waiting on a `WaitContext` isn't enough, the timer must be ack'd. This
technically isn't needed on Windows, but that is an implementaiton
detail and also people often copy existing usages of APIs and might not
realize this detail.

Change-Id: Ic29151b4871bebacd14c19c6dcb9e35779175c79
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825225
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-03 18:19:23 +00:00
Frederick Mayle
2f813de683 devices: vmwdt: fix potential timer deadlock
Use the `mark_waited` method (non-blocking) instead of `wait`
(blocking).

It is technically possible for a vCPU thread to disable a timer after it
has fired but before the worker successfully calls `wait`. In that case,
the worker would get stuck and be unable process timer events for other
vCPUs and also would be unable to shutdown. I haven't seen this happen
in practice.

Change-Id: I49e18ba525392a08f5dc1e22181876cf6a013173
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825223
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Sebastian Ene <sebastianene@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2024-09-03 18:16:13 +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
Yuan Yao
7810ca8faf vmm_host: rename VhostUserListenerTrait to VhostUserConnectionTrait
CL chromium:5796596 introduces a new mechanism for providing a
vhost-user backend device from a socket file descriptor. This approach
enables the socket to be pre-connected before it is passed.

This CL renames the VhostUserListener trait to VhostUserConnectionTrait
for greater generality supporting chromium:5796596.

BUG=b:361212225
TEST=cargo build

Change-Id: I16baaa7d321d4f617b8663c88544ed87280b39bf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5803224
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
2024-09-03 10:50:15 +00:00
Richard Zhang
2744e5fef6 gpu: Add parameter for a custom cursor file
This will be used to display a custom mouse cursor for Surfaces. This CL
won't change any functionality

BUG=b:362814745
TEST=builds and presubmits

Change-Id: If4e5a41bdaa92fecf680aa09fe8e2ca154946d07
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825087
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
Reviewed-by: Pujun Lun <lunpujun@google.com>
2024-08-30 18:17:58 +00:00
Daniel Verkamp
8cc63c4219 devices: virtio: make Queue track its own Interrupt
When constructing a Queue from a QueueConfig, require the caller to pass
the corresponding Interrupt, and remove the &Interrupt argument from the
Queue::trigger_interrupt() function. This prevents mismatches of Queue
and Interrupt, especially in the case of a re-activation after a reset
where the old and new Interrupt are not the same.

BUG=b:360926085

Change-Id: I31ad9704d4963e46f7ce1b7b7a43aec1a92e342d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5798666
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-08-23 01:23:11 +00:00
Daniel Verkamp
24c97b0596 devices: virtio-console: consume self in WorkerHandle::stop()
Clean up the unnecessary Option<> wrapping the worker thread.

Resolves review comments from https://crrev.com/c/5798107 - no
functional change intended.

Change-Id: Iee3ca099a923da23fe48f10e8a33261180479c85
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5801012
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-21 01:23:44 +00:00
Daniel Verkamp
93180de38a devices: virtio-console: restore port outputs when stopping worker
The WorkerPort takes ownership of the output stream when it is created
in WorkerPort::from_console_port(), so if we stop the worker, we need to
restore the output stream to its original location in ConsolePort.

BUG=b:360926085

Change-Id: I1af5c6edfffc31d620895edb1627e01b9ddf8afe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5801010
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
2024-08-20 23:43:04 +00:00
Daniel Verkamp
6aee3efa60 devices: virtio-console: stop worker thread on reset
After stopping all queues in the worker thread, also stop the worker
thread itself so that the Interrupt it contains is dropped.

Previously, the worker thread would hold onto the old (no longer used)
Interrupt instance, even when a new Interrupt was provided by the next
call to activate(). With the change, the worker thread with the old
Interrupt will be cleaned up so the next activate() will cause
ensure_worker_started() to be called again and create a new worker with
the new Interrupt.

BUG=b:360926085

Fixes: 2e277ed5bb ("devices: virtio-console: refactor and consolidate")
Change-Id: Ib57bbb768ab4c211b7e6f408f2c75beee8f08bd8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5798107
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-20 20:48:14 +00:00
Keiichi Watanabe
759a86e3fd devices: fs: Cosmetic change for the order of cast and bitwise operation
Follow-up of the comment of https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5740485/comment/4043e33d_785f0b63/.
Casting before bitwise operation looks a bit safer.

No functional change.

BUG=none
TEST=CQ

Change-Id: I30e1fcff87e21ee3bec5ebc115715074793db329
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5772144
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2024-08-19 08:25:08 +00:00
Daniel Verkamp
914d1b2894 devices: vhost-user frontend: factor out vring stop code
The repeated logic for stopping queues in reset() and virtio_sleep() is
moved into a function so it can be shared.

Change-Id: Ifbab9840293530540d8008b1a677342089e9f393
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5793968
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-16 22:18:22 +00:00
Daniel Verkamp
8a1dfbe1be devices: vhost-user: remove bool from enter_suspended_state return
Require vhost-user backends that implement VhostUserDevice to have a
functional enter_suspended_state() now that all of our devices implement
it.

Also drop the suspended flag in DeviceRequestHandler, since the state of
the device can be derived from the state of the queues.

Change-Id: I8642fdb16c09e18ef0ac3a5da523a71d8fe17b37
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5792080
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-16 22:18:09 +00:00
Daniel Verkamp
4ea9cfb9f6 devices: vhost-user: require VhostUserDevice enter_suspended_state
All device backends should implement this.

The only two missing devices (fs and wl) can trivially implement it,
since they have no worker threads aside from the per-queue workers.

Change-Id: Ic7b9f649ff68502212e7f7fd5004f3a05ee0849e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5792079
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
2024-08-16 18:08:45 +00:00
Daniel Verkamp
6716333617 devices: vhost-user: require VhostUserDevice snapshot functions
Add implementations of snapshot/restore to the two vhost-user device
backends that did not have them yet (fs and wl) - these just return an
error for now, but this allows removing the default implementation
from the VhostUserDevice trait so newly-added devices can't forget to
implement them.

Change-Id: I1137e0b394e7ee51cd46d0b2177625da6cb9d489
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5792078
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-16 18:07:53 +00:00
Daniel Verkamp
b6a3b35a0b devices: proxy: log device name in errors
This makes it possible to distinguish between the many ProxyDevice
instances.

Previously, the error message did not include the device name:

  child device process failed recv: [err]

The new message looks like this:

  recv from pcivirtio-console child device process failed: [err]

Change-Id: Ica12de1f3b9927d04a0f7de6177d014949ccca28
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5785310
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-16 18:00:23 +00:00
Daniel Verkamp
31eda0ce99 devices: vhost-user-console: add snapshot/restore
Change-Id: I065f333f4187d58bb01b6f74d1ed0341265f449c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5784333
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-15 17:36:14 +00:00
Daniel Verkamp
2e277ed5bb devices: virtio-console: refactor and consolidate
This replaces the console backend for the virtio and vhost-user console
devices with a shared implementation.

There is one main worker thread per console device, which handles all
virtio queues for that device, and one thread per port to read from the
input source in a blocking fashion.

BUG=b:354677018
BUG=b:298289666

Change-Id: I376180e26497ed6391a9f49b7d9a5c4d5aafa64f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5739275
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-08-14 19:59:44 +00:00
Daniel Verkamp
3de11f75fb devices: vhost-user: give snapshot an exclusive reference
This allows reusing the same snapshot function as virtio devices, which
provides &mut self.

BUG=b:347782866

Change-Id: I130605d3629253ea4037ebf4e9560ed96be53c19
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5784112
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-12 19:50:03 +00:00
Daniel Verkamp
f4ff2b63cf devices: vhost-user: prefix debug_name with vu-*
The vhost-user device frontend was using the default virtio-* name,
which made it easy to confuse with a normal virtio device.

In particular, the snapshot file name uses debug_name() to name the
file, so previously the snapshot for e.g. a vhost-user console device
would be named "pcivirtio-console-0". After this change, a vhost-user
console's snapshot file will be named "pcivu-console-0" instead.

Change-Id: I2d7235af5173877b95152d79b7372c80c3bb64d1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5784414
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-12 19:29:22 +00:00
Frederick Mayle
4c04d710f3 devices: vhost: user: error in default snapshot/restore methods
Our vhost-user framework now requires opt-in elsewhere for each device,
they need to implement `enter_suspended_state` and advertise the
DEVICE_STATE vhost-user protocol feature, so this change is unlikely to
break anything.

Change-Id: If0848803b57cb77a2748fa4b0ef9a92d2f7f6ce7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5784110
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-08-12 18:10:28 +00:00
Daniel Verkamp
b6f2582cfc devices: vhost-user: snapshot as serde_json::Value
This makes the vhost-user device backend implementations more similar to
the virtio device backends.

The snapshot format is entirely a backend-specific implementation
detail, so this does not affect vhost-user compatibility with other
devices or frontends.

BUG=b:347782866

Change-Id: I14f6407b4f7c5246b08f5cab85493c65caa2dee2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5777254
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-08-12 17:47:12 +00:00
Daniel Verkamp
56bea5a2f3 devices: virtio-input: handle event source hangups
If the event source descriptor gets a hangup event (for example, for an
input device connected to a socket event source that becomes
disconnected), the input device should stop polling it. Otherwise, the
WaitContext::wait() call in the v_input thread will continually return
the is_hungup event, causing that thread to busy loop forever.

This change removes the input event source from the WaitContext and logs
a warning message in this case. This means there will be no further
input events, but the guest should continue to run normally, and the
input thread will not waste CPU time.

BUG=b:358246547

Change-Id: I3c6f05d072eb60aee531deac14e65bf54c6d6783
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5770547
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-09 20:04:23 +00:00
Daniel Verkamp
d77e50fb56 devices: virtio-input: use Rust String type for names
It isn't necessary to convert the names into bytes until the last
moment, and this operation is cheap, since String has a zero-cost
conversion into a byte slice. This simplifies the device setup code.

This also fixes incorrect strings for input devices using the evdev
event source, which previously contained a trailing NUL byte; the virtio
input spec requires that strings do not include a NUL terminator.

Change-Id: I054cc117828e6db989cabbc5890a8aceb09ac26a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5772331
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-09 20:02:54 +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
Frederick Mayle
bf1615f840 devices: vhost: user: add snapshot/restore to unit test
BUG=b:301269927

Change-Id: I9859d1e38cf236a85e55034f21dc1a0a97b7678d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5766739
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-08-08 23:01:19 +00:00
Yuan Yao
f247406733 device: fs: add security_ctx option
To support FUSE_SECURITY_CONTEXT feature, the virtio-fs needs to write
security context passed by guest to /proc/thread-self/attr/fscreate.
This write operation may be invalid for some hosts. If the write
operation failed, guest can not create files/directories in shared
directory.

This CL adds a security_ctx option to virtio-fs. If the option is set
to false, virtio-fs will not enable the FUSE_SECURITY_CONTEXT feature.
The default value is false.

BUG=b:357774649
TEST=run virtio-fs in cuttlefish. Verify file creation in guest
successes.

Change-Id: I51ce965df948c217ab86a6604931c438cd5ee13e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5768058
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
2024-08-08 01:51:53 +00:00
Daniel Verkamp
fa716e0173 devices: virtio-wl: remove duplicated cfg check
Fixes a clippy warning in Rust 1.80.

Change-Id: I662fa02935e38e04c3d5de2118623a27bbc0198b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5763716
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-08-07 16:06:13 +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
Yuan Yao
54e5b6b204 device: vhost_user: Enable seccomp filter vhost-user-fs
Vhost-user-fs currently lacks seccomp filter support, which cause
security concerns to put into real usage. This change introduces
virtio-fs device's seccomp policy filter to vhost-user-fs when sandbox
is enabled.

When specified path of socket does not exist for vhost-user device, the
vhost-user device will call socketpair to create a socket. To support
the syscall, the rule allowing socketpair is added to vhost_user.policy.

Also, this CL adds disable-sandbox option for vhost-user-fs-device. The option
is set to false by default, the vhost-user-fs will enter new
mnt/user/pid/net namespace. If the this option is true, the
vhost-user-fs device only create a new mount namespace.

BUG=b:355159487
TEST=run manual tests
TEST=run e2e test in chromium:5746575

Change-Id: I6c18386f690af7b0d2e1550c0b3881d444280a8b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5741356
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
2024-08-05 10:22:57 +00:00
Keiichi Watanabe
1ff9a40984 devices: fs: Clear O_APPEND for file creation when writeback=true
When writeback is enabled, O_APPEND handling is done in kernel so
crosvm's virtiofs device needs to clear the flag when opening a
file. Otherwise, a file may be corrupted because pwrite() ignores
offset for FD with O_APPEND.

This case is already handled in passthrough.rs by update_open_flags(),
but it hasn't covered the case of `create` and `atomic_open` requests.
We should call update_open_flags() to clear O_APPEND for those cases.

In addition, this CL adds tests for checking flags of an FD opened
with atomic_open.

BUG=b:321254986
TEST=download videos and validate the contents

Change-Id: I404b15bf925731141610f5929693117ea2957d72
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5740485
Reviewed-by: Yuan Yao <yuanyaogoog@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2024-08-01 06:07:23 +00:00
Yuan Yao
3f8df5a95d device: fs: add unit tests for FS_IOC_SETPATHXATTR ioctl
Add unit tests for FS_IOC_SETPATHXATTR ioctl. Validate handling of valid
and invalid input data. Also, test the path matching and xattr setting
logic.

BUG=b:333641954
TEST=cargo test --package devices --lib -- virtio::fs::passthrough::tests

Change-Id: I753b02fae9e457a02e774f35752d87df0000a693
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5737596
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2024-07-29 06:07:27 +00:00
Yuan Yao
3e52105f8b device: fs: add unit tests for FS_IOC_SETPERMISSION ioctl
Add unit tests for FS_IOC_SETPERMISSION ioctl. Validate handling of
valid and invalid input data. Also, test the path matching and
permission setting logic.

BUG=b:333641954
TEST=cargo test --package devices --lib -- virtio::fs::passthrough::tests

Change-Id: Id6f462ab8fcb7b683adddc22363afec84429bfdf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5730457
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2024-07-29 02:19:53 +00:00
Frederick Mayle
8983a9f0e7 devices: vhost: vsock: implement reset
Some guests try to reset the device when entering a suspended state.

BUG=b:353650093

Change-Id: I9bff40889b9619a4bae13f1405c27b6e8ede2ae3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5742395
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-07-26 17:19:18 +00:00
Elie Kheirallah
99685eec8e devices: vmwdt: change functions to return Results
There were lots of unwraps in the code. Change the functions to return
results and return errors when possible. Otherwise, expect instead.

BUG=N/A
TEST=presubmit

Change-Id: I218aabefc30e40185eb6855117e85f1ff8bac09a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5704476
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-07-25 17:42:16 +00:00
Elie Kheirallah
4743e88d35 devices: vmwdt: add snapshot/restore support
Add snapshot/restore support to vmwdt
Keep track of timer state, if the timer was armed with oneshot mode or
repeating mode, repeating cycle, remaining time, next time interval.
Restore the timer with the correct mode and time.

BUG=b:274145255
TEST=Tested on Pixel Fold. Built virtualizationservice apex and
installed on device. Test was done using Microdroid. Tested by invoking
crosvm located in the virtualizationservice apex. Commands: crosvm
suspend --full SOCKET && crosvm snapshot take PATH SOCKET && crosvm
resume --full SOCKET.

Change-Id: I57385e72d8b7fe7393624d265bb2bed834eeffb9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5619450
Auto-Submit: Elie Kheirallah <khei@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-07-25 01:07:03 +00:00
Elie Kheirallah
1bae5dbf6b devices: Vmwdt: get vcpu pid/tid mapping from VM
Vmwdt is getting the pid/tid of vCPUs whenever a write happens. Instead,
get the Vcpu PID/TID on VM startup.

BUG=b:274145255
TEST=presubmit

Change-Id: I4f41dd20b807b320b6202d36061b18d4c9aa77df
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5703919
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-07-25 00:38:15 +00:00