Commit graph

1969 commits

Author SHA1 Message Date
Alexandre Courbot
839577a796 media: libvda: allow to build without linking to libvda
libvda is only available on ChromeOS, and being unable to link to it
with regular builds reduces our build coverage.

Add a "libvda-stub" feature that, if enabled, results in dummy C stubs
being build for all the exported libvda functions. This allows builds
with the "libvda" feature to pass, although of course the resulting
video device would immediately crash and thus should not be used.

BUG=b:244619291
TEST=`cargo build --features="video-decoder,video-encoder,libvda-stub"`
completes.
TEST=`cargo build --features="video-decoder,video-encoder,libvda"`
reports link errors against libvda.
TEST=`cargo build --features all-x86_64` builds libvda and completes
without error.

Change-Id: I9bb60f6caf670081d67c91275727f3888272d64b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3947844
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-10-21 13:57:31 +00:00
David Stevens
60aa43629a devices: vhost-user: add protocol flag for shmem
Add a vhost protocol feature flag for shared memory region support. This
is necessary to avoid sending the GET_SHARED_MEMORY_REGIONS message to
backends which don't support it.

BUG=b:252901073
TEST=crosvm device wl

Change-Id: I044926e982526c3c76063b5386cab0db72524707
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3951472
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-10-21 01:09:07 +00:00
Noah Gold
81549b21d9 devices: add err code for disk image open failed.
Adds a new error code for when we fail to open a disk image. Also adds
an exit code we were missing upstream.

BUG=b:253348635
TEST=intentionally messed up the disk image path and verified we get
this error.

Change-Id: I197b4c5d80682dd1ee2a42d02df852276d204c17
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3961530
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-10-20 20:27:58 +00:00
David Stevens
e72be7b593 devices: vhost-user: wl: fix shared memory
Fix shared memory support for vhost-user wl implementation. Handle
set_slave_req_fd being called before get_shared_memory_regions and make
sure the wl device only tries to get its shared memory mapper once.

BUG=None
TEST=crosvm device wl

Change-Id: I724712399bd6a9ffbffb22dd69d431f54df58282
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3965812
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-10-20 09:22:29 +00:00
Sreenad Menon
877b350c4b devices: virtio: Determine block queue size and number of queues at runtime
Qualcomm has developed a wrapper program which uses CrosVM's libdevices
crate. Some Qualcomm products use 128 as virtio block queue size and
some of them use 256 depending on the memory constraints.
Number of virtqueues per device may also vary on different products.

This change lets virtio block new() function accept arguments that
specifies virt queue size and number of virt queues.
Qualcomm's wrapper program calls new() method with required number of
queues and queue size at runtime.

When they are not provided at runtime, they get their default values.

Change-Id: I71d8340e9a97009ae855cc0403d45f8c5c1cb55f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3965432
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-20 01:25:48 +00:00
Sreenad Menon
5ad8b5afc5 devices: virtio: Always inject interrupts if hypervisor can handle
Gunyah hypervisor supports virtio-mmio transport only in some
products on which CrosVM is also used. Qualcomm has developed
a wrapper program which uses CrosVM's libdevices crate.

Gunyah hypervisor has some optimizations for how virtio-mmio
register access are handled. Normally they are synchronous access -
meaning any access of virtio-mmio register by a guest will cause
a fault, which requires blocking the guest VCPU until the access
can be served by CrosVM running in a different VM. Since that could
induce long delays for guest (esp since the OS in which CrosVM is
hosted is considered untrusted), Gunyah hypervisor caches all
virtio-mmio registers in its address space.
Any read access is handled without requiring intervention from CrosVM.
Write access is handled asynchronously - i,e a write will cause
hypervisor to updates its copy of the register, unblock the guest vcpu
and simultaneously notify CrosVM about the update.
By the time CrosVM gets to notice the update, guest could have
progressed lot more.

This works reasonably well for many devices and registers.
One problem case is writes to VIRTIO_MMIO_INTERRUPT_ACK, which signals
the guest having seen an interrupt. CrosVM seems to rely on synchronous
handling of this register write. Any attempts to kick guest via signal
method of 'struct Interrupt' (devices/src/virtio/interrupt.rs) skips
sending a kick if prior kick is "not yet" acknowledged, which fails
if writes to VIRTIO_MMIO_INTERRUPT_ACK is asynchronous.

