Commit graph

1106 commits

Author SHA1 Message Date
Daniel Verkamp
ff783c3b7d docker: update ADHD commit to fix kokoro build
https://crrev.com/c/1856586 uses a new audio_streams interface but did
not update the revision used in kokoro/docker builds to match.  Update
it to fix the crosvm kokoro builder.

BUG=None
TEST=docker/wrapped_smoke_test.sh

Change-Id: I12fda23861aad4b5a12eda79298ac507382188a5
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1876831
Reviewed-by: Fletcher Woodruff <fletcherw@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-10-25 23:54:12 +00:00
Daniel Verkamp
7f64f5030b descriptor_utils: check for size overflow in new()
Move the check for length overflow that was in available_bytes() into
Reader::new() and Writer::new().  This simplifies callers, since they
can assume that once a valid Reader or Writer has been constructed,
available_bytes() cannot fail.  Since we are walking the descriptor
chain during new() anyway, this extra check should be essentially free.

BUG=None
TEST=cargo test -p devices descriptor_utils

Change-Id: Ibeb1defd3728e7b71356650094b0885f3419ed47
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1873142
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-10-25 17:49:40 +00:00
Daniel Verkamp
67bdbc1a57 fuzz: block_fuzzer: add msix_config to activate
Fix fuzzer build after the VirtioDevice activate() API change requiring
the msix_config parameter.

BUG=chromium:1017954
TEST=`USE='asan fuzzer' emerge-nami crosvm`

Change-Id: I1bd63369e7d112ee55265747a88d64e6545e572a
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1880137
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
2019-10-25 05:18:59 +00:00
Xiong Zhang
a5d248c863 devices: implement MSI control socket
Allocate per device VmMsi msg_socket for communication between virtio
devices and main VM process, which owns the KVM fd and issues ioctl to
KVM for KVM_IRQFD and KVM_SET_GSI_ROUTING.

BUG=chromium:854765
TEST=None

Change-Id: Ie1c81534912eaab7fbf05b5edef7dca343db301c
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1828339
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-10-24 20:46:41 +00:00
Zide Chen
d6be9614ba devices: finish the functions to enable MSI-X
- add a new field "vector" to struct Queue, which represents the entry
  number to the MSI-X Table. This can be used to find out the desired irqfd
  to inject MSI-X interrupts to the guest.
- enable MSI-X when MSI-X Enable bit of the Message Control word is
  being set: allocate irqfd per MSI-X vector; register the irqfd to KVM;
  update GSI routing to KVM.
- update GSI routing if the Message Data or Message Addr of individual
  MSI-X table Entry is being changed in run time.

BUG=chromium:854765
TEST=cargo test -p devices

Change-Id: I81533999ab6cd9ec5f111b256caf34077a4a7d1a
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1828338
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-10-24 20:46:40 +00:00
Zide Chen
1f20497b86 devices: implement MsixConfig struct and generic MSI-X functions
The MsixConfig struct is responsible for all the operations of MSI-X
Capability Structure and MSI-X Table.

A msix_config object is created for each virtio device.

BUG=chromium:854765
TEST=cargo test -p devices

