Commit graph

1911 commits

Author SHA1 Message Date
Alexandre Courbot
5286194102 virtio: video: allow dead code in the utils module
The utils module contains code commonly used by backends, but not
necessarily used by all. This can lead to compiler warnings about unused
code depending on which backends are compiled in. Silence them by
allowing dead code in that module only.

BUG=None
TEST=`cargo build --features "video-decoder,video-encoder,libvda"` does
not emit any warning.

Change-Id: Ia5cb28f84a2367f450c69eb505347cc4a0d95ba1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3960215
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-10-19 17:50:20 +00:00
Idan Raiter
cbf1e0c61b devices: stop resetting ReadNotifiers in vhost user
Upstreaming a fix from nkgold@ for the following issue:

ReadNotifiers shouldn't ever be reset as their state is managed by the
type that exposed the notifier (e.g. StreamChannel). Resetting it can
lead to lose notifications. idanr@ discovered that EventAsync::clone_raw
was creating a regular EventAsync (e.g. with reset), and it was being
used with read notifiers. This CL replaces clone_raw with a new factory
that produces `without_reset` EventAsyncs.

BUG=b:253255209
TEST=presubmit, downstream

Change-Id: I0b9de2f12cc3597ba05a8ac108f4cd0a8e726b3f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3960857
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Idan Raiter <idanr@google.com>
2022-10-19 17:13:15 +00:00
Koki Ryu
16da55f236 Add --net option to the crosvm run command
Currently, --tap-name, --tap-name, --host-ip...etc commands are all used
to create a vhost-user net device. This CL unifies the command line arguments.

BUG=b:246224081
TEST=run the following tests:
- `cargo test -p devices virtio::net::tests`
- `cargo test -p net_util`

Change-Id: Ie1342f23f0951e5a81e54547bf725c0d9be19f97
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3893869
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Koki Ryu <kokiryu@chromium.org>
2022-10-19 02:18:27 +00:00
Pujun Lun
b849ebd0e1 crosvm: GPU and display arg parsing for Windows.
This replaces the handwritten arg parser with the serde_keyvalue
based parser. Eventually we will unify the arg parsing with Unix.

BUG=b:233676779
TEST=cargo b --features all-msvc64,gpu --no-default-features
TEST=cargo t -p vm_control --features all-msvc64,gpu
     --no-default-features
TEST=cargo t -p crosvm sys::windows::config::
     --features all-msvc64,gpu --no-default-features

Change-Id: I36a563be9767c7e5cbd3ab44f6a9ba23cd64cdb6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3939033
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-10-18 05:17:53 +00:00
Gurchetan Singh
9142190652 rutabaga_gfx: allow running context types without 3D component
It's not necessary to build 3D rendering support to run the
cross-domain context type.

Default implementations are added for some hypercalls, since
the guest kernel may still think it's running a KMS display.
That adds log-spam if errors are present.

BUG=b:173630595
TEST=Run weston terminal in the guest

Change-Id: I8155cf9d9867a329927b7dd4bb22c385510966a2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3961536
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2022-10-18 01:54:59 +00:00
Noah Gold
cb55cd0394 tracing: rename tracing to cros_tracing.
`tracing` conflicts with a crates.io crate. Since we may support tokio
tracing in the future, and want to submit some benchmarks against it
right now, we should rename our crate.

BUG=b:253517247
TEST=presubmit

Change-Id: I32bf64a7ce1830e881bd582e4606932782df65c6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3957598
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-10-17 20:49:16 +00:00
Pujun Lun
fad7b68139 devices: generate EDID for disabled displays.
As we always report the maximum number of displays (16), the kernel
would issue VIRTIO_GPU_CMD_GET_EDID for all displays even if they
are marked as not enabled. However, VirtioGpu::get_edid() would
return an error if the display is not enabled.

We could report some default EDID for disabled displays. Also
noticed that EdidBytes has 2 impl blocks, which doesn't seem
necessary, so they are merged now.

BUG=b:253482501
TEST=tested in Windows downstream

