Commit graph

1289 commits

Author SHA1 Message Date
Zach Reizner
f9fc42376a flesh out high level documentation
This change adds a CONTRIBUTING.md and some architectural documentation
for people new to submitting code to crosvm.

TEST=check the gittiles markdown
BUG=None

Change-Id: Ib792220ae50329413f487c5d87b29ad3b2f7c59c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2013213
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-01-22 19:10:45 +00:00
Matt Delco
4389dab579 seccomp: remove redundant unconditional rules
Minijail's policy compiler complains when there's multiple
unconditional rules for a syscall.  In most cases the rules
are redundant to common_device.policy.  I don't know what
to do about the intentionally contradictory rules for open
and openat, other than to remove then from the common device
policy and add it to all the others.

BUG=None
TEST=Ran compile_seccomp_policy.py until it stopped
complaining.

Change-Id: I6813dd1e0b39e975415662bd7de74c25a1be9eb3
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1918607
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-01-22 17:36:36 +00:00
Matt Delco
45caf91aaa crosvm: add support for bpf policy files
Change adds supports for providing pre-compiled bpf files as the policy
file for jailing.  In short it's more effient to compile once on the
build machine than each time at runtime. Additionally libminijail's
support for more efficient bpfs (which use a binary tree instead of
a linear search) is currently only available via tools that are based
around pre-compiled use.

BUG=None
TEST=Ran build_test and verified that tests can pass with both bpf and
policy files (though the tests might only exercise the jail for the
plugin).

Change-Id: Idd93e3c802fc79da93850d6bad1db660576bc9ba
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1914416
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-01-22 17:36:35 +00:00
Gurchetan Singh
425aaacad1 gpu_buffer: update minigbm bindings
gbm_bo_get_stride_or_tiling has been recently removed, so update
the bindings to reflect this and other changes.

BUG=chromium:1044341
TEST=build

Change-Id: Ieed3045bd05244a582660ecf9340128e8fa10090
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2013763
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
2020-01-22 16:08:52 +00:00
A. Cody Schuffelen
e058314700 Use DiskFile in read_cb
This will allow passing in other data sources for the qcow read methods,
without adding extra copies.

TEST=Unit tests
BUG=b:140069322
Change-Id: I2815fa6e416b554968b97959e4b6cd4c93a722f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982829
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-01-22 07:50:03 +00:00
A. Cody Schuffelen
e99b6c7e81 Make DiskFile, CompositeDisk Debug
Making DiskFile Debug allows placing it inside the QcowFile.

TEST=Compiles
BUG=b:140069322
Change-Id: Idf20b7909146b0c2a60d864da386e362e8be97a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982828
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-22 07:50:01 +00:00
Noah Gold
90878fb30e Remove warning for VIRTIO_INPUT_CFG_UNSET.
As indicated in the comments, it seems that this warning is unnecessary.
We've added explicit handling for the UNSET case, and left the warning
intact to handle any out of range values.

BUG=chromium:1041054
TEST=builds.

Change-Id: I2d41159f2d4ccbb4d75d2a8f4bab54586ec65442
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1995308
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Auto-Submit: Noah Gold <nkgold@google.com>
2020-01-21 17:16:59 +00:00
Chuanxiao Dong
1375c284b7 vhost: impl on_device_sandboxed for virtio device
vhost set_owner fn only needs to be called once. Put it in activate
fn will block the vhost devices to be activated again in future.
on_device_sandboxed is a good place to put the set_owner as it only
run once. So put it there.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them can work
TEST=cargo test -p devices

Change-Id: I45308e26b026c9141e4426d8b1bbe1944612a915
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954173
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-19 09:24:42 +00:00
Chuanxiao Dong
92ee1489ce vhost: add cleanup_vqs to do some cleanup stuff
Activate_vqs is used to do the queue preparation before really
running. The virtio-vhost device might need to do some cleanup
to allow a second round activate in the future. How to do the
cleanup is depending on how the vhost virtio devices.

Just add an interface called cleanup_vqs to allow the vhost virtio
devices to do their own cleanup stuff.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them can work
TEST=cargo test -p devices

Change-Id: I2472e79a8b63c9336f886cde55ffef6a78008ad8
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954172
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-19 09:24:40 +00:00
Daniel Verkamp
5de0604f29 seccomp: allow statx syscall where stat/fstat was allowed
This is used in Rust 1.40.0's libstd in place of stat/fstat; update the
whitelists to allow the new syscall as well.

