Commit graph

958 commits

Author SHA1 Message Date
Daniel Verkamp
6160e479f6 usb: switch to new libusb_wrap_sys_device API
Replace use of our custom, patched libusb APIs with the new
libusb_wrap_sys_device() function, which has been submitted to libusb
upstream. This allows us to drop the bindings for the custom APIs (and
will also allow us to drop the libusb patch that introduces them).

For now, keep this path behind the sandboxed-libusb feature to allow
crosvm to build against older libusb versions that do not have the new
API. This should be cleaned up eventually once we are comfortable with
raising the minimum libusb version required.

BUG=b:133773289
TEST=Attach Android device to Linux VM; deploy app via adb

Change-Id: Ie249c6f3f3b4c63210dd163ca7ad03e2de8a8872
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1676601
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-27 17:51:06 +00:00
Daniel Verkamp
6a8cd101b2 main: add --rwroot option to run
This allows specifying a read-write rootfs (rather than read-only as
with --root), including the automatic kernel command line additions
normally added by --root.

BUG=None
TEST=Boot crosvm with --rwroot and write to root filesystem

Change-Id: I6a3dc9176bffdefe664139cb33bf3e65a751dbf2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679531
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-27 17:29:53 +00:00
Daniel Verkamp
06944ec625 usb: Arm seccomp policy needs _llseek, not lseek
Since our Arm version is a 32-bit process, it uses the _llseek syscall
rather than lseek for 64-bit file offset support.  Fix the seccomp
filter to match.

Fixes a SIGSYS when attaching a USB device to Linux VM on Arm.

BUG=None
TEST=Attach USB device to kevin; verify device in `adb devices`

Change-Id: Ia46e60df17950bfbe967c4730c62ddb26fb6faa7
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1677318
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-27 17:07:01 +00:00
Daniel Verkamp
76199b4a05 kernel_loader: check phdr memory size addition
The mem_offset + phdr.memsz addition is using untrusted input
(phdr.memsz) and can overflow; add an explicit check to avoid panics on
invalid values.

BUG=None
TEST=/usr/libexec/fuzzers/crosvm_zimage_fuzzer in cros_fuzz shell

Change-Id: Ie6f7f27bd00958ff85201cecaa75ce2b19779b8b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1674664
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-25 17:12:06 +00:00
Daniel Verkamp
6b51bd334f fuzz: zimage: use a fixed guest memory size
GuestMemory::new returns an error if the requested size is not divisible
by the page size.  The zimage fuzzer was using a GuestMemory size based
on the size of the fuzzer input; however, it doesn't necessarily make
sense to limit the guest memory to the size of the input.  Pick an
arbitrary 256 MB (matching the block fuzzer), which is also a page size
multiple to resolve the original issue.

BUG=chromium:977883
TEST=/usr/libexec/fuzzers/crosvm_zimage_fuzzer in cros_fuzz shell

Change-Id: I08c6be9d920bede18d67f8a1c5c39b9d37fb839c
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1645040
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-25 17:12:05 +00:00
Daniel Verkamp
dade4c7425 devices: pci: preserve read-only bits in write_reg
The 32-bit write_reg() function for PCI configuration space masked off
non-writable (read-only) bits from the incoming value, but it did not
preserve the original bits from the register; this results in writes to
read-only registers to clear all read-only bits to 0 instead. Preserve
the original value of the read-only bits and add a test to verify that
this works.

BUG=None
TEST=./build_test

Change-Id: Icc67b429f17d519ec4e9090f8e0ce48aaff76491
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660204
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-25 04:36:47 +00:00
Daniel Verkamp
5e3442e675 devices: pci: check BAR address alignment
Each PCI BAR address must be aligned to at least its own size to allow
the BAR sizing mechanism to work properly.  Add a check in add_pci_bar()
to enforce this.

BUG=None
TEST=Boot vm_kernel in crosvm