This patch introduces a 'async_intr_status' flag in signal method which allows
the kick to be always delivered to guest independent of the status of
acknowledgement of prior kicks. Hypervisor will queue kick requests and
deliver another kick after current kick is processed.

Its expected that only the Qualcomm wrapper program will initialize the
interrupt object with 'async_intr_status' flag set and hence the upstream
CrosVM should not be affected because of this change.

BUG=b:243368499

Change-Id: I76568d9d8bc3be00c75c52d4a51d39410c5c35b3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3965686
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-20 01:25:48 +00:00
Elie Kheirallah
eb27c46876 devices: adding Suspendable trait to BusDevice and PciDevice
Add supertrait Suspednable to BusDevice and PciDevice

Bug=b:232437513
Test=WIP

Change-Id: I74162399091fc4bc5fdef4bbeefb2639148bd283
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924745
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
2022-10-20 00:47:45 +00:00
Frederick Mayle
3d4b4809ba base: cross platform Event API
Trying to reconcile the difference between the linux and windows
implementations.

Code relying on the eventfd count must now use the linux specific
`EventExt` interface.

BUG=b:231344063
TEST=presubmits

Change-Id: I14eb50f7a02d766a00f27aca388823309633e193
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864030
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-10-19 20:17:42 +00:00
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
Tatsuyuki Ishi
fbe77b7123 virtio: video: Implement plane layout calculation for YUV420
This is required to get H.265 and VP8/9 to work in the FFmpeg backend.

BUG=b:239897269
TEST=cargo test + FFmpeg backend tested in later commit.

Change-Id: I1d5b3305e688ddab82f8a4afe84dc7438ee27b2b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924263
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 11:03:51 +00:00
Tatsuyuki Ishi
200b293626 media: ffmpeg: Convert SwConverter to a AvFrame-based API.
We were already accepting AvFrame for swscale inputs, but for the output
a different SwConverterTarget trait was being used.

The old interface had a few issues:
- The use of memory mapping traits, putting a dependency on crosvm/base
- Insufficient metadata, not being able to represent custom padding on
  the stride or non-contiguous plane layouts
- Inconsistency between input and output types

In this patch, we:
1. Introduce a AvFrame-based API to replace the old SwConverter API.
2. Add a TryAsAvFrameExt extension trait inside devices/ to convert
   virtio handles to AvFrames.
   (This is placed inside devices to avoid ffmpeg depending on base.)
3. Add a new wrapper type, MemoryMappingAvBufferSource, that wraps a
   MemoryMappingArena and implements AvBufferSource for it. This was
   technically not sound, but it's a low-risk attack vector that we
   implicitly allowed before. The patch doesn't change the behavior; it
   just makes this assumption more explicit.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices -p ffmpeg

Change-Id: Id15e19b7d2452d1bc722a65f941c2c9150876205
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889245
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 09:47:01 +00:00
Tatsuyuki Ishi
37b3acc7e5 virtio: video: Fix encoder output size being 0 for GuestPages.
In case of GuestPages the stride is obtained from the SetParams request
which is specified as 0 for output buffers in the virtio-video protocol.
This obviously doesn't work, and replacing the use of stride with the
plane size fixes it.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices -p ffmpeg

Change-Id: I2ed584c647400802b875a9d68fc8ede1a9db0db0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920262
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 09:47:01 +00:00
Tatsuyuki Ishi
c96c9b5eef virtio: video: Enrich GuestResource with more metadata.
This adds:
- A buffer size field for each plane
- Width, height, format field for each image

This is for introducing helpers to convert video GuestResources into
AvFrames.

In practice, these metadata were readily available either from the
protocol or through rubataga RPCs, but they have not been stored in the
GuestResource struct. With these change these fields would be available
for usage in constructing AvFrames.

A tricky topic is the source of the metadata. Right now, neither the
virtio_video_params struct nor virtio-gpu backend metadata alone can
provide all the metadata we need. See code comment in
GuestResource::from_virtio_object_entry and go/crosvm-enc-ffmpeg for
future work discussions.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: Icb47274d2dd379a10bdf878ed91ffbc238685c6d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911110
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 09:47:01 +00:00
Tatsuyuki Ishi
c706b5badb virtio: video: Relax encoder param change checks.
V4L2 clients such as FFmpeg goes through a configuration sequence like
the following:
1. Set input format
2. Register input buffers
3. Set output format
4. Register output buffers