Change-Id: I666961fe33a6143b9d022049abf05be4ec757a8d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3957536
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-17 16:23:45 +00:00
Alexandre Courbot
ab613b56a1 video: decoder: vda: use wrapping multiplication for timestamp
When decoding using libvda, the frame timestamp is truncated to 32-bits
and needs to be restored to its original value. This is done by doing a
multiplication with the truncation factor. However, if libvda gives us
an invalid timestamp, the multiplication can overflow and cause the
video device process to panic. Avoid this by switching to a wrapping
multiplication - the passed timestamp will still be invalid, but the
decoder device will signal an error instead of crashing.

BUG=None
TEST=cargo build --features "video-decoder,libvda"

Change-Id: Iabe683a997e0e9dea8c2bea53ef520f53868e590
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3958881
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-10-17 04:31:17 +00:00
Dennis Kempin
5a32a2d198 Enable vaapi feature upstream
The feature can be built but not tested without access to an intel
GPU.
To enable the build, the testvm and dev container are updated to
include libva.

BUG=b:244619376
TEST=presubmit

Change-Id: Ia8c4dc46ccbcd244bf57441f2c550a6b73c67b1c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3946027
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-10-14 20:31:19 +00:00
Idan Raiter
28de38563d devices: vhost-user: GPU features fix and handle tasks like other devices
- Spawn detached tasks with an AbortHandle like other devices.

- Bug fix: without calling queue.ack_features at the beginning of
  start_queue, VIRTIO_RING_F_EVENT_IDX causes a hang.

BUG=b:243061269
TEST=presubmit, downstream

Change-Id: I03eba1c60a541cf7862feb434fc9fc1064319629
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3950853
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Idan Raiter <idanr@google.com>
2022-10-14 19:36:09 +00:00
Jason Macnak
f4d2214077 devices: gpu: Add DPI to display parameters
... and include this information in the EDID blob.

BUG=b:163864461
TEST=cargo build
TEST=Android build
TEST=launch Cuttlefish with various DPIs and inspect
     `adb shell dumpsys SurfaceFlinger`

Change-Id: I3f9ca0283f335d51063bf8e555ff2ffa7ead104b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3954473
Reviewed-by: Pujun Lun <lunpujun@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-10-14 18:04:48 +00:00
Ryuichiro Chiba
f202332893 devices: virtio: Fix the vhost worker to set actual queue size to the vhost device
Vhost worker uses the maximum queue size the host offers when setting a
queue size to the vhost device, which leads inappropriate behavior when
a guest preapares a virtqueue whose size is smaller than the maximum
size.
Fix the vhost worker to set the actual queue size to the vhost device.

BUG=b:235857465
TEST=`cargo build`
TEST=`./tools/run_tests`
TEST=host and guest can communicate via vhost-vsock

Change-Id: I99af745788c347ca2770b979252f8ea8dde34462
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3946422
Commit-Queue: Ryuichiro Chiba <chibar@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Takaya Saeki <takayas@chromium.org>
2022-10-13 01:40:38 +00:00
Pujun Lun
3b2ecd9570 gpu: a few fixes for Windows build.
1. gpu_control_tube is not used on Windows yet. We will make use of
   it and test it in the downstream first before removing the Unix
   feature flag.
2. In Gpu::keep_rds(), skip appending descriptors of stdout and
   stderr since it is hard to find such descriptors on Windows, and
   this function won't be called on Windows anyways.
3. Some functions in gpu_display should be guarded with gfxstream
   feature flag, since we don't need to link against gfxstream
   binary when we are building/tesing without gfxstream.

BUG=b:213149288
TEST=presubmit

Change-Id: I28c3d16d82916e6d4a542aa008dd09015141716c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3947825
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-12 18:09:48 +00:00
Daniel Almeida
fb0eda5a28 media: libva: picture: allow sharing the underlying Surface
While the current design works well for progressive content, in
interlaced content a common strategy is to decode both fields to the
same Surface.

Thus, add support for sharing the underlying Surface. This means that we
can only retrieve the Surface if we are the last Picture with a
reference to it.

While we are at it: only retrieve Surfaces if we are the last users

In preparation for interlaced decoding support, only retrieve Surfaces
back into the surface pool if we are the last users. This means that the
surface will not be dropped until both of its fields have been dropped.

BUG=b:214478588
TEST="cargo build --features=video-decoder,vaapi" successfully
builds the libva crate

