Commit graph

1033 commits

Author SHA1 Message Date
Daniel Verkamp
0b86007d3e Add usb_sys wrapper for usbfs
This wraps the Linux USBDEVFS ioctl interfaces.

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

Change-Id: Id855c66c4eb2ac01bb65073b5dd339c1c3d45c38
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1783600
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-09-09 18:20:41 +00:00
Daniel Verkamp
13eea9f028 usb: clarify transfer cancellation API
Rather than having a get_canceller() function on UsbTransfer, make the
submit function return the canceller.  This makes it clear that the
transfer can't be cancelled before it is submitted.

BUG=None
TEST=None

Change-Id: Ice36c3096a1f8a5aafe93b5d5e27eb371183c19f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1783599
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-09-09 18:20:40 +00:00
Daniel Verkamp
f5a52516b1 fuzz: fix block fuzzer build after block API change
Block::new() now takes a Box of the underlying file; update the block
fuzzer accordingly.

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

Change-Id: Ib636e13da5dcd347dd33c40a11508e016ea73b70
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1780336
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-09-03 21:08:38 +00:00
Cody Schuffelen
30c5a9ef0b Replace "AsRawFd" with "AsRawFds" for disks.
This supports virtio disks that depend on multiple file descriptors. All
of the file descriptors are passed to the jail when relevant.

Bug: b/133432409
Change-Id: Idf2e24cd2984c0d12a47a523c13d24c1ba8d173e
Signed-off-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691761
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-30 16:08:58 +00:00
Cody Schuffelen
7d533e5952 Extract disk creation logic out of qcow and src.
Bug: b/133432409
Change-Id: Iba25d5f6bb5f60619bb2f5a3d72ddfd3a81650b4
Signed-off-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691460
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-28 23:52:36 +00:00
Zach Reizner
971589f7ec docker: make using X11 gpu display easier with docker
This change makes using docker a bit easier when displaying on the hosts
X11 server. The biggest change was that build_crosvm.sh will install the
hosts NVIDIA proprietary driver if needed.

TEST=docker/build_crosvm.sh
     docker/crosvm_wrapper.sh
BUG=None

Change-Id: If64074715b0ad3a06727a4cc764d3ac06c4dfece
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1759139
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-08-28 22:59:34 +00:00
Lepton Wu
373673c43a seccomp: add clock_gettime gettid to gpu policy.
Some code path of mesa requires clock_gettime:
08f1cefecd/src/egl/drivers/dri2/egl_dri2.c (L3189)

Also cxa_guard in llvm begin to call gettid from this CL:

https://llvm.googlesource.com/libcxxabi/+/57e82af58dd4515ab4885f32273268f34f757101

BUG=b:140078110
BUG=b:139318078
TEST=manual - boot arcvm

Change-Id: I258ae5b8d6f38886406acac6a0ac8ca8886a64af
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1773506
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Lepton Wu <lepton@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Lepton Wu <lepton@chromium.org>
2019-08-28 01:11:09 +00:00
Daniel Verkamp
a445ae1fbe Remove remaining byteorder crate references
Remove the last (unused) reference to byteorder in vm_control/Cargo.toml
and remove it from the list of external crates in README.md.

BUG=None
TEST=./build_test

Change-Id: Ie70c0bc2f96c19b34ef1596885245eca7bc202f4
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761156
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-26 23:41:54 +00:00
Daniel Verkamp
034f7a3a1c devices: pci: replace byteorder with from_le_bytes()
Use the standardized from_le_bytes() functions rather than the byteorder
crate.

BUG=None
TEST=./build_test

Change-Id: I07a062bf63c5d3ae1e25f403713bf9a1677e8cba
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761155
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-26 23:41:53 +00:00
Daniel Verkamp
e7e7e51fb0 devices: virtio: replace byteorder with {to,from}_le_bytes()
Use the stabilized standard to_le_bytes() and from_le_bytes() functions
rather than the byteorder crate.

BUG=None
TEST=./build_test
TEST=cargo test -p devices virtio_pci_common_config

Change-Id: I4106a41484760b9e7e586de07135874238bcadb0
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761154
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-26 23:41:52 +00:00
Daniel Verkamp
c2444305a9 devices: vsock: replace byteorder with from_le_bytes()
BUG=None
TEST=cargo test -p devices vsock