Right now, this fails at 3. because the format change is rejected due to
existing registered input buffers. However, none of the encoder
functions are called yet at this point, and a configuration sequence
like above is supposed to work.

Relax the check to allow for compatibility. As noted in code this is an
over-relaxation that might cause unintended behavior if a format change
happens after a ResourceQueue request (which calls encode()), but I'm
not aware of any implementation actually doing that, so this will be a
TODO for the future.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices -p ffmpeg

Change-Id: I199f9ddd30208aa0dd896cd62566cf19a8ce9ccc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920261
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-09-29 04:13:01 +00:00
Dennis Kempin
d6cd312571 Split arc_quota out of the chromeos feature
This allows us to enable the feature in upstream builds.

The feature is automatically enabled for the chromeos feature,
so it should be a noop for ChromeOS builds.

BUG=b:244618505
TEST=presubmit / build_packages implicit-system crosvm

Change-Id: I2ea2d668a0f8c2faa92aad5452df0bf660d85e0e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3919815
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-28 18:13:00 +00:00
Dennis Kempin
891455563b system_api: Add copy of ChromeOS's system_api
Adds a script that copies the bindings we need upstream. We cannot
use the original repository, as it's part of the large platform2 git
repository, and the original build.rs depends on ChromeOS tooling to
generate these bindings.

So instead, this change adds a script that can be called from a
chromiumos checkout of crosvm to update the upstream bindings.

This allows us to enable certain features that talk to ChromeOS
dbus services. They won't be functional upstream, but at least we
can compile and test the code.

To make things more consistent, we no longer replace the crate
with the ChromeOS version when building for ChromeOS.

BUG=b:244618505
TEST=presubmit

Change-Id: I504cbf6d12b0cb50d9935f5e49b7fa72b692d45c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3919814
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-28 18:13:00 +00:00
Jason Macnak
9ce7255fa0 devices: gpu: Don't hardcode display 0 for EDID
BUG=b:163864461
TEST=launch Cuttlefish with multiple displays

Change-Id: Idc61e86cb03b7b2afca6a416cbf6770b8b217cf2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911101
Commit-Queue: Jason Macnak <natsu@google.com>
Reviewed-by: Pujun Lun <lunpujun@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-28 16:18:01 +00:00
Tatsuyuki Ishi
18b779fef0 virtio: video: Add conversion helper for virtio Format to AvPixelFormat.
Generalize and move it out of the decoder for potential future use in
the encoder module.

A ffmpeg.rs module is introduced to accommodate any video-related code
that requires the ffmpeg feature flag, similar to what we have for
libvda.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: I341d6d238b5593d16cbdc8dd8c96eb2fa4e143fe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911109
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-28 02:54:50 +00:00
Idan Raiter
6af40edd41 rutabaga: Fix typo rutabagE -> rutabagA
Some types have a typo on them. For the FFI case we don't currently use
the definition so it should be safe to rename.

BUG=b:244622199
TEST=presubmit

Change-Id: I9e3c29755f0c4479b54bef206f9173ab22030ab9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3913992
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Idan Raiter <idanr@google.com>
2022-09-27 18:44:09 +00:00
Alexandre Courbot
980fb8896c devices: video: fix build
http://crrev.com/c/3911103 renamed a member of BufferInfo, but did not
update the video code that uses it.

BUG=b:3911103
TEST=cargo build --features "video-decoder,video-encoder,ffmpeg,vaapi,libvda"

Change-Id: Icc8c5c2f564ea2fdaeee12abe57cfd29c8373a72
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920255
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
2022-09-27 03:15:28 +00:00
Pujun Lun
db5bb70726 devices: make resource_bridge::ResourceInfo use SafeDescriptor.
It used to use File instead. In VirtioGpu::export_fence() and
VirtioGpu::export_resource(), we had to turn SafeDescriptor into
File, which is not supported on Windows (to avoid converting a
SafeDescriptor that is not a file handle to a File). To make them
more platform-agnostic, we replace them with SafeDescriptor.

BUG=b:213149288
TEST=presubmit

Change-Id: I259bbc4d3461bc68b5a7a1e24d50bf77bdc6a5b0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911103
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2022-09-26 23:08:48 +00:00
Daniel Verkamp
5c3815747a devices: vhost-user: clean up config functions
The generic type used in read_config() and write_config() was only used
to check the offset against the size of that type; the backend device is
capable of checking this itself, so we can drop the type from the
function signatures.