Change-Id: Ide7c34d335d49a201f20b0a4307bcda97d1d61b7
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1828337
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-10-24 20:46:39 +00:00
Zide Chen
1d15851b27 devices: implement msix capability structure
The MSI-X feature is ported from Cloud-hypervisor commit 69e27288a2e.
(https://github.com/intel/cloud-hypervisor.git)

In this commit:

- add a new "msix" module to the pci crate.
- implement the MSI-X Capability Structure.
- implement per virtio device msix_vectors() function which represents the
  supported MSI-X vector for this device.

BUG=chromium:854765
TEST=launch Crosvm on eve and Linux
TEST=cargo test -p devices
TEST=./bin/clippy
TEST=./build_test.py --x86_64-sysroot /build/eve

Change-Id: I5498b15a3bf115e34764e6610407b3ba204dae7f
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1873356
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-10-24 20:46:37 +00:00
Chirantan Ekbote
1955fd1fb3 fuzz: Add virtqueue fuzzer
BUG=none
TEST=Run it with cros_fuzz

Cq-Depend: chromium:1863177, chromium:1863178
Change-Id: I1a989d7b90116e210a8aae63205c5e8cf6b70faa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1863889
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
2019-10-24 15:23:29 +00:00
David Stevens
f60d367467 gpu_renderer: fix fd leak on export failure
BUG=None
TEST=arcvm boots

Change-Id: Id5d3bb422fcaa4906d1a6dfca2f98269d1bafc2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1847537
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2019-10-24 02:19:10 +00:00
Daniel Verkamp
7154c0f1e3 fuzz: remove misleading block fuzzer comment
This looks like it's copied from the qcow fuzzer, and it doesn't apply
to the block fuzzer.  The actual behavior of the block fuzzer is
correctly described by the comment later in the file.

BUG=None
TEST=`USE='asan fuzzer' emerge-nami crosvm`

Change-Id: I9ccd6deba44af8b8df471ee0078ace385696151f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1853698
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-24 00:06:54 +00:00
Matt Delco
193d684046 plugin: only pause on EINTR
In the case of 1) an IO exit & callout to plugin, then 2) a pause
request by another thread, the vcpu thread will eagerly check for a
pause request and might cause another callout to the plugin for the
pause.  We haven't yet run KVM again for it to emulate the completion of
the IO.  It's probably less risky to call back into KVM again and let it
finish the emulation before we callout to the plugin to make other
potential state changes to the VM.  This change also reduces the
overhead of the non-pause case by not checking for a pause request on
each VM exit.

The tradeoff is that a pause request might take longer, but these are
(or should be) relatively rare so it's better to slow these down (and be
more conserative/sane about the state of the VM when pause is reported)
in favor of making the non-pause VM exits faster.

BUG=None
TEST=Local build and run of "build_test".

Change-Id: I38609eccd9a2196835f99de5ea84a586928fab30
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1863725
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-10-23 22:20:19 +00:00
Matt Delco
4ad168c0d7 crosvm: add support for immediate exit
Adds ability to set the immediate exit bit and ask kvm if it's
supported.

BUG=None
TEST=local compile and test

Change-Id: I5c58a5920ebda13267efeb079c0bb671f83464ee
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1847857
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-10-23 22:20:15 +00:00
Matt Delco
30de32f2af plugin: rename signal call
There was a rename of the signal handler function for rt
signals.  This renames the plugin use to be consistent with the
non-plugin case.

BUG=None.
TEST=Local compile.

Change-Id: I5bf2e19754183022dbfe31fd1fdeceb83e07c18a
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1846680
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-10-23 22:20:03 +00:00
Daniel Verkamp
af18794da4 usb_util: use sys_util::vec_with_array_field
Drop the copy of vec_with_array_field now that it is available in a
common location.

BUG=None
TEST=cargo build

Change-Id: Ia272803737a4cb3e4e84213c48aa8e28c17bab2c
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865680
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-10-23 21:03:24 +00:00
David Stevens
f3c160e241 gpu_buffer: remove dead code
This code was left behind when BackedBuffer was removed.

BUG=none
TEST=compile

Change-Id: I450a98af8a2cbea1f86e4fd825f054f7853f7a18
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1847538
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2019-10-23 14:02:05 +00:00
Dylan Reid
47e05fa29b arch: Remove unused CrateMmioDevice Error
Change-Id: I138d709dcea8b7902f3469ae203fd453c13506dd
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1873688
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-23 10:19:53 +00:00
Matt Delco
893c1200dd crosvm: defer IPC on set calls
If a plugin makes a set call on vcpu registers then we
can improve performance by deferring the IPC and instead
conbining the request with the next resume call.

BUG=None
TEST=build and run.

Change-Id: I4eb54a3f6eb30c98971aa2f099e3ea5899767eed
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1825262
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-10-23 06:22:00 +00:00
Matt Delco
3156937410 crosvm: delete resume response from protobuf
The resume response was deleted in a earlier change.  This change
removes the message type from the proto file and adjusts crosvm
so it can still build after this removal.

BUG=None
TEST=build and run.