Change-Id: I80412a86f51ab639fab6af229572fb7bc800a928
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3946300
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-10-12 07:40:27 +00:00
Sebastian Ene
b5edcab20b devices: vmwdt: Add watchdog reset reboot reason
When we detect a VCPU stall we propagate the watchdog reboot error code
to the event tube. The newly added error code WATCHDOG_REBOOT = 36 is
returned from the crovm process.

Bug: 245900797
Test: manual testing, build and Virtualization apk on a device
Signed-off-by: Sebastian Ene <sebastianene@google.com>
Change-Id: Ib1ce97de911784b33d130d40536be26813edc3d7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3936647
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-12 06:34:58 +00:00
Keiichi Watanabe
cc8e94dc59 vm_memory: Add a method to check if a guest address range is valid
The current crosvm implementation is using
`GuestMemory::checked_offset()` for the following two cases:
(1) To get a valid `GuestAddress` representing `addr + offset`.
(2) Guarantee that the memory range `[addr, addr+offset]` is valid.

However, using `checked_offset()` for the case (2) is wrong because the
method only checks if the end address `addr+offset` is valid and doesn't
check if an invalid region exists between `addr` and `addr+offset`.

So, this CL adds `GuestMemory::is_valid_range()` to replace the (2)
cases.

BUG=b:251753217
TEST=cargo test in vm_memory
TEST=start a vm with virtio devices

Change-Id: I21bce5d1c60acdff79284cdad963849a6e19e19c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3945520
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-10-12 03:57:43 +00:00
Jason Macnak
1e077db461 devices: gpu: Support display hotplug
Adds `crosvm gpu <>` commands which allows for interactively
adding/listing/removing virtio-gpu displays/scanouts.

Also updates the virtio gpu device to use a Map<u32, Scanout>
instead of a Vec<Scanout> and always report the maximum number
of displays (16) with enabled/disabled. This helps handle the
case of removing a display that is not the last display number.

BUG=b:163864461
TEST=cargo build
TEST=cargo build (with gpu feature disabled)
TEST=Android build
TEST=launch Cuttlefish
TEST=crosvm gpu list-displays <socket>
TEST=crosvm gpu add-displays
     --gpu-display=width=900,height=600
     --gpu-display=width=600,height=480
     <socket>
TEST=crosvm gpu list-displays <socket>
TEST=crosvm gpu remove-displays
     --display-id=1
     <socket>

Change-Id: I7530498897eb4e84199eaeb3d66df006df62817f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911102
Commit-Queue: Jason Macnak <natsu@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-11 16:20:31 +00:00
Vikram Auradkar
c4a4dc9b23 net_util: Add windows slirp support
BUG=b:237011316
TEST=presubmit and tested in wine

Change-Id: I1b6160142b8161d4b09d3fd98dfacde354e238b4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3934818
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-10-11 15:25:38 +00:00
Xiong Zhang
75dbd9763e acpi: Add customized acpi _PRx method
Without _PRx method, device couldn't put into D3cold. In order to
put vfio-pci device into D3cold in VM, this commit add _PRx method
for vfio-pci device. When guest call _PRx method, crosvm will trap
it and forward the _ON/_OFF request to host vfio-pci kernel driver
which manage physical device PM.

BUG=b:194390621
TEST=dump ssdt table in a guest with vfio-pci device

Change-Id: I5ec6ebc84f5328574b62b2d6e091ffe9605d1dd4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3822009
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Victor Ding <victording@chromium.org>
2022-10-11 13:32:01 +00:00
Daniel Verkamp
67f930a70c devices: bus: propagate error rather than unwrap()
The Suspendable trait's restore() function allows returning a Result, so
we can use the `?` operator to return errors in case the serde_json
deserialization process fails, rather than using `unwrap()` on the
Result, which would panic if the call failed. This doesn't make much
difference for this particular case, since it is in test code, but we
should provide a good example in case this code gets copied for other
implementations of the Suspendable trait.

BUG=None
TEST=cargo test -p devices

Change-Id: I8252fef5ee8f19c73f08971352984cd91766aa0c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3942512
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
2022-10-10 19:39:58 +00:00
Elie Kheirallah
f0553fe16a devices: Adding Suspendable to ConstantDevice and DummyDevice
Added suspendable trait to ConstantDevice.
Generate tests for ConstantDevice.
Added suspendable trait to DummyDevice.
Generate tests for DummyDevice.

Bug=b:232437513
Test=cargo test

