Commit graph

1786 commits

Author SHA1 Message Date
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
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
Daniel Verkamp
1eedd1bfb4 fuzz: replace SharedMemory with tempfile
The block, qcow, and zimage fuzzers all created a SharedMemory and then
converted it into a file; with the new base API changes, this is no
longer supported.  Replace the SharedMemory uses with tempfile to fix
the build (this also simplifies the code).

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

Change-Id: I50d4e8c57ed41419c79a3fac440654224696f80c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2463895
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-12 09:45:46 +00:00
Suleiman Souhlal
015c3c1eb9 x86_64: Introduce --no-smt flag.
When set, VCPUs aren't presented to the guest as hyperthreads,
on Intel.

Instead, present them as different, non-hyperthreaded cores on
the same package. Presenting them as hyperthreads might make the
guest scheduler migrate tasks between VCPUs more aggressively,
which can be expensive in a VM.

AMD will need a different CL.

BUG=b:169828263
TEST="cat /proc/sys/kernel/sched_domain/cpu0/domain0/name" in
    the guest returns "MC" instead of "SMT" when starting crosvm
    with --no-smt.

Change-Id: Ifdb4d54a3d7d83c5620fa768ce88ba1a0d85ee50
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2460534
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Suleiman Souhlal <suleiman@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Suleiman Souhlal <suleiman@chromium.org>
2020-10-10 12:10:05 +00:00
Daniel Verkamp
253269b836 docker: update adhd commit to fix kokoro build
Fixes compilation errors:

error[E0308]: mismatched types
   --> devices/src/pci/ac97_bus_master.rs:558:17
    |
558 |                 sample_rate,
    |                 ^^^^^^^^^^^ expected `usize`, found `u32`

BUG=None
TEST=docker/build_crosvm_base.sh && docker/wrapped_smoke_test.sh

Change-Id: Idede11303ff7fd4195bc5fab6cdf2303138a4069
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2462940
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-10 02:08:49 +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
Lepton Wu
2c5dd1b018 readme: add a note about using virtiofs as rootfs.
This is convenient for development.

BUG=None
TEST=None

Change-Id: I2ee06d70a7e47ea1c4de0e9cb54d382cb8b050d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2460862
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Lepton Wu <lepton@chromium.org>
Tested-by: Lepton Wu <lepton@chromium.org>
Auto-Submit: Lepton Wu <lepton@chromium.org>
2020-10-08 17:43:30 +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
A. Cody Schuffelen
3faab5a16e Allow more than 4 virtio-console serial ports.
As these are PCI devices, the guest can handle and dynamically discover
more of these devices.

Test: create a Cuttlefish device with 18 serial ports, check the device IDs
Bug: b/170149708
Change-Id: Ia2ad73b3a05ee885ce222917c72a53b423fde7c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2450455
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-10-07 06:14:31 +00:00
Andrew Walbran
cf014f3554 Add more build dependencies to README.
BUG=None
TEST=sudo apt install ...

Change-Id: Ic30b659049818c673f69068112350687bdf2666e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2452791
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Andrew Walbran <qwandor@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Andrew Walbran <qwandor@google.com>
2020-10-06 18:39:14 +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
Zach Reizner
2c770e6f79 hypervisor: replace RunnableVcpu with VcpuRunHandle
This removes RunnableVcpu as an associated type on Vcpu traits, instead
using the new VcpuRunHandle type to enforce the same guarantees. This
simplifies implementations of Vcpu becuase only one impl is needed with
all the methods provided.

The other advantage to removing RunnableVcpu was that a Vcpu could be
try_cloned, defeating the purpose of consuming the Vcpu in the first
place with to_runnable. The type system and ownership model gave a false
sense of compile time safety. The usage of VcpuRunHandle is more
consistent with the fact that it is a runtime check that the programmer
is doing the safe thing. It's also consistent with all hypervisor impls.

BUG=None
TEST=./build_test

Change-Id: I14bbc5d939744cb92fb9cb3152edb82603cadd11
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2442096
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-03 02:59:54 +00:00
Noah Gold
b0e9842602 Update safety comments for DataInit.
Previously DataInit did not specify that any implementor `T` must not
contain implicit padding, though implementors of DataInit often include
a safety statement mentioning that they have no implicit padding. This
CL updates DataInit to clarify that any implementor must certify it has
no implicit padding to be safe / free of undefined behavior.

BUG=none
TEST=none (comment only change)

Change-Id: Ieddce51949bfa65de65a891deae071a744b0a4ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2439301
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-10-02 04:10:12 +00:00
Gurchetan Singh
cf68ea6f3e crosvm: finish up flexible array wrapper
We added the file, but forgot the flexible array. Fix this.

BUG=chromium:892806
TEST=kvm/hypervisor tests pass, atlas tryjobs pass

Change-Id: Ic52d3c9a9e67f1619151a08d3dd0e879de658066
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2347068
Reviewed-by: Daniel Verkamp <dverkamp@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-02 03:28:07 +00:00
Dylan Reid
0cd3606024 docs: Add note about rust-vmm integration
This is mostly a place holder that will be replaced if and when we
determine a complete plan for consuming crates from rust-vmm.

Change-Id: I8eec6313f40822a887b34d51b462268de5d01fd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2429813
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-10-01 20:43:41 +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