Change-Id: I27d36a51b1e7eb59258d23da38199b86d7cb3659
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1825260
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-10-23 06:21:58 +00:00
Chirantan Ekbote
4fad33b679 descriptor_utils: Consume all buffers when reading or writing
The consume function in both the read and write methods should consume
all the VolatileSlices that are given to it rather than just the first
one.  The previous implementation was not wrong, just inefficient.  This
should fix that.

Also add a test to make sure that this doesn't regress in the future.

BUG=none
TEST=unit tests

Change-Id: I02ec22269cdd6cdc329dd62367b99352a4dc1245
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865271
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-10-23 03:22:13 +00:00
Zide Chen
aef6e53ed9 virtio-net: reduce number of virtual interrupts to the guest
It's quite costly to inject virtual interrupt to the guest, especially
in INTx case.

To reduce the number of interrupts, in process_rx(), we don't have to
inject interrupt on every frame, but wait until process_rx() finishes
processing all frames.

On eve, iperf3 gets ~15% improvement, "iperf3 -R" gets ~30% improvement.

BUG=chromium:854765
TEST=iperf3 on eve and Linux

Change-Id: Ie0560d8f42235d2371addb6de34c5f93d11a405f
Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865021
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
2019-10-22 21:09:33 +00:00
Fletcher Woodruff
95dbad3db6 ac97: add sample format to create_*_stream
The audio_streams interface now supports specifying a sample format.
Update call sites to indicate that the desired format is S16LE.

BUG=chromium:1010667
TEST=aplay within vm

Cq-Depend: chromium:1856646
Change-Id: Ib69ff9b39196905f0f429eaf771f6f92901bfc71
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1856586
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Fletcher Woodruff <fletcherw@chromium.org>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
2019-10-22 20:57:08 +00:00
Daniel Verkamp
187fd02b59 Cargo.lock: update rust-protobuf to 2.8.1
This is the latest version of rust-protobuf at the moment, and it
includes fixes so that the generated code no longer triggers rustc
warnings about missing `dyn` specifiers on trait objects.

Note that Cargo.lock is unused in normal Chrome OS builds; this only
affects other environments like running `cargo build` directly.

This change was generated using:

  cargo update -p protobuf -p protoc-rust --precise 2.8.1

BUG=chromium:1015571
TEST=cargo check --features=plugin

Change-Id: Id1ea387be70ef81ae62b6d39f99d85d48c938d58
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1869552
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-22 19:13:14 +00:00
Daniel Verkamp
e09ac979c5 plugin: add missing #include <string.h> in test
Fixes warnings during test build:

  <stdin>: In function 'main':
  <stdin>:52:17: warning: implicit declaration of function 'strerror'
  [-Wimplicit-function-declaration]
  <stdin>:70:9: warning: implicit declaration of function 'memcmp'
  [-Wimplicit-function-declaration]

BUG=None
TEST=docker/wrapped_smoke_test.sh

Change-Id: Ibec87db4ca289bec9b1a2c7080fdefebb6e86158
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1863822
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-22 00:09:26 +00:00
Daniel Verkamp
b05e3a5035 docker: add DRM to upgrade_checkout_commits.sh
The DRM repository was added to checkout_commits.env without a
corresponding addition in upgrade_checkout_commits.sh.  Add it and
upgrade all repositories.

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

Change-Id: Iee7ae7005284cb3b7d0e8e8c983d4ef381781f8e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1863821
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-22 00:09:24 +00:00
Daniel Verkamp
1769b63686 bin/fmt: remove use of cargo fmt
This simplifies our formatting script so that it does not need any of
the Cargo metadata to run; the new version just finds all Rust files
(*.rs) and runs `rustfmt` on them individually.

BUG=None
TEST=bin/fmt
TEST=bin/fmt --check

Change-Id: I45aaee497d4f1dfcc03b3e2c5c2f27feb974dc80
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865371
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-10-21 19:26:04 +00:00
Daniel Verkamp
3be01bd505 devices: vhost: simplify vhost imports
Rather than using `use ::vhost::...` to disambiguate the imports, remove
the conflicting `use virtio_sys::vhost` and add `virtio_sys::` to each
location that used `vhost::...` previously.

