Commit graph

1809 commits

Author SHA1 Message Date
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
Steven Richman
ce33acefff hypervisor: add vcpu methods: id, nmi, window off
New Vcpu methods get the vcpu ID for a vcpu and the current thread.
A new VcpuX86_64 method injects NMIs. request_interrupt_window now
takes a bool parameter, so the request window flag can be turned off.

These methods are to support the userspace irqchip. The thread-local
vcpu ID will help route MMIO requests to the appropriate APIC. Clearing
the interrupt window request is needed because KVM won't clear the
flag if the kernel APIC is disabled.

BUG=chromium:1077058
TEST=boots with KVM kernel irqchip, KVM split irqchip

Change-Id: I2a08988e71663f0d2a63985f3239568c7a9befea
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2419673
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-11-05 03:24:36 +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
Colin Downs-Razouk
e5774c3a8b hypervisor: userspace ioevent changes
For hypervisors that do not handle ioevents in-kernel, we need to make
some minor adjustments to the hypervisor abstraction api:
  - register/unregister_ioevents needs &mut self instead of &self
  - move handle_io_events from Vcpu to Vm, because the ioevents are
  registered on the Vm not the Vcpu.

BUG=chromium:1077058
TEST=cargo test -p hypervisor

Change-Id: Iddd61502a716143e117c454e64a9c9bd2578148d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2405299
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:11 +00:00
Daniel Verkamp
6c987cf924 fuzz: block_fuzzer: remove use of AsRawFd
The Event API has changed so that it exposes only RawDescriptor, not
RawFd, so the block fuzzer's use of as_raw_fd() no longer worked.

The actual intent of the code using as_raw_fd() was to clone the Event,
so just use the existing Event::try_clone function which achieves the
same result without using platform-specific code.

BUG=chromium:1144535
TEST=`FEATURES=test USE='asan fuzzer' emerge-amd64-generic crosvm`

Change-Id: I64689dde1b1351997aa2f11ed440416e3d226815
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2514901
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-03 03:32:24 +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
4694cd31c6 base: Remove AsRawFd from SharedMemory
Just another small step towards AsRawDescriptor universal
usage.

BUG=b:162363783
TEST=./build_test

Change-Id: I370f6dbeec10b9e4df75e5e4a5258c4d00a0ac9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2488724
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-10-31 07:12:34 +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
Daniel Verkamp
0b0dd364ff fuzz: block_fuzzer: add new base_features arg
virtio::base_features() now takes an argument to indicate whether the
protected VM feature is enabled; update the block fuzzer to match.

BUG=chromium:1142959
TEST=`FEATURES=test USE='asan fuzzer' emerge-amd64-generic crosvm`

Change-Id: I79de47d2bfff8705a4d35c6d978c1d08b36d0db7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2508468
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-10-30 20:15:47 +00:00
Alexandre Courbot
23be1ee5f8 msg_socket: use is_empty() instead of testing for zero-length
This makes clippy happy and compilation goes without warning.

BUG=None
TEST=crosvm builds.

Change-Id: Iacfca0615f055ce333baf135900b3bd04bcd29f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2505274
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-10-29 19:25:03 +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
Colin Downs-Razouk
b428fa1c15 hypervisor: allow shared MemSlotOrd
Move MemSlotOrd out of the kvm hypervisor implementation so other
implementations can share the same struct.

BUG=chromium:1077058
TEST=cargo test -p hypervisor

Change-Id: I9d992699defab53e32517bb40e29192e31c45983
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2405301
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-10-28 05:37:33 +00:00
Daniel Verkamp
4060eb5cd4 resources: add allocator sets for mixed low/high
This will allow allocating an MMIO region that can be in the high (>4G)
address space, but prefers to be in the low region if possible.

BUG=b:169430664
TEST=Boot Crostini with GPU

Change-Id: If90c0d90c95b0dcb3cb451eb7f573eede5ea3b2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2436370
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-10-28 05:01:46 +00:00
Daniel Verkamp
59865d4af4 arch: allocate all IO BARs before device BARs
This will allow IO BARs that need to be in the low (32-bit) memory
region to be allocated first, followed by device BARs, allowing device
BARs to be allocated in the low 32 bits of address space when possible.

BUG=b:169430664
TEST=Boot Crostini with GPU enabled

Change-Id: I5387b1e00ed6d5cbcff7b25e10f6115ff797c85b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2436369
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-28 05:01:44 +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
Dennis Kempin
a5262a177f acpi_tables: Add test case for reading SDT data from files
Seemed like an easy test to add.

BUG=b:171082843
TEST=This is a test

Change-Id: I2a10c0965be2952cd3150965e4127a27a3ec6dff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2495844
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
2020-10-27 05:22:34 +00:00
Dennis Kempin
831b11e869 Add scripts to run code coverage
One script to run coverage for the whole smoke test suite,
the resulting file can be uploaded to codecov.io for consumption:
https://codecov.io/gh/denniskempin/crosvm

Another script to run tests + coverage for a single crate,
which is useful during development to keep track of coverage
while adding tests (IDEs can display the generated lcov.info file)

BUG=b:171082843
TEST=Manual testing of both scripts