Change-Id: Iee9d866c4982bd79935337682bd50b9205b95024
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660203
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-25 04:36:46 +00:00
Daniel Verkamp
4dd6ddbc39 devices: pci: allocate BARs with correct alignment
Each PCI BAR must be aligned to at least its own size to allow the BAR
sizing mechanism to work.  Change all BAR allocations to use
allocate_with_align(), specifying the size as the alignment.

In particular, this fixes the alignment of the XHCI BAR, whose size is
larger than a page (the default MMIO allocator alignment).

BUG=None
TEST=Boot vm_kernel in crosvm

Change-Id: Icba03771a896b9b4feae608efdb7685fe24f8b98
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660202
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-25 04:36:45 +00:00
Xiong Zhang
c9b0ea544d devices: pci: Change host brige into Intel
For kvmgt linux guest, intel graphic driver i915 need intel host bridge
located at 0000:00.0, so this patch change the vendor id of 0000:00.0 device
to intel.

BUG=none
TEST=none

Change-Id: I52f2341d25859f2b7d4a3837f4f0c8a4b2443525
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581139
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-25 04:36:44 +00:00
Daniel Verkamp
0b4232fcd9 devices: pci: use header type 0 for host bridge
Previously, we were using header type 1 (which is meant to be used only
for PCI-to-PCI bridges), which upsets the Linux PCI probing code:

