Commit graph

1662 commits

Author SHA1 Message Date
Michael Hoyle
6b19695c81 Add "base" crate and transition crosvm usages to it from sys_util
For now, this crate simply re-exports all of sys_util, but it will
be updated to provide new interfaces when needed. This is the
first step to making crosvm not directly depend on sys_util, so
that we can make the interface changes we need without fear of
negatively affecting (i.e. completely breaking) other usages
within chromeos.

BUG=b:162363783
TEST=./build_test

Change-Id: I7d0aa3d8a1f66af1c7fee8fd649723ef17027150
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2325168
Tested-by: Michael Hoyle <mikehoyle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-08-06 18:19:44 +00:00
Ram Muthiah
b83b48bbe5 x86_64 set bios structures regardless of img type
Regardless of what image type crosvm is running (kernel or bios), the
acpi tables, mptables, and smbios should all be set since they depend
on vm-initialization-time set values like the cpu count and the
available pci devices. The guest should not have to setup these
structs differently based on the crosvm inputs.

BUG=b:161912521
TEST=Booted cuttlefish with and without uboot

Change-Id: I98eb7176a6822769dcfb32d6decab717d08236e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2325254
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Ram Muthiah <rammuthiah@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Ram Muthiah <rammuthiah@google.com>
2020-08-06 08:42:34 +00:00
Steven Richman
24a89faeb3 Fix hypervisor and devices test compilation on ARM
Run unit tests for the old ioapic only on x86.  Fixes use statements in
hypervisor tests.  Run the hypervisor vcpu enable_feature test only on
x86, like in the kvm crate.

TEST=cargo test --no-run --target=aarch64-cros-linux-gnu
TEST=cargo test --no-run --target=aarch64-cros-linux-gnu -p devices
TEST=cargo test --no-run --target=aarch64-cros-linux-gnu -p hypervisor
BUG=1112839

Change-Id: Ie8dc152de6acd37b93e394642208a86a746c9308
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2337151
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Steven Richman <srichman@google.com>
Commit-Queue: Steven Richman <srichman@google.com>
2020-08-06 04:28:37 +00:00
Keiichi Watanabe
156cea0d43 sys_util: Fix all the default clippy warnings
Fix following warnings so that cargo clippy passes under sys_utils:
* new_without_default
* wrong_self_convention
* or_fun_call
* comparison_chain

Note that we still have warnings on other targets such as --tests.

BUG=chromium:1111728
TEST=cargo clippy passes under sys_util directory

Change-Id: I286c4e0386e44a9aba5e78594a6f30c1046ef7ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2331885
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-08-06 03:28:13 +00:00
Keiichi Watanabe
94e8d811a5 sys_util: Fix clippy:missing_safety_doc warnings
BUG=chromium:1111728
TEST=cargo clippy

Change-Id: Ia9727cbf8041d660d219f1df3e0775d6e18e1fe3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2331884
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-08-06 03:28:12 +00:00
Keiichi Watanabe
bb14010332 sys_util: Apply clippy's autofix
Ran the following command under /sys_util/:
`rustup run nightly cargo clippy --fix -Z unstable-options`

BUG=chromium:1111728
TEST=build

Change-Id: I2ecb04f8dea6711c9f0f658185ecdb201ba1f659
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2331883
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-08-06 03:28:09 +00:00
Daniel Verkamp
379702c402 block: only send config interrupt on successful resize
If the resize failed (for example, if the block device was read only),
there is no need to notify the guest of a change in configuration space.
This prevents potential confusion due to the guest printing a capacity
change message even when the resize was unsuccessful.

BUG=None
TEST=`crosvm disk resize` a read-only disk (--disk)

Change-Id: Ica86654bf38d9fae9d681955438f52bce96dc427
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2324063
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-06 02:02:14 +00:00
Chirantan Ekbote
b9966c96c1 devices: Remove lifetime parameter from DescriptorChain
The lifetime parameter on the DescriptorChain struct ensures that it
doesn't outlive the GuestMemory that it references.  However, this has
the unfortunate effect that DescriptorChains cannot be sent across
thread boundaries (because they don't have a static lifetime).

Instead, have the DescriptorChain clone the GuestMemory instead.  This
ensures that the DescriptorChain will not outlive the GuestMemory while
also allowing it to be sent across thread boundaries.

dgreid - re-base and modify `next_async` to remove lifetime as well.

BUG=b:150264042
TEST=unit tests

Change-Id: I745d80d640c9766cbf36db0419c48fe077e0080d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2103601
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-08-05 22:35:16 +00:00
Daniel Verkamp
5f3931874b block: remove unnecessary drop
Clippy warns that this drop is not doing anything:

  error: calls to `std::mem::drop` with a reference instead of an owned
  value. Dropping a reference does nothing.

The code compiles without the drop, and resizing still works, so just
remove it.

BUG=None
TEST=bin/clippy
TEST=`crosvm disk resize 1 $((10*1024*1024*1024)) $SOCKET`

Change-Id: I1abf26fcd517a76b3007b70eb73545812a0dd79a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2324062
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-08-04 23:29:31 +00:00
Andrew Walbran
71b6203652 cros_async: Use preadv64 / pwritev64.
These are identical on 64-bit targets and the right thing on 32-bit
targets if we ever have any. More importantly, they exist in the Android
version of the libc crate while preadv and pwritev don't yet.

BUG=b:158290206
TEST=cargo test

Change-Id: Ic6746c4934e577a871b5f690be015ecf3842f3d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2316157
Tested-by: Andrew Walbran <qwandor@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Auto-Submit: Andrew Walbran <qwandor@google.com>
2020-08-04 14:11:55 +00:00
paulhsia
36067153bf ac97: Skip flaky reg check in unit test
If the builder context switch to other tasks right after the
`bm.writeb`, then the results from `bm.readw` could be unexpected.

BUG=chromium:1086337
TEST=Build

Change-Id: I708b11ad3a556069a7b514f072222e913d91d643
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2330879
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
2020-07-31 23:30:56 +00:00
Daniel Verkamp
1d0f16005d arch: share PCI device IRQs
Allow the caller of generate_pci_root to specify a maximum number of
IRQs to share between all PCI devices, and use this on x86 to limit the
total number of IRQs to fall within the number of interrupts present on
the current kernel APIC implementation.

BUG=b:161745666
BUG=chromium:1109486
TEST=Boot crosvm with many PCI devices

Change-Id: I07f0e4dab97fc952260ecacc2d84c02c77be1309
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2317899
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Lepton Wu <lepton@chromium.org>
2020-07-31 08:29:09 +00:00
Daniel Verkamp
e0d7c8266a clippy: remove set -u to fix errors on older bash
With versions of bash before 4.4 (such as bash 4.3 provided by the cros
sdk), expanding an empty array when `set -u` is in effect causes an
error:

  bin/clippy: line 93: CLIPPY_ARGS[@]: unbound variable

This could be avoided by testing the CLIPPY_ARGS variable before
expanding it, but this is such a small and simple script that removing
`set -u` seems more appropriate.

BUG=chromium:1105466
TEST=`bin/clippy` with no args inside cros_sdk

Change-Id: Id56a99bf23f3d9b97b6b7f8a62dce95f9112caa6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2324061
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-07-31 04:30:18 +00:00
Tiancong Wang
61724a4ce0 fuzzer: Add vm_memory to fuzzer Cargo
After vm_memory was added, the dependency wasn't added. So it
caused crosvm-fuzz fail to build. This patch adds the dependency.

BUG=chromium:1110970
TEST=USE="asan fuzzer" emerge-amd64-generic crosvm

Change-Id: Ic71243365ed8603928ba30bce7b7361ca368bf1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2327870
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Tiancong Wang <tcwang@google.com>
2020-07-30 20:11:52 +00:00
Dylan Reid
be88444c55 disk: Add Asyncdisk Trait
The AsyncDisk Trait will be used by block to issue asynchronous
operations on kernels that support async IO.

TEST=Added unit tests

Cq-Depend: chromium:2265040
Change-Id: I83adb83df278c4d19ac5dd4e5b91fb5bf96d4e89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2306785
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-07-30 03:16:43 +00:00
Dylan Reid
82d7b9f094 vm_memory: Implement cros_async::BackingMemory for GuestMemory
Implementing `BackingMemory` signals that `GuestMemory` regions can be
used in uring transactions where the lifetime in which the kernel can
modify the memory is not well defined.

Change-Id: I3541fff4c5dac226062a94483672f570e7adeb18
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2275725
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
2020-07-28 21:36:21 +00:00
Andrew Walbran
ce64fc06d7 Update version of minijail in Cargo.lock.
Also update the version used in Docker/kokoro.

BUG=None
TEST=cargo test

Cq-Depend: chromium:2315829
Change-Id: I659dd48d9f87c610df9fc3cb0cc05594a4ea7138
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2316158
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Allen Webb <allenwebb@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-28 17:57:45 +00:00
Keiichi Watanabe
d9b8c77e85 crosvm: Add a pre-upload hook to run clippy
BUG=chromium:1105466
TEST=repo upload a CL

Cq-Depend: chromium:2297362
Change-Id: Ibbabaf4d8a1180dcbbe2732b07bcd0a8e38de5f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2303129
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-07-28 16:29:06 +00:00
Keiichi Watanabe
29495300de bin/clippy: Add option to skip cleaning cache
Add --use-cache option in bin/clippy to run cargo-clippy without
deleting cache. It is useful when we use bin/clippy for multiple commits
in pre-upload hook.

BUG=chromium:1105466
TEST=bin/clippy w,w/o --use-cache

Change-Id: I386c7e08ad48ea2446a91e99d4b6523673211d6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2297005
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-07-28 16:29:02 +00:00
Zach Reizner
ff1194a0b5 block: make control_socket optional for worker thread
The Block device constructor takes an optional control_socket, but it
can't spawn worker threads without a control_socket. This change makes
the control_socket truly optional by allowing the worker thread to not
have a control_socket.

BUG=None
TEST=crosvm run && crosvm resize

Change-Id: I887e32cfb532e14c249340702ebc85101486a36e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2318368
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-07-28 12:35:12 +00:00
Daniel Verkamp
f2ea888204 sys_util: use is_null rather than == null_mut
Fixes a clippy warning:

  Comparing with null is better expressed by the `.is_null()` method

BUG=None
TEST=bin/clippy

Change-Id: I04d310107763075bc59fdadf7db8bd3c6f54500b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2317890
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-27 21:36:23 +00:00
Alex Lau
640ef0fdc7 devices: virtio: video: convert VideoError to CmdResponse
This cleanup makes CmdResponse the only response type, rather than
writing VideoErrors directly. In addition, this makes all responses
easily cloneable for async event responses, which was not the case
before as VideoError encapsulates many uncloneable errors.

BUG=b:161774071
BUG=b:140082257
TEST=cargo clippy
TEST=USE=test emerge-$BOARD crosvm
TEST=play a YouTube video

Change-Id: Ife40e4d833899aae2e12612a12d277178c225ce2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311496
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-07-25 11:41:03 +00:00
Alex Lau
1fb6557c86 devices: virtio: video: allow sending multiple async responses on event
This will be used by encoder by allowing multiple responses from a mojo
VEA RequireInputBuffers event, as well as moving virtio-video specific
logic for sending EOS buffers and cancelling pending requests from
Worker::handle_event_resp.

BUG=b:160730771
BUG=b:140082257
TEST=cargo clippy
TEST=USE=test emerge-$BOARD crosvm
TEST=play a YouTube video

Change-Id: I19bce3b04e736aac0e686d9cb309976108e61033
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2309893
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-07-25 11:41:03 +00:00
Alex Lau
4b9b7ea604 devices: virtio: video: Pass DescPool by reference
This does not change any behavior.

BUG=b:140082257
BUG=b:161774071
TEST=cargo clippy
TEST=USE=test emerge-$BOARD crosvm
TEST=deploy and play YouTube video

Change-Id: I3a649ee0657a53deaf8ab40471bb9440b06807e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2305500
Reviewed-by: Alex Lau <alexlau@chromium.org>
Tested-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-07-25 11:41:01 +00:00
Dylan Reid
ec058d6c46 vm_memory: A crate to hold vm-specific memory objects
Move GuestAddress and GuestMemory to a new crate for VM memory. This
will make separating sys_util and crosvm independent making it easier
to use sys_util functions outside of crosvm.

Change-Id: I12e14948ea85754dfa6267b3a3fb32b77ef6796e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311251
Auto-Submit: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-24 21:42:34 +00:00
Dylan Reid
bedfa1edc8 tpm: Update libtpm2 to master
The git submodule needs to be updated to work with newer chroot libssl.

In addition, the new OpenSSL version uses the getrandom syscall, so it
needs to be added to the seccomp policies.

TEST=build_test works again, vm's boot with a --software-tpm

Change-Id: Ie3242e9fa4dba42bf6266e674f987d8c9dbc1dbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2316380
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-07-24 08:08:21 +00:00
Daniel Verkamp
0c40f609d2 gfxstream: remove unused Unsupported error variant
This was introduced in a CL that did not use it, so it seems to be
unnecessary (maybe copy-pasted from another error enum).

Fixes a clippy warning:

  error: variant is never constructed: `Unsupported`

BUG=None
TEST=bin/clippy

Change-Id: Iaccf6c86a5ef9e36efad1053776b6ee2db53a2cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2316379
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-24 05:10:25 +00:00
Lingfeng Yang
d6ac1ab3a7 kvm: allow registering memory from current address space
This is good for enabling non-exportable Vulkan host coherent memory,
along with anything else where an exportable OS object isn't supported.

This CL introduces:

1. ExternalMapping, which wraps an external library mapping using
function callbacks, for purposes of sharing device memory to the guest
in the case where the device memory is not compatible with the mmap interface.
This is common in Vulkan when VkDeviceMemory is host visible but not
external, or external but based on an opaque fd.

The lifetime of the library mapping is tied to the lifetime of the
ExternalMapping.

2. Usually, we would send such memory requests over a socket to the main
thread. However, since these new objects require more metadata than
other requests that are sent over the wire (because there's information
about inheritance and refcounts), we also plumb the "map_request" field,
which wraps a single ExternalMapping.

Note that this ExternalMapping will not work in the sandbox case. In the
sandbox case, we will then have to figure out how to serialize/deserialize
ExternalMapping requests over a socket.

BUG=b/146066070, b/153580313
TEST=compile and test

Change-Id: I3b099b308aec45a313a8278ed6274f9dec66c30b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034029
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-24 00:19:11 +00:00
Lingfeng Yang
29cd3fb4bb Bump display_wl buffer count to 3
may help with backpressure in high fps situations

It was found that display.flip() can take a long time, at least if
framebuffer_region() is called, which causes dropped frames. The idea is
that if the server is still using the frame we may have to wait $omeTime
to get it back for drawing the next one, and the wait can be long
compared to the time to copy.

BUG=b/153580313

Change-Id: I00c50479b40383d2329d7eb714248a7154a22aba
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2224017
Commit-Queue: Lingfeng Yang <lfy@google.com>
Tested-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-23 21:28:29 +00:00
Colin Downs-Razouk
9e0a85e664 devices: pit lazy thread creation
Currently the PIT creates a thread when the Pit object is instantiated,
but this is a problem when sandboxing is enabled, because minijail does
not want to fork when there is more than one thread.

This change updates the PIT to only create the woker thread once the PIT
has been read from or written to.

Split irqchip mode still does not seem to quite work in sandbox mode,
there appears to be some other sort of bug, but when run with the
hypervisor abstraction it does run. So this fix is mostly applicable
once hypervisor abstraction has been integrated.

BUG=chromium:1077058
TEST=ran test VM with --split-irqchip without --disable-sandbox and it
gets further than before, plus ran cargo test -p devices.

Change-Id: Idf511bde825d4a004f1492dcbd27f6829e872735
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2304258
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-07-23 20:38:45 +00:00
Alexandre Courbot
cd0b65f3a5 devices: video: do not request the context several times in a method
In some methods the context was queried several times, which complicates
the code a bit and potentially generates error-handling code that cannot
possibly be used once the context has been successfully obtained once.

Merge all these context requests into a single one for each method.

BUG=b:161774071
TEST=crosvm builds

Change-Id: Ia4a5036a0ed0fd20a928c448e62fdd8e37e8a914
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311497
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-07-23 10:21:26 +00:00
Dylan Reid
fc5220e4df cros_async: Deref U64Source to the inner source
Allow U64Source to Deref to the inner u64 producer. The first user will
be asynchronous timers that that need to rearm the inner timer.

Change-Id: If23b7a03df5ef407ae7a0c1fdc76d460e628727b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2299842
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-07-23 05:22:27 +00:00
Dylan Reid
a70743b271 cros_async: Allow access to inner types of async IO
Users might need to access the inner type of an asynchronous IO object.
This will be needed for fallocate on kernels before 5.6.
Also allow consuming the async object and returning then inner type.
That is needed to allow resetting devices over virtio.

Change-Id: Iae56f6a8bfe56f5b04be47aa5a3e3f32dc22ba15
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2275724
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-07-23 05:22:25 +00:00
Lingfeng Yang
745081a31f gfxstream: Add submit cmd support
Needed for syncfd support (transfer doesnt come with fence
import/export)

Needed for address space graphics protocol on virtio-gpu

BUG=b/156130048

Change-Id: If6f55985f04fd8a2862650b2cbd37a3ab816fb90
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2224015
Commit-Queue: Lingfeng Yang <lfy@google.com>
Tested-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-23 04:15:07 +00:00
Noah Gold
ee02cb6f36 [data_model] VolatileSlice use IoSlice.
Switches from using libc::iovec directly to using our own IoSliceMut.
This also renames IntoIovec to IntoIobuf, along with the associated
methods. Effectively this pushes conversion into iovec closer to
where it is used.

Test: FEATURES=test emerge-eve crosvm
Change-Id: I2f907aa321a43d751a82e8430c74ac08b95772f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2300842
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-07-21 23:20:22 +00:00
Gurchetan Singh
f2b29b8dfb devices: gpu: set scanout blob
Blobs contain explicit metadata about scanout buffers that is
only inferred otherwise. This is useful for possible YUV with
virtio-gpu-2d or compressed 3d formats. The format modifier is
intentionally left out since virtualized KMS can not guarantee
that the host compositor will support a certain modifier at any
particular moment -- this can be queried from virglrenderer if
need be.

BUG=chromium:924405
TEST=compile and test

Change-Id: I3130df18378f40193118b78d03f564b7f5984d67
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2250460
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-07-21 20:59:41 +00:00
Daniel Verkamp
da6a1ddda4 devices: pci: add function to iterate over BARs
The new get_bars() function will be used to find all of the memory
and/or I/O BARs that need to be added to or removed from the bus objects
(mmio_bus and io_bus) and KVM mappings to handle guest-initiated
remapping of BAR locations.

BUG=None
TEST=cargo test -p devices
TEST=Boot vm_kernel in crosvm

Change-Id: Ic559abc2a22dee7c3d5c96d242ceaf2154135eb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2300693
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-21 20:24:34 +00:00
Daniel Verkamp
de0bbc9fab devices: pci: store BAR configurations
This simplifies the code that wants to access per-BAR properties like
size and type; rather than recalculating it from PCI register contents,
it can directly access the data that is already in the desired Rust
types.

BUG=None
TEST=cargo test -p devices pci

Change-Id: I073d39c605899053ad3497c4d0140432b343b793
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2308075
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-21 20:24:33 +00:00
Daniel Verkamp
de06f15777 devices: pci: enforce minimum valid BAR sizes
PCI BARs have a minimum size based on the number of bits reserved for
the type bitfield, which is stored in the low bits of each BAR.  The
minimum size is derived from the number of bits used to store the type:
2 bits (4-byte minimum) for I/O bars and 4 bits (16-byte minimum) for
memory BARs.

Previously, since the minimum size was not enforced, callers could
create invalid configurations that would allow the guest to overwrite
the type bits of the BARs.  Luckily, this only happened in the unit
tests, which are fixed in this change.

BUG=None
TEST=cargo test -p devices

Change-Id: I30d65485254b49655c9ad7bec51e43533fe2c01d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2300692
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-21 20:24:30 +00:00
Keiichi Watanabe
36b2a0df71 crosvm: Fix clippy::needless_doctest_main
We can omit main() function in documantation tests.
cf. https://doc.rust-lang.org/rustdoc/documentation-tests.html#pre-processing-examples

BUG=none
TEST=cargo test
TEST=bin/clippy

Change-Id: Iaad756ac32d106b2b2bcee44c9301244f647f8f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2301675
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-07-21 13:18:10 +00:00
Kaiyi Li
dd348a4407 main: restrict the use of vulkan and syncfd flags
When using vulkan and syncfd in the gpu parameters with backend
other than gfxstream, crosvm should quit with error messages.

BUG=None
TEST=cargo test --features=gpu,gfxstream

Change-Id: I63c3634598297450ab31f1c1d50c24a0d143e80d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2295841
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Auto-Submit: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-21 06:39:23 +00:00
Zach Reizner
94d77df61c enable core scheduling with the chromeos feature
This change includes support for core scheduling in sys_util and the
usage of it within the vcpu threads.

Because the core scheduling prctl is not yet stabilized, this feature is
specific to Chrome OS for now. To indicate this, the new "chromeos"
feature has been added to the appropriate Cargo.toml files.

TEST=cargo build --features "chromeos plugin"
BUG=b:153989878

Change-Id: I8b6ce00b26c482739536b632f08e55264dc513a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2284184
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-07-21 02:19:51 +00:00
Dylan Reid
39a4354895 cros_async: Expose MemRegion to users
Allow users outside this crate to build MemRegions to user with
asynchronous IO.

Change-Id: Ia95f7c27cc5816181f61ca73641bec6fc11a0e3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2275723
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-07-20 01:40:46 +00:00
Dylan Reid
68ef7cfc9a cros_async: Skip zero length reads and writes
Sometimes the guest asks to read or write zero bytes. Skip sending that
to the kernel as it is a no-op.

Change-Id: I67ac3cd75551b994517eedb02830b3ea9451fb15
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2275722
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-07-20 01:40:44 +00:00
Daniel Verkamp
9affaf1ae0 cros_async: handle errors in synch fallocate/fsync
This incidentally fixes the clippy warnings about passing a unit value
to a function in the Ok(s.fallocate(...)) and Ok(s.fsync()) calls.

BUG=None
TEST=cd cros_async; cargo test

Change-Id: I75af11720bdff9b935453f0d75b528222183b33a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2304473
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-07-18 23:03:51 +00:00
Alex Lau
4c02765473 docker: update platform2 commit for libvda changes
BUG=None
TEST=docker/build_crosvm_base.sh && docker/wrapped_smoke_test.sh

Change-Id: Ie63d1628e790bb4a8f4314e2882159838b4acf3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2299605
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-07-18 07:52:57 +00:00
Alex Lau
6fc81e1cd1 crosvm: Fix H264 profile conversion in decoder.
Decoder currently ends up converting from H264 baseline profile provided
by virtio-video to H264 main profile to libvda.

BUG=b:161421220
BUG=b:140082257
TEST=cargo clippy
TEST=emerge-$BOARD dev-rust/libvda crosvm, start arcvm and play video in YouTube

Cq-Depend: chromium:2299802, chromium:2299604
Change-Id: I946af99b918b22b4dcb0e9ebab044c83f39ed9bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2301325
Tested-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-07-17 23:21:13 +00:00
Alex Lau
48a494bafd crosvm: Add missing virtio-video profiles and convert to correct virtio profile in decoder.
Add missing virtio-video profiles and convert to them from libvda profiles.

BUG=b:161261612
BUG=b:140082257
TEST=cargo clippy
TEST=emerge-$BOARD dev-rust/libvda crosvm, start arcvm and play video in YouTube

Cq-Depend: chromium:2299802, chromium:2301325
Change-Id: I061c7eddc881eb785aa7c06cf587cc747007cb74
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2299604
Reviewed-by: Alex Lau <alexlau@chromium.org>
Tested-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-07-17 23:21:11 +00:00
Chirantan Ekbote
2135787b74 devices: fs: Support FS_IOC_{GET,SET}FLAGS
Needed by arcvm.

BUG=b:159870893
TEST=`lsattr foo` and `chattr +S foo` inside a VM.  Check with strace
     that it's making the ioctl.

Cq-Depend: chromium:2297090
Change-Id: I11b490062b3c777c0cf4543f3d09f94e3790453b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2297004
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Lepton Wu <lepton@chromium.org>
2020-07-17 22:30:32 +00:00
Dylan Reid
becca3722d io_uring: handle EBUSY from uring_enter
enter can fail if there are too many pending ops. This will return
EBUSY. The user will have to handle some completions before trying
again. Only count sqes as submitted by resetting self.added when enter
returns success.

The number of sqes must also be guarded if too many are added before the
kernel can update the head pointer.

TEST=added ebusy unit test

Change-Id: I0c20677f1332732aab09f025e110eca0c2a42500
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2296699
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-07-17 15:06:15 +00:00