Additionally, fix the config functions to use the offset rather than
reading/writing the whole config and copying out the relevant parts.

This makes the config function implementation identical for all
vhost/user/vmm/ code.

BUG=None
TEST=mount vhost-user-fs filesystem in guest

Change-Id: I22493f4e87bff68ef9d68f1d1a0feeb29ec059da
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3867543
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-09-26 08:46:28 +00:00
Takaya Saeki
ae9280a20a devices: virtio: video: add run_async method to Worker
Implement `run_async` method in `Worker` for the video device.
`run_async` is necessary for implementing vhost-user video device, which
prefers async wait loop.

For now, the async runner depends on the wrapper of WaitContext, which
the implementation of decoder device depends on, rather than making the
decoder device async.  In addition, this commit does not unify the block
`run` and `run_async` yet.

BUG=b:179756087
TEST=cargo build succeeds.

Change-Id: Iec14a342bade14bf1f68ec0211da3dd2b52c85da
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3783295
Commit-Queue: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-09-26 06:54:07 +00:00
Takaya Saeki
a150978ca0 devices: virtio: video: make Worker async friendly
Update `Worker` of the video device to make it easier to add async run
method; separate the interrupt into two `SignalableInterrupt`s for the
command/event queues, and move `Event`s to outside `Worker`. These are
changes preparing for introducing `run_async` method to `Worker`.
`run_async` will need separate Interrupts for the command queue and the
event queue, and will not need `Event`s inside `Worker`.

BUG=b:179756087
TEST=simple_decoder test script (see the crosvm book) worked with and
without -p "pci=nomsi" guest kernel parameter, which triggers interrupt
resample by disabling MSI-X interrupt.

Change-Id: Ia169e11bb5ecf992f768ab65cfb19a7a9f8fc9f0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3850019
Commit-Queue: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-09-26 03:26:37 +00:00
Ryan Neph
2a8339f85d rutabaga_gfx: make non-sandboxed opaque fd mapping explicit
When sandboxing is disabled, rutabaga.external_blob is unset and blob
resources with RUTABAGA_MEM_HANDLE_TYPE_OPAQUE_FD can be mapped via
rutabaga.map() as VmMemorySource::ExternalMapping. This is already
implicitly allowed for the Virglrenderer component, which doesn't
recognize the OPAQUE_FD handle type upon export_blob() and automatically
falls back on the ExternalMapping path. Mesa CI currently relies on this
for testing Venus in Crosvm with the host lavapipe driver.

When sandboxing is enabled, rutabaga.external_blob is set and opaque
fds MUST be mapped from the hypervisor process via Vulkano as
`VmMemorySource::Vulkan` instead.

This CL makes non-sandboxed OPAQUE_FD mapping explicit, documents the
two mapping paths, and prepares for virglrenderer to support sandboxed
OPAQUE_FD mapping.

For the non-sandboxed configuration, Crosvm exports a RutabagaHandle
with handle of type RUTABAGA_MEM_HANDLE_TYPE_OPAQUE_FD upon blob
creation with virglrenderer. When mapped, the RutabagaHandle is dropped,
closing the cloned opaque_fd, and virgl_renderer_resource_map()
completes the mapping internally by looking up the resource_id and
dispatching to the context type from which it was created.

BUG=b:244591751
TEST=`deqp-vk -n dEQP-VK.memory.mapping.*` using venus with lavapipe host driver
TEST=CQ

Change-Id: I2ff32cf8868d6c9c1eb16480456cde98d376cc65
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3900320
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Ryan Neph <ryanneph@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2022-09-22 21:43:19 +00:00
Pujun Lun
698d2dcc3a devices: add feature flags to render_server_fd.
We want to hide this variable from platforms that don't use it.

BUG=b:213149288
TEST=presubmit

Change-Id: I0d44d2bc50843b86d82b4084f95c8d1a1f750aa6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3895401
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chia-I Wu <olv@google.com>
2022-09-22 20:21:59 +00:00
Pujun Lun
05e0443fe5 gpu: add a serializer for context mask.
Apart from being used for arg parsing, GpuParameters is also sent
through a Tube on Windows. Since we've added a deserializer for
the context_mask field, we also need a serializer for it.

BUG=b:233676779
TEST=cargo test -p devices --features=all-linux
virtio::gpu::parameters::tests::context_mask_serialize_deserialize