The `use ::vhost::...` syntax confuses rustfmt when run directly on
these two files, causing it to rewrite the imports into something that
doesn't actually compile.

BUG=None
TEST=rustfmt --check devices/src/virtio/vhost/net.rs
TEST=rustfmt --check devices/src/virtio/vhost/vsock.rs

Change-Id: I8483f5327a1e2b3ae4887f0b3cef20a917d7410e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865370
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-10-21 19:26:03 +00:00
Daniel Verkamp
cfb7db44eb fuzz: add USB descriptor parsing fuzzer
The new USB descriptor parsing code is a nice candidate for a fuzzer,
since it takes an arbitrary stream of bytes as input and parses it.

BUG=chromium:987833
TEST=`USE='asan fuzzer' emerge-nami crosvm`

Cq-Depend: chromium:1863465
Change-Id: I3bbdbf081e9a9dd590c781467f8bd44fa1dcab64
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1862117
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-17 23:22:08 +00:00
Daniel Verkamp
92568c9c27 Reformat with rustfmt from Rust 1.38.0
This just removes a few extraneous blank lines that the new rustfmt
doesn't like.

BUG=None
TEST=bin/fmt --check

Change-Id: I4482f873bdfe19f2f73f86cfdd99d6cce873593c
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1863000
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-10-17 03:35:36 +00:00
Daniel Verkamp
130fbbe71d Add explicit dyn for trait objects
Fix "trait objects without an explicit `dyn` are deprecated" warnings
introduced in Rust 1.38.

BUG=None
TEST=emerge-nami crosvm

Change-Id: I8ca6aa747475268ae898adddd5d091d401326ceb
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1862999
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-17 03:35:35 +00:00
Daniel Verkamp
6494117e17 usb: replace libusb with Rust usb_util library
Drop the dependency on libusb and reimplement the host USB backend using
usb_sys to wrap the Linux usbdevfs ioctls.

This allows sandboxing to work without any dependency on libusb patches,
and it gives us the flexibility to modify and update the USB backend
without depending on an external third-party library.

BUG=chromium:987833
TEST=`adb logcat` on nami with Nexus 5 attached
TEST=deploy app to phone with Android Studio
TEST=Run EdgeTPU USB accelerator demo (including DFU mode transition)

Cq-Depend: chromium:1773695
Change-Id: I4321c2b6142caac15f48f197795a37d59d268831
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1783601
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-17 00:20:24 +00:00
Xiong Zhang
bed8b0017d vfio: Add msi support
crosvm doesn't support MSI/MSI-x, but kvmgt vgpu support MSI only
through cfg msi capability. This is a simple msi implementation, it
detects msi capability and track msi control, data and address info, then
call vfio kernel to enable / disable msi interrupt.

Currently it supports one vetor per MSI. It could extend to multi vetors and
MSI-x.

BUG=chromium:992270
TEST=none

Change-Id: I04fc95f23a07f9698237c014d9f909d011f447ef
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581142
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-10-17 00:17:07 +00:00
Daniel Verkamp
04a82c7be1 devices: vfio: fix clippy warnings
Fix boxed_local, const_static_lifetime, useless_format, and
redundant_closure clippy warnings in the VFIO code.

This fixes all clippy warnings except a single instance of
let_and_return in VfioPciDevice::keep_fds(), since that code is modified
in an upcoming patch.

BUG=None
TEST=./build_test.py
TEST=bin/clippy

Change-Id: I548adbc6b92448fc0db82ed72214d73b0eabaf5c
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1822697
Reviewed-by: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-17 00:17:05 +00:00
Chirantan Ekbote
a7b75c8a21 rust-toolchain: Change to stable
We end up using newer features of the language pretty much as soon as
they hit stable so have a toolchain version that's older than the latest
stable will quickly break.

Also, cargo doesn't install any extra components for this named
toolchain (rls, rust-analysis) and it's not immediately obvious why
things stopped working.

Instead, change the toolchain file to say stable to avoid these issues.

BUG=none
TEST=none

