Commit graph

1265 commits

Author SHA1 Message Date
Dylan Reid
81516aa3e0 linux_input_sys: Ignore dead code warnings
Flag these three as allowed to be unused to make crosvm warning-free
again.

Change-Id: Id9bf18728c481484e31860836de6f0a1d1e55c5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1988282
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-01-08 11:15:37 +00:00
Stephen Barber
dc7c07bd08 crosvm: align pmem region size to 2MiB
Linux commit 7ea6216049ff9cf250a6722cd766d99c8d1424e5 "mm/sparsemem: prepare
for sub-section ranges" added validation of memory region sizes for hotplugging.
This requires alignment of the region to 2MiB, which can be done with a
MemoryMappingArena that will pad the end of the region with read-only pages.

BUG=chromium:1031408
TEST=crostini.Sanity.artifact with 5.4 guest kernel

Change-Id: I526f23a5ef32edd3268cd23f010e2bc20f9c305a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1979257
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2020-01-07 22:40:18 +00:00
Ryo Hashimoto
0b788defc6 devices: virtio: wl: Support multiple sockets
Guest can specify which socket it wants to connect by passing a
parameter to VIRTWL_IOCTL_NEW_CTX_NAMED.

Even after this CL, only the unnamed wayland socket is used for composition.
Additional sockets are used for IPC purpose (e.g. camera).

BUG=b:146100044
TEST=Camera works

Cq-Depend: chromium:1962108
Change-Id: Ibd8efbae1b2177cc0381d88d151643183c31b519
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963412
Tested-by: Ryo Hashimoto <hashimoto@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
2020-01-07 07:59:06 +00:00
Xiong Zhang
3ec8cc4f52 Vfio: Ignore vfio device's multifunction flag
PciRoot doesn't support multifunciion which forward pci config r/w
from function > 0 to function 0, so if the vfio device have multifunction
flag, guest will find the existence of all the other functions, actually it
is from the function 0. In order to fix these extra functions, this
patch clear the multifunction flag, so guest won't probe the other
functions.

BUG=chromium:992270
TEST=pass through a device with multifunction into guest

Change-Id: I395636411e0d7d2a3729de16e638d7f6b2dde552
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954221
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-07 05:58:48 +00:00
Xiong Zhang
5c6bf3e32d Vfio: Add igd Opregion support
igd opregion is used by igd driver to get vbt info and exhange info
between bios and driver, but it isn't a standard pci resource, host
bios allocate, reserve its memory, and report the memory base address
through cfg_register 0xFC on native.

As crosvm doesn't have bios, it is hard to allocate and reserve opregion
for guest. Here opregion is faked as mmio memory, and let crosvm
allocate guest memory from mmio space, report its base to cfg_register
0xFC also.

guest driver read cfg_register 0xFC to get opregion base address, then rw
it throgh this address. Read is forwarded to vfio kernel and write is
ignored.

BUG=chromium:992270
TEST=crosvm --vfio /sys/devices/pci0000:00/0000:00:02.0, pass through
host igd into linux guest, the physical local display lightup and show linux desktop.

Change-Id: I1cc3618e99313fc1f88b96dcbc635f090b19340c
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1688689
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-07 05:58:46 +00:00
Daniel Verkamp
f2eecc4152 disk: move qcow into disk crate
Move qcow from being its own crate into a module of the disk crate,
similar to the composite disk module.

This will allow use of qcow from disk and vice versa without introducing
a circular crate dependency.

BUG=None
TEST=./build_test.py
TEST=USE='asan fuzzer' emerge-nami crosvm

Change-Id: I77512bbe4b94faff1b5460f9796ee56505135580
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1972477
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-01-06 21:26:38 +00:00
Daniel Verkamp
521cf5d6d3 qcow_utils: remove unused convert functions
The convert_to_qcow2 and convert_to_raw functions are no longer used
now that concierge's export operation exports the unmodified disk image
in a tarball instead of converting it to qcow2.  Remove the unused
functions to clean up unreachable code.

BUG=None
TEST=cargo build -p qcow_utils
TEST=emerge-nami crosvm vm_host_tools

Change-Id: I525a9123481bd8cb6ebf022a289ecdf6e7ceaff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1972476
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-01-06 21:26:37 +00:00
Noah Gold
7898b80860 gpu_display: add X11 input bindings.
Adds bindings to the X11 display window to capture keyboard & mouse
input & send it to the guest via an EventDevice.