Change-Id: Ic0a01acc07ac39b5962e3cfad970dae1ae8c8b27
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3906468
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-22 16:34:19 +00:00
Pujun Lun
9a415a2559 gpu: don't use raw descriptors of resource bridges on Windows.
Resource bridges are not supported on Windows, so we shouldn't try
to add their raw descriptors in Gpu::keep_rds().

Struct Gpu is updated to hold the ResourceBridges struct rather
than the Vec<Tube>.

BUG=b:213149288
TEST=presubmit

Change-Id: I6b71076d17057728b927d93462e3aee29f3ac8af
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911100
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-22 16:33:59 +00:00
Grzegorz Jaszczyk
572519253d audio: fix VirtioSnd re-activation
Hitherto the activation could succeed only once since take() function on
Option "Takes the value out of the option, leaving a None in its place."
Above resulted with crosvm crash in guest suspend/resume scenario when
the activate was called more than once (for the second time snd_data
and stream_source_generators was None).

To overcome above issue use clone for snd_data. For
stream_source_generator the clone can't be
easily used due to missing Clone support for stream_source_generators
embed data types (e.g.
369 | struct AudioBuffer<'a> {
370 |     buffer: &'a mut [u8],
    |     ^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for
    `&mut [u8]`

and some other). Therefore for stream_source_generator move
create_stream_source_generators from new() to activate.

BUG=b:246728970
TEST=Perform multiple suspend/resume s2idle cycle for borealis VM and
make sure that 1) crosvm doesn't crash anymore 2) audio from borealis VM
is still working after VM suspend/resume cycles.

Change-Id: I8b27042e4cc0e5efb1d92756ac3b71a5a744f705
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3904649
Commit-Queue: Norman Bintang <normanbt@chromium.org>
Reviewed-by: Norman Bintang <normanbt@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2022-09-22 09:14:19 +00:00
Frederick Mayle
1c3ba38583 base: don't export platform specific Event types
TEST=cargo build && ./tools/dev_container ./tools/run_tests --target=host --build-target=mingw64 --build-only
BUG=b:231344063

Change-Id: I125f4b200abdc6758bae93d98c590c2139fe915b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864025
Auto-Submit: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-21 21:35:48 +00:00
Pujun Lun
ea55d0fecd rutabaga_gfx: add an interface to enable GLES 3.1 for gfxstream.
GLES 3.1 is not yet well tested with gfxstream backend on Windows
and we don't enable it by default. We control this via command
line arg for now.

BUG=b:213151426
TEST=presubmit

Change-Id: Ic3f8ac0e10ab988cc7bb4a5ab741ee6542617943
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911097
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2022-09-21 21:21:14 +00:00
Daniel Verkamp
02214710df devices: vhost-user: remove incorrect get_config offset check
The offset field of the VHOST_USER_GET_CONFIG message indicates the
offset within the whole device configuration, not within the buffer in
the message, so offset does not need to be less than size.

BUG=None
TEST=connect fs device with modified read_config() impl

Change-Id: Ifabac14ec087da200a09f41aa3a0041e96cf56f3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3867542
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
2022-09-21 18:44:38 +00:00
Daniel Almeida
53523c943c video: decoder: vaapi: retry flush() if new buffers are available
The previous implementation would silently not flush all buffers if not
enough output buffers were available. It would also unconditionally emit
the FlushCompleted event.

Fix this by retrying the flush whenever new output buffers are
available, and only exiting the flush state when there is nothing left
to flush.

BUG=b:214478588
TEST="cargo test --features=video-decoder,vaapi
virtio::video::decoder::backend::vaapi::tests::test_get_capabilities"

Change-Id: I47402d3e561ca98ba93462f448eb4eb76acd3eee
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3783001
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-21 03:24:28 +00:00
Daniel Almeida
e64a119bed video: decoder: vaapi: change flush() signature
Some codecs might need to return frames on flush. This is notably the
case on h264, as it has to output the frames in the DPB on flush, but
the current design makes it impossible.

Fix it by changing the signature of flush to allow for possibly
returning frames when flushing. These frames are appended to the ready
queue and outputted as soon as output buffers become available.

BUG=b:214478588 TEST="cargo test --features=video-decoder,vaapi
virtio::video::decoder::backend::vaapi::tests::test_get_capabilities"

Change-Id: Ifd982518bc09cbdd3c32da5409e348a3a2e0b91d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3783000
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-21 03:15:59 +00:00
Noah Gold
90063081cb devices: simpler disk image opens + bug fix for Windows.
* Fixes a regression where we stopped setting sparseness on Windows
  disk images when they were opened.