Change-Id: I9da35f894898198413737f9caa29a7f772e4f720
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761153
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-26 23:41:52 +00:00
Daniel Verkamp
d1245509b2 x86_64: replace byteorder with {to,from}_le_bytes()
BUG=None
TEST=./build_test

Change-Id: Ic7873c6b70d9a0e9f34b7a2977845552144934ea
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761152
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-26 23:41:51 +00:00
Daniel Verkamp
f8fc71a760 qcow: replace byteorder with {to,from}_be_bytes()
Use the standard byte order conversion functions rather than the
byteorder crate.

BUG=None
TEST=./build_test
TEST=cargo build -p qcow_utils
TEST=cargo test -p qcow

Change-Id: I9ff7368cc54c539db1996f81d4220cabf7e6e301
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761151
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-26 23:41:50 +00:00
Daniel Verkamp
09430fe59e arch: fdt: replace byteorder with to_be_bytes()
Use the standard library u32 and u64 byteorder conversion functions (now
that they are stabilized) rather than the byteorder crate.

BUG=None
TEST=./build_test

Change-Id: I7d2b523c2df5f7cdf1cd7d5b760ede8e827e0517
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761150
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-26 23:41:49 +00:00
Daniel Verkamp
afef8d7baf usb: clean up clippy unit_arg warning
Fix the last instance of this clippy warning:

  warning: passing a unit value to a function

... and remove this warning from the "To be resolved" list in
bin/clippy.

BUG=None
TEST=bin/clippy passes without warnings

Change-Id: Ic1d558e935366d80eeadb96bf1ff951ce50edd5b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1766623
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-26 19:34:39 +00:00
Zide Chen
4d7fd7f93d devices: virtio: set zero length mmio eventfd for VQ notification address
By registering the notify address with Datamatch::AnyLength, KVM is able
to take advantage of KVM_FAST_MMIO_BUS to accelerate eventfd handling.

Seems this doesn't violate the virtio spec because "writing the 16-bit
virtqueue index" refers to the implementation of front-end driver, for
example, Linux's vp_notify() function. While how to handle the VQ index
write in VMM is not covererd by virtio spec. Here Crosvm ensures that
every VQ has dedicated notify address and KVM implements the notification
by eventfd, which should be fine with the spec.

On eve Pixelbook (R77 host kernel 4.4.185), in 5000 samples, on average
the MMIO write vmexit takes 0.96us with fast_mmio enabled, while it takes
3.36us without fast_mmio.

without fast_mmio:
    232812.822491: kvm_exit: reason EPT_MISCONFIG rip 0xffffffff986f18ef info 0 0
    232812.822492: kvm_emulate_insn: 0:ffffffff986f18ef:66 89 3e (prot64)
    232812.822493: vcpu_match_mmio: gva 0xffffb0f4803a1004 gpa 0xe000f004 Write GPA
    232812.822493: kvm_mmio: mmio write len 2 gpa 0xe000f004 val 0x1
    232812.822495: kvm_entry: vcpu 1

with fast_mmio:
    230585.034396: kvm_exit: reason EPT_MISCONFIG rip 0xffffffff9a6f18ef info 0 0
    230585.034397: kvm_fast_mmio: fast mmio at gpa 0xe000f004
    230585.034397: kvm_entry: vcpu 1

BUG=chromium:993488
TEST=Boot Crostini on eve and run iperf benchmark
TEST=Analysis kernel trace for vmexit handling time

Change-Id: Id1dac22b37490f7026b6c119c85ca9d104a8a3f4
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/+/1762282
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-08-23 19:49:54 +00:00
Daniel Verkamp
6f9215cecd crosvm: silence unused code warning for NonZeroU8
After a recent refactoring of display support, this import is only used
when building with the "gpu" feature enabled. Put it behind a cfg check
to avoid a warning when building without gpu support.

BUG=None
TEST=cargo build
TEST=emerge-nami crosvm

Change-Id: I4e407e09daa93c74203f3472dad5a3713b99d122
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1762448
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-22 20:43:24 +00:00
Daniel Verkamp
b7bee37759 gpu_display: fix clippy warnings
Remove a redundant closure and an unneeded return statement to assuage
`cargo clippy`.

BUG=None
TEST=bin/clippy