Change-Id: I9c02b64a1bb0175a2c7fd70702328e4082819b91
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1863894
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2019-10-16 22:12:41 +00:00
Chirantan Ekbote
99e6a6fb1f devices: fs: Add fuse constants and struct definitions
Add the constants and struct definitions from the kernel fuse interface.
These bindings are manually generated from `include/uapi/linux/fuse.h`
in the kernel repo.

BUG=b:136128319
TEST=none;  these aren't used anywhere yet

Change-Id: I03d11bc55eca6b8269f1e63a1187ef458ee16f28
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1705655
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2019-10-16 06:53:47 +00:00
Chirantan Ekbote
b5964164c4 devices: Refactor DescriptorChainConsumer, Reader, and Writer
Refactor the Reader and Writer implementations for DescriptorChains.
This has several changes:

  * Change the DescriptorChainConsumer to keep a
    VecDeque<VolatileSlice> instead of an iterator.  This delegates the
    fiddly business of sub-slicing chunks of memory to the VolatileSlice
    implementation.
  * Read in the entire DescriptorChain once when the Reader or Writer is
    first constructed.  This allows us to validate the DescriptorChain
    in the beginning rather than having to deal with an invalid
    DescriptorChain in the middle of the device operating on it.
    Combined with the check that enforces the ordering of read/write
    descriptors in a previous change we can be sure that the entire
    descriptor chain that we have copied in is valid.
  * Add a new `split_at` method so that we can split the Reader/Writer
    into multiple pieces, each responsible for reading/writing a
    separate part of the DescriptorChain.  This is particularly useful
    for implementing zero-copy data transfer as we sometimes need to
    write the data first and then update an earlier part of the buffer
    with the number of bytes written.
  * Stop caching the available bytes in the DescriptorChain.  The
    previous implementation iterated over the remaining descriptors in
    the chain and then only updated the cached value.  If a mis-behaving
    guest then changed one of the later descriptors, the cached value
    would no longer be valid.
  * Check for integer overflow when calculating the number of bytes
    available in the chain.  A guest could fill a chain with five 1GB
    descriptors and cause an integer overflow on a 32-bit machine.
    This would previously crash the device process since we compile with
    integer overflow checks enabled but it would be better to return an
    error instead.
  * Clean up the Read/Write impls.  Having 2 different functions called
    `read`, with different behavior is just confusing.  Consolidate on
    the Read/Write traits from `std::io`.
  * Change the `read_to` and `write_from` functions to be generic over
    types that implement `FileReadWriteVolatile` since we are not
    allowed to assume that it's safe to call read or write on something
    just because it implements `AsRawFd`.  Also add `*at` variants that
    read or write to a particular offset rather than the kernel offset.
  * Change the callback passed to the `consume` function of
    `DescriptorChainConsumer` to take a `&[VolatileSlice]` instead.
    This way we can use the `*vectored` versions of some methods to
    reduce the number of I/O syscalls we need to make.
  * Change the `Result` types that are returned.  Functions that perform
    I/O return an `io::Result`.  Functions that only work on guest
    memory return a `guest_memory::Result`.  This makes it easier to
    inter-operate with the functions from `std::io`.
  * Change some u64/u32 parameters to usize to avoid having to convert
    back and forth between the two in various places.

BUG=b:136128319
TEST=unit tests

Change-Id: I15102f7b4035d66b5ce0891df42b656411e8279f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1757240
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-10-15 18:26:29 +00:00
Xiong Zhang
2515b75630 vm_control: Add VmIrqRequest Socket
When vfio device's msi/msi-x or virtio device's msi-x is enabled,
its irq routing info should be notified to kvm. But this is a runtime
vm service call, so vm_control is used to call vm service.

VmIrqRequest->AllocateOneMsi() is used to allocate one gsi for a msi
and a msi-x vector, and link gsi with irqfd through vm->register_irqfd.
The orignal interrupt_evt and interrupt_resample_interrupt is used for
INTX only.

VmIrqRequest->AddMsiRoute is used to add msi routing info into kvm
route table.

BUG=chromium:992270
TEST=none

Change-Id: I4f1beeb791943e09d957573dd2a58d55bf895d16
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1846603
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
2019-10-15 11:41:38 +00:00
Daniel Verkamp
8eb944b480 devices: proxy: do not acknowledge write commands
Write accessess cannot fail (in the CommandResult sense) and the result
did not carry any data, so remove the response from the Write command.

