Commit graph

672 commits

Author SHA1 Message Date
Alexandre Courbot
828150b5d4 devices/video/decoder: use decoder format type in DecoderDevice
Replace the libvda profile type by the more generic crosvm format type
to make this part of the interface portable.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: Ia0eb210278e4e4d945a4caa304c072ce68771440
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477404
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
2020-11-05 04:24:19 +00:00
Alexandre Courbot
3bb00ba75e devices/video/decoder: return VideoResult from DecoderDevice
Replace libvda::Result by the more generic VideoResult in the
DecoderDevice interface. Since all callers of the interface ended up
converting libvda errors into VideoErrors anyway, this turns out to be a
better fit.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: Idc3be76ab312c95b9d234550270adef44ea86f3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477403
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-11-05 04:24:18 +00:00
Alexandre Courbot
673b9cea79 devices/video/decoder: introduce DecoderBackend interface
The virtio video decoder was working directly with libvda to
provide the video decoding service to the guest. In the future we may
want to add other ways of providing decoding support, like
software-based decoding (useful for testing the virtio device and the
guest support), or direct decoding using the host's native capabilities.

Introduce a DecoderBackend interface that the decoder will use to
perform the actual decoding, and start moving the libvda-related code as
an implementation of it. At the moment the interface still uses libvda
types for parameters and return values for the purpose of keeping the
change simple, but we will replace them in the subsequent changes.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: I9d47cc934d34a0c706c2112831e827b6b1aa5d0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2460526
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-11-05 04:24:17 +00:00
Chirantan Ekbote
75ba87522b p9: Support ascii casefolding
Enable ascii casefold support for the 9p server when requested on the
command line.  Needed by arcvm.

BUG=b:162388795
TEST=`stat foo.txt` and `stat FoO.TXt` return identical results even
     though only foo.txt exists

Cq-Depend: chromium:2498170
Change-Id: Icf507ac0d8413e7794fdd643296d507781897039
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2501545
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-11-04 14:37:45 +00:00
Chirantan Ekbote
2449288cc8 devices: p9: Update for API change
The p9 crate API changed so that the new() function now returns a
result.  Update the caller to match.

Additionally, the implementation also changed to use different syscalls
so update the seccomp filters to match.

BUG=b:162388795
TEST=Start a vm with a 9p mount and test the changed operations to make
     sure they still work.

Cq-Depend: chromium:2494169
Change-Id: I7c4e1fd2fb192206402e895b09e519c3e769ae3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2494328
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-11-04 14:37:23 +00:00
Jason Macnak
046ed143a7 devices: gpu: gfxstream: Add ANGLE flag for Gfxstream
... to allow configuring Gfxstream host renderer based
on whether or not the guest Android is using ANGLE as
its native OpenGL driver.

BUG=b:165022040
TEST=launch_cvd --gpu_mode=gfxstream

Change-Id: I566ed1e7590f7f3db99960440421fd65bba08f7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2466604
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Jason Macnak <natsu@google.com>
2020-11-04 06:13:49 +00:00
David Staessens
0c4bba741a crosvm: Increase maximum resolution in virtio video encoder.
This CL increases the maximum resolution in the virtio video encoder
from 1920x1080 to 4096x4096. While devices are typically not able to do
realtime encoding in huge resolutions, they are usually still supported
by the HW encoder.

BUG=b:168262411
TEST=Record using Camera test app in 1600x1200 resolution on hatch

Change-Id: I62bdead25861dd3384d7c9d8ad1a8877e5af3215
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2508094
Reviewed-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Staessens <dstaessens@chromium.org>
Commit-Queue: David Staessens <dstaessens@chromium.org>
2020-11-04 05:53:11 +00:00
Dennis Kempin
336a9ef925 pl030: Add simple tests
This CL justs adds two very simple tests to improve overall test coverage.

Not sure what the best practices would be for mocking out the system
time, so I have skipped that functionality for now.

BUG=b:171750410
TEST=No change in functionality, just an added test.