Original implementation by zachr@chromium.org.

BUG=chromium:1023975
TEST=None

Change-Id: I33156a8ca0b8c610a2080e3b6891cca2a865734b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971121
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-01-03 20:03:53 +00:00
Noah Gold
1d80dcc01c Add keycode translator.
The keycode translates scancodes into Linux keycodes so they can be sent
to the virtio-input device. The translation is based on Chromium's existing
table, but converted into Rust.

BUG=chromium:1023975
TEST=None

Change-Id: Icd709e40c6d12775fdce0738f3dde3620f6c7da5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1962872
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-01-03 20:03:52 +00:00
Noah Gold
778953faa1 Add Linux input_event struct & generator funcs.
BUG=chromium:1023975
TEST=builds.

Change-Id: Ibc9e1f58b1188f197d57534f60e1cdc16091f116
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1962752
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-01-03 20:03:49 +00:00
Chuanxiao Dong
313f64127f virtio: implement reset for balloon/rng/blk/net
The reset method will be called when guest virtio driver is
resetting the device. Currently the balloon/Rng/block/net
virtio drivers will re-configure the virt queue during the
reset so they required to be re-activated for using the new
virt queue configurations. To support this, need these device
models to return back the moved ownership of the important
variables so that they can do the re-activate.

BUG=chromium:1030609
TEST=Launch linux guest and follow the reproduce steps in BUG#1030609 to check
if balloon/Rng/block/net driver still complain failure.

Change-Id: I5b40fd303ea334484c590982e3e0874ea4e854ee
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971097
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-03 11:12:04 +00:00
Chuanxiao Dong
572ca0cca2 virtio: call virtio device reset method for reset
It refers to the implementation of the Cloud-hypervisor
commit:
- vm-virtio: Reset underlying device on driver request

If the driver triggers a reset by writing zero into the status register
then reset the underlying device if supported. A device reset also
requires resetting various aspects of the queue.

The reset method of a virtio device might return false if it is failed
to reset the device or it is not implemented. In this case, we don't
reset the queues. Otherwise the queues will also be reset together with
a successful device reset.

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

Change-Id: Iad2be38149e423a79d8366dc72e570a1d6eb297c
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971096
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-03 11:12:01 +00:00
Dmitry Torokhov
3dc90d0124 plugin: mount read-only /proc into the jail
Breakpad requires /proc, so let's mount it (as read only) into plugin
jail. We can't initiate it from concierge as concierge can only pass
bind mounts to crosvm, whereas here we need to mount or own copy of
/proc that reflects out own namespace(s).

BUG=None
TEST=Run Plugin VM, check /proc of the plugin process.

Cq-Depend: 1982695
Change-Id: I5d673e3c8733a61afc5986f9bf110b05c45bbdce
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982820
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2019-12-31 00:19:44 +00:00
Allen Webb
d4afd7033c Cast refernces of libc::RLIMIT_NOFILE to i32 for newer libc crate.
BUG=chromium:1021609
TEST=emerge-sand crosvm

Change-Id: I9658d3816cc846be2b6320f2f03036375de67cbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1979532
Tested-by: Allen Webb <allenwebb@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Allen Webb <allenwebb@google.com>
2019-12-26 19:58:14 +00:00
Dylan Reid
691a619926 devices: fix warning about extra parens
rust 1.40 has a new warning when there are extra parens, soRemove them.

Change-Id: Ibb565cac41ba8d72879f4cb8b949f2be30e55167
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1978140
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2019-12-23 21:20:13 +00:00
Dmitry Torokhov
e2e6cd8fe6 Fix parsing arguments that require a value at the end of command line
We may be in state of waiting for the value for the parameter, and run
out of the parameters. In this case we should try to parse the parameter
as if it does not have a value and see if that succeeds.

This makes sure that

	crosvm run ... --plugin-mount

fails with error that --plugin-mount option needs a value instead of
succeeding.

BUG=None
TEST=cargo test

Change-Id: I9f3f1f3c7e6e2ca88efed1eeea5a52dd4aae70ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1975097
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2019-12-22 10:55:05 +00:00
Dmitry Torokhov
9daf7907a3 When parsing --parameter <value> argument do not clobber parser errors
When parsing arguments in form of "--parameter <value>", because it is
yet unclear whether the parameter needs a value or not, we first try to
parse it together with the next argument, and if that fails, try to
parse it standalone. If both fail, then we should take the error from
the first one, as it is more informative. This way, doing

	crosvm run --plugin ... --plugin-mount bin --plugin-mount lib