Change-Id: I52384762400a146cb0e7deb3d54dccf59b6134db
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2492914
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
2020-10-27 05:22:32 +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
Fergus Dall
efb2186785 crosvm: Suppress useless error messages when creating serial device
When creating a serial device of type UnixSocket crosvm will race with
vmlog_forwarder to bind a socket to the address. This is expected to
fail in most cases, so don't log an error message if it does unless
the reason was unexpected.

BUG=none
TEST=Booted termina and checked for logs about failing to bind sockets

Disallow-Recycled-Builds: test-failures
Change-Id: I446dd803662de57221b501a6f87957035c4593de
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2494321
Tested-by: Fergus Dall <sidereal@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Fergus Dall <sidereal@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-10-24 01:47:39 +00:00
Daniel Verkamp
55ef29aaa3 disk: qcow: fix write_zeroes with backing file
The qcow disk format implemented the discard and write zeroes requests
by deallocating the underlying cluster when possible, with the
assumption that a deallocated cluster would return all zeroes if it is
read until it is written again.

Add an alternate implementation of write_zeroes that is used when a
backing file is present that uses the straightforward approach of
allocating all clusters and zeroing them out in the raw file rather than
using deallocation.

BUG=b:171230599
TEST=BLKZEROOUT test case
TEST=cargo test -p disk

Change-Id: I745f6dc7aa411ec9b1be0150ba1bc96c011ada9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2490605
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-23 21:26:10 +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
Noah Gold
7cc7c233a7 Simplify read_u64 for UringSource.
When using uring, we can just call `read_to_vec` rather than having to
call `libc::read`. Unfortunately, PollSource cannot do the same without
hitting an illegal seek (e.g. with eventfds), so we still have to keep
the read_u64 method around.

BUG=None
TEST=`cargo test` in `cros_async`.

Change-Id: I2c61468bec4a3f130c153eccf2875c047c61a2a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2482430
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-10-22 07:39:10 +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
Noah Gold
abf9f6e969 Remove unneeded type parameter on async traits.
The compiler & clippy weirdly didn't flag these type parameters &
constraints as unused. This CL removes them.

BUG=None
TEST=builds

Change-Id: I435f73957e7243628d7a0b0e73c1d543f410bb98
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2488846
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-10-22 07:08:22 +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
John Bates
0405973907 devices: gpu: enable the shader disk cache with new mesa default
A new build option for Mesa allows it to be built with support
for the disk cache but with it disabled by default. The
MESA_GLSL_CACHE_DISABLE environment variable must be set to
false to enable it in that case.

BUG=b:168540438
TEST=run with --gpu=cache-path=/tmp,cache-size=50M and
     confirm that files are created in /tmp/mesa_shader_cache.

Change-Id: I456e224ec4d2d8ed1f20689706ff4752b5706bb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2485901
Tested-by: John Bates <jbates@chromium.org>
Auto-Submit: John Bates <jbates@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Commit-Queue: John Bates <jbates@chromium.org>
2020-10-21 18:01:11 +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
Daniel Verkamp
298f1724a1 fuzz: adapt block_fuzzer for Block::new features param
The Block::new() function now requires the base virtio features to be
passed as the first parameter; add it to the block fuzzer to fix the
fuzzer build.

BUG=chromium:1139427
TEST=`FEATURES=test USE='asan fuzz' emerge-amd64-generic crosvm`

Change-Id: Ia8afd1e38b7bb2bf55dfc18805684e3c462e66a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477250
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-10-18 03:27:28 +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
Will Deacon
6560c18e8b crosvm: Introduce a '--protected-vm' parameter for protected guests
Extensions to KVM will allow guests to run in a mode where the host
has limited access to their memory, requiring Linux guests to use
bounce-buffering for transferring data to/from the host.

Introduce an experimental '--protected-vm' option to crosvm, which
for now just forces the use of bounce-buffering in the guest by
appending "swiotlb=force" to the kernel command line.

BUG=None
TEST=./build_test

Change-Id: Id01e2ed50fe3c242af2e85279b26e08d6230669c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2453559
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-16 01:36:10 +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
Zach Reizner
ab04758814 build_test: misc options, improvements, amd bug fixes
New option, --size-only, speeds up using build_test for getting release
binary size by skipping everything else. The lto flag is also added for
release builds to get a more realistic comparison.

The list of crates to test is built up automatically instead of
hard coded. To modify what gets included, empty .build_test_* files are
checked for existance. This is better than hard coding the list of
packages because it was frequently out of date.

For certain crate tests, a dynamic library that only exists in a sysroot
is required. This change includes a fix that adds the sysroot's lib
directory to the LD_LIBRARY_PATH env variable, similar to how
PKG_CONFIG_LIBDIR is modified.

TEST=build_test
BUG=None

Change-Id: I626cbcccf40035a0d29001cef7989a091848e4c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2444273
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-10-15 13:40:32 +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
David Stevens
e341d0ab7b Expand video sandboxing for AMD devices
BUG=b:170062417
TEST=tast run grunt-DUT arc.Boot.vm and no resource bridge logspam

Change-Id: I84e185c4507b8df6b09505a369f09933d3d6143f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2461149
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2020-10-14 16:17:17 +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