Commit graph

1248 commits

Author SHA1 Message Date
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
Stephen Barber
bbc866e7de seccomp: add memfd_create to arm gpu_device.policy
BUG=chromium:1031360
TEST=graphics.CrostiniTraceGlxgears

Change-Id: I9b416a4a50b7747a0914b33d719f2459c499f71d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954219
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-12-06 09:35:33 +00:00
Xiong Zhang
85abeff27f vfio: Implement bar mappable
if device bar is mappable, map bar's gpa to hpa in EPT, guest vcpu
could access this bar directly through EPT without trapping. This
could improve performance.

vm.add_mmio_memory could help do this, here vfio_pci send
RegisterMmapMemory request through vm_control socket to do this.

BUG=chromium:992270
TEST=none

Change-Id: I3b4274372f7dcd32e18084d55f037b6fe45ed422
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581147
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-12-06 08:47:29 +00:00
Daniel Verkamp
c0385a0916 sys_util: don't implement File*Volatile for SharedMemory
The implementations of FileReadWriteVolatile and FileReadWriteAtVolatile
for SharedMemory are never used; SharedMemory is typically accessed as a
memory mapping, not as a writable/readable file-like object.  Remove the
implementation of these traits for SharedMemory to simplify porting to
other platforms where SharedMemory may not necessarily be backed by a
file-like object.

BUG=None
TEST=./build_test.py

Change-Id: I9c1e46ad2d3299b8676fad33151cde7c4b1c7b8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1937555
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-12-06 04:28:39 +00:00
Daniel Verkamp
c0a1f5318e devices: use File rather than shm in tests
Two virtio descriptor_utils tests were using SharedMemory to stand in
for I/o targets with a fixed size; replace these with File to avoid
needing the FileReadWriteVolatile impl for SharedMemory, which isn't
used anywhere else in the crosvm code base.

This slightly changes the behavior under test in the reader_failing_io
test, since it was previously using the SharedMemory seal functionality
to make the region ungrowable; this is an unusual corner case, and (as
mentioned in the comment that was previously at the end of the test) it
is testing implementation details of write() on shared memory on Linux.
Instead, just use a read-only file so that write() to it will fail and
cause the same observable result.

BUG=None
TEST=./build_test.py

Change-Id: I6d62cd70791f1dec625b750ecd01cc51e307f971
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1939783
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-06 04:28:37 +00:00
Zach Reizner
bfbe888041 seccomp: move gettid to common_device.policy
The gettid syscall is used in some corners of glibc and it is a fairly
harmless syscall (we already give getpid), so this change moves it to
the common policy.

TEST=None
BUG=chromium:996938

Change-Id: I129644273f2f02fe917255c7157c48b99c329045
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1952565
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-12-06 03:21:11 +00:00
Daniel Verkamp
bb712d649f devices: virtio: enable MSI-X for all devices
All virtio devices can use the same generic calculation for number of
MSI-X vectors required: number of queues plus one for configuration
changes.  Move this calculation to the VirtioPciDevice implementation
and remove the Option to unconditionally enable MSI-X support for all
PCI virtio devices.

BUG=chromium:854765
TEST=Verify all virtio interrupts in /proc/interrupts are PCI-MSI

Change-Id: I5905ab52840e7617b0b342ec6ca3f75dccd16e4d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925169
Reviewed-by: Zide Chen <zide.chen@intel.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-06 01:45:44 +00:00
Fletcher Woodruff
277ea5f4b4 ac97: combine PlaybackError and CaptureError
PlaybackError and CaptureError encode the same error cases. Combine the
two into one Error type, AudioError.

BUG=None
TEST=builds

Change-Id: I44259227d67a0284c9a11c4aafd86fafe1006f8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925727
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
2019-12-04 18:02:49 +00:00
Dylan Reid
38b9ad8620 sys_util: Ignore struct_util doc comment
The code in the doc comment didn't compile, fix the missing command.
Ignore the snippet because it depends on arch::__IncompleteArrayField,
and getting it to compile isn't worth adding a crate dependency.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: Ibaee50d0d44fbfb9ca2862b1dda220a0a1e5696b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1944097
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-04 05:57:29 +00:00
Chirantan Ekbote
1a5fe95471 linux.rs: Set open file limits for all devices
The virtio-fs device opens a lot of fds and needs to have a pretty high
open file limit.  In order for this to be successful on Chrome OS, the
parent process (concierge) also needs to have a very high open file
limit.  This unfortunately has the side-effect of raising the open file
limit for _all_ crosvm devices.

Deal with this by setting the open file limit back down to a reasonable
value (1024) for all devices that use `create_base_minijail`.  This was
the value of the open file limit for concierge before the increase.