will fail with error that "bin is not absolute path" and not that value
is missing for "--plugin-mount".

BUG=None
TEST=cargo test

Change-Id: Icc3bb0fcab4fb90e38eff3d116679091b598120d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1975096
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-22 10:55:04 +00:00
Dmitry Torokhov
d65265c636 crosvm: fix removing comments when processing -file options
As it turns out trim_end_matching() does not do what I expected (namely
trim the string when it encounters matching substring) but rather
expects to remove exactly matching suffix, so it actually fails to
remove comments. Let's switch to using splitn() that does what I want.

BUG=b:144454617
TEST=Run Plugin VM

Change-Id: Ibe8cd14d9d3c14ff99dd9abfa8f286e452d96913
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1975095
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-12-22 10:55:02 +00:00
Gurchetan Singh
78f6d4b134 devices: gpu: remove hung display from PollEvents
This display isn't typically used when the virt-wl device is
available and it can lead to hung fds during plug/unplug with
external displays and docks.

BUG=chromium:1027379, chromium:1027447
TEST=
Tested five times each on R79-12607.47.0 sarien:
  => without patch --> CPU usage goes to 100% after unplug
  => with patch --> CPU usages remains normal

Change-Id: Iea57f05002acc661f36b180e9e88c37b1f1b9047
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1977100
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2019-12-20 23:45:39 +00:00
Stephen Barber
d0e2a253de crosvm: treat FailEntry as fatal to a vcpu
FailEntry indicates an arch-specific failure to enter a VM. Treat this as
fatal to the vcpu.

Pass the u64 hardware failure reason from the kvm_run struct up to the client.

BUG=chromium:1036009
TEST=crosvm on hatch nested VM dies immediately instead of infinite looping

Change-Id: Iecb279b5b08ae1edc085717dce65e3ca46cbd30e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1977221
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-12-20 21:33:44 +00:00
Dmitry Torokhov
458bb64344 crosvm: allow shorthand notation in plugin-mount and plugin-gid-map
Let's allow shorthand notation in the form of:

	--plugin-mount=<src>[:[<dst>][:<writable>]]
	--plugin-gid-map=<inner>[:[<outer>][:<count>]]

so that we can invoke crosvm as

	crosvm ... --plugin-mount=/bin --plugin-mount=/dev/log::true \
		--plugin-gid-map=123 --plugin-gid-map=567::5

as repeating the data for both src and destination muddies the waters
and is prone to errors.

BUG=None
TEST=cargo test

Change-Id: I6f0a075ea3b27d4ec3dcf88698069930c158e759
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1967786
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2019-12-18 01:11:47 +00:00
Xiong Zhang
5aef647486 vfio: Disable igd stolen memory
igd stolen memory isn't a standard pci resource, so guest couldn't
access it. Once guest i915 driver see its size is zero, i915 won't use
it. Here sotlen memory's size register PciCfg 0x51 is forced to zero.

BUG=chromium:992270
TEST=crosvm run --vfio=/sys/devices/pci0000:00/0000:00:02.0, pass
through host igd into linux guest. The physical local display lightup and show linux desktop.

Change-Id: I1a0a6edda5d92d32307ea8025ef96677ca62c125
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1688368
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-12-17 10:25:05 +00:00
Dmitry Torokhov
0f4c5fff7a crosvm: plugin-mount-file and plugin-gid-map-file options
List of bind-mounts and gid maps can be quite long, so let's allow
listing them in text files, when convenient.

BUG=b:144454617
TEST=Run Plugin VM

Change-Id: I1218dab5a7e87b9f1ba44de6828da890fddb99fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1967785
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2019-12-17 09:56:47 +00:00
Dmitry Torokhov
c689fd92e6 crosvm: factor our parsing bind-mount and gid map options
In order to support specifying list of bind-mounts and gid maps options
via files, factor out the parsing code.

BUG=b:144454617
TEST=Run Plugin VM

Change-Id: I772116cd77827ef722559e9fce450235fdbf6478
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1967784
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2019-12-17 09:56:45 +00:00
Zhuocheng Ding
1918627791 x86_64: add tsc_deadline_timer support
Support TSC deadline mode of LAPIC timer, this can potentially increase
the precision of guest timer.