This should improve the speed of write requests for sandboxed devices.

For example, with the sandboxed serial device, boot time with a release
build of crosvm on my workstation goes from 1.7 seconds to 1.2 seconds,
measured by timing a boot with a missing init so that the kernel panics
and shuts down immediately.

BUG=None
TEST=time crosvm run -p init=bogus vm_kernel

Change-Id: I125bb831235ca741ae1cc6c86a02a5d863d1a211
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1853970
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-14 23:59:49 +00:00
Xiong Zhang
1fb6c0d019 kvm: Let device could modify its irq routing
Current all devices use kvm default irq routing table, but when MSI
or MSI-x are enabled,  they have their own irq routing, here
add_irq_route_entry() is added into vm's function, then device could
add its irq routing into VM's irq routing table and replace the
default kvm irq routing info.

BUG=chromium:992270
TEST=none

Change-Id: I111f9c3c09ef66b08c6f0432e936ec7e4fd6d270
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581145
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-14 03:54:47 +00:00
Jianxun Zhang
a462f74b26 docker: fix a failure when building crosvm
What fixed by this change failed crosvm build with docker on
non-Nvidia platforms.

BUG=None
TEST=./build_crosvm_base.sh
./build_crosvm.sh
./wrapped_smoke_test.sh

Change-Id: Ib2cc70d5bd98bcad25410ba54c0492491a3ea799
Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1842519
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-10-10 18:33:47 +00:00
Jianxun Zhang
34533fe3ee docker: fix minigbm failure when building base image
Running ./build_crosvm_base.sh failed with the below error:

...
/scratch/minigbm/helpers.c: In function 'layout_from_format':
/scratch/minigbm/helpers.c:156:7: error: \
'DRM_FORMAT_ABGR16161616F' undeclared (first use in this function)
  case DRM_FORMAT_ABGR16161616F:
...

The header file in the libdrm-dev package from debian distro hasn't
included the missed macro. This change builds libdrm from the
upstream source to fix the issue.

BUG=None
TEST=./build_crosvm_base.sh
echo $?

Change-Id: Ifaae4313781ea02ebac9658ab8be9d990a3d5d25
Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1841890
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-10-10 18:33:45 +00:00
Zach Reizner
a8adff0ff1 devices: jail serial device
This change plumbs the jail throughout the arch specific device creation
process. It also adds a custom callback support for the ProxyDevice so
that the main process can interrupt the child serial process when it has
incoming bytes.

TEST=crosvm run
BUG=None

Change-Id: I6af7d2cb0acbba9bf42eaeeb294cee2bce4a1f36
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1752589
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-10-10 02:09:13 +00:00
paulhsia
0b6f02fea7 device: ac97: Cleanup interrupt logic
- Send only one event while re-sampling.
- Don't sent event if the new sr is identical to the old one

This can reduce the rate to trigger the issue.

BUG=chromium:937977
TEST=Build and run lots of aplay and arecord in guest vm

Change-Id: Ibd21f363076c977ae256079e2615094b7ed2408b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1840752
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
2019-10-08 11:53:24 +00:00
Stephen Barber
7595d80248 devices: virtio_net: handle errors in tapfd poll adding/removal
Add error handling for adding/removing the tapfd to epoll.

We only remove the tap fd from the poll context if the tap is
readable, i.e. it would busy loop, so don't assume it's removed
from the poll context when there's a deferred rx frame.

BUG=chromium:1010742
TEST=arcvm network works

Change-Id: I84aab2dbe7ea31d724f04d3b3fb0a6916f232300
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1842399
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-10-08 08:55:59 +00:00
Daniel Verkamp
04e9c03f03 devices: ac97: fix interrupt triggering logic
Do not write to the irq_evt eventfd when interrupt_high is false; the
value written to the eventfd is ignored, so despite the '0' in the call,
this would re-trigger the interrupt even when it should not have been
asserted.  Since ac97 is a PCI device, its interrupt is level triggered,
and re-asserting it on EOI is handled by the irq_resample_thread code.