Change-Id: I38b7b84350c503a9b307a10789b5f328135ac036
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3831266
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Elie Kheirallah <khei@google.com>
2022-10-10 18:12:53 +00:00
Victor Ding
ec820fc4ae vfio_pci: add support for runtime power management
Allow devices to perform runtime power management via
VFIO_DEVICE_FEATURE IOCTL.

BUG=b:194390621
TEST=host's VFIO_DEVICE_FEATURE can be triggered from guest

Change-Id: Id649a1e5fe317dfb315f841a152ec8b81fab8e7c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3822004
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Victor Ding <victording@chromium.org>
2022-10-10 10:56:05 +00:00
Alexandre Courbot
4008ce3958 devices: gpu: simplify display parameters parsing
Use the new ability of serde_keyvalue to parse tuple enums to directly
parse display arguments into their target struct. This requires an
incompatible update on the syntax, but it doesn't seem to be used on
Unix anyway.

Windows code still uses its own parser so it is not affected by this
change.

TEST=cargo test --features "gpu" parse_gpu

Change-Id: I2b718600015a57f5dd6675e9d60de3b8c149a80f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920254
Reviewed-by: Pujun Lun <lunpujun@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-10-07 01:50:20 +00:00
Daniel Verkamp
b60140b37e tree-wide: use "crosvm" capitalization everywhere
Fix a few stray references to "CrosVM" and "CrosVm" so that we refer to
the crosvm project with consistent capitalization.

BUG=None
TEST=None

Change-Id: If5c3c131774d6e5da1d27466810642aec3cb42ac
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3938640
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-10-07 01:10:12 +00:00
Idan Raiter
a55eea9cc8 vmm_vhost: Introduce GPU_MAP
Adds a new message that can be used to map GPU memory via Vulkano.

BUG=b:244622199
TEST=presubmit & downstream

Change-Id: I4018cfda7573d4df2d89225060d5d61c8ac5d3d9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924935
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Idan Raiter <idanr@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
2022-10-06 20:41:57 +00:00
Daniel Verkamp
699c06cdc3 cargo doc: fix warnings
BUG=None
TEST=tools/cargo-doc

Change-Id: I332849dd0df415f634df4c9ad664176f8b8891cf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3936732
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-10-06 20:23:59 +00:00
Idan Raiter
466deb7a78 rutabaga: Introduce device id, remove physical index
Add a new identifier for a device, the "device id". This is a
combination of the device UUID + driver UUID. Reason for not only using
device UUID is that the spec calls out both must match:

https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#external-memory-handle-types-compatibility

We have also seen some less-ideal implementations of device UUID on
Windows that return mostly zero with a few bits set, so adding the
driver UUID should increase confidence.

physical_device_idx is removed.

BUG=b:244622199
TEST=presubmit & downstream