BUG=None
TEST=launch linux guest and run `lscpu`, tsc_deadline_timer is present
in the output.

Change-Id: I7adc87827a51ba8d1866ebee201759f2769ba664
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1951429
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2019-12-13 06:52:11 +00:00
Dylan Reid
eaff194759 sys_util: Expose setting FD flags as a pub fn
Other users will want to set flags on FDs. Particularly asynchronous
code that wants to set FDs as non-blocking. Add a helper that handles
fetching and or-ing in the given flags so users don't have to handle
that themselves.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: Iabe438fbbb1ec305f693dbe1348930ef153edcf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1955044
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-12-12 21:13:37 +00:00
Zach Reizner
0a433f8ca9 gpu_display: generate xlib bindings for input handling and keysyms
BUG=chromium:1023975
TEST=builds

Change-Id: Ic281eb0115e74f8f4fce43c57987be5ad0d50e81
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930408
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-12-12 21:11:38 +00:00
Daniel Verkamp
5118381f2a fuzz: add block_size to block_fuzzer constructor
Fix the build of block_fuzzer after "devices: block: add block_size
option for disks".

It might be nice to generate the block size from the random fuzz data,
but that would complicate things (we'd have to handle failure of
Block::new due to invalid sizes), so let's leave that as a future
improvement for now and just use a block_size of 512 to match previous
behavior.

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

Change-Id: Ia16ef6a57fc8ce4407f8ec9dda0e708302916c4c
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1962535
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-12-12 19:44:07 +00:00
Daniel Prilik
afa30327f8 devices: virtio: add support for VIRTIO_PCI_CAP_SHARED_MEMORY_CFG
Could be used by virtio-fs and virtio-gpu.

(cherry picked from crrev.com/c/1493014)
[took out PCI portions and modified commit message -- @gsingh]

BUG=chromium:924405
TEST=build and run

Change-Id: I47fd4482aa7c11e08bfb4f6c990221ae7a11a11d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963333
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2019-12-12 10:28:34 +00:00
Jason Macnak
bf19558be5 Makes gpu renderer flags configurable via command line
BUG=b:134086390
TEST=built crosvm and booted cuttlefish locally with gpu

Change-Id: I4d816ddb52a2eadd06088d204d95118289a3f587
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927873
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2019-12-11 16:58:39 +00:00
paulhsia
8d3f9ba350 ac97: bus_master: Check pi_info before warm reset
According to ac97 spec, warm reset is specified to no-op when the device
is running. We should ignore it while the device is recording audio as
well.

BUG=chromium:1026538
TEST=Build

Change-Id: I64be922149c90be9a7a8669ef6d56591e6de632b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1960058
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
2019-12-11 16:09:36 +00:00
Fletcher Woodruff
65588b2535 ac97: extract moving to next buffer into function
Create a function move_to_next_buffer which handles incrementing civ and
piv properly.

Set the PICB register when that function is called, not when we read a
guest buffer.

BUG=chromium:968724
TEST=playback on-device

Change-Id: Ib384efceeac4be0e056c20591d93fe32b7305db6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954207
Reviewed-by: Fletcher Woodruff <fletcherw@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-11 01:04:46 +00:00
Gurchetan Singh
bf433ea9f6 crosvm: move vec_with_array_field to data_model
Move it to the newly created flexible array file.

BUG=chromium:892806
TEST=compiles

Change-Id: I6c423a885cec17e376b0da87a4adbd17c71ff6f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1325510
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-11 00:34:36 +00:00
Zach Reizner
65b98f1ccc utilize EventDevices to make virtio-input devices
BUG=chromium:1023975
TEST=./build_test

Change-Id: I10267e535d4d1dae90b2b5f30db046c388791a16
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930409
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-12-11 00:25:55 +00:00
Daniel Verkamp
2767223fdb devices: block: add block_size option for disks
This allows overriding the default logical block size (512 bytes) with
other values, such as 4096 for 4K block size disks.

BUG=chromium:942700
TEST=crosvm run -r vm_rootfs,block_size=4096 vm_kernel
TEST=verify block size with lsblk --output-all