BUG=b:142344095
TEST=Check /proc/<pid>/limits for various crosvm device processes and
     see that they have the proper value for "Max open files".

Change-Id: I87e3fe62fe22e68bff5ba5b60d85d39060a111dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1939527
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-11-28 03:05:57 +00:00
Daniel Verkamp
4cc280bcff disk: add get_len() to eliminate need for Seek
This new trait allows DiskFile implementors to provide the length of the
file directly rather than using SeekFrom::End with seek().

BUG=None
TEST=./build_test
TEST=Boot Termina in crosvm

Change-Id: I9447ebb43dbd5fbb32a3a6b6d2fc969b9406cdbc
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913961
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-27 21:22:41 +00:00
Daniel Verkamp
624c51bee3 disk: switch from WriteZeroes to WriteZeroesAt
This eliminates an extra seek per guest write zeroes request.

Additionally, it allows us to stop depending on the file cursor and pass
the offset directly, making multi-queue implementation easier.

BUG=chromium:858815
TEST=Boot Termina in crosvm

Change-Id: I8b15a39752a1b68597a2b1e1fd72382a484a3cb2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913521
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-27 21:22:40 +00:00
Daniel Verkamp
41d889eb26 sys_util: do not deallocate space in write_zeroes
Replace the implementation of File write_zeroes with one that uses
fallocate() with the FALLOC_FL_ZERO_RANGE flag instead of
FALLOC_FL_PUNCH_HOLE.  This means it will keep space allocated for the
zeroed region instead of deallocating it.  The PunchHole trait is
available for this purpose instead, and the virtio-blk implementation
already relies on these two traits for their differing behaviors.

BUG=chromium:858815
TEST=cargo test -p sys_util write_zeroes

Change-Id: I69ab06037f72dc219e6ea9409654f97eeaba32c3
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913520
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-27 21:22:39 +00:00
Daniel Verkamp
6eadef77a3 sys_util: add WriteZeroesAt trait
Add a variant of WriteZeroes that allows the caller to specify the
offset explicitly instead of using the file's cursor.  This gets rid of
one of the last bits of shared state between disk file users, which will
help in implementing multi-queue support.

Additionally, modify the WriteZeroes trait to use a generic
implementation based on WriteZeroesAt + Seek when possible.

BUG=chromium:858815
TEST=Boot Termina in crosvm

Change-Id: If710159771aeeb55f4f7746dd4354b6c042144e8
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913519
2019-11-27 21:22:37 +00:00
Xiong Zhang
3064a7164a Setup vcpu's MTRR
When vfio pass-through is enabled, guest will be very slow. The root
casue is gfn is uncachable in EPT.

From the comments in kernel vmx_get_mt_mask(vcpu, gfn, is_mmio)
function, EPT memory type with VT-d, VT-d without snooping control
feature: can't guarantee the result, try to trust guest through
kvm_mtrr_get_guest_memory_type(vcpu, gfn).

But crosvm doesn't set mtrr, so host kernel will set uncachable for all
gfn in ept.

This patch set the default cache type as WB, and set mmio cache type as
UC, so the guest ram is WB.

BUG=chromium:992270
TEST=crosvm --vfio /sys/devices/pci0000:00/0000:00:02.0, pass through
host igd into linux guest, the guest runs smoothly and guest desktop
could be shown on physical local display.

Change-Id: I151aae7835910cfbc9e38464ee901e5da281de1e
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1813458
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-11-27 09:04:26 +00:00
Chirantan Ekbote
3ea11281eb io_jail: Use rlim64_t for minijail_rlimit
The libminijail API defines rlim_t as an alias for rlim64_t.  Change the
FFI bindings to use rlim64_t.

BUG=none
TEST=`tast run kevin vm.Virtiofs`

Change-Id: I21ece499bcef187b358574bca0918b39f5971586
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1933612
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2019-11-27 08:45:56 +00:00
Zach Reizner
2b0bc61ea7 gpu_display: amend GpuDisplay to import and attach EventDevices
This change also includes stubs for the wayland and x11 impls.

TEST=compiles
BUG=chromium:1023975

Change-Id: Ia2bcb5c2ed75ea47071dd77e149e60901a56595c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930407
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-11-26 21:05:44 +00:00
Zach Reizner
6f8823abb5 gpu_display: add EventDevice to bridge gpu_display to a virtual input device
The EventDevice is a data structure that allows a generic gpu display to
send and receive input events in evdev's format to a generic input
device, such as virtio-input.

BUG=chromium:1023975
TEST=None

Change-Id: Ic663cc8c7a3031aee929e09620c5430c27a25190
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930406
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-11-26 21:05:44 +00:00