* Simplifies how disk images are opened. io_concurrency is not
  currently used and may be repurposed in a way that won't use the more
  complicated code in disk image opening.

BUG=b:247582339
TEST=builds

Change-Id: I25dd71985d512e5d6991a74e4e1b01fa798856a9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3908372
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-21 01:48:26 +00:00
Tatsuyuki Ishi
3af6d25d61 virtio: video: Move decoder utils to the root video module.
We want to use this for the encoder too, so move it to a place that can
be accessed from both.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices video

Change-Id: I5f880a9907d0750249d50a8b36f8431f180c31a4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889332
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-21 01:44:38 +00:00
Tatsuyuki Ishi
39108c7dfc virtio: video: Decouple EventQueue tests from the video-decoder feature.
We want to share this module between the encoder and decoder, so as a
prerequisite remove the test's dependency on decoder features by making
a test-local copy of the struct.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices video

Change-Id: I09726e2da823994d4a9000bb23a8f5dbed4fdbca
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889331
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-21 01:44:38 +00:00
Tatsuyuki Ishi
f30d6fd9e8 media: ffmpeg: Add a separate flush helper for encoder.
The decoder and encoder uses different calls for flushing. Add a new
flush_encoder helper for that, and rename the existing one to
flush_decoder.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: Id237424209dc8d64d43424570003d735ee164d36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3868598
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-09-20 04:27:00 +00:00
Tatsuyuki Ishi
8a2af8f2ff media: ffmpeg: Add bindings for encoding methods.
try_send_frame and try_receive_packet together forms the basis of the
(AVFrame-based) encoding API. This change adds helper methods for them,
with the return value being handled similarly to their decoding
counterpart.

TryReceiveFrameResult has been renamed to TryReceiveResult as the
encoding interface shares the handling of these return codes, and we'll
be sharing this logic between try_receive_packet and try_receive_frame.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: I32c11053daed86c32067ac2b2a8f7218f6dbcd4f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3868597
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-20 04:27:00 +00:00
Daniel Verkamp
e539372226 devices: virtio: block: impl DiskOption::open for Windows
Move the logic for locking and DiskFile creation into an implementation
of DiskOption::open(), matching the sys::unix structure. This will
allow future consolidation of the vhost-user devices.

For now, the Windows variant of DiskOption::open() only knows how to
create a SingleFileDisk (not qcow, composite, etc.); switching to
create_disk_file() is left as future work.

This also makes a few tweaks to the creation of the BlockAsync instance
in order to make the unix and windows versions more similar - compare:
- devices/src/virtio/vhost/user/device/block/sys/windows.rs
- devices/src/virtio/vhost/user/device/block/sys/unix.rs

No functional change intended.

BUG=None
TEST=tools/presubmit --all

Change-Id: Iadb1a8913a7445d7c091d0e359c7d8792704c35a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892136
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-09-20 03:42:20 +00:00
Pujun Lun
43fe5ca94e gpu: add plumbing code for Windows only objects.
We've seen third-party DLLs hooking into CreateWindowExA and
causing stack overflow (b:202288586, b:244141583). Adding the
offending DLLs to the blocklist fixed the issue, but it is hard
to know what other DLLs would cause the same issue in the wild.
Hence, we want to spawn WindowProcedureThread and create
windows as early as possible and then pass them all the way
down to GpuDisplay.

We are also passing the kiwi specific gpu_device_service_tube
along the stack.

BUG=b:213150276
TEST=presubmit

Change-Id: Ib1e3a4f11523ea36ede74c99f401c23a8c94a2c3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892519
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2022-09-19 19:57:50 +00:00
Daniel Verkamp
835a85b983 devices: proxy: ensure device drop gets called
Explicitly drop the device object before calling libc::exit() so that
the Drop impl for the device has a chance to be called.

Change-Id: Id93447925f71340c78a1d80efdff5b1574801409
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3900327
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-09-19 18:27:00 +00:00
Daniel Verkamp
8e0a4cb345 devices: extend IrqLevelEvent documentation
Describe the resample event and how it is meant to be used by a device.

BUG=b:243465984
TEST=tools/cargo-doc