Change-Id: I7a4e99c9d11203c5569ff28d2a5477bf8fd1b3a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2500948
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2020-11-04 00:28:11 +00:00
Steven Richman
0c47e9441e devices: irqchip: register events in IOAPIC
Previously the caller of ioapic::new was responsible for calling
register_irq_event on the IOAPIC's outgoing events.  The MSI IrqRoutes
for these outgoing events used the same GSIs < 24 as the incoming
PIC/IOAPIC routes.

This worked for the split irqchip, because PIC/IOAPIC events are handled
in userspace and MSI events in the kernel, so there was no confusion
about which route an event should use.  But with the userspace irqchip,
the routes have to be differentiated, otherwise incoming and outgoing
IOAPIC events with the same GSI trigger each other in a loop.  Also,
registering all outgoing IOAPIC events upfront increased the number of
irq event tokens by 24, even though only a few outgoing events are used.

Now the IOAPIC is responsible for registering outgoing events and it
allocates new GSIs >= 24 for its MSI routes.  An event and route are
only set up when a redirection table entry is configured with non-zero
MSI data.

BUG=chromium:1077058
TES=boots with split irqchip

Change-Id: I87c1df6150d50205810759ef152e1c9b33bcfe4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2419672
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-11-03 21:15:14 +00:00
Colin Downs-Razouk
bd5327620d devices: irqchip: handle multiple events per irq
There were some assumptions built into the hypervisor abstraction
implementations that we would only ever be registering a single Event
for any irq number, but that is no longer the case since 1d0f160. So
this change updates the hypervisor abstraction trait functions to allow
callers of irq_event_tokens to distinguish between multiple events that
refer to the same irq number using an IrqEventIndex. This index is then
used when calling service_irq_event.

Also, if register_irq_event would add a new irq event that the main
thread should wait on, register_irq_event will return the associated
IrqEventIndex. This change also updates linux.rs to use these changes.

The --split-irqchip mode may work even without this fix, depending on
which devices are sharing irqs. If the devices using shared irqs are all
virtio pci devices they may switch to MSIx mode and then not need their
original interrupt event.

BUG=chromium:1077058
TEST=disabled MSI mode on pci devices, forced additional irq sharing,
  and verified that --split-irqchip mode still works + cargo test -p
  devices

Change-Id: I4feb2817b6c477284ad463c0221d1f156813b6ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2405300
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-11-03 21:15:13 +00:00
Victor Hsieh
fe8a4ba74b fuse: Replace split_at in the Writer trait with write_at
This simplies the complexity to deal with ownership and mutability,
while considering both the virtio-fs and regular FUSE use cases.

BUG=b:168305155
TEST=./build_test

Change-Id: Ic77d8e0b922e74a5733b99eeff41946177666c8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2500944
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2020-11-03 00:14:08 +00:00
Michael Hoyle
6a0960a4a7 base: First steps towards universal RawDescriptor
This involves removing RawFd trait implementations from
Event and Timer, and resolving the echoing dependencies from
there.

Ultimately, this results mostly in changes across ioctl
(new thin layer in base), kvm, msg_on_socket, and a few other
areas. As usual, most changes are negligible.

BUG=b:162363783
TEST=./build_test

Change-Id: I47dec94666bc3430fed627b4767919c9cb4fce6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2462330
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-31 07:12:34 +00:00
Michael Hoyle
e392c46953 base: Add WaitContext
This is a layer above PollContext with a more generic interface.
As PollContext is used so widely, this is quite a large change
in order to accomodate the interface update, especially with the
use of RawDescriptor. In some cases this has caused an echo
of updates to RawDescriptor, which is fine because of our eventual
goal to move the whole codebase to it regardless.

Note there are a few instances of forcing the RawDescriptor update
chain to stop, ex. ioctl. This is to keep the scope of this CL
concentrated and avoid changing entire other areas.

Note that this CL leaves out a few additional pieces of work:
 - The sole usage of EpollContext over PollContext (event_loop),
which poses a bigger challenge for interface changes
 - Full PollToken renaming, which is a tiny change turned difficult
due to the unavailability of type aliases for traits.
 - Renaming certain methods which have been updated to use
RawDescriptor such as keep_fds. Some have enough dependencies that
they are worth avoiding to keep this CL pointed, but will be
addressed in future CLs to make sure the whole codebase is on the
fd->descriptor train

BUG=b:162363783
TEST=./build_test