Change-Id: I4b6043738de0be3bbf73d05fb3e4c909ce48bc58
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1751912
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-20 21:21:26 +00:00
Gurchetan Singh
5ce68e42ca devices: gpu: remove BackedBuffer/GpuRendererResource distinction
We always advertise VIRTIO_GPU_F_VIRGL and don't activate the
worker thread if Renderer::init fails.  We're unlikely to
encounter an platform where we can initialize a GBM device, but
can't initialize virglrenderer.

Since our virtio-gpu implementation depends on virglrenderer, we can
pipe 2D hypercalls to virglrenderer (QEMU does this too, when built
with the --enable-virglrenderer option).

Also remove virgl_renderer_resource_info since it's unlikely to work
with non-Mesa drivers.

BUG=chromium:906811
TEST=kmscube renders correctly (though there's a prior bug in closing
the rendering window -- see chromium:991830)

Change-Id: I7851cd0837fd226f523f81c5b4a3389dc85f3e4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1743219
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2019-08-20 17:46:26 +00:00
Gurchetan Singh
593dc3b34e gpu_renderer: remove EGL related functions
Now that we're not creating EGL images anymore, we can remove
EGL logic.

BUG=chromium:906811
TEST=freecad works without any local Mesa patches

Change-Id: I09db1c828ae1a331eaeae7c66653a49fe42a04bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1725451
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-20 17:46:25 +00:00
Gurchetan Singh
b8a833f6cc gpu_renderer: use GBM inside virglrenderer
With YUV support + modifier support coming up, it makes sense to
move GBM allocation inside virglrenderer so we can upstream
our use cases.

In addition, this allows us to use gbm_bo_map(..) for the freecad
issue, which would otherwise be resolved through local patches in
our graphics drivers.

BUG=chromium:906811
TEST=freecad works without Mesa patches

Change-Id: I61db5c58a5bc5a79fda3cec8ad6c322fae6acc9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1725450
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2019-08-20 17:46:24 +00:00
Gurchetan Singh
84d59e76b3 Dockerfile: stop tracking virglrenderer master
With crrev.com/c/1745316, the regular ChromeOS build started
adding epatches to virglrenderer. Therefore, don't track virglrenderer
master for the time being, until we can upstream and/or remove our
downstream APIs.

BUG=chromium:906811
TEST=docker/wrapped_smoke_test.sh

Change-Id: I9567e9286130048fb793fecb4ff3801b7d64ddba
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1758371
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-20 17:46:23 +00:00
Fletcher Woodruff
99c9c685b5 ac97: remove duplicated code
Crosvm's AC97 device had code that was duplicated between playback and
capture stream creation. Abstract that code out so it can be shared.

BUG=chromium:968724
TEST=aplay /dev/urandom within container

Change-Id: If2fb50a0655656726dd9c6255bc84493e91c04e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749948
Tested-by: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
2019-08-20 15:34:29 +00:00
Dmitry Torokhov
47becf5b04 plugin: switch to using /mnt/empty for root
We have stopped mounting /var/empty as we have decided that /mnt/empty
should be used instead.

BUG=chromium:933582,b:139436326
TEST=Start plugin VM.

Change-Id: I50bbf9d4a9ebd86d54cb9ecc67891921f46e27e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1757343
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Dmitry Torokhov <dtor@chromium.org>
2019-08-19 00:38:00 +00:00
Xiong Zhang
3c8f32dfb0 vfio_sys: Add vfio.h to vfio_sys
Import kernel include/uapi/linux/vfio.h, it define ioctl interface.

BUG=none
TEST=none

Change-Id: If8e0dae22cb566ae32dfd61d6f2b147f56727611
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1580456
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-08-16 23:16:53 +00:00
Daniel Verkamp
58010b2731 devices: virtio: add copy_config() helper function
Add a new virtio configuration copying function to replace all of the
slightly varying read_config() and write_config() implementations in our
virtio devices.  This replaces a lot of tricky bounds-checking code with
a single central implementation, simplifying the devices to a single
call to copy_config() in most cases.

The balloon device is also changed to represent its config space as a
DataInit struct to match most other devices and remove several unwrap()
calls.

BUG=None
TEST=./build_test
TEST=Boot vm_kernel+vm_rootfs in crosvm
TEST=Start Crostini on nami

Change-Id: Ia49bd6dbe609d17455b9562086bc0b24f327be3f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749562
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-16 07:20:21 +00:00
Gurchetan Singh
35a9d838db gpu_renderer: update bindings
BUG=chromium:906811
TEST=compile