Change-Id: I0a2ad7b5593e0222e69c932fed20499f6d2fccbf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892525
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-09-19 18:00:30 +00:00
Pattara Teerapong
2d7d5e99c2 devices: virtio: snd: fix StreamInfo test memory leaks
StreamInfo unit tests leave the stream in an arbitrary state after
finish testing. Some streams have spawned a worker in `prepare()`, but
haven't released the worker in `release()`. These are reported as
memory leaks.

Implement drop on StreamInfo to release the stream if the end state is
PREPARE, START, or STOP.

BUG=b:242021318
TEST=1. `setup_board --board=amd64-generic --profile=asan`
     2. `build_packages --board=amd64-generic crosvm`
     3. `FEATURES=test emerge-amd64-generic crosvm`

Change-Id: I8cb7a25b61bfacdfcda4c7ba06ed2ab2b6a4ea40
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3901569
Commit-Queue: Pattara Teerapong <pteerapong@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2022-09-19 11:33:21 +00:00
Ryan Neph
bf6e7d9060 rutabaga_gfx: unmap from gpu thread for virglrenderer
Virglrenderer must not unmap from any thread other than the virtio-gpu
thread because virglrenderer is not thread-safe and EGL requires that
only one thread own a context concurrently.

For the VirglRenderer RutabagaComponent, we can unmap directly from the
virtio-gpu thread. In fact, we can greatly simplify the use of
ExternalMapping if we eliminate the associated map/unmap callbacks for
all RutabagaComponents.

Now VirtioGpu is responsible for ensuring that the map/unmap occurs and
is registered/unregistered. Also, the shared `map_request:
Arc<Mutex<ExternalMapping>>` spanning the KVM and virtio-gpu threads is
no longer necessary.

BUG=b:244626679
TEST=OpenGL and Vulkan gameplay with sandboxing disabled
TEST=OpenGL and Vulkan gameplay on ChromeOS with sandboxing

Change-Id: I4acaf4aabff3891536ca0439221cfbd021dba123
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3888602
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Ryan Neph <ryanneph@google.com>
2022-09-16 17:29:37 +00:00
Pujun Lun
797ff4a795 vm_memory: create udmabuf stub for Windows.
BUG=b:213149288
TEST=presubmit

Change-Id: I250209912cff96da505e6ccfb76f9dba4b9a6683
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3885377
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-15 19:03:49 +00:00
Alexandre Courbot
829f0d3d25 devices: video: decoder: remove unused lifetime
This lifetime is not used anywhere and clippy complains about it.

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

Change-Id: I09fe49b2c89cfc80891acb47592f0de6ebc26ea3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889320
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-09-15 08:58:46 +00:00
Pattara Teerapong
14516a1dee devices: virtio: snd: refactor StreamInfo into a separate file
Refactor StreamInfo into a separate file and add unit tests for state
transitions.

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

Change-Id: I3aa17bdbd29bb768f6471a91f4cf93c56d68574d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889321
Commit-Queue: Pattara Teerapong <pteerapong@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2022-09-15 02:53:36 +00:00
Alexandre Courbot
2c171901ee virtio: vhost: user: remove use of serde's flatten in VhostUserParams
The use of flatten is problematic as it introduces type ambiguity if we
need to parse a string from either the embedding or the embedded
structure. For this reason we are now discouraging its use.

Replace the only place where it was used (the VhostUserParams struct)
with a manual parser that requires the 'vhost' parameter to come first.
This is a bit more constraining but at the same time is probably clearer
than having it in the middle of device-parameters anyway.

BUG=b:217480043
BUG=b:241300017
TEST=cargo test -p devices vhost_user_params

Change-Id: I35847196fa6dc4858112ffe1e2883d64c2fae514
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889329
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-09-15 02:07:56 +00:00
Alexandre Courbot
d47cd8366e virtio: vhost: user: introduce tests for VhostUserParams parsing
We are going to make some changes to VhostUserParams' parsing, so add
tests to make sure we don't break anything along the way.

BUG=b:217480043
TEST=cargo test -p devices vhost_user_params

Change-Id: I898b4b2293bc6233fed6703fb6de1b8238a16d5d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889326
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-15 02:07:56 +00:00
Alexandre Courbot
caddede98e virtio: vhost: user: rename VhostUserParams's device_params to device
This is both a shorter and better name for this member.

BUG=b:217480043
TEST=cargo build

Change-Id: I4698fc9c411361837b65d42c4e64516a477eb2a5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889325
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-15 02:07:56 +00:00