Change-Id: Iff2cfe8f90dea55f1388f8e91bdc698e121a8e43
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2455726
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-31 07:12:30 +00:00
Chih-Yu Huang
bd27bd0eac virtio: video: Only clear output resource after ProvidePictureBuffers()
At CL:2494322, we moved the clearing output resources logic from
handle_provide_picture_buffers() to clear_queue(). That CL only
considered the resolution change case, but didn't handle the flush
case correctly.

When the userspace flush the decoding, it streamoff the output queue.
But VDA doesn't request new set of buffers, ProvidePictureBuffers()
won't be called. In this case, crosvm shouldn't clear the output
resources. Crosvm only needs to clear the set of queued resource ids.

Also, when VDA sends ProvidePictureBuffers() the first time, V4L2
output queue at the userspace is not streaming. So the userspace won't
streamoff the output queue. In this case, we also don't need to clear
the output resources.

BUG=b:171860073
TEST=pass android.media.cts.MediaCodecTest#testDecodeAfterFlush
TEST=pass android.media.cts.AdaptivePlaybackTest

Change-Id: I2a425c1fd9e61322d92dc54930dd88242c964de3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2505284
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
2020-10-29 12:56:30 +00:00
Noah Gold
d4ca29b5d9 Restore default virtio features for virtio-input.
A prior CL (@81d5adbad7) removed VIRTIO_F_VERSION_1 from the features on
virtio-input, which causes boot failures on VMs that require those input
devices. This CL pipes protected-vm down to virtio-input & restores the
features.

BUG=none
TEST=builds

Change-Id: Ic54c7135c3ed4abf4c9d0a2c6969a0abaef7e7b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2503486
Auto-Submit: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Will Deacon <willdeacon@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-28 06:50:55 +00:00
Victor Hsieh
bae88f4f65 fuse: extract FUSE as a crate from virtio/fs
The current crate still require some work to be really reusable as a
regular FUSE, i.e. with a new reader/writer against /dev/fuse. This
change intends to focus on creating the crate, without trying to find
the optimal interface, and still keep virtio/fs working.

BUG=b:168305155
TEST=./build_test
TEST=USE='asan fuzzer' emerge-hatch crosvm

Change-Id: I8b623c9262221113b720c10125a6770763f14dc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2466484
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2020-10-27 16:18:51 +00:00
Chih-Yu Huang
8ba5fc9819 virtio: video: clear output resources when the output queue is cleared
Originally, we clear all the output resources when getting
ProvidePictureBuffers command from VDA. At this point only VDA
discards the output buffers. crosvm should keep the output resources
until the output queue is cleared.

Note that at crrev.com/c/2494602, GAVDA will ignore the output buffers
after calling ProvidePictureBuffers(). So it's safe that crosvm passes
the output buffers after getting ProvidePictureBuffers command.

BUG=b:171442927
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP9_adaptiveDrc

Change-Id: I54dd364e7509c18fb3a3cd193da97dd107ceec44
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2494322
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-26 06:34:08 +00:00
Alex Lau
e29e95e9b2 devices: virtio: video: Implement video encoder device
BUG=b:140082257
TEST=emerge-$BOARD crosvm
TEST=v4l2-encoder-sample
TEST=tast run DUT arc.VideoEncodeAccel.h264_192p_i420_vm after crrev.com/c/2256525 (on hatch and eve)

Change-Id: I7f1c1bb6a8ba192ab7a598227e59fc9ec307ad8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2167311
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-10-23 08:47:44 +00:00
Alexandre Courbot
11376b0959 devices/video/decoder: remove unneeded reference to session key
The argument passed to get() and get_mut() is already a reference, so we
don't need to add another redirection to it.

BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: I0d299c284c00b68160676332dcf5387aed078b7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2484062
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-10-22 07:21:43 +00:00
Daniel Verkamp
4a401cce0c devices: virtio: block: disable EVENT_IDX feature
This disables the VIRTIO_RING_F_EVENT_IDX optimization, which seems to
be causing I/O to sometimes not complete when used with the Linux virtio
block guest driver.  The exact root cause is not clear (possibly a
race/memory ordering issue when reading and updating the event index),
but disabling the feature flag is enough to get back to a reliable state
while the failure is debugged.