Change-Id: Ie4ee8df9e944a4b6bf148dfa04ab7946992a0351
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1725449
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2019-08-15 18:20:10 +00:00
Stephen Barber
eff26bbeb3 devices: use libc::exit instead of process::exit
We don't always shut down the worker threads cleanly, which can lead to a race
when crosvm is exiting. Worker threads that attempt logging to stderr may fail
an expect(), panic, and then panic again trying to write to stderr causing
SIGILL.

Work around this issue for now by using libc's exit, which won't run any
rust-specific cleanup.

BUG=chromium:978319,chromium:992494
TEST=crosvm shuts down without SIGILL/core dumps

Change-Id: I8a99ce8a34220afdf503402d44721a9bea5ec460
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1746830
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-08-14 18:12:16 +00:00
Daniel Verkamp
301583c01a data_model: allow reading structs from io::Read
Add a from_reader() function that allows reading a DataInit type from a
std::io::Read stream.

BUG=None
TEST=./build_test

Change-Id: Iaacae489db2c265d6b1a9af6e18c11c9e6efe354
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1737723
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-14 03:44:28 +00:00
Daniel Verkamp
3d690c6f53 devices: virtio: block: use descriptor chain utils
Rewrite the virtio block device to use the descriptor Reader/Writer
interfaces - this greatly simplifes the block device code.

This also lets the block device handle arbitrary descriptor layouts,
since the descriptor reader/writer handles that transparently for us.

BUG=chromium:990546
TEST=./build_test
TEST=Boot crosvm with vm_kernel+vm_rootfs on workstation
TEST=Boot full Crostini environment on nami

Change-Id: Ie9a2ba70a6c7ed0ae731660fd991fb88242e275f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721371
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-08-13 16:48:45 +00:00
Daniel Verkamp
57debaa85e devices: virtio: make create_descriptor_chain pub
Allow use of this helper function in other virtio devices that want to
write virtio descriptor chains as part of their tests.

BUG=chromium:990546
TEST=./build_test

Change-Id: Ib986646dc36b6406c88f20950586e1c665adf167
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1732851
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-13 16:48:44 +00:00
Daniel Verkamp
1765e6f80f devices: virtio: add volatile read/write for desc chains
This will allow streaming data between a FileReadWriteVolatile and the
descriptor chain Reader/Writer types.

BUG=chromium:990546
TEST=./build_test

Change-Id: Idc97ce99dd1cc340444298f705df4f12e339095d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721370
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-13 16:48:43 +00:00
Daniel Verkamp
977f008bc3 devices: virtio: add seek() for descriptor chains
This allows moving the read/write cursor around within a chain of
descriptors through the standard io::Seek interface.

BUG=chromium:990546
TEST=./build_test

Change-Id: I26ed368d3c7592188241a343dfeb922f3423d935
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721369
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-13 16:48:42 +00:00
Daniel Verkamp
3671305696 devices: virtio: add Error type for descriptors
Add an error type to describe descriptor Errors in more detail.

This lets us return a more accurate error in a later CL in this chain by
adding a VolatileMemoryError variant.

BUG=chromium:990546
TEST=./build_test

Change-Id: I08680d0cb64bfc3667bac7b2ad8a8bc0e78e8058
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1733988
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-13 16:48:41 +00:00
Jianxun Zhang
b600dd5bec Fix compiling warnings in test code
This change fixes two small warnings in smoke test:

   Compiling crosvm_plugin v0.17.0 (/platform/crosvm/crosvm_plugin)
warning: unused import: `std::mem::size_of`
   --> devices/src/virtio/input/event_source.rs:292:9
    |
292 |     use std::mem::size_of;
    |         ^^^^^^^^^^^^^^^^^
    |
    = note: #[warn(unused_imports)] on by default

warning: variable does not need to be mutable
   --> devices/src/virtio/input/event_source.rs:385:13
    |
385 |         let mut evt_opt = source.pop_available_event();
    |             ----^^^^^^^
    |             |
    |             help: remove this `mut`
    |
    = note: #[warn(unused_mut)] on by default

   Compiling arch v0.1.0 (/platform/crosvm/arch)

BUG=None
TEST=./wrapped_smoke_test.sh
Pass smoke test. The 2 warnings disappear in the output.

Change-Id: Ib4de48e9586e80087e30411e225265554d5e7a11
Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1742921
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-09 01:00:57 +00:00
Zach Reizner
0f2cfb095d crosvm: add x-display argument for choosing the X11 gpu display
TEST=cargo run -- run --gpu --x-display :0
BUG=None

