Commit graph

1068 commits

Author SHA1 Message Date
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
Zach Reizner
3e0fa36886 eliminate usage of uninitialized
uninitialized is deprecated and considered too dangerous to use for any
of the use cases we were using.

BUG=None
TEST=passes smoke_test

Change-Id: I5392cb8ec132f374d9b5590f72eb2cb329a82421
Reviewed-on: https://chromium-review.googlesource.com/1626795
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-05-23 07:35:18 -07:00
Jakub Staron
6b7373af98 crosvm: Removes used_desc_heads arrays from various virtio devices.
BUG=None
TEST=tast run ${IP} vm.CrostiniStartEverything

Change-Id: I14bdc330bff23ef3397251a81bdf63e37c1e1dfd
Reviewed-on: https://chromium-review.googlesource.com/1611014
Commit-Ready: Jakub Staroń <jstaron@google.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-23 07:35:16 -07:00
Zach Reizner
b42b645cfa x86_64: regenerate bootparam bindings without unions
TEST=crosvm run still works
BUG=chromium:761517

Change-Id: I6e95dde573febb5e498107b84b574373d1685c9a
Reviewed-on: https://chromium-review.googlesource.com/1625947
Commit-Ready: Zach Reizner <zachr@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-23 07:35:15 -07:00
Jakub Staron
e6c9558998 crosvm: Moves logic of consuming a DescriptorHead to Queue.
Moves logic of consuming available descriptor heads from AvailIter
to Queue. Adds pop() function to the public interface of the Queue.

This will let us remove the used_desc_heads arrays from various virtio
device implementations because pop() is not borrowing the queue for
the whole loop scope.

BUG=None
TEST=tast run ${IP} vm.CrostiniStartEverything

Change-Id: I8eda48e41b5ec1b2d59f3177435abafb9ad5f3a3
Reviewed-on: https://chromium-review.googlesource.com/1611013
Commit-Ready: Jakub Staroń <jstaron@google.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-23 02:14:58 -07:00
Zach Reizner
cf0d298223 wl: limit vfd recv size to leave room for VFDs
The IN_BUFFER_LEN variable limits the amount of data that will be read
into a single page sized descriptor. The old value for it left room for
the 16 byte header but reserved no space for VFDs. This happens to work
fine if the size of the read data and VFDs did not exceed the buffer
size, but, in rare circumstance, the maximum amount of data would be
read along with a FD getting received, spilling the descriptor and
causing it to fail to write to it. The guest driver does not handle this
gracefully and usually panics due to corruption.

The new value reserves room for the max number of VFDs so that the
descriptors will not end up with too much data.

BUG=chromium:951576
TEST=while true; do
         (/opt/google/cros-containers/bin/wayland_demo&);
         pkill -f /opt/google/cros-containers/lib/ld-linux-x86-64.so.2;
     done

Change-Id: Ic0c1c10f81a91b5e5cd076e3ded8d3cc0564b614
Reviewed-on: https://chromium-review.googlesource.com/1623558
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@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: Dylan Reid <dgreid@chromium.org>
2019-05-23 02:14:57 -07:00
Daniel Verkamp
1acf7b65bf usb: implement Interrupt on Short Packet bit
Transfer requests have a flag called Interrupt on Short Packet (ISP)
that we have been totally ignoring.  Now that the control request
execution phases have been rearranged in previous changes, we can
correctly trigger an event when a transfer fills fewer bytes than
requested.

This fixes firmware update on the Edge TPU USB Accelerator (Coral):
https://coral.withgoogle.com/docs/accelerator/get-started/

BUG=chromium:831850
TEST=Run Edge TPU test model from get-started page

Change-Id: I0d21e408a19c2e2eba562362bfe636c75dbb7160
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1593716
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 02:14:37 -07:00
Daniel Verkamp
ced74e6f2f devices: cmos: report memory size in CMOS
This matches the QEMU CMOS implementation and is used by BIOSes to
determine the valid memory regions to add to the e820 map.