BUG=chromium:1042461
TEST=`crosvm disk resize` does not trigger seccomp failure

Change-Id: Ia3f0e49ee009547295c7af7412dfb5eb3ac1efcb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2003685
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-01-17 23:04:03 +00:00
Stephen Barber
dd21cf7b38 README: remove line claiming no hardware is emulated
We emulate some hardware now, so this statement isn't accurate.

BUG=none
TEST=none

Change-Id: Id8e0e1189001d5b5fe62e032a28fe797bfd9721b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2007998
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
2020-01-17 18:56:11 +00:00
Chirantan Ekbote
5058253c98 MsgSocket: Don't implement Deref
The Deref trait is usually only implemented by smart pointers or by
trivial wrappers around the underlying type. MsgSocket does not fit into
either category because it wraps a `UnixSeqPacket` to provide new
functionality. Having it implement can lead to confusing error messages,
especially for people who are new to rust and are not familiar with the
Deref trait and Deref coercion.

For example, calling `sock.send()` on a MsgSocket without first adding
`use msg_socket::MsgSender` leads to the compiler complaining about
mis-matched types for the `send` method. `UnixSeqPacket::send` expects a
`&[u8]` while `MsgSocket::send` expects a `&M`. The compiler also gives
no clues that it is implicitly coercing the socket to a `&UnixSeqPacket`
and using the `send` method from there.

Drop the `Deref` implementation. `MsgSocket` already implements
`AsRef<UniqSeqPacket>` so anything that _needs_ to access the underlying
`UnixSeqPacket` should just use that.

BUG=none
TEST=unit tests

Change-Id: If02ef7173ae21d85d517e808489ed4d6d09ae90b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2002997
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-01-17 13:17:39 +00:00
Dmitry Torokhov
470b1e7508 crosvm: log 'run' arguments parsing errors also to syslog
We are inconsistent in when we print errors to stdout versus strerr and
syslog, with argument parsing errors from "crosvm run" subcommand only
logged to stdout whereas other types of errors going to stederr/syslog.
Let's make sure argument parsing errors will be logged to stderr/syslog as
well, otherwise it is very confusing to analyze crosvm failures when
started by VM concierge as it does not dump crosvm stdout/stderr anywhere.

BUG=None
TEST=Try "crosvm run" with bad arguments when syslog is available,
see error messages in syslog.

Change-Id: Ie7a284f4a604716ecc655c5a38ec2147b55d63a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2002677
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-01-16 10:16:24 +00:00
Dylan Reid
8c1b754123 sys_util: Fix unused trait warning
Commit "d5aa99542: disk: use seek to determine file length" added these
traits to sys_util but didn't use them.

Change-Id: I0babbbc75450e20f9f7ae7d5f94dd6285c12a8bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1999948
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-01-14 16:24:53 +00:00
Jason Macnak
60eb1fbe89 gpu_display: implement stub display
Adds a stub display that emulates a display without actually
displaying contents anywhere.

This is needed for transitioning Cuttlefish to always using minigbm
as its gralloc implementation. Cuttlefish currently uses a custom
gralloc and hwcomposer implementation when running without hardware
acceleration. The Cuttlefish team would like to start with removing
our custom gralloc implementation and use minigbm. For this, we need
to add a virtio 2D backend to crosvm. Our hwcomposer implementation
currenlly sends framebuffers from the guest to the host via sockets.
The gpu backend still requires a display so we need a stub display
to use with the 2D backend for the period of time while we are
either still using our hwcomposer implementation or until our
hwcomposer implementation is updated to use the virtio backend for
display.

BUG=b:123764798
BUG=chromium:1033787
TEST=built and launched with Cuttlefish locally

Change-Id: I1a7e259d914a53252200c59589c4142e76c6b96b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1993947
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2020-01-14 00:31:00 +00:00
Yusuke Sato
1617c21918 seccomp: Allow 9p device to use open/openat
This allows us to use export a directory to a VM with the
'--shared-dir tag:/dir' crosvm command line flag without relying
on seneschal. The fs device's policy already does the same.

BUG=b:123309049
TEST=Start tot ARCVM, run 'mkdir /var/run/arc/arcvm && mount -t 9p
  -o "trans=virtio,version=9p2000.L,cache=none,access=any"
  host_generated /var/run/arc/arcvm && ls /var/run/arc/arcvm',
  verify ls prints files.