BUG=None
TEST=`aplay /dev/urandom` from Crostini on nami

Change-Id: I6ad8e40b818e0495ad58b6902d88dd61103aed9d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1838762
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-08 01:57:20 +00:00
Chirantan Ekbote
bf67203f97 sys_util: Add ReadWriteAtVolatile trait and *vectored functions
Add the FileReadWriteAtVolatile trait, which is basically the same as
the FileReadWriteVolatile trait but additionally takes an offest.  This
is only useful for types that are seekable and can allow concurrent
operations on the same underlying type.

Also add `*_vectored` versions of all the functions.  These match the
`*_vectored` functions in the standard library and can reduce the number
of system calls needed to read or write a whole buffer.

Implement both traits for `&mut T` if `T` implements them.

Change the trait implementation for `File` to a macro so that we can
also implement it for `GuestMemory`.

BUG=b:136128319
TEST=unit tests

Change-Id: I3d8eb7bba17fe3247e18649b1b04e21a91a841e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1724229
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-10-07 19:00:34 +00:00
Chirantan Ekbote
41e61d1fc3 virtio: queue: Enforce DescriptorChain ordering
The virtio spec requires that all read-only descriptors appear in the
chain before any write-only descriptors.  Enforce this in the
`checked_new` function by adding a new `required_flags` parameter.  The
`next_descriptor` function will set this to `VIRTQ_DESC_F_WRITE` if the
current descriptor is write-only.  This ensures that once we see a
write-only descriptor, all following descriptors must be write-only.

BUG=b:136127316
TEST=none

Change-Id: Id8f942a4236a20f62f35439f3648dbec17e14c00
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1757239
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2019-10-06 05:35:47 +00:00
Stephen Barber
28a9d2b70d devices: virtio_net: avoid busylooping when no rx buffers available
If the guest is unable to return rx queue buffers to the device, we should
temporarily stop polling for reads on the tap fd. Otherwise, we'll spin and
burn CPU needlessly.

BUG=chromium:1010742
TEST=repro from b/141940546

Change-Id: Iac004e870779a8dd39004f44b44e17a2b45bcfa1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1836914
Tested-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-10-03 19:44:37 +00:00
Fletcher Woodruff
82ff397489 sys_util: allow adding handlers for all signals
Currently, sys_util's register_signal_handler only permits handlers for
real-time signals. Rename that function to register_rt_signal_handler
and add a new register_signal_handler that supports all signals, then
update references to the old name.

BUG=chromium:1008990
TEST=builds

Change-Id: I455e14c562cd1f2ca4b308b4e38c503845321926
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1836185
Tested-by: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
2019-10-03 06:57:34 +00:00
Cody Schuffelen
f9b035d50c Support composite disks.
This adds a new disk file type next to raw files and qcow images that
represent an indirection to further raw disk files. The disk file
itself is a proto file with references to file paths for other disks to
open and their virtual offsets and lengths.

The intention is to make it easy to assemble a single virtual hard disk
out of several distinct partition files. In the particular case of
Cuttlefish running Android in a VM, this is relevant as the Android
build system distributes partitions as separate raw files. While the
simple solution is to pass each partition as a separate raw disk, some
functionality (like the bootloader) assumes there is a partition table
with multiple distinct partitions on a single disk.

Implementing composite disk support in the VMM bridges this gap through
supporting the general-purpose case of a disk built out of multiple
component files.

If desired, this can be extended to support qcow files to support
unusual configurations like a mixed qcow/raw disk.

Enabled with the "composite-disk" feature.

Bug: b/133432409
Change-Id: I2b0c47d92fab13b5dc0ca5a960c7cfd2b7145b87
Signed-off-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1667767
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-03 00:59:14 +00:00
Daniel Verkamp
b5237bbcf0 devices: virtio: pmem: use descriptor reader/writer
Convert the virtio pmem device to use the descriptor_utils Reader/Writer
helpers to simplify the code and allow support of arbitrary descriptor
layouts.

BUG=chromium:966258
TEST=./build_test.py

Change-Id: I9ccbdf2833980e4c44e19975f9091f9aea56c94b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1811713
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-10-01 22:48:41 +00:00