The particular test case that triggers this typically reproduces as a
hung task in btrfs waiting for an I/O completion that never shows up.
With the EVENT_IDX feature disabled, I am not able to reproduce the hang
after many hours of running the test case.

BUG=chromium:1097385
TEST=Run reproducer test case; do not observe any hung tasks

Change-Id: Iaf37722f23c05276ec65f4d4a10c4a47af764538
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2486671
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-21 21:47:44 +00:00
Will Deacon
7d2b8ac342 devices: virtio: Advertise VIRTIO_F_ACCESS_PLATFORM for protected VMs
Virtio 1.1 introduces the VIRTIO_F_ACCESS_PLATFORM reserved feature bit,
which allows the guest operating system to discover that a virtio device
has limited access to memory. In the case of Linux, this forces the use
of the DMA API for virtio transfers, which in turn can bounce data
through a shared window that is negotiated between the guest and the
hypervisor.

Advertise the VIRTIO_F_ACCESS_PLATFORM reserved feature bit when crosvm
is running with the '--protected-vm' option.

BUG=None
TEST=./build_test

Change-Id: I78e8d9e78999790059639b64611b8081c39d24ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2453560
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-10-21 19:01:47 +00:00
Victor Hsieh
02d190c783 device: virtio: fs: Stop using bytes_written
bytes_written is a method of virtio::descriptor_utils::Writer. In order
to decouple from virtio, replace it and count the bytes inside the fuse
server.

Also replace some write_obj with write_all that were missed in 7ab6aac8.

BUG=b:168305155
TEST=./build_test

Change-Id: Ib38d13b317f5bca2b5549215f4cd7c2ffb975339
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477248
Reviewed-by: Victor Hsieh <victorhsieh@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2020-10-20 21:04:54 +00:00
Michael Hoyle
3038e40a6b base: Refactor mmap to use builder pattern.
BUG=b:165423256
TEST=./build_test

Change-Id: Ia67c1a7fe29b66c9cab38476eecde8c25a55617b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2442569
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-16 07:15:24 +00:00
A. Cody Schuffelen
00c392ae47 Use larger read buffers for virtio-console.
This improves performance on high-throughput virtio-console
communication.

Test: Run together with https://android-review.googlesource.com/c/device/google/cuttlefish/+/1459363
Bug: b/155695742
Change-Id: I78062f648ee18040c80ace109ab4d62e8ee1fbca
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2470376
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-10-16 04:36:42 +00:00
Noah Gold
5767987e5f Replace PollOrRing w/ async trait IoSourceExt.
This CL makes the following fundamental changes to cros_async:
1. Removes PollOrRing and replaces it with IoSourceExt, and the
   subtraits ReadAsync & WriteAsync. The blanket implementation of
   IoSourceExt has been dropped, and replaced with source specific
   implementations of the trait. Those implementations are where
   the code from PollOrRing has been moved.
2. Pinning for IoSource has been dropped from UringSource & the uring
   futures. This appears to be safe because the IoSource doesn't contain
   any self refs, or perform any operations beyond forwarding to the
   RegisteredSource. (The FD is duped before being passed to
   RingWakerState by RegisteredSource, so there doesn't seem to be any
   data which would require pinning.)
3. U64Source was replaced by EventAsync.

It also switches all Error enums to use thiserror, which reduces
boilerplate.

BUG=None
TEST=cargo test -p cros_async

Cq-Depend: chromium:2421742
Change-Id: Ie1dd958da2e1f8dec1ae1fd8c0b4e754223d330d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2416996
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-10-16 02:15:40 +00:00
David Stevens
157fa0fdb2 devices: virtio: video: don't close output fds
libvda takes ownership of output fds, so don't maintain ownership and
attempt to close them within the decoder device.

Closing output fds twice was benign if the decoder device performed
the second close. However, if the decoder device closed an fd while
libvda's IPC thread was processing the fd, then the IPC thread's failure
to close the fd would trigger an assert. Note that because fds are
recycled, this could happen when the decoder was processing either
bitstream or output fds.

BUG=b:169535727, b:170451397
TEST=android.media.cts.AdaptivePlaybackTest#testVP8*