Change-Id: Ia6db05f369a76557a2afb8b48b5cc2b66cf84b01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954220
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-12-10 23:33:56 +00:00
Lepton Wu
84be74727c Remove render node forward code
We don't use it for ARCVM now.
BUG=None
TEST=`emerge-eve crosvm`
Change-Id: I14343a2eb24c24a0216950b7c4eeb56ac482973e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1958569
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Lepton Wu <lepton@chromium.org>
Auto-Submit: Lepton Wu <lepton@chromium.org>
2019-12-10 19:14:40 +00:00
Dylan Reid
bb30b2f7cf Add runnable vcpu
Add a new type `RunnableVcpu` for a vcpu that is bound to a thread. This
adds type safety to ensure that vcpus are only ever run on one thread
because RunnableVcpu can't `Send`. It also ensures multiple vcpus can't
run on the same thread.

Change-Id: Ia50dc127bc7a4ea4ce3ca99ef1062edbcaa912d0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898909
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-12-10 05:16:06 +00:00
Zhuocheng Ding
7434c00020 crosvm: PIT: use full address and avoid conflict
The PIT implementation has the assumption that addresses are I/O port
numbers, so we should use full address mode. i8042 is also changed to
full address mode to avoid the conflict on port 0x61.

BUG=chromium:908689
TEST=None

Change-Id: Ibbb851e3a46ac7fc71576990a1618196de92e33c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945794
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-10 05:08:11 +00:00
Zhuocheng Ding
0e8c11e354 devices: IOAPIC: ignore interrupt polarity
Interrupt polarity is ignored by kvm since 3.15, and the irqfd interface
does not support polarity. We should not consider polarity either.

BUG=chromium:908689
TEST=Unit tests in file. Integration testing is blocked on rest of
split-irqchip being implemented.

Change-Id: Ibae23b81274f867bbf56009854611628dbb4c154
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945793
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-12-10 05:08:08 +00:00
Jason Macnak
cc7070b284 Support configurable screen sizes
This change enables Cuttlefish to run with a user specified display size on top
of virtio gpu accelerated graphics rendering.

This change makes the width and height an argument/flag and adds the necessary
plumbing to pass this width and height through the gpu backend.

BUG=b:134086390
TEST=built crosvm and booted cuttlefish locally

Change-Id: Idabf7ef083b2377e3ebf3b50dd0296f4bf7e8ddc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927872
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Jason Macnak <natsu@google.com>
2019-12-10 04:24:26 +00:00
Chirantan Ekbote
4f9f5c7479 devices: fs: Support fs crypto ioctls
Add support for FS_IOC_{GET,SET}_ENCRYPTION_POLICY.  Unfortunately,
since the I/O direction is encoded backwards in the ioctl definitions,
these will only work with on a kernel that's compiled with a patch to
mark them as unrestricted FUSE ioctls.

BUG=b:136127632
TEST=Compile and run the vfs_crypto.c program on a virtio-fs mount
     inside a VM

Change-Id: I124c5a943111b453dd44921a079a2baa1036dfd4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1952570
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2019-12-10 03:10:57 +00:00
Daniel Verkamp
f21572c718 qcow: avoid out-of-bounds access in alloc_refblocks
When all refblocks are consumed, the loop looking for the first free
cluster would access the element at refcounts[refcounts.len()], which is
out of bounds.  Modify the free cluster search loop to check that the
index is in bounds before accessing it.

BUG=chromium:1030751
TEST=qcow_fuzzer

Change-Id: Ib2384b9cf1edeaadb99be5fc67c27a55c03fc6e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1953766
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-12-10 02:24:14 +00:00
Chirantan Ekbote
aa77ea4045 linux.rs: Don't use /proc/sys/fs/file-max
Don't use /proc/sys/fs/file-max when setting the max open file limit for
the virtio-fs device.  This will fail when the value is larger than the
hard limit set for the crosvm process, unless it also has CAP_SYS_ADMIN
in the initial namespace.

Instead, just use the hard limit as returned by `prlimit64`.  Increasing
the soft limit up to the hard limit is allowed even for completely
unprivileged processes.  It is up to the process that spawned crosvm to
ensure that the hard limit is high enough that the virtio-fs server will
not run out of fds.

BUG=b:142344095
TEST=Start a termina VM with a virtio-fs device after applying
     CL:1939193

Change-Id: I4fb4c33ffe6378ed3109fddcb0fc2bf3da850252
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1957767
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-12-09 23:39:16 +00:00
Jason Macnak
c4a871fb70 Adds a flag_or_value command line argument option
... to allow for specifying either '--gpu' to get default params or
'--gpu=width=800,height=600,egl,surfaceless' to get custom params.