BUG=b:133358982
TEST=Boot u-boot qemu build; observe memory size

Change-Id: I27956bc05738b5dd5b84240d5137cb06846aaab9
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1625330
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-23 02:14:28 -07:00
Zach Reizner
2b570f698a net_sys: regenerate if.h bindings using Rust native union
TEST=crosvm run, network still works
     cargo test -p net_util
BUG=chromium:761517

Change-Id: I3ee0e43376ff7f2ba76202138e47505c73958087
Reviewed-on: https://chromium-review.googlesource.com/1623557
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@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>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-05-23 02:14:24 -07:00
Zach Reizner
90c3271ce5 kernel_loader: regenerate bindings without unions
TEST=crosvm run <snip> vmlinux, kernel loads properly
BUG=761517

Change-Id: I2c1ce6f89c1a4d3a03df87b4e1931f63a7f5e569
Reviewed-on: https://chromium-review.googlesource.com/1623456
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@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-23 02:14:24 -07:00
Daniel Verkamp
85691d3406 aarch64: add DT entries for multiple serial ports
Add device tree entries for all four serial ports to make arm match the
x86_64 behavior.

BUG=chromium:953983
TEST=`echo test > /dev/ttyS1` etc. from termina on kevin

Change-Id: I334f7ad3e2ee9bc2599b0e8195e51140e8001e51
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1620893
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 02:14:11 -07:00
Daniel Verkamp
207b1fd2b5 devices: serial: implement MSR loop behavior
This fixes the Linux serial driver loopback test for the 4th serial port
(COM4, aka /dev/ttyS3).

The default value of the modem status register is always returned in the
current crosvm implementation; however, this doesn't match the expected
value in the loopback mode test used by the Linux kernel 8250 serial
driver.  The other 3 serial ports (/dev/ttyS[012]) skip this test
because of the UPF_SKIP_TEST flag in STD_COMX_FLAGS, but the 4th port
uses STD_COM4_FLAGS instead, which doesn't have UPF_SKIP_TEST.

The mapping of MCR to MSR bits is defined in the 16550 UART data sheet:
http://www.ti.com/product/pc16550d

BUG=chromium:953983
TEST=`echo test > /dev/ttyS3` in crosvm

Change-Id: I1b52111235a500fef2dee00c5803a2221a25e0c6
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1620704
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 02:14:11 -07:00
Daniel Verkamp
af00eb7e26 arch: initialize 4th serial port
Fix an off by one in the loop range so that all 4 UARTs are initialized.

Note that the 4th serial port (/dev/ttyS3) still doesn't work in Linux;
this is because our UART doesn't correctly emulate the loopback mode,
which is tested by the Linux serial driver.  This test is skipped for
the first three ports due to the UPF_SKIP_TEST flag in STD_COMX_FLAGS,
whereas STD_COM4_FLAGS does not set UPF_SKIP_TEST (and fails the test).
This will need to be resolved separately.

BUG=chromium:953983
TEST=`echo test > /dev/ttyS3` inside VM

Change-Id: Ic768584820e8b532ee4241df79ef8b9c17c4657a
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1620703
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Trent Begin <tbegin@chromium.org>
2019-05-23 02:14:10 -07:00
Daniel Verkamp
03b238bcc0 smbios: fix clippy warnings
Resolve a couple of minor clippy warnings:
- const implies static lifetime, so it can be omitted
- dereference bytes of str instead of clone()

BUG=None
TEST=bin/clippy
TEST=cargo build; boot vm_kernel+vm_rootfs.img

Change-Id: I29ff9bf7fdecd64286c2199e8e45c21103de9ce1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1618284
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-22 20:57:04 -07:00
Jorge E. Moreira
9c9e0e71bd crosvm: Implement the file type for serial ports
BUG=chromium:953983