Change-Id: I06c5b7d117dc4057cbd01bdb90167f7f23ab336e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2473978
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2020-10-16 00:37:06 +00:00
Will Deacon
81d5adbad7 devices: virtio: Consolidate reserved feature bits into free function
All virtio devices pass VIRTIO_F_VERSION_1 explicitly. In preparation
for passing additional reserved feature bits, introduce a free function
so that devices only have to worry about device-specific features.

BUG=None
TEST=./build_test

Change-Id: Ifcf309fa010ea518b17b047b0e95e5ad5c7522bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2453558
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Will Deacon <willdeacon@google.com>
2020-10-15 14:56:58 +00:00
Zach Reizner
304e731cdb make hypervisor traits object safe
This allows code to create references to traits such as `&dyn Vcpu` for
`&dyn IrqChip`. This also allows keeping such traits inside of opaque
`Box` like wrappers.

To achieve this, trait methods referencing `Self` have an additonal
`where` clause that restricts them to sized types. Associated types are
removed and replaced with their trait equivalents (as parameters) or an
opaque Box (as return values).

To work around certain cases where a concrete type is needed, such as
for KVM based `IrqChip` impls, the `downcast_rs` trait is used to allow
`dynamic_cast` style casting.

The binary size impact of this change is small. For comparison, here is
the size change with this commit:

armv7a  -0.49% (-9 kiB)
aarch64 -0.17% (-3 kiB)
x86_64  +1.77% (+40 KiB)

BUG=None
TEST=build_test

Cq-Depend: chromium:2466660
Change-Id: I1a408734832d2971ea2979c1bc64b2ffe051b02d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2439298
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-10-15 14:31:20 +00:00
Victor Hsieh
7ab6aac800 device: fs: replace read_obj with from_reader in server
BUG=b:168305155
TEST=./build_test

Change-Id: I6874c325ef0f614e449fb3177ba5edb8dc0f3364
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2469501
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Victor Hsieh <victorhsieh@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-10-14 23:15:31 +00:00
David Stevens
27fdbba0d2 devices: virtio: video: Ensure failures are logged
BUG=b:170062417
TEST=Compiles

Change-Id: I12236ce7cb5498086f9ede0e3c3de4aff7d4b78e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2461150
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2020-10-14 16:17:19 +00:00
Chih-Yu Huang
65687c376b virtio: video: call set_output_buffer_count() just before passing the first buffer
GAVDA checks if the client sends any buffer between 2
AssignPictureBuffers() call. To guarantee crosvm always passes buffers
after AssignPictureBuffers() call, this CL moves the call just before
passing the first buffer to VDA session.

BUG=b:168557465
TEST=run android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrcEarlyEos
     and not see GAVDA's error log mentioned at commit message

Change-Id: I777ff914688ea589a4cf8921fc05ad59d3161b5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2463052
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-14 05:27:27 +00:00
Chih-Yu Huang
3db25abe21 virtio: video: Check queue type when cancelling Clear tag
AsyncCmdTag::Clear tag contains the queue type information. This CL
checks if the queue type matches the target when cancelling the
command.

BUG=b:168557465
TEST=android.media.cts.AdaptivePlaybackTest#testVP8_flushConfigureDrc

Change-Id: I8960ebaebc48c4fffbc8aaa326edeab449284c09
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437685
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-10-14 05:27:26 +00:00
Noah Gold
ee71c80b08 Mark MsgSocket as !Sync.
Semantically, MsgSocket is !Sync: multiple threads reading/writing to
the same end of the socket will result in U.B.. This CL brings the
syntactic definition of MsgSocket in line with its semantic meaning by
marking it as !Sync. While earlier work caught one of the other
consumers that was using a socket end in a Sync manner, this CL has
found another: the usb crate.

The fixes proposed for the usb crate are mostly for compilation's sake,
and should have little material effect on the operation of crosvm. Note
that they will assure correctness, since the send/recv for the socket
end involved are in the same critical section.

BUG=None
TEST=builds

Change-Id: I38469d9ed3228a43457b7d43879a6b4fff97b9a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2466960
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-10-14 01:36:09 +00:00
David Stevens
0b668f6054 devices: gpu: send resource info response for blobs
BUG=b:169212117
TEST=Play YouTube in ARCVM