Change-Id: I8f8b265fc8a7de159508afbee5114b6a3f084d01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1995319
Tested-by: Yusuke Sato <yusukes@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Lepton Wu <lepton@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Yusuke Sato <yusukes@chromium.org>
2020-01-13 21:26:19 +00:00
Daniel Verkamp
d5aa995423 disk: use seek to determine file length
Add a new disk-specific DiskGetLen trait which uses io::Seek instead of
File::metadata() to determine the length so that it works on raw block
devices (e.g. /dev/sda) as well as regular files.

BUG=b:146811529
TEST=`crosvm run --disk /dev/sda` and verify block device length

Change-Id: I6936863490efaa479a3c8745c75c373748c800a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1990855
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Trent Begin <tbegin@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-01-13 21:16:29 +00:00
Yi Sun
54305cd5e2 Add a new command to dump version info.
With command "version", we can dump version information via "crosvm version".
By default it would dump the version specified in Cargo.toml like following:
"crosvm package version 0.1.0".

And if the environment varable "PKG_VERSION=123456" is given during building crosvm,
it would dump followed by a package version, like following:
"crosvm package version 0.1.0-123456".

Sometimes, we need to know which exact version does a crosvm binary come
from for developing and testing. It is useful if the git sha is built-in a
crosvm binary.

BUG=none
TEST=PKG_VERSION=xxxxxx Cargo build && crosvm version
TEST=PKG_VERSION=xxxxx emerge-eve crosvm && crosvm version
TEST=./bin/fmt
TEST=./bin/clippy
TEST=./build_test.py --x86_64-sysroot /build/eve

no errors reported and all behavor is as expected.

v2: Refine version info.

Change-Id: I89686dbe6ab2888d8a6ce5752a37241b4c00160d
Signed-off-by: Yi Sun <yi.sun@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1989256
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-13 10:40:34 +00:00
Dylan Reid
4377f048e9 x86_64: fix warning on 1.40
The extra parens crept back in during a recent refactoring.

Change-Id: Iaba13ddea9b7bada09f6079db7e7f8133cbfc896
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1994726
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-12 14:09:06 +00:00
Chirantan Ekbote
a54c64302a msg_socket: Change trait type parameters to associated types
The `MsgSender` and `MsgReceiver` traits take a type parameter for the
message to be sent / received.  However this ends up trickling down to
every user of these traits, who need to add these type parameters
whenever they want to use the trait.

Change the type parameters to associated types instead.  The associated
types keep the same trait bounds but now users of the traits don't need
to care about the exact message being sent / received.

BUG=none
TEST=cargo test

Change-Id: I733a21877cbe49b7904040b8cc6c3436d5e3439f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1993160
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-01-12 05:54:05 +00:00
Chuanxiao Dong
81c804cc7a virtio: resolve some new introduced clippy warnings
BUG=None
TEST=./bin/clippy
TEST=cargo test -p devices

Change-Id: Ic5183ef887a85bc14357fd29bc7ea70caded61a8
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1988704
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-10 06:10:22 +00:00
Zach Reizner
19ad1f3d3a devices: remove user_command from proxy device
The only device that used user_command was Serial. This change makes
Serial device use a thread to read from its input instead of using
user_command.

BUG=chromium:1033787
TEST=./build_test
     run crosvm with stdio serial with and without sandbox

Change-Id: Ia0f2ee83d94ad2fee3f1f4f89aa734b976e33507
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1966435
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-01-09 07:53:57 +00:00
Stephen Barber
58df38b615 devices: net: add control queue for enabling/disabling offloads
Add a control queue for virtio_net, and implement the command to set
available networking offloads.

Set offloads initially when acking features from the guest. We previously set
offloads on unconditionally.

Add TUNSETOFFLOAD to the allowed ioctls for virtio_net.

BUG=chromium:1031413
TEST=boot 5.4 guest, check vmtap offloads enabled with ethtool
TEST=enable ip_forward in guest, check vmtap offloads disabled with ethtool

Change-Id: I4129aa03419798906bd95cf65a6a4ab63069f50b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1968200
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-08 23:10:13 +00:00
Gurchetan Singh
5c1208d128 devices: gpu: log hung-up display
This could be useful for debugging feedback reports.

BUG=chromium:1027379
TEST=compile

Change-Id: I520dedb0d0639f27cd5c2f81b09271bc4a243850
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1986298
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-01-08 20:18:04 +00:00
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