Change-Id: I0c1dc6216ebfdb61db85d3d9665f88f7231d99c8
Reviewed-on: https://chromium-review.googlesource.com/1618281
Commit-Ready: Jorge Moreira Broche <jemoreira@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-05-22 20:57:00 -07:00
Daniel Verkamp
3007ff3cf4 x86_64: load initrd at max address
This matches behavior of other bootloaders (grub2, iPXE), and the kernel
seems to be relying on this; decompression of the initrd fails if the
initrd is loaded right after the kernel as before, but succeeds if
loaded at the maximum address.

BUG=None
TEST=Boot Debian kernel + initrd on workstation

Change-Id: If7712efb05f55ef413a419dfe276ed3f68c335b7
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1616989
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-20 15:47:23 -07:00
David Riley
be1ad40a0e devices: gpu: Fallback to allocating with virgl if no fourcc mapping.
BUG=chromium:963559
TEST=freecad starts and displays

Change-Id: I0d7a6ad5622b46a3fb0792eafd3dad1ed850e01d
Reviewed-on: https://chromium-review.googlesource.com/1613842
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2019-05-16 09:04:22 -07:00
Trent Begin
17ccaadc24 crosvm: add cmdline flags for configuring serial outputs in guest machine
This change allows an output to be set for each serial device for a
guest machine (stdout, syslog, or sink).

BUG=chromium:953983
TEST=FEATURES=test emerge-sarien crosvm; cd sys_util; cargo test;
./build_test; manual testing on x86_64 and aarch_64

Change-Id: I9e7fcb0b296c0f8a5aa8d54b1a74ae801f6badc8
Reviewed-on: https://chromium-review.googlesource.com/1572813
Commit-Ready: Trent Begin <tbegin@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Trent Begin <tbegin@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-05-15 13:36:25 -07:00
Zach Reizner
6868c0a72f add docker supported builds and tests
BUG=None
TEST=docker/build_crosvm_base.sh
     docker/build_crosvm.sh
     docker/wrapped_smoke_test.sh
     docker/crosvm_wrapper.sh
     kokoro/kokoro_simulator.sh
     bin/smoke_test

Change-Id: I55a805ba6326c3c58973d1fe21172a5e3551c1e2
Reviewed-on: https://chromium-review.googlesource.com/1593723
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-05-15 13:36:19 -07:00
Daniel Verkamp
050af40382 x86_64: support loading bzImage kernels
The current kernel loader expects an extracted ELF kernel; this adds
complexity to the build and test process for the guest kernel, since the
normal output of a Linux kernel build is a bzImage-format kernel.

bzImage also supports compressed kernels, which are smaller on disk and
potentially quicker to load, depending on disk and CPU speed.

Add support for loading of bzImage-format kernels, and use the 64-bit
boot protocol as described in the official Linux/x86 boot protocol:
https://www.kernel.org/doc/Documentation/x86/boot.txt

The existing ELF loader is kept for compatibility with shipping kernel
images; if a kernel image doesn't have the ELF signature, it is passed
to the bzImage loader as a fallback.

BUG=None
TEST=Boot bzImage and extracted ELF kernels on x86-64

Change-Id: I90be4cd597d15bc89e63f0f6cbc781c5c8c2eaeb
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1609969
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-14 23:57:41 -07:00
Daniel Verkamp
21accb31ac usb: execute control requests in DataStage
If a control request has a DataStage, execute the request during the
data stage so that we can get the actual length of the transferred data.
This will allow the ISP (Interrupt on Short Packets) bit to be
implemented correctly; we need to know the actual length during
processing of the DataStage TRB rather than at the StatusStage as we did
previously. (Note that ISP isn't implemented yet in this change; this
just passes the correct length to xhci_transfer.on_transfer_complete,
which doesn't do anything useful with the length yet in the short
transfer case.)

BUG=chromium:831850
TEST=Test adb on Crostini

Change-Id: I340424269aa139b0d9698f44ce9d3a457f3eb899
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1593715
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-10 15:26:02 -07:00
Daniel Verkamp
9fb20d9c53 usb: refactor intercepted control request handling
Certain control requests need to be intercepted for special handling
rather than being passed through directly to the device.  Clean up the
implementation of these intercepted requests by getting rid of the
confusing intermediate analyze_request_setup function and merging it
with the actual handling of each intercepted request in the new
execute_control_transfer function.  This keeps the custom handling all
in one place rather than scattered around the file and removes the need
for the extra HostToDeviceControlRequest enum.