Change-Id: Ica6cb900a939a368e3a73d739616d4f55c92c6f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2430874
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2020-10-12 18:16:39 +00:00
Gurchetan Singh
79bf5c6151 devices: virtio: gpu: rustify error handling
- Reduces lone error! statements
- Reduces the number of match arms

BUG=b:169212117
TEST=compile and run gpu

Change-Id: I8eac2f1dd93e058a50212e33e4379dd96df9f184
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2462552
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-10-12 18:16:37 +00:00
Chirantan Ekbote
b696d4feb2 fs: Don't use path-based operations
There are no *at variants for the xattr syscalls so we were using the
path-based variants by reading the /proc/self/fd symlink.  While this
symlink can track renames it cannot track if the user hard links the
file to some other location and then unlinks the original location.  In
this case the symlink simply shows that the path was deleted even though
the fd is still valid.

To deal with this, stop using the path-based method.  For regular files
and directories, we can simply open them and then make the appropriate
f{get,set,list,remove}xattr syscall.  For non-regular files and
directories we can emulate an *at syscall by changing the CWD to /proc
and then making the path-based syscall via the self/fd path.  Even
though the symlink is no longer valid, manipulating the fd via this path
still works.

BUG=b:168689429
TEST=Create a file, set an xattr, hard link it to a new location,
     unlink the original, and then verify that {get,set}fattr still
     works on the new link

Change-Id: Ic291f432b96f18e3e7ccbcf27737d5f8fd240a65
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437684
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-10-12 15:45:19 +00:00
Judy Hsiao
03cd6684c9 ac97: Support multi sample rate for playback
Enables VRA mode to support different sample rates for playback.
With the change, the resampling can be reduced in the GuestOS.

BUG=b:168082107
TEST=`sox -n -t s16 -c2 -r${RATE} synth sine 440 vol 0.1\
      | aplay -D hw:0,0 -r${RATE} -f S16_LE -c2` works
      correctly in the GuestOS.

Cq-Depend: chromium:2434114
Change-Id: I7d254173d41ac6b4688894113808785de9162b50
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2399167
Tested-by: Judy Hsiao <judyhsiao@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Judy Hsiao <judyhsiao@chromium.org>
Auto-Submit: Judy Hsiao <judyhsiao@chromium.org>
2020-10-09 12:59:33 +00:00
Alex Lau
aba864281b devices: virtio: video: Re-add queue_type to AsyncCmdTag::Clear
The queue_type field was removed in crrev.com/c/2408597 as
decoder is no longer using it, but it will be used by the encoder.

BUG=b:140082257
TEST=USE=test emerge-$BOARD crosvm

Change-Id: Iae552cc05b82eea67a7cff854ba350fb579a8f5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2456226
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-10-08 19:49:00 +00:00
David Stevens
32f4c4cfdd devices: virtio: video: cancel after clearing output queue
A recently introduced workaround for a VDA limitation caused clearing
the output queue to be handled synchronously instead of going through
the Async path used when clearing the input queue. This change makes
sure that we still cancel any pending resources on the output queue.

BUG=b:170053625
TEST=arc.VideoDecodeAccelPerf.vp9_2160p_60fps_vm 20 times w/o warnings

Change-Id: Ib24bdc3053c40ffb6f953021f29ef7a31ea216a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2452313
Tested-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2020-10-07 09:59:25 +00:00
Michael Hoyle
685316f0bd base: EventFd -> Event renaming
Note the CL size is large entirely due to the rename,
the changes are mostly negligible.

Also making a few small additional changes in sys_util
areas that don't need much attention in base. This includes
typedefing and adding specific imports for areas that don't
require significant interface changes.

BUG=b:162363783
TEST=./build_test

Change-Id: I4a2c9c4cdce7565806ed338e241c6b8c82c855c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2415180
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-06 13:50:09 +00:00
Chih-Yu Huang
8683e8e0a9 devices: virtio: video: handle ResourceDestroyAll for in/out queue separately
Originally we clear all the fields about both input and output
resource when either input or output queue gets ResourceDestroyAll
command.

In this CL, we handle this command for the input or output queue
separately.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrc

Change-Id: Ib7873a8192e9e0d01d6ea869eb8ea8661b6d1060
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2417793
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-01 18:53:46 +00:00
Chih-Yu Huang
0ebb18ce3f devices: virtio: video: split InputResources out of Context struct
At crrev.com/c/2416067 we split OutputResources out of Context struct.
Similiarly, this CL splits the fields that related to the input
resource to a dedicated struct `InputResources`.

Note that the field `res_id_to_res_handle` was shared by both input
and output resources. This CL split this field into both InputResources
and OutputResources struct.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrc

Change-Id: I664815078e08f1e78ec9de2f6674dbdedd7fd482
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2428486
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-01 18:53:45 +00:00
Chih-Yu Huang
7f880974e5 devices: virtio: video: re-design the methods of OutputResources
At crrev.com/c/2416067 we split the fields that are related to output
resource from Context struct out to OutputResources struct. Also, we
move the methods that only interact with these fields to the
OutputResources's implementation. However, these methods are designed
from the aspect of Context struct, not OutputResources.

In this CL, we re-design the method of OutputResources to make the
interaction between Context and OutputResources more clear.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrc

Change-Id: Ib9a3fad8e0d71159c07ce5345b067a2c9924a119
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2417791
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-01 18:53:44 +00:00
Chih-Yu Huang
3c77612eb3 devices: virtio: video: split OutputResources out of Context
Some fields of the `Context` struct are related to the output
resources. These fields should be cleared together. This CL
consolidates these fields to another struct to make the code clear.

Note that we add `keep_resources` and `set_output_buffer_count` fields
into OutputResources struct. Originally these two fields are not
cleared with other fields together. So this CL is not just a refactor
CL, it changes the reset logic.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrc

Change-Id: I6843e835b6c488e74623704618ee54a5273eb7ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2416067
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-01 18:53:43 +00:00
Daniel Verkamp
10154a9310 devices: vfio: use separate MSI and MSI-X sockets
Previously, the VFIO code was using a single IRQ VM control socket
within an Arc<> container for both MSI and MSI-X; however, MsgSocket is
not technically Sync.  In order to remove the Sync trait from MsgSocket,
split the MSI and MSI-X uses into two separate sockets and remove the
Arc wrapper.

BUG=None
TEST=./build_test

Change-Id: Ib620521be3d02bc9b66c1cc771c34feb8622993c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2436399
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-09-30 20:08:13 +00:00
Michael Hoyle
08d86a44a0 base: Add timer package
Very little of substance is added here, just the base boilerplate

BUG=b:162363783
TEST=./build_test

Change-Id: I2e3b3b45cf1d7234784d769b4dced31f10a8774d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2366110
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-09-30 19:44:42 +00:00
Michael Hoyle
a7e38ab421 base: Add shared memory layer to base.
This is very largely boilerplate, but changes some interfaces
to accept different parameters, esp using Descriptor.

BUG=b:162363783
TEST=./build_test

Change-Id: I81b513c0de9448c2de505fe5d3a61a29f4eccb78
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2342591
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-09-30 19:44:40 +00:00
Chirantan Ekbote
48537d43b6 fs: Reduce unnecessary map lookups
Change the inner helper methods to take an &InodeData instead of an
Inode.  This removes the need to fetch the data from the map, which can
reduce unnecessary lookups when the calling method already has the data
on hand.

BUG=none
TEST=cargo test

Change-Id: Ia57a543e68d7aa63544f187bdefefe5a4d20c6a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437683
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-30 15:02:29 +00:00
Chirantan Ekbote
e367a1d0a4 fs: Drop unnecessary extra readdir function
Now that readdirplus is handled by the server there's no need to have a
separate do_readdir method. Just merge it into the readdir method.

BUG=none
TEST=cargo test

Change-Id: I77475a64a13316bfbcd97a91610c6aa2ec0a9aae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437682
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-30 15:02:28 +00:00
Chirantan Ekbote
53377a8495 fs: Add helper functions for common operations
Add helper functions for common operations so that we don't have to
copy-paste the same thing everywhere.

BUG=none
TEST=cargo test

Change-Id: Ia9dd132336470cdaa5ecef72945f23f6d1dd4401
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437681
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-30 15:02:25 +00:00