Change-Id: I8174227e3d4bcadf778b7a73c9f84bb475169326
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3926105
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Idan Raiter <idanr@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2022-10-06 20:18:48 +00:00
Daniel Verkamp
9c019a9453 devices: vhost-user: vmm: add VhostUserVirtioDevice abstraction
Each vhost-user device frontend (devices/src/vhost/user/vmm/*) has its
own VirtioDevice implementation; however, most of the code is common
between all devices. This patch adds a VhostUserVirtioDevice struct that
is used for all vhost-user frontends. It accepts some options at time of
creation to customize the supported features and queue count per device
type.

This patch attempts to maintain the previous behaivor of all device
types, so there should be no functional change. Additional cleanup and
refactoring should be possible, but it will be done in follow-up
patches.

BUG=b:249361790
TEST=Connect crosvm vhost-user frontends to all supported backends

Change-Id: I7054fbeaba39b94a1da05792204bc48573ce7caa
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864878
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-10-06 20:00:33 +00:00
Dennis Kempin
8a38e8f36e Re-enable video-decoder feature
This was disabled in https://crrev.com/c/3835500 due to the lack
of ffmgeg 5.0 in our dev containers.
The container has since been upgraded in https://crrev.com/c/3892621

BUG=b:244619658
TEST=presubmit

Change-Id: Ia2bd41fbd780bad7d7706e0ffe7554e202ec0eb1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3907377
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-06 18:28:56 +00:00
Elie Kheirallah
7a11fa44d1 devices: Added suspendable.rs with the Suspendable trait.
Suspendable trait will be implemented for structs that will
snapshot/restore/sleep/wake, related to suspend/resume with snapshotting.
Added test generation for suspendable trait.

Bug=b:232437513
Test=cargo test

Change-Id: I071bad026c15ce346b6657871e7578528768bfc2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3842812
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Steven Moreland <smoreland@google.com>
2022-10-05 21:22:34 +00:00
Ryan Neph
21c739216e gpu: remove virtio-gpu event trigger upon descriptor hang-up
Prevent runaway CPU usage and rapid power consumption when an event
source unexpectedly hangs-up by removing the descriptor from WaitContext.

BUG=b:250923109
TEST=CQ
TEST=glxgears in crosvm linux guest

Change-Id: Idbf4becd7c3195cb57c0e780c0957201c3d9ba9f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3928618
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Ryan Neph <ryanneph@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2022-10-05 17:52:55 +00:00
Alexandre Courbot
7d894a9cd0 video: encoder: stop spamming the syslog with resource replacement messages
virtio-video typically expects that a resource will be imported once and
reused afterwards, but the encoder works with arbitrary buffers that it
needs to reimport every time. This results in a bunch of

    Replacing source resource with id X

and

    Replacing dest resource with id X

messages printed in the host's syslog every time a new buffer is
submitted.

Demote these messages to debug so they don't clutter the syslog.

TEST=arc.VideoEncodeAccel.h264_360p_i420_vm while looking at
/var/log/messages

Change-Id: I37f6d034aa91bf6c8ff3ee8cc0977cc3ef76975a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924767
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-10-05 01:58:00 +00:00
Alexandre Courbot
967f8f8d13 devices: video: decoder: vaapi: fix build of VP8 decoding test
GuestResource and FramePlane recently received new members, but this was
not reflected in the test.

TEST=`cargo test --features "video-decoder,vaapi" -p devices -- vp8 --ignored` passes on Hatch.

Change-Id: I09ebd74fc79dcace5357a10c54ee06fbdd0dce77
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3932437
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
2022-10-05 01:39:19 +00:00
David Stevens
4c372205c6 vm_control: rework exposing VmMemory via viommu
Rework how to specify which VmMemoryRequests are exposed to passthrough
devices via virtio-iommu. Instead of specifying this on a per-request
basis, specify it at at a property of the VirtioDevice. This allows the
feature to work even for vhost-user devices.

BUG=b:243061269
TEST=presubmit

Change-Id: I3c381705f10ae0822896a4b9be760202cf79d925
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3865353
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-10-05 01:23:42 +00:00
Dennis Kempin
4c211a4d41 Extract vtpm out of the chromeos feature
And enable it in upstream all-linux builds.
The feature is enabled for chromeos by default, so should
be a no-op for chromeos builds.

We can probably simplify the cfg() attributes further by
only enabling the feature for x86, so we do not need the
extra check each time. But that'll require ebuild changes.

BUG=b:244618505
TEST=presubmit
TEST=cargo build --no-default-features --features=vtpm

Change-Id: Ibb33c04ab5e6486969fefc6f3e57503be4eccdf3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924741
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-04 21:11:30 +00:00
Keita Suzuki
50181346e6 devices: vhost-user: block: Add hot-resizing feature in vhost-user block
Current implementation does not allow hot-resizing feature to be used in
vhost-user block devices because the backend device cannot notify the
frontend that the device configuration has changed. Fix this by adding
and establishing the backend to frontend vhost-user message connection to
the vhost-user block backend, send the HANDLE_CONFIG_CHANGE_MSG to the
frontend, and send interrupt to the guest kernel from the frontend
device when receiving the message.

BUG=b:191845881
TEST=cargo run devices -s /path/to/socket.sock --block ...
cargo run run --vhost-user-blk /path/to/vhost-sock,
cargo run disk resize 0 $SIZE /path/to/socket.sock

Change-Id: Ifab75d65c429dfcea5e632b899f014278a6e6750
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3859218
Commit-Queue: Keita Suzuki <suzukikeita@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Morg <morg@chromium.org>
2022-10-04 12:50:16 +00:00
Keita Suzuki
24630fe1e4 devices: vhost-user: allow backend device to send vhost-user message
Current implementation of vhost-user backend devices cannot directly
send vhost-user messages from the backend to the frontend since the
established connection is stored directly to `VhostShmemMapper`. This
limits the messages that could be sent to memory share-related messages.

To overcome this limitation, introduce struct `VhostBackendReqConnection`
which exposes the required backend to frontend requests and keeps track of
the underlying transport (struct `Slave`), and refactor `Slave` out from
current VhostShmemMapper.The state of the connection is managed using enum
`VhostBackendReqConnectionState`.

This patch also moves the timing of when `BackendReqHandler` is created in
the frontend to when `VhostUserProtocolFeatures::SLAVE_REQ` is negotiated
when creating VhostUserHandler.

BUG=b:191845881
TEST=run ./tools/run_tests

Change-Id: I90235a527d58067f73a509907b4cefc09516f562
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3856036
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-10-04 12:50:16 +00:00
Alexandre Courbot
753916a7d3 video: decoder: ffmpeg: handle INVALIDDATA in try_receive_frame()
The INVALIDDATA error can be returned by both try_send_packet() and
try_receive_frame(). In both cases we should just skip the invalid input
until the decoder can catch up with something that makes sense.

TEST=arc.VideoDecodeAccel.h264_vm unconditionally passes on Hatch

Change-Id: I4467b50c35fb36562a4b662d14071afcf02f1eb2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924583
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-10-04 09:21:13 +00:00
Pattara Teerapong
b74bc68371 devices: virtio: snd: reset streams on error
Try to recover from a fatal error by resetting all streams instead of
exitting and putting the device into an unrecoverable state.

On error, all workers will be stopped and streams will be reset, then
workers will be restarted.

Flag `just_reset` will be set on all stream after a reset. This flag
let the invalid state transition to return Ok instead of Err. This let
the guest driver able to stop the stream even when the state is
desynced from device side. Once a valid state transition is made, the
flag is removed.

BUG=b:242021318
TEST=`restart cras` while playing music and recording audio in ARCVM
TEST=`restart cras` while calling `aplay` and `arecord` in termina
TEST=unit test

Change-Id: Ic329e2f82e572e6fcd69a6a197909b494d0360b5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3823181
Commit-Queue: Pattara Teerapong <pteerapong@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2022-10-04 08:10:51 +00:00
Pattara Teerapong
a79baab67b devices: virtio: snd: refactor run_worker
Refactor run_worker by extracting the worker running logic to
run_worker_once function.

BUG=b:242021318
TEST=play music and record audio in ARCVM

Change-Id: Idb2012b92fc113db9b8e16c066e10b72f66a7cdb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889334
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Pattara Teerapong <pteerapong@chromium.org>
2022-10-04 08:10:51 +00:00
Federico 'Morg' Pareschi
047e64ada4 devices: virtio: add syslog support to vvu console
BUG=b:233833487
TEST=tested on a DUT, verified guest logs appear on the host

Change-Id: I08b014655000ed7ccecd7ee34bac80e919395276
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3929990
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Morg <morg@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-10-04 02:44:08 +00:00
Daniel Verkamp
f29a992754 tree-wide: apply cargo fmt --nightly
Fix a few recently introduced formatting mismatches.

Change-Id: I1617683532d3cc45f67ec15408fbd4ec4c9d6bb2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3928132
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-10-03 21:39:26 +00:00
Frederick Mayle
c96a9f58a2 virtio: console: allow non-seekable input
pread only works for seekable files, so, for example, a pipe could not
be used. The non-async Console uses read calls and doesn't have this
issue.

There is a possibility of breaking something with this change. Suppose
crosvm was passed an input FD with the cursor at the end of a non-empty
file. Before the async console would read the full file from the
beginning, but now it would immediately EOF.

Another difference is that if the device is reset and then reactivated,
it will continue reading from where it left off instead of restarting at
the beginning of the input.

In both cases, I think the new behavior is better and additionally
matches the non-async console's behavior. The async console is
relatively new, so hopefully no one is depending on this part of its
behavior yet.

BUG=b:243198718
TEST=presubmit

Change-Id: I8e07e231d5def250eb5f42e9a4546fce721cc4bc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3842811
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-30 20:32:02 +00:00
Colin Downs-Razouk
e0de18a6a5 base: timer: handle 0 interval explicitly
Make it official that setting a Timer's interval to 0 is the same as
setting it to None, meaning it will not be periodic. Fixed the windows
timer to behave this way again, and updated Timer docstring.

Also updated APIC timer to use None for interval which is clearer.

Bug: b:248612697
Test: tested with UserspaceIrqChip in dynamic tick mode
Change-Id: I57713c3ace345a8c64b9219a8e60f36c54a9481c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3925006
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2022-09-30 16:50:22 +00:00
Tatsuyuki Ishi
8f2ccb3b50 virtio: video: Introduce FFmpeg encoder backend.
The FFmpeg backend is a software emulated video encoder device backend.
It can be used for testing, for developing guest kernel changes and
more.

The backend roughly mirrors how the FFmpeg decoder backend is
implemented right now, with the notable difference that it does not use
swscale as the de-facto input format is NV12 or YUV420 and the guest can
likely provide buffers in that format.

BUG=b:239897269
TEST=See testing instructions in the updated book document.

Change-Id: Iae9928bdad86729f890e738acfa58e21573a115b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920263
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-09-30 05:36:51 +00:00
Tatsuyuki Ishi
d3e58b0275 virtio: video: Add support for converting AvPixelFormat -> Format.
For simplicity, use the same error type as Format -> AvPixelFormat.

This will be used and tested in the FFmpeg encoder backend.

BUG=b:239897269
TEST=cargo build --features "video-encoder,video-decoder,ffmpeg"

Change-Id: Ie5cf2a29379c0d52c78cee50ed6571f4859eee75
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924881
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-09-30 05:36:51 +00:00
Tatsuyuki Ishi
244033437e virtio: video: Add an Error implementation for TryFromFormatError.
As a convention, error types should always implement Error, so we're
doing it here.

The traits are manually implemented as opposed to using ThisError; it
was simple enough, and using ThisError requires making the error type an
enum which makes it more verbose to construct.

BUG=None
TEST=cargo build --features "video-decoder,ffmpeg"

Change-Id: If94926c1b2f14295b29c877c2c70d361b4adee90
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3925332
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-30 05:36:51 +00:00
Daniel Verkamp
ffff52fe72 devices: vhost: user: vmm: add Connection type
This abstracts away the cross-platform differences: cfg(unix) uses a
Unix domain stream socket to connect to the vhost-user backend, and
cfg(windows) uses a Tube.

BUG=b:249361790
TEST=tools/presubmit --all

Change-Id: I47651060c2ce3a7e9f850b7ed9af8bd035f82de6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924834
Reviewed-by: Richard Zhang <rizhang@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-09-29 21:33:41 +00:00
Pujun Lun
c99038b59a devices: move ResourceBridges struct out of sys folder.
Now that we've made VirtioGpu::export_fence() and
VirtioGpu::export_resource() compile on Windows, we can make
resource bridges related code compile there as well. We are adding
an assert to make sure it is not really used on Windows, though,
since that is unsupported.

BUG=b:213149288
TEST=presubmit
TEST=tested in downstream

Change-Id: Iad06055c0aff5b6ce1fa6cb7bc0d0789750033bd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3928606
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2022-09-29 21:20:11 +00:00
Tatsuyuki Ishi
106ae7ada1 virtio: video: Tolerate and fixup zero plane encoder SetParam requests.
Per virtio-video spec, if the device encounters a field with value it
does not support, it should update the field with a valid value and then
return that.
It's actually debatable whether an empty plane array is allowed in the
first place, but this seems to be what happens in the case we use a non-
default format (everything but NV12) from FFmpeg v4l2m2m. Moreover, the
guest kernel currently ignores SetParams errors, so it seems justifiable
that we should avoid rejecting this input and instead gracefully handle
it.

With this change + later commit introducing the FFmpeg encoder, FFmpeg
in the guest works with `-pix_fmt yuv420p -c:v vp8/h265_v4l2m2m`. Note
that for VP8 a WebM container should be used. VP9 was not supported as
an encoder accelerator somehow so this was not tested.

BUG=b:239897269
TEST=cargo test --features "video-encoder,video-decoder,ffmpeg" -p devices video
TEST=Linux guest test described above

Change-Id: I843af7cef35cc231b8668efcf716a48a37959c86
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924264
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 11:03:51 +00:00