pci 0000:00:00.0: ignoring class 0x060000 (doesn't match header type 01)

Switch to the standard type 0 header instead, which makes the kernel
happy and matches what real hardware uses.

BUG=None
TEST=Boot vm_kernel (Linux 4.19) in crosvm

Change-Id: I33d10bda39edf6d949827963cebbfe66c9147ea2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660892
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-25 04:36:42 +00:00
Zach Reizner
4a93a21ab3 gpu_renderer: make Box3 less error prone with constructor
The argument order of the new_2d constructor was very odd. That has been
changed to the ordinary x,y,w,h order. Also, each Box3 is checked by
is_empty() before being used, which prevents some degenerate operations
on zero area boxes.

TEST=cargo run -- run --gpu
BUG=None

Change-Id: I6954fa4846f20353517fe81028058b639752d8ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670549
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-06-24 23:59:15 +00:00
Zach Reizner
f448721872 data_model: add sub_slice method to VolatileSlice
The new method is a copy of the get_slice trait method without the
restriction that the returned VolatileSlice has a lifetime limited to the
VolatileSlice, rather the VolatileSlice's lifetime parameter, which is
longer.

TEST=None
BUG=None

Change-Id: I1578981fcd046ce2d6232b28746c08d912c51b4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670548
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-24 23:59:10 +00:00
Zach Reizner
f51787b1c7 gpu_display: fix dangling NULL pointer in dwl_context_setup
If the dwl_context_setup routine fails after creating a wayland
connection succesfully (e.g. if an extension is missing), the fail label
is jumped to in order to disconnect the wayland connection and
deallocate the wl_display structure. That label did not set
self->display to NULL after calling wl_display_disconnect, which would
cause the dwl_context_destroy routine to call wl_display_disconnect again,
which is a double free. This CL fixes that ommission.

TEST=None
BUG=None

Change-Id: I5b6c2d6fadda82dff4130bd4abb0e7764c15e004
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1668528
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-06-24 23:59:06 +00:00
Jakub Staron
4aaefc377f devices: Use Reader/Writer interfaces in virtio-net.
BUG=chromium:966258
TEST=tast run ${IP} vm.CrostiniStartEverything
TEST=tast run ${IP} vm.CrostiniNetworkPerf

Change-Id: I99c5b9e564c219b76593d729fb934722fc8a3431
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1658980
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-06-24 07:53:29 +00:00
Chirantan Ekbote
dd11d43473 gpu: Allow more than one resource bridge socket
Currently the wayland device accesses buffers allocated by the gpu
device via a dedicated socket connection.  Upcoming virtual devices like
vdec and camera will also need access to these buffers.  Modify the gpu
device so that it can process requests on multiple resource_bridge
sockets.

Each future device that needs access to gpu device buffers should create
a new resource bridge socket pair and add it to the list of sockets that
the gpu device monitors.

The actual interface between the devices is unchanged.

BUG=b:133381367
TEST=run glxgears in a crostini container with and without gpu enabled

Change-Id: I58693881945965071a53653bf4f86681725267d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1652876
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
2019-06-24 03:29:42 +00:00
Jakub Staron
cc91fc8252 devices: Add separate seccomp policy for pmem device
This change adds separate seccomp policy for pmem device. Previously,
pmem device was using block device seccomp policy.

BUG=None
TEST=Boot VM and run xfstests on pmem device

Change-Id: I3f25d64d4da6ad8f0ff22b285e1a7e958f545c55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1652441
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jakub Staroń <jstaron@google.com>
2019-06-21 21:47:58 +00:00
Dylan Reid
b38bde9bd1 fuzz: Comply with new guest memory requirement for page alignment
When the input's length is not page aligned, round it up. This allows
the fuzzer to provide more random inputs without causing the `unwrap`
call to trigger false positives when creating guest memory.

BUG=chromium:972172
TEST=run fuzz case from the bug

Change-Id: Iaf8f2ba943f38b90e168301dbb8c15dee5ee45c8
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1659626
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-21 21:12:39 +00:00
Jakub Staron
d0bf5dc602 crosvm: Implement Reader/Writer interface over DescriptorChain.
This change adds a convinient interface over DescriptorChain. It hides
the complexity of DescriptorChain and allows to treat it as a pair
of read-only and write-only buffers. In the future, it will also allow
to easily support indirect descriptors.

BUG=chromium:966258
TEST=cargo test --package devices descriptor_utils
TEST=run crosvm without sandbox, share a directory, compare
checksum of shared file between host and guest

Change-Id: I9fb722ee2024c8d7d40f560571ec7d7c454bfc2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1647370
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jakub Staroń <jstaron@google.com>
2019-06-21 20:27:08 +00:00
Dylan Reid
70d7bad284 qcow: disallow crazy l1 table sizes
Before this change, a corrupt or malicious qcow file could cause crosvm
to allocate absurd amounts of memory. The fuzzer found this case,
limit the L1 table size so it can't cause issues.

BUG=chromium:974123
TEST=run fuzzer locally, add unit test

Change-Id: Ieb6db6c87f71df726b3cc9a98404581fe32fb1ce
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660890
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-21 19:22:33 +00:00
Dylan Reid
c9f254b192 qcow: Fix invalid_cluster_bits test
Start with a valid header so the invalid cluster bits field is tested in
isolation. Before this change the test would pass even if the cluster
bits check was removed from the code because the header was invalid for
other reasons.

BUG=none
TEST=this is a test

Change-Id: I5c09417ae3f974522652a50cb0fdc5dc0e10dd44
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660889
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-21 19:22:31 +00:00
Jorge E. Moreira
0dfe1be88a crosvm: Ensure slices are the same size when copying.
Bug=b/135190799
TEST=run cuttlefish in debian host

Change-Id: I7f9343dd202da2a163b3e8aeb8fbde5eb4cfb1d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1659144
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2019-06-21 19:12:40 +00:00
Daniel Verkamp
c62f41681c usb: update USBDEVFS_CONNINFO_EX value to new size
The layout of struct usbfs_conninfo_ex was changed in the final revision
of the patch, so the corresponding ioctl number needs to change to
match, since the parameter size is encoded in the ioctl.

The new size is 0x18 or 24, which matches the struct usbfs_conninfo_ex
layout with 7 ports.

BUG=chromium:977020
TEST=Attach Android device to Linux VM on nami

Change-Id: Iec60b4c04880d7d2c71fdea49cfdf7fb5a75f5c6
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1669530
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2019-06-21 09:13:29 +00:00
Trent Begin
923bab011f crosvm: default serial parameter num field to 1 if not provided
If multiple serial parameters do not have `num` fields, or a different
parameter has already defined serial num 1, then crosvm will show an
error.

BUG=chromium:974885
TEST=cargo test; emerge-sarien crosvm && cros deploy dut crosvm;
Manual testing with and without num field in --serial parameter

Change-Id: Ia80247e8d055179adfd9e7471a98e8a2923cf1f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1662773
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Trent Begin <tbegin@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Trent Begin <tbegin@chromium.org>
2019-06-20 18:08:25 +00:00
Dmitry Torokhov
bb340d9a94 usb: update xhci policies to allow newer libusb
The updated version of libusb uses USBFS_CONNECTINFO and
USBFS_CONNINFO_EX ioctls, as well as readlink and lseek syscalls,
so let's enable them.

BUG=b:133773289
TEST=Try attaching a USB device to Crostini VM.

Change-Id: Ibdcab2da9abe1c0bb35c989d9d62b44ce403e268
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650534
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
2019-06-13 15:23:44 +00:00
Dylan Reid
a094f91d2c qcow: Limit file setups that consume excessive RAM
qcow currently makes assumptions about being able to fit the L1 and
refcount tables in memory. This isn't necessarily true for very large
files. The new limits to the size of in-memory buffers still allow 1TB
files with default cluster sizes. Because there aren't any 1 TB
chromebooks available yet, limit disks to that size.

This works around issues found by clusterfuzz related to large files
built with small clusters.

BUG=972165,972175,972160,972172
TEST=fuzzer locally + new unit tests

Change-Id: I15d5d8e3e61213780ff6aea5759b155c63d49ea3
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1651460
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-12 01:31:54 +00:00
Dylan Reid
21c941786e qcow: Calculate the max refcounts as a u64
u32's get multiplied together and can overflow. A usize was being
returned, make everything a u64 to make sure it fits.

Change-Id: I87071d294f4e62247c9ae72244db059a7b528b62
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1651459
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-12 01:31:46 +00:00
Dylan Reid
cae80e321a qcow: better limits on cluster size
Add a lower limit because cases such as eight byte clusters aren't
practical and aren't worth handling, tracking a cluster costs 16 bytes.

Also put an upper limit on the cluster size, choose 21 bits to match
qemu.

Change-Id: Ifcab081d0e630b5d26b0eafa552bd7c695821686
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1651458
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-12 01:31:44 +00:00
Xiong Zhang
44bb3dd909 src/linux.rs: Modify socket instead of add socket when remove other sockets
When an ill socket is detected, it will be removed from poll_context and
control_sockets, then the remaining good sockets should change their indices,
So modify should be used instead of add, as all of them have been added
into poll_context already, the add will return an error.

This change is merge of another change at
I977be57ea0898cc8226505f7d3da103a46ea626c that was identical to this one
except it contained the following similar commit message:

linux: when renumbering control sockets, use modify instead of add

In some circumstances, a VM control socket will get removed from the
list of control sockets in the run_control loop. Usually, the last
control socket in the list gets removed, but if that is not the case,
the control sockets will get reordered to fill in the gap in the list.
The `add` method of `PollContext` was used to change the token used for
a given control socket, when `modify` should have been used instead.
The problem with using `add` when a control socket is already part of a
`PollContext` is that it will return an error and terminate crosvm. This
CL fixes that issue.

BUG=none
TEST="crosvm run --vfio=$GVT_UUID", then run many gpu workloads in guest
TEST=crosvm run --gpu

Change-Id: Ic00a781d8839e652e2a8fd54ccd8e55849fa20bb
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Signed-off-by: Zach Reizner <zachr@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581151
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-06-10 17:09:03 +00:00
Jakub Staron
b6515a9167 crosvm: fix clippy warnings
Resolve a couple of minor clippy warnings:
 - unneeded return statement
 - use `if let` instead of `match` for single pattern destruction
 - use `values()` function to iterate over map values
 - supress warning about `ptr::null()` as expressed by the comment

BUG=None
TEST=./bin/clippy
TEST=cargo build

Change-Id: Ic4cea94cd3a25a9edf6ef38119de8c46dcfec563
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1646739
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Jakub Staroń <jstaron@google.com>
2019-06-08 04:27:37 +00:00
Jakub Staron
d879219ac0 serial: fix clippy warnings
Resolve couple of minor clippy warnings:
 - unneeded return statement in last expression of the function
 - redundant closure

BUG=None
TEST=./bin/clippy
TEST=cargo build

Change-Id: I602e56289315cb88779c0029d400b24a8180b899
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1646738
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jakub Staroń <jstaron@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-06-08 04:27:37 +00:00
Jakub Staron
4197d3a3a1 crosvm: add license blurb to bin/clippy and bin/fmt files
bin/clippy and bin/fmt were missing license blurbs at the top,
so update them to include the license blurbs.

BUG=None
TEST=None

Change-Id: Ic6bb5af3885d3735dcad42614aff7ac3dd33d638
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1646736
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jakub Staroń <jstaron@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-06-08 04:27:35 +00:00
Daniel Verkamp
0e94e3c1ea fuzz: adapt zimage fuzzer to new kernel loader API
After CL:1636685, the kernel_loader API is different - we need to pass a
File instead of just a slice to load_kernel().

Borrow and adapt the make_elf_bin() function from the kernel_loader
tests to create a shared memory file from a slice of bytes to fix the
fuzzer.

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

Change-Id: Ic17f6479fb355d45063ce6292552cb1e5664831a
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1645039
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-06 16:38:24 +00:00
Daniel Verkamp
3bebfa29dc usb: reset backend device on port reset
This enables the full firmware update/reset/use device in application
mode sequence for Edge TPU USB Accelerator.

There is a bit of a UI hiccup: once the firmware update and reset is
complete, the device re-enumerates with a different VID/PID, and the
"Connect to Linux" prompt shows up again.  The user must re-affirm that
the device should be connected to Linux to proceed with using the Edge
TPU.  This may be unavoidable - I'm not sure if we can tell the
difference between a newly-inserted device and a reset one.

Allowing USBDEVFS_DISCONNECT_CLAIM should be safe, since it can only
operate on file descriptors passed into the xhci device jail.

BUG=chromium:831850
TEST=Run Edge TPU Accelerator demo and verify that it can update FW

Change-Id: I3d61c7bd914830ce25448b1ae4d60e1c16f10aed
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1599881
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-05 19:19:10 +00:00
Jakub Staron
a3411eaac1 crosvm: virtio-pmem device
Adds support for virtio-pmem device as an alternative for virtio-blk.

Exposing disk image to guest as virtio-blk device results in both guest
and host independently caching the disk I/O. Using virtio-pmem device
allows to mount disk image as direct access (DAX) in the guest and thus
bypass the guest cache. This will reduce memory foodprint of the VMs.

BUG=None
TEST=cargo test
TEST=Boot patched termina kernel in crosvm; mount virtio-pmem device as
DAX and run xfstests.

Change-Id: I935fc8fc7527f79e5169f07ec7927e4ea4fa6027
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1605517
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Jakub Staroń <jstaron@google.com>
2019-06-05 07:28:54 +00:00
Zach Reizner
127453d7ec eliminate mut from non-mut references
This manifested itself in a couple places that were turning shared
memory buffers into slices for the purposes of passing these slices to
`Read` and `Write` trait methods.

However, this required the removal of the methods that took `Read` and
`Write` instances. This was a convenient interface but impossible to
implement safely because making slices from raw pointers without
enforcing safety guarantees causes undefined behaviour in Rust. It turns
out lots of code in crosvm was using these interfaces indirectly, which
explains why this CL touches so much.

TEST=crosvm run
BUG=chromium:938767

Change-Id: I4ff40c98da6ed08a4a42f4c31f0717f81b1c5863
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1636685
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-06-04 20:29:25 +00:00
Zach Reizner
6a0bfb037a docker: add adhd to checkout_commits.env and update all commits
This change also includes some code that was missing from
upgrade_checkout_commits.sh that actually generated the new
checkout_commits.env.

BUG=None
TEST=kokoro/kokoro_simulator.sh
     docker/build_crosvm_base.sh
     docker/build_crosvm.sh

Change-Id: If2505dd9af060d15c36eaf54741d4ae371f6a3c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1641585
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-06-04 00:46:18 +00:00
Cody Schuffelen
6d1ab50943 Initial BIOS support.
The --bios argument is added as an alternative to the kernel positional
argument. The BIOS runs in unreal mode (16-bit cs selector set to the
end of 32-bit address space), which matches the default state KVM puts
the segment and data registers into.

Example usage:
Build u-boot with "make qemu-x86_defconfig && make"
Run crosvm with "crosvm_wrapper.sh run --bios=u-boot.rom"

This produces the following message:
"""
U-Boot 2019.01-00017-gdc76aabe6a-dirty (May 21 2019 - 12:17:02 -0700)

CPU:
DRAM:  16 MiB
unable to get online cpu number: -19
Warning: MP init failure
Model: QEMU x86 (I440FX)
Net:   No ethernet found.
error: can't find etc/table-loader
Hit any key to stop autoboot:  0
=>
"""

At this point the u-boot shell works with stdin/stdout, but virtual
disks passed with --rwdisk weren't immediately visible from running
"virtio scan" and "virtio info".

This change puts the bios loading together with the linux kernel loading
code since there is a lot of overlap in functionality.

Bug: b/133358982
Test: ./crosvm_wrapper.sh run --mem=4097 --bios=u-boot.rom
Change-Id: I65b0e1044233af662a642c592d35b106217f3c13
Reviewed-on: https://chromium-review.googlesource.com/1622648
Commit-Ready: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-05-31 17:21:46 -07:00
paulhsia
580d418656 linux: Add cras-capture option for cras-audio device
The flag can enable capturing audio from CRAS server to the cras-audio
device.
We'll re-enable capture function on Crostini after finishing capture
permission works.

BUG=chromium:932268
TEST=Boot vm with crosvm --cras-audio --cras-capture to check recording
     functionality.

Cq-Depend: chromium:1628633
Change-Id: I7502cbd668cbc722224164d9f69e50a16b0ab86b
Reviewed-on: https://chromium-review.googlesource.com/1628687
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2019-05-31 02:56:41 -07:00
Daniel Verkamp
d7738ec486 enumn: fix duplicate fn in doc tests
Two parts of the documentation mention the generated `fn n`, which (as
of Rust 1.35) causes a doc test failure.  Change these code blocks to be
ignored instead of executed to avoid the problem.

BUG=None
TEST=cargo test --doc -p enumn

Change-Id: I9d08d2a35d65930bd2fa899256c00e1da643ba4f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1632035
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-05-30 01:11:16 +00:00
Daniel Verkamp
99c65d41f8 rust-toolchain: upgrade to Rust 1.35.0
BUG=None
TEST=docker/wrapped_smoke_test.sh

Change-Id: I0a159d9b54d97098d633ce80b92eeb48eb5c4b55
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1632036
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-05-30 01:11:13 +00:00
Dmitry Torokhov
ee42b8cab0 crosvm: fix unused variable warning in create_virtio_devices
The gpu_device_socket is not used when GPU support is disabled.

BUG=chromium:967436
TEST=cargo build --no-default-features

Change-Id: I5c0ef0ecf27349bcfbc19474879a282c9f6fb8ef
Reviewed-on: https://chromium-review.googlesource.com/1631292
Commit-Ready: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2019-05-29 06:27:40 -07:00
Daniel Verkamp
ca39ac0a95 devices: block: issue fsync when FlushTimer expires
The RequestType::Flush handler correctly uses fsync(), which issues an
fsync to the underlying disk image file.  However, the flush timer
(started on write and cancelled if a flush request is executed) was only
calling flush(), which is insufficient when the disk image is a raw file
- it just flushes in-memory buffers and does not issue an fsync.

BUG=None
TEST=Issue writes in crosvm; verify fsync in strace output

Change-Id: I1de8a35615031b5fdf5599dd6b49015d0b245c31
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1632876
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-05-29 06:27:33 -07:00
Gurchetan Singh
7ec58fafba virtio-gpu: add gpu control socket
The GPU process will need access to KVM.

BUG=chromium:924405
TEST=compile

Change-Id: I9e454d79a36a40a20c6c4b3a62ea367f339e526b
Reviewed-on: https://chromium-review.googlesource.com/1626793
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
2019-05-28 21:11:21 -07:00
Jingkui Wang
6c1e23eee3 crosvm: update xhci abi to use new bit_field features
We don't need schema anymore. Will use bool and custom enums.

BUG=None
TEST=local build and run crosvm

Change-Id: I1396916878f2903b17a75f375aee4eec1ced0583
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1564780
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-25 02:31:16 -07:00
Dylan Reid
a27f3a74d3 Add an OWNERS file
Per new cros policy.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I57c6b4bb5465c5fcdd9477c23547a835c0cfaf33
Reviewed-on: https://chromium-review.googlesource.com/1627218
Commit-Ready: Chris McDonald <cjmcdonald@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-05-25 02:31:07 -07:00
Jakub Staron
0854c168df devices: input: Removes used_desc_heads array.
Removes last usage of used_desc_heads/used_count pattern from crosvm.

BUG=None
TEST=cargo check

Change-Id: Ib80a22538f5d1e1c1055e0ea13156eb0ced15503
Reviewed-on: https://chromium-review.googlesource.com/1626327
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-05-24 15:10:46 -07:00
Gurchetan Singh
96beafc1c1 linux.rs: create a socket between gpu device and host
The GPU process needs to access KVM from host coherent
memory.

BUG=chromium:924405
TEST=compile

Change-Id: I3db9dce044e2a5cc816f48f28d943024dad7e7eb
Reviewed-on: https://chromium-review.googlesource.com/1626792
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-24 15:09:26 -07:00
Gurchetan Singh
53edb817da crosvm: {WlDriverRequest, WlDriverResponse} --> {VmMemoryRequest, VmMemoryResponse}
These type of requests are not necessarily specific to the virtio-wl,
and other devices (virtio-gpu) may want to use them.

BUG=chromium:924405
TEST=compile

Change-Id: Iad0889da8ab3d23bb2378448fc05e3c840a93d93
Reviewed-on: https://chromium-review.googlesource.com/1626791
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-24 15:09:26 -07:00
Gurchetan Singh
56ebd12380 virtio-gpu: add plane size
This is useful if the guests wants to map a host GBM
buffer.

BUG=chromium:924405
TEST=compile

Change-Id: I7fb68aa49c4ce4f2a020b8ce96ad558290380b5f
Reviewed-on: https://chromium-review.googlesource.com/1591460
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-24 15:09:25 -07:00
Daniel Verkamp
cf68e76280 aarch64: use 64-bit memory space for PCI MMIO range
This makes the PCI root bridge's MMIO range consistent with the
newly-added device memory range.  We already fill out the full 64-bit
address/size fields, so we might as well use the corresponding bus range
type.

BUG=None
TEST=boot termina on kevin

Change-Id: I9ecad38c76dac764853c6232cc486cfc7737a269
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1579327
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-23 07:35:19 -07:00