Change-Id: I76b4b33a6b14cb6fad322ffa95f00cce976f81a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670550
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-08 03:19:58 +00:00
Jianxun Zhang
7f855be1f9 docker: support passing extra arguments to scripts
One of the usages is to specify proxy setting so
that these scripts can download packages behind
proxies. It looks cleaner and more flexible than
tweaking the docker file that's checked in the repo.

BUG=None
TEST=run commands behind a network proxy
./build_crosvm_base.sh --build-arg http_proxy --build-arg https_proxy
./build_crosvm.sh --build-arg http_proxy --build-arg https_proxy
./wrapped_smoke_test.sh -e http_proxy -e https_proxy

Change-Id: Id3729a1343b12c1c7553e047701f770620e3c975
Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1737540
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-07 23:31:48 +00:00
Tomasz Jeznach
a1b54ce9b5 usb: handle transfer errors after port is detached
When USB device is detached from kernel driver there might be multiple
pending USB transfers enqued, each completing with TransferStatus::NoDevice.
Once backend device is detached from system it's ok to ignore subsequent
detach request errors in transfer completion handler.

BUG=chromium:987500
TEST=ADB USB device attach/detach cycles with active adb service.

Change-Id: I4026e68df860c483973f51f9787bf3d48d2716b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1737471
Tested-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-07 14:38:14 +00:00
Jorge E. Moreira
28ea102c0e devices: fix virtio-queue range check
The check for validity of a DescriptorChain needs to ensure that
self.len bytes starting from self.addr are valid valid guest memory
addresses. The last byte of that range (assuming self.len > 0) is
self.addr + self.len - 1.

BUG=b/138459777
TEST=run cuttlefish locally with 4.19 kernel

Change-Id: I2eb6e70e099b3849ac1f6cdd0dfeed092c2a2b02
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1728481
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
2019-08-07 00:37:05 +00:00
Zach Reizner
267f2c80d1 split crosvm into a library and a main "crosvm" binary
This change has 3 parts:
- Modify the Cargo.toml to point at the bin and the lib source.
- Move modules and Config struct into the lib source
- Fix the argument/plugins module's doc comments which had never been
  tested.

The motivation for this change is to make testing crosvm's major
functionality (booting guest kernels, emulating hardware, etc) easier to
do from a cargo test. Being able to launce a crosvm config via the API
instead of the binary's command line will be possible with this change.

A side benefit is that this also enables doc tests in the lib side of
crosvm. The doc tests in binaries are not run due to a limitation in how
they get tested by cargo.

TEST=cargo test
     ./build_test
     kokoro/kokoro_simulator.sh
     emerge crosvm
BUG=None

Change-Id: I9d4b3a24231b895e8dfaf9e7b0f2b33350772041
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1730333
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-08-06 19:23:06 +00:00
Jorge E. Moreira
1e26230f3a Allow to connect standard input to a serial port other than the guest console
Before this change, setting console=true on a serial port caused that
port to be the one connected to the crosvm process' standard input. By
adding an extra 'stdin' argument to the serial parameters it's
possible to make those concepts independent.
Just as with the console argument, stdin defaults to serial port
1 (ttyS0) when not provided and it's possible to set no serial port
connected to stdin (or set as the console) by defining the first
serial port without the stdin (console) argument.

BUG=b/138616941
TEST=boot debian guest in debian host, boot cuttlefish in debian host
Change-Id: I7273e6860218521073df93a4ad71e31c7da522a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1731139
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-08-03 20:03:23 +00:00
David Riley
54e660ba8b gpu: Add sandboxing support for pvr.
BUG=chromium:892280
TEST=glxgears with virtio-gpu on hana

Change-Id: Ib92b21c124e30eacb3fc28558e2eb5d8d4a92567
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1717739
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Riley <davidriley@chromium.org>
Commit-Queue: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: David Riley <davidriley@chromium.org>
2019-08-01 19:34:05 +00:00
David Riley
06787c5b6c gpu: Add sandboxing support for mali/ARM.
ARM platforms have different library locations and also required GPU
devices to be availble to the GPU process.

BUG=chromium:892280
TEST=glxgears with virtio-gpu on kevin and nami