Note: this introduces some potential ambiguity if the flag_or_value
argument is the last arg specified before a positional argument.
For example, 'crosvm run --gpu something' could either be parsed
as a single value ('--gpu=something') or a flag and a positional
argument ('--gpu' and 'something'). This change currently expects
that the functor passed to set_arguments() will return an error
on '--gpu=something' in order to resolve the disambiguity.

BUG=b:134086390
TEST=built crosvm and booted cuttlefish locally

Change-Id: Ib9be604af82583a39d7bd0a403e2168ef7350389
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1929603
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-12-09 22:36:59 +00:00
Chuanxiao Dong
39087b289a devices: clone the EventFds before activate
The interrupt_evt/interrupt_resample_evt/queue_evts were move to activate
so the reset method has to return them back (although there is no virtio
device implemented the reset method yet).

Instead of move, another way is just clone these EventFds so that they
don't need needed to be returned.

The advantage of doing this can avoid changing every virtio device reset
method (again, currently there is no virtio device implemented the reset
method yet, but this method is going to used when needs to support the
reset of a virtio device) for returning them, which can simplify the code.
And reset method just needs to take care their own specific resources.

The disadvantage is that, the clone of an EventFd is try_clone which might
return error code (although this shouldn't happen). If in such case, the virtio
device won't be activated.

BUG=None
TEST=launch crosvm guest with virtio devices(rng/balloon/blk/net).

Change-Id: I6e55782c3ecc46bfa878aff24b85a58a7ed66365
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925682
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-09 03:06:47 +00:00
Lepton Wu
d62df4aa6e seccomp: Allow clock_gettime for audio device
Instant::Now() is called from buffer_completed in ac97_bus_master.rs
sometimes, so we need this. It seems we've already added this to
arm. I guess that code path is only triggered on "slow" devices, that's
why we missed it here in the first place.

BUG=b:139318078
TEST=manual - Run betty-arcvm-pi board under qemu.
Change-Id: I45395eea4d69942c4e9577a39c8074888b4f637c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954222
Tested-by: Lepton Wu <lepton@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Lepton Wu <lepton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Lepton Wu <lepton@chromium.org>
2019-12-07 02:51:17 +00:00
Stephen Boyd
754b906304 aarch64: use gicv3 when available
BUG=chromium:1028450
TEST=tast run -build=false crostini.LaunchTerminal

Change-Id: Ibe3adbe5a86dda42d323632ed14f8dccc283a62e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1934894
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-06 23:59:23 +00:00
Stephen Boyd
cef1079c20 seccomp: Add initial arm64 seccomp filters
BUG=chromium:1029666
TEST=tast run crostini.LaunchTerminal.download_buster

Change-Id: I8fa7dc9df4d5f0144aed80fcd60307036fc7e16d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1946765
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-12-06 19:06:34 +00:00
Daniel Verkamp
92a2c49349 sys_util: guest_memory: check u64 to usize conversion
Replace the unchecked conversion with a try_from() rather than just
truncating without warning.  This gives a more useful error message when
a >4GB guest memory size is requested on a 32-bit platform.

BUG=chromium:1028747
TEST=`crosvm run -m $((5 * 1024)) ...` on kevin

Change-Id: Ib1fcf4019eefdc9ee8f93a5307802e6d6d43d01c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1937552
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-12-06 09:37:53 +00:00
Daniel Verkamp
6a84706795 linux: check memory size calculation overflow
On systems where usize is 32 bits wide (e.g. 32-bit arm), the
calculation of memory_size in bytes based on the -m configuration option
in megabytes would silently overflow when the resulting value was wider
than 32 bits.

Change the shift that converts megabytes to bytes into a checked_mul so
that a suitable error is produced if the size overflows.

Additionally, change the cfg.memory type to u64 instead of usize; this
is representing a size in megabytes, so its maximum value isn't related
to the size of an object in memory anyway, and this avoids the need for
a cast in the memory_size calculation.  Requesting a memory size larger
than the crosvm process can map will still result in an error at a later
stage in guest startup.

BUG=chromium:1028747
TEST=`crosvm run -m $((5 * 1024)) ...` on kevin

Change-Id: I8fef7070bab4dafff70ed54738b26d0bb7632150
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1937551
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-12-06 09:37:52 +00:00