Also add a check in get_standard_request to verify that the request is
indeed a standard control request so that the caller does not need to
check.

BUG=chromium:831850
TEST=Test adb on Crostini

Change-Id: I73b1db76941c39f124cfd0f51f14c15017ba9141
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1593714
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-10 15:26:01 -07:00
Daniel Verkamp
659b1779e2 usb: remove pointless Options in UsbRequestSetup
The get_type and get_direction helpers return Options, even though
they can only possibly return a non-None value; all bit patterns of the
fields they are interpreting are defined.  Drop the Options and return
the enum values directly to simplify callers and remove dead code.

Fix up a typo ("recipienet" -> "recipient") while we're in the
neighborhood.

BUG=chromium:831850
TEST=Test adb in Crostini

Change-Id: Ie26a1ed1c15f5f17b5ae80be78ce5f8ff51fab28
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1593713
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-10 15:26:01 -07:00
Daniel Verkamp
d999084539 usb: factor out common control request handling
The device to host and host to device branches of HostDevice's
handle_control_transfer function are basically identical, differing only
in whether to do a read or write and when to do it.  Split this code out
into its own function, execute_control_transfer, to reduce code
duplication and prepare for future changes.

BUG=chromium:831850
TEST=Test adb in crostini

Change-Id: Ic659f18ca97e2c1c71f67f3543096fe69228969a
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1593712
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-10 15:26:00 -07:00
Daniel Verkamp
ac83a5996c usb: hold lock throughout resample handler
Rather than acquiring the lock twice, lock it once and hold it while
doing the check and potential follow-up call to interrupt().  This looks
like it could be a race to me, but I don't know if it can actually cause
problems in practice.  In any case, it's better to only acquire the lock
once.

BUG=chromium:831850
TEST=Test adb in Crostini

Change-Id: Id7aa76e543cd5b858faf128f516e8d63e27cf3e7
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1592579
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-08 19:35:36 -07:00
Daniel Verkamp
82c0b1d721 usb: set event loop thread name
Set the name of the thread created to run the Xhci controller event loop
so that it can be identified more easily in a debugger.

BUG=None
TEST=Attach to running crosvm with gdb and verify 'info threads' name

Change-Id: Id73a580b35231ec7fa7aec5bd51027d32e483bff
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1594192
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-08 19:35:15 -07:00
Daniel Verkamp
bbd24c5a83 aarch64: make Android fstab optional
Always build the device tree, even if the Android fstab isn't specified.
Device tree is always required for Arm boards, unlike x86, where the
device tree is only needed for Android booting.

BUG=chromium:959921
TEST=Start Crostini on kevin

Change-Id: Ib775511786286200f4bfa360f9675a59451bb048
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1597348
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Greg Hartman <ghartman@google.com>
2019-05-07 08:15:48 -07:00
Daniel Verkamp
f2346c1b5f usb: fix deadlock in try_detach removal path
The UsbHub::try_detach function, which is only called from the libusb
hotplug callback when devices are removed, calls into
port.get_backend_device(), which acquires the backend_device lock, and
then calls port.detach(), which also tries to acquire the backend_device
lock, while still holding onto the backend_device. This clearly leads to
a deadlock.

Add an extra block in try_detach to keep the backend_device lock scoped
so that it is dropped before calling port.detach().

BUG=chromium:958117
TEST=Hot remove usb device from Crostini; verify it is gone in lsusb