Change-Id: If1baeb1edda76d057e88ab5e88ce22f02e5d30a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1717738
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Riley <davidriley@chromium.org>
Commit-Queue: David Riley <davidriley@chromium.org>
Auto-Submit: David Riley <davidriley@chromium.org>
2019-08-01 19:34:04 +00:00
David Riley
62c533c9a3 gpu_renderer: Make eglDebugMessageControlKHR usage optional.
BUG=chromium:892280
TEST=glxgears with virtio-gpu on kevin and nami

Change-Id: I2158f4fe3411006ce5498b01d12ca627aa985f53
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1717737
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Riley <davidriley@chromium.org>
Commit-Queue: David Riley <davidriley@chromium.org>
Auto-Submit: David Riley <davidriley@chromium.org>
2019-08-01 19:34:03 +00:00
paulhsia
7cf768d02d ac97: Fix device real time priority issue
- Add allow sched_setscheduler call in seccomp policy
- Change the real time priority constant AUDIO_THREAD_RTPRIO to 10 to match
all other clients' priority.

Run the following commands to test
1. ulimit -r 10
2. crosvm run -r ./vm_rootfs.img -c 1 -m 1024 -s /run --cid 5 --host_ip \
   100.115.92.25 --netmask 255.255.255.252 --cras-audio \
   --params="snd_intel8x0.inside_vm=1 snd_intel8x0.ac97_clock=48000" \
   --mac d2:47:f7:c5:9e:53 ./vm_kernel
3. aplay -Dhw:0,0 -f dat /dev/zero
4. ps -AT -o comm,rtprio | grep crosvm
should see a thread running with rtprio=10

BUG=chromium:983533
BUG=b:138262556
TEST=Test with eve (x86_64) and bob (arm)

Change-Id: Idc3711d03d716741f7cefd9a89b14ae4c20c2033
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1729089
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
2019-08-01 09:25:59 +00:00
Dylan Reid
969a0b49ff qcow: bounds check the refcount table offset and size
If the header puts the refcount table outside the file size or if it
specifies a table much larger than needed, fail to open the file.

These might not be hard qcow errors, but they are situations that crosvm
will never encounter.

BUG=986061
TEST=fuzzer with new test cases completes in less than 5 seconds.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: If048c96f6255ca81740e20f3f4eb7669467dbb7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1716365
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-31 09:37:34 +00:00
Daniel Verkamp
a08e40bf81 rust-toolchain: upgrade to Rust 1.36.0
Update the rust-toolchain file and Docker image used in kokoro to match
the Chrome OS toolchain.

BUG=None
TEST=docker/wrapped_smoke_test.sh

Change-Id: I95cbf9bcaadd49b8476f2829bc75958dbea304e3
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1724850
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-07-30 05:35:31 +00:00
Daniel Verkamp
fb32e98f86 sys_util: drop redundant empty return type
rustfmt incorrectly formats the `handler` parameter in
register_signal_handler in a way that actually breaks compilation.

This bug has been reported upstream already, but it is not fixed yet on
the version of rustfmt available with stable rust:
https://github.com/rust-lang/rustfmt/issues/3673

However, the empty return type can just be omitted in this case, which
avoids the rustfmt bug.

BUG=None
TEST=`bin/fmt --check` passes with Rust 1.36.0

Change-Id: I75c49c66f1db9cb6ae73cc0f6f3e66351176c474
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1724849
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-30 05:35:30 +00:00
Zach Reizner
2ea297ac76 seccomp: add sendto, writev, and readv to common seccomp policies
Using syslog from glibc will use some syscalls we haven't seen before,
leading to the process getting killed. This change fixes that.

TEST=use syslog from C
BUG=chromium:988082

Change-Id: I4cfb317a8faf70188995487f4fa844229683d6d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721616
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-27 03:50:22 +00:00
Zach Reizner
92e75f0e2a gpu_display: fix use after free for the wayland socket path
Using .map in the way it was caused the CString to get moved into the closure
and then dropped by that closure. The returned pointer is then used in
dwl_context_setup after it was freed by the drop.

This change fixes that first by using .as_ref() before calling .map to
prevent the move. As an additional safeguard, some optional types were
added to the closure to make sure a reference to the CString was being
handled instead of a moved CString.

TEST=vmc start --enable-gpu termina
BUG=chromium:988082

Change-Id: I58c2c002f08688ecd85715d9cd45085dffb32457
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721615
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-07-27 03:50:21 +00:00