Commit graph

1647 commits

Author SHA1 Message Date
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
Daniel Verkamp
05b13d0eff kvm: return removed memory region
When a memory region is added to the guest, ownership is passed to the
Vm object.  However, it was not possible to get the memory region back
when removing it from the Vm.  Update the return type of
remove_memory_region so that the original boxed memory region can be
returned to the caller.

BUG=None
TEST=cargo test -p kvm

Change-Id: Ie39a57e0c037ed25a603865cb3dce1af1478e143
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2300840
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-07-17 11:16:42 +00:00
Daniel Verkamp
f4f8f86873 Fix new clippy warnings from Rust 1.45.0
Fix a few instances of and_then(Ok(...)) in syslog:
https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map

And an unused (overwritten) variable assignment in the argument tests.

BUG=None
TEST=docker/wrapped_smoke_test.sh

Change-Id: Id59b1749fd7eba1fe7dfeb7938ecbbc9d0f9aa6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2303275
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-07-17 06:49:30 +00:00
Dylan Reid
eef1c93fdc uring/async: Add fsync and fallocate
These will be needed by by block.
Note that support for uring fallocate was added in 5.6. The users will
have to handle falling back to synchronous calls if fallocate returns
EINVAL.

BUG=901139
TEST=added fallocate unit tests

Change-Id: I51d635adcf0bb4dd55c5bfe50719f2fde2b88e49
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2274996
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-07-17 06:13:17 +00:00
Dylan Reid
bae84398e5 sys_util: Move set_errno to the only place it's used
Move the OS specific errno handling to the handle_eintr test code which
is the only place that uses it.

The function was already only compiled for test code and the ifdefs have
started to spread with the added android support. Moving the code to the
test that uses it makes it more obvious that it is test-only code.

TEST=cargo test passes

Change-Id: I9fea1bb30052c0edc41c9609e2698221daefa580
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2296828
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-07-17 00:50:43 +00:00
Lepton Wu
ff7796372b seccomp: x86_64: Allow fstat for video device
libvda depends minigbm, on amdgpu, minigbm calls dri_init
to check GPU type. dri_init calls drmGetRenderDeviceNameFromFd
in libdrm which calls fstat.

BUG=b:161376212
TEST=manual - Run arcvm on grunt

Change-Id: I3dcb723711030d25e85cf3cac4cc7c66e0e2077f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2301439
Commit-Queue: Lepton Wu <lepton@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Lepton Wu <lepton@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Lepton Wu <lepton@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-07-17 00:48:12 +00:00
Colin Downs-Razouk
e00cd6826c devices: irqchip: kvm: route and event issues
Fixes for several bugs found in the KvmKernelIrqChip and the
KvmSplitIrqChip that were found while testing the hypervisor abstraction
layer integration:
  - Fixed determination of which routes are MSI routes when setting
  routes in KVM.
  - Fixed issue with setting conflicting routes.
  - Updated service_irq_event to read the associated EventFd that
  triggered the irq event, and updated the documentation. Also updated
  KvmKernelIrqChip's implementation to simply print an error because
  that function should never be called on KvmKernelIrqChip.
  - Fixed a bug with add_vcpu in both KvmKernelIrqChip and
  KvmSplitIrqChip.

BUG=chromium:1077058
TEST=added a new test, ran devices tests, ran a VM with abstraction
  integration changes with both irqchips

Change-Id: I255fbe498f6586d90cb196ff173a574a2cae0453
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2300843
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-07-16 21:13:28 +00:00
Andrew Scull
1590e6fb3e Add feature flag for audio.
This will allow it to be disabled for Protected KVM usecases on Android.

BUG=b:158290206
TEST=cargo test

Change-Id: Ibddd8a98c42bb0847aba804f5e33df29feedd783
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2292372
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2020-07-16 17:57:55 +00:00
Andrew Walbran
67448289e5 Use platform abstraction around libc::__errno_location.
It has a different name on Android.

BUG=b:158290206
TEST=cargo test

Change-Id: I424d0ddf24c008a06570c709354c7c2dd9395738
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2294865
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2020-07-16 13:34:19 +00:00
Colin Downs-Razouk
fe368791f8 devices: irqchip: KvmSplitIrqChip impl
Implementation of a KVM split irqchip. KVM's "split irqchip"
functionality only works for x86/x86_64 so this is implemented in the
kvm/x86_64.rs sub-module. The chip has a userspace Pic, Ioapic, and Pit.

This change necessitated a couple modifications to the irqchip traits:
  - The create_pit function has been removed, and it's now implied that
  the creation of the irqchip handles the creation of the pit.
  - A finalize_devices function has been added. This function will need
  to be called on the irqchip after all devices have been setup. The
  purpose of finalize_devices is to allow the irqchip to register any
  userspace devices with the io_bus or mmio_bus, and for the irqchip to
  supply any necessary EventFds to these devices.
  - A service_irq_event function has been added. This function works a
  lot like the service_irq function, except it's specifically designed
  to work the same way an IRQFD works: it first asserts then immediately
  deasserts the line. If a resamplefd is associated with the irq line,
  the deassert doesn't happen immediately, but happens when an EOI
  occurs for a vector associated with the line. The service_irq function
  will still exist for unittests.
  - A process_delayed_irq_events function has been added. There
  is a case where a deadlock can occur if the main thread blocks on
  locking the ioapic in order to service an irq event, while a vcpu
  thread holding the ioapic lock waits on the main thread to process the
  addition of a MSI route. So the irqchip delays the servicing of irq
  events if it finds a locked ioapic, and the
  process_delayed_irq_events function should be called regularly
  by the main thread in order to re-try servicing any delayed irq events.

Bug: chromium:1077058
Test: split irqchip runs all available x86-specific irqchip tests.
  Also added some tests specific for the split irqchip. Ran these tests
  and cargo test -p hypervisor -p devices

Change-Id: I14866645b86b3bf318440051069ff165e2cf9d88
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2290192
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-07-16 00:45:31 +00:00
Nicholas Verne
71e73d847e crosvm: Support UnixDatagram sockets for serial output.
BUG=chromium:1053847
TEST=Listen to the socket from VmLogForwarder, observer messages
forwarded into separate output file.

Change-Id: Ia472e34b78db599e91f63e72a13bf8539d0d6312
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2287077
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Nicholas Verne <nverne@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Auto-Submit: Nicholas Verne <nverne@chromium.org>
2020-07-16 00:05:19 +00:00
Gurchetan Singh
7b652a3011 devices: gpu: send back map response
To validate caching from the host.

BUG=chromium:924405
TEST=compile and test

Change-Id: I3292c938df442d1162ad994103ba3fd7e6f2f16c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2160032
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-07-15 23:54:19 +00:00
Victor Hsieh
fe863ad1bc p9: fix lcreate to respect the open mode
lcreate is not just used for creat(2), but open(2) as well. So it is
possible that the read/write mode is specified manually.

BUG=chromium:1105484
TEST=Run the test program in the bug. Read returns 0 like on other
     filesystem.

Change-Id: I4fb642deb09831f00d3bd83e973e8a42c54ec5d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2297228
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Victor Hsieh <victorhsieh@chromium.org>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2020-07-15 22:15:14 +00:00
Andrew Walbran
e43468f066 sys_util: Add IoctlNr type, as different platforms use different types.
In particular, Android targets use c_int whereas normal Linux targets
use c_ulong. An ioctl number should always fit in 16 bits, so casting
from c_uint (as bindgen uses for the constants) to either other type
should be safe.

BUG=b:158290206
TEST=cargo test

Change-Id: I3d808ba9a5588a75c029a299e3609d97e328e3cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2288229
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Andrew Walbran <qwandor@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-07-15 19:10:23 +00:00
Ram Muthiah
d7c1591e54 x86_64 configure_vcpu handles image type
Regardless of what image type crosvm is running, it must set the cpuid
since the cpuid is not set by software. This missing setting was
preventing uboot from jumping to the 64 bit kernel since it thought
the cpu was not long mode capable.

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

Change-Id: Ib8902b324532daf2a0e8ff462603207ff0c64bad
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2298171
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Ram Muthiah <rammuthiah@google.com>
2020-07-15 16:36:16 +00:00
Chirantan Ekbote
906b43c5c9 cros_async: Make raw waker Send + Sync
std::task::Waker unconditionally implements Send + Sync so the raw waker
that we provide also must implement those traits.  Switch to using an
Arc<AtomicBool>.

This also fixes an inconsistency where the waker was defined to be an
Rc<Cell<bool>> but all the vtable functions were treating as an
Rc<AtomicBool>.

To reduce the vtable boilerplate use the ArcWake trait from the futures
crate.

BUG=none
TEST=unit tests

Change-Id: I3870e4d7f6ce0de9f6ac3313a2f4474ae29018b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2287079
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-07-15 09:28:23 +00:00