Change-Id: Ibbbf68623390e3d25576f544b815c2a5607934fc
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1594158
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-03 18:49:09 +00:00
Greg Hartman
5dd8694d77 Add Android fstab support to aarch64, based on x86_64 version
Test: cargo test on x86_64 and aarch64, boot on aarch64
Change-Id: I29fb269abedaaca4168581aa7f92d413d51e9232
Reviewed-on: https://chromium-review.googlesource.com/1585279
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Greg Hartman <ghartman@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Greg Hartman <ghartman@google.com>
2019-05-02 21:02:36 -07:00
Jingkui Wang
e23231ccff usb: fix serial devices by removing device context verification
1. Removed for device slot reset and evaluate context. The verification was
   unnecessary and may cause some guest kernel operations to fail.
2. The context was updated after dequeue pointer set
3. Reset device when it's attached.
4. Add seccomp rules to allow the above reset.

The verification was copied from another implementation which works for
adb, but does not work with serial devices. The verification is also not
part of the spec, so we removed it here.

BUG=b:131336977
TEST=local build and test

Change-Id: Ifd7994ff5512346d1bab27654e60c97a602da8a6
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Signed-off-by: Zach Reizner <zachr@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1558934
Tested-by: kokoro <noreply+kokoro@google.com>
2019-05-01 01:50:22 -07:00
Sonny Rao
d5f6608f3e linux: handle margin file with multiple values
We're changing the content of the low_mem margin file to handle
multiple values to support notification for multiple memory pressure
levels.  The values will be from most critical to least, so we need to
handle this by fetching the first value.

BUG=chromium:736538
TEST=run vm.CrostiniStartEverything with and put memory pressure on the system

Change-Id: I0278ed492ddda1594d53750e0d4024a878210c9f
Reviewed-on: https://chromium-review.googlesource.com/1584644
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-04-29 20:57:24 -07:00
Jakub Staron
f55f75d689 crosvm: Fix misleading field name in VmComponents struct.
Renames field memory_mb to memory_size. All usages of this
field treat it as a memory size in bytes, not megabytes.

BUG=None
TEST=cargo check
TEST=cargo check --package aarch64 --target aarch64-unknown-linux-gnu

Change-Id: I7b1aefe4f0b612d5eeb2987dc2a0fce6db0dd228
Reviewed-on: https://chromium-review.googlesource.com/1585617
Commit-Ready: Jakub Staroń <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-29 20:57:13 -07:00
Zach Reizner
aff94ca6da usb: support for listing attached usb devices
Originally, crosvm would list details about an attached usb device for a
given port. This change allows getting details about multiple ports at
once. This is intended to simplify command line usage and downstream
consumers like concierge.

TEST=various vmc commands
     Chrome UI for handling USB devices
BUG=chromium:831850

Change-Id: I55681a7fea7425c897a22a579dcc15567683ef54
Reviewed-on: https://chromium-review.googlesource.com/1529765
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-27 01:36:47 -07:00
Jakub Staron
d99cd0ae0b crosvm: Extracts Wayland commands from from VmRequest.
BUG=None
TEST=cargo test
TEST=cargo test --package msg_socket
TEST=cargo test --package devices
TEST=cargo test --package vm_control
TEST=tast -verbose run ${IP} vm.CrostiniStartEverything

Change-Id: I07f034b1cc41e30b9deae68ea9c510b0923e17a8
Reviewed-on: https://chromium-review.googlesource.com/1565299
Commit-Ready: Jakub Staroń <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-27 01:36:38 -07:00
Jakub Staron
1f828d7cd7 Extracts BalloonAdjust from VmRequest.
Extracts BalloonAdjust from VmRequest into BalloonControlCommand.

BUG=None
TEST=cargo test
TEST=cargo test --package msg_socket
TEST=cargo test --package devices
TEST=cargo test --package vm_control
TEST=tast -verbose run ${IP} vm.CrostiniStartEverything

Change-Id: Ia9f5778c37c8fd4fa560df413134d1b441142f64
Reviewed-on: https://chromium-review.googlesource.com/1565298
Commit-Ready: Jakub Staroń <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-04-25 00:59:51 -07:00
Stephen Barber
d6945a09b8 crosvm: add license blurb to all files
A few files were missing license blurbs at the top, so update them all
to include them.

BUG=none
TEST=none

Change-Id: Ida101be2e5c255b8cffeb15f5b93f63bfd1b130b
Reviewed-on: https://chromium-review.googlesource.com/1577900
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-04-24 15:51:38 -07:00
Matt Delco
73e1e4e7b6 crosvm: only clear signal when needed
Only clear signal when EINTR is indicated, rather than doing it after
each attempt to run the VM.

BUG=None
TEST=Local compile.  Ran my diagnostic plugin and confirmed that pause
can still be trigger.  Ran my benchmarking plugin and saw the time used
decrease by about 13%.  The net reduction with 2 other changes is about
42%.

Change-Id: I118e05c6c62d1251946dd6432d4c933a3b8504fc
Signed-off-by: Matt Delco <delco@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1573219
Commit-Ready: Matt Delco <delco@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-24 15:51:12 -07:00
Matt Delco
e3fdadb8e1 crosvm: use pipe instead of socket for vcpu communication
Pipes have better performance than sockets, so switch the vcpu
communication over to pipes.  The vm communication channels will
continue to use sockets since that communication isn't performance
critical (and those messages sometimes exchange file descriptors, and
that functionality requires sockets).

TEST=local compile and confirmed that my diagnostic plugin is still
happy. The time it takes to run my benchmark plugin has decreased by
20%.  This combined with my prior commit results in a net wall-clock
time reduction of 32%.
BUG=None

Change-Id: I44c198d62a3bbe3b539ff6ac79707d02488876e3
Signed-off-by: Matt Delco <delco@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1572873
Commit-Ready: Matt Delco <delco@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-24 15:51:11 -07:00
Matt Delco
2ec62db5f7 crosvm: reduce excess chatter with plugin
This change helps to improve performance in plugin communications by
removing unnecessary communication exchange.

The existing protocol basically requires the plugin to send a request
msg and wait for a reply msg.  Prior to this change a plugin had to send
a wait request before it got a wait reply (which typically contains an IO
event notication). Similarly, when the plugin sends a resume request
there's also a resume reply that's sent.

The reply to the resume message serves no worthwhile purpose and can be
removed. In the common case there's also no need for the plugin to send
a wait request message--the prior operation was a resume so both sides
know that the only next legal operation is a wait.  Thereforce, crosvm
can send a wait reply message without waiting for the plugin's request.

Another way to look at the situation is that a resume request message is
now answered by a wait reply message, and the overall message exchange
pattern looks less like http and more like async I/O.

The plugin's first call to wait is the one time that a wait request is
sent.  This in turn will receive an wait-init reply.

TEST=Ran my diagnostic plugin and confirmed that it still passes (after
working around an 8-byte limitation in crosvm).  Run my benchmarking
plugin and observed the time it takes to complete go down by 16.5%.
BUG=None

Change-Id: I9c93ba1d3a8f7814ca952f3dc7239d48675192e2
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1571066
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Matt Delco <delco@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-24 15:51:11 -07:00
Daniel Prilik
f82d6320e7 aarch64: add PCI device memory region to fdt
The device memory SystemAllocator allocates device addresses past the
end of physical memory. If a device tries to actually use this address
to register a new PCI BAR, the kernel will fail with a "can't claim BAR,
no compatible bridge window" error. On ARM, the kernel must be informed
of where PCI bars are allowed to be allocated through the Device Tree.

This CL adds a new PCI memory region to the fdt for device memory.

BUG=chromium:936567
TEST=see CL:1493014. Run on ARM.

Change-Id: I0faa6f7082ae53f7a792cec53a21adba109bc00d
Reviewed-on: https://chromium-review.googlesource.com/1558940
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-22 12:28:11 -07:00
Daniel Verkamp
622788fb46 sys_util: add size to mmap InvalidRange error
The current error doesn't provide sufficient information to debug
InvalidRange errors; add the size of the region so that the bounds of
the comparison can be determined from the error message.

BUG=None
TEST=cargo test -p sys_util

Change-Id: I8e7fbd750ab84c43bbf0435230b7d3cf466783da
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1574964
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-22 12:28:08 -07:00