Commit graph

1106 commits

Author SHA1 Message Date
Stephen Barber
eff26bbeb3 devices: use libc::exit instead of process::exit
We don't always shut down the worker threads cleanly, which can lead to a race
when crosvm is exiting. Worker threads that attempt logging to stderr may fail
an expect(), panic, and then panic again trying to write to stderr causing
SIGILL.

Work around this issue for now by using libc's exit, which won't run any
rust-specific cleanup.

BUG=chromium:978319,chromium:992494
TEST=crosvm shuts down without SIGILL/core dumps

Change-Id: I8a99ce8a34220afdf503402d44721a9bea5ec460
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1746830
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-08-14 18:12:16 +00:00
Daniel Verkamp
301583c01a data_model: allow reading structs from io::Read
Add a from_reader() function that allows reading a DataInit type from a
std::io::Read stream.

BUG=None
TEST=./build_test

Change-Id: Iaacae489db2c265d6b1a9af6e18c11c9e6efe354
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1737723
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-14 03:44:28 +00:00
Daniel Verkamp
3d690c6f53 devices: virtio: block: use descriptor chain utils
Rewrite the virtio block device to use the descriptor Reader/Writer
interfaces - this greatly simplifes the block device code.

This also lets the block device handle arbitrary descriptor layouts,
since the descriptor reader/writer handles that transparently for us.

BUG=chromium:990546
TEST=./build_test
TEST=Boot crosvm with vm_kernel+vm_rootfs on workstation
TEST=Boot full Crostini environment on nami

Change-Id: Ie9a2ba70a6c7ed0ae731660fd991fb88242e275f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721371
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-08-13 16:48:45 +00:00
Daniel Verkamp
57debaa85e devices: virtio: make create_descriptor_chain pub
Allow use of this helper function in other virtio devices that want to
write virtio descriptor chains as part of their tests.

BUG=chromium:990546
TEST=./build_test

Change-Id: Ib986646dc36b6406c88f20950586e1c665adf167
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1732851
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-13 16:48:44 +00:00
Daniel Verkamp
1765e6f80f devices: virtio: add volatile read/write for desc chains
This will allow streaming data between a FileReadWriteVolatile and the
descriptor chain Reader/Writer types.

BUG=chromium:990546
TEST=./build_test

Change-Id: Idc97ce99dd1cc340444298f705df4f12e339095d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721370
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-13 16:48:43 +00:00
Daniel Verkamp
977f008bc3 devices: virtio: add seek() for descriptor chains
This allows moving the read/write cursor around within a chain of
descriptors through the standard io::Seek interface.

BUG=chromium:990546
TEST=./build_test

Change-Id: I26ed368d3c7592188241a343dfeb922f3423d935
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721369
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-13 16:48:42 +00:00
Daniel Verkamp
3671305696 devices: virtio: add Error type for descriptors
Add an error type to describe descriptor Errors in more detail.

This lets us return a more accurate error in a later CL in this chain by
adding a VolatileMemoryError variant.

BUG=chromium:990546
TEST=./build_test

Change-Id: I08680d0cb64bfc3667bac7b2ad8a8bc0e78e8058
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1733988
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-13 16:48:41 +00:00
Jianxun Zhang
b600dd5bec Fix compiling warnings in test code
This change fixes two small warnings in smoke test:

   Compiling crosvm_plugin v0.17.0 (/platform/crosvm/crosvm_plugin)
warning: unused import: `std::mem::size_of`
   --> devices/src/virtio/input/event_source.rs:292:9
    |
292 |     use std::mem::size_of;
    |         ^^^^^^^^^^^^^^^^^
    |
    = note: #[warn(unused_imports)] on by default

warning: variable does not need to be mutable
   --> devices/src/virtio/input/event_source.rs:385:13
    |
385 |         let mut evt_opt = source.pop_available_event();
    |             ----^^^^^^^
    |             |
    |             help: remove this `mut`
    |
    = note: #[warn(unused_mut)] on by default

   Compiling arch v0.1.0 (/platform/crosvm/arch)

BUG=None
TEST=./wrapped_smoke_test.sh
Pass smoke test. The 2 warnings disappear in the output.

Change-Id: Ib4de48e9586e80087e30411e225265554d5e7a11
Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1742921
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-09 01:00:57 +00:00
Zach Reizner
0f2cfb095d crosvm: add x-display argument for choosing the X11 gpu display
TEST=cargo run -- run --gpu --x-display :0
BUG=None

Change-Id: I76b4b33a6b14cb6fad322ffa95f00cce976f81a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670550
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-08-08 03:19:58 +00:00
Jianxun Zhang
7f855be1f9 docker: support passing extra arguments to scripts
One of the usages is to specify proxy setting so
that these scripts can download packages behind
proxies. It looks cleaner and more flexible than
tweaking the docker file that's checked in the repo.

BUG=None
TEST=run commands behind a network proxy
./build_crosvm_base.sh --build-arg http_proxy --build-arg https_proxy
./build_crosvm.sh --build-arg http_proxy --build-arg https_proxy
./wrapped_smoke_test.sh -e http_proxy -e https_proxy

Change-Id: Id3729a1343b12c1c7553e047701f770620e3c975
Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1737540
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-07 23:31:48 +00:00
Tomasz Jeznach
a1b54ce9b5 usb: handle transfer errors after port is detached
When USB device is detached from kernel driver there might be multiple
pending USB transfers enqued, each completing with TransferStatus::NoDevice.
Once backend device is detached from system it's ok to ignore subsequent
detach request errors in transfer completion handler.

BUG=chromium:987500
TEST=ADB USB device attach/detach cycles with active adb service.

Change-Id: I4026e68df860c483973f51f9787bf3d48d2716b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1737471
Tested-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-07 14:38:14 +00:00
Jorge E. Moreira
28ea102c0e devices: fix virtio-queue range check
The check for validity of a DescriptorChain needs to ensure that
self.len bytes starting from self.addr are valid valid guest memory
addresses. The last byte of that range (assuming self.len > 0) is
self.addr + self.len - 1.

BUG=b/138459777
TEST=run cuttlefish locally with 4.19 kernel

Change-Id: I2eb6e70e099b3849ac1f6cdd0dfeed092c2a2b02
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1728481
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
2019-08-07 00:37:05 +00:00
Zach Reizner
267f2c80d1 split crosvm into a library and a main "crosvm" binary
This change has 3 parts:
- Modify the Cargo.toml to point at the bin and the lib source.
- Move modules and Config struct into the lib source
- Fix the argument/plugins module's doc comments which had never been
  tested.

The motivation for this change is to make testing crosvm's major
functionality (booting guest kernels, emulating hardware, etc) easier to
do from a cargo test. Being able to launce a crosvm config via the API
instead of the binary's command line will be possible with this change.

A side benefit is that this also enables doc tests in the lib side of
crosvm. The doc tests in binaries are not run due to a limitation in how
they get tested by cargo.

TEST=cargo test
     ./build_test
     kokoro/kokoro_simulator.sh
     emerge crosvm
BUG=None

Change-Id: I9d4b3a24231b895e8dfaf9e7b0f2b33350772041
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1730333
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-08-06 19:23:06 +00:00
Jorge E. Moreira
1e26230f3a Allow to connect standard input to a serial port other than the guest console
Before this change, setting console=true on a serial port caused that
port to be the one connected to the crosvm process' standard input. By
adding an extra 'stdin' argument to the serial parameters it's
possible to make those concepts independent.
Just as with the console argument, stdin defaults to serial port
1 (ttyS0) when not provided and it's possible to set no serial port
connected to stdin (or set as the console) by defining the first
serial port without the stdin (console) argument.

BUG=b/138616941
TEST=boot debian guest in debian host, boot cuttlefish in debian host
Change-Id: I7273e6860218521073df93a4ad71e31c7da522a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1731139
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-08-03 20:03:23 +00:00
David Riley
54e660ba8b gpu: Add sandboxing support for pvr.
BUG=chromium:892280
TEST=glxgears with virtio-gpu on hana

Change-Id: Ib92b21c124e30eacb3fc28558e2eb5d8d4a92567
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1717739
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Riley <davidriley@chromium.org>
Commit-Queue: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: David Riley <davidriley@chromium.org>
2019-08-01 19:34:05 +00:00
David Riley
06787c5b6c gpu: Add sandboxing support for mali/ARM.
ARM platforms have different library locations and also required GPU
devices to be availble to the GPU process.

BUG=chromium:892280
TEST=glxgears with virtio-gpu on kevin and nami

Change-Id: If1baeb1edda76d057e88ab5e88ce22f02e5d30a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1717738
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Riley <davidriley@chromium.org>
Commit-Queue: David Riley <davidriley@chromium.org>
Auto-Submit: David Riley <davidriley@chromium.org>
2019-08-01 19:34:04 +00:00
David Riley
62c533c9a3 gpu_renderer: Make eglDebugMessageControlKHR usage optional.
BUG=chromium:892280
TEST=glxgears with virtio-gpu on kevin and nami

Change-Id: I2158f4fe3411006ce5498b01d12ca627aa985f53
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1717737
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Riley <davidriley@chromium.org>
Commit-Queue: David Riley <davidriley@chromium.org>
Auto-Submit: David Riley <davidriley@chromium.org>
2019-08-01 19:34:03 +00:00
paulhsia
7cf768d02d ac97: Fix device real time priority issue
- Add allow sched_setscheduler call in seccomp policy
- Change the real time priority constant AUDIO_THREAD_RTPRIO to 10 to match
all other clients' priority.

Run the following commands to test
1. ulimit -r 10
2. crosvm run -r ./vm_rootfs.img -c 1 -m 1024 -s /run --cid 5 --host_ip \
   100.115.92.25 --netmask 255.255.255.252 --cras-audio \
   --params="snd_intel8x0.inside_vm=1 snd_intel8x0.ac97_clock=48000" \
   --mac d2:47:f7:c5:9e:53 ./vm_kernel
3. aplay -Dhw:0,0 -f dat /dev/zero
4. ps -AT -o comm,rtprio | grep crosvm
should see a thread running with rtprio=10

BUG=chromium:983533
BUG=b:138262556
TEST=Test with eve (x86_64) and bob (arm)

Change-Id: Idc3711d03d716741f7cefd9a89b14ae4c20c2033
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1729089
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
2019-08-01 09:25:59 +00:00
Dylan Reid
969a0b49ff qcow: bounds check the refcount table offset and size
If the header puts the refcount table outside the file size or if it
specifies a table much larger than needed, fail to open the file.

These might not be hard qcow errors, but they are situations that crosvm
will never encounter.

BUG=986061
TEST=fuzzer with new test cases completes in less than 5 seconds.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: If048c96f6255ca81740e20f3f4eb7669467dbb7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1716365
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-31 09:37:34 +00:00
Daniel Verkamp
a08e40bf81 rust-toolchain: upgrade to Rust 1.36.0
Update the rust-toolchain file and Docker image used in kokoro to match
the Chrome OS toolchain.

BUG=None
TEST=docker/wrapped_smoke_test.sh

Change-Id: I95cbf9bcaadd49b8476f2829bc75958dbea304e3
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1724850
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-07-30 05:35:31 +00:00
Daniel Verkamp
fb32e98f86 sys_util: drop redundant empty return type
rustfmt incorrectly formats the `handler` parameter in
register_signal_handler in a way that actually breaks compilation.

This bug has been reported upstream already, but it is not fixed yet on
the version of rustfmt available with stable rust:
https://github.com/rust-lang/rustfmt/issues/3673

However, the empty return type can just be omitted in this case, which
avoids the rustfmt bug.

BUG=None
TEST=`bin/fmt --check` passes with Rust 1.36.0

Change-Id: I75c49c66f1db9cb6ae73cc0f6f3e66351176c474
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1724849
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-30 05:35:30 +00:00
Zach Reizner
2ea297ac76 seccomp: add sendto, writev, and readv to common seccomp policies
Using syslog from glibc will use some syscalls we haven't seen before,
leading to the process getting killed. This change fixes that.

TEST=use syslog from C
BUG=chromium:988082

Change-Id: I4cfb317a8faf70188995487f4fa844229683d6d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721616
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-27 03:50:22 +00:00
Zach Reizner
92e75f0e2a gpu_display: fix use after free for the wayland socket path
Using .map in the way it was caused the CString to get moved into the closure
and then dropped by that closure. The returned pointer is then used in
dwl_context_setup after it was freed by the drop.

This change fixes that first by using .as_ref() before calling .map to
prevent the move. As an additional safeguard, some optional types were
added to the closure to make sure a reference to the CString was being
handled instead of a moved CString.

TEST=vmc start --enable-gpu termina
BUG=chromium:988082

Change-Id: I58c2c002f08688ecd85715d9cd45085dffb32457
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721615
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-07-27 03:50:21 +00:00
Zach Reizner
f5285c647a gpu_display: add X11 backend
This change adds an X11 backend to the gpu_display crate. With this
addition, the virtio-gpu device can display to traditional linux
desktops that only have X11 output.

Change-Id: I86c80cac91ca5bdc97588194a44040273ae69385
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591572
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2019-07-25 22:15:48 +00:00
Zach Reizner
b2110bef59 tree-wide: use PollContext::build_with where possible
The old method of creating a PollContext and calling `add` inside of
`and_then` chains was an ugly way handle the Results that can crop up
after each call. The `build_with` function is equivalent but operates on
a slice which has way less boilerplate.

TEST=./build_test
BUG=None

Change-Id: I8b0d6532680e04c501187397bd211014a2363c25
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715581
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-07-24 06:07:20 +00:00
Zach Reizner
229063c2bf sys_util: poll: add build_with and add_many helper functions
These functions are wrappers around multiple `add` calls that will fail at the
first error. This replaces lots of ugly `and_then`, `and`, and `ok` calls that
had been sprinkled around the to initialize a `PollContext`.

TEST=cargo test -p sys_util
     ./build_test
BUG=None

Change-Id: I69aa1c9ad87677cf220eda57148ff8eb2268bf67
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715580
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-07-24 06:07:19 +00:00
Dylan Reid
2f0c0b3f5d sys_util: fix new warning initializing Once
"warning: use of deprecated item 'std::sync::ONCE_INIT': the `new` function is now preferred"

Change-Id: I029611f2978d5baf3b0bc426ab2285e282708da0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715577
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-24 02:22:23 +00:00
Dylan Reid
e19cae8c6a tree-wide: Use new trait object syntax
A few places were using the old syntax without `dyn`. Nightly compilers
have started warning more aggressively, so fix up the last of those.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I4df49b4a27a62acfd8c542cec903e4c5b31bedcc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715576
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-24 02:22:23 +00:00
Dylan Reid
c3bee1f8c3 tree-wide: update to new inclusive range syntax
1.38 nightly started warning about using `...` vs `..=`, update to avoid
the warning.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: Ibc3d24c5410b6eed9a1207db21e529ec6a763376
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715575
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-24 02:22:21 +00:00
Dylan Reid
13c2191395 qcow: Add a zero_cluster method to raw file
Zeroing a cluster will be done from more than one place in qcow.rs soon,
add a helper to reduce duplication.

Change-Id: Idb40539f8e4ed2338fc84c0d53b37c913f2d90fe
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1697122
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-19 21:19:13 +00:00
Jorge E. Moreira
cb3ec5ed2b Refactor input devices interactions with buffers in guest memory
Input devices were using GuestMemory's read_to_memory and
write_from_memory under the (incorrect) assumption that these function
used the io::Read and io::Write traits, when they in fact use AsRawFd.

BUG=b/137138116
TEST=ran cuttlefish in workstation

Change-Id: I7ab1e2d0ab685dd25dcc91e794766c2f210665f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1700418
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
2019-07-17 22:04:23 +00:00
Jorge E. Moreira
009392ac76 Don't call UNGRAB IOCTL on a socket
That IOCTL only makes sense on devices from /dev/input

BUG=none
TEST=ran cuttlefish in workstation

Change-Id: I1aa1eea1a10db9a4d67337546782e118fceb14ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1703209
Tested-by: Jorge Moreira Broche <jemoreira@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-07-17 19:23:13 +00:00
Gurchetan Singh
ed88b0ef5e devices: gpu: advertise support for capset 3
Useful for prototyping new features.

BUG=chromium:924405
TEST=compile

Change-Id: Ibdc4a70761493939ca96b92540b9e0cca88c17a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650290
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-16 17:21:39 +00:00
David Tolnay
e33b55c429 tempfile: Unify the two tempdir implementations
Looks like we ended up with two totally different tempdir
implementations: one from CL:520706 and the other from CL:1409705.

This CL consolidates them into one implementation.

BUG=chromium:974059
TEST=tempfile: cargo test
TEST=crosvm: cargo check --all-features
TEST=devices: cargo check --tests
TEST=sys_util: cargo check --tests
TEST=local kokoro
TEST=./build_test

Cq-Depend: chromium:1574668
Change-Id: Id70e963c9986ed2fc5f160819c4a7f9f16092b3b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1573227
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
2019-07-11 16:15:38 -07:00
Daniel Verkamp
8f94a9ff71 devices: silence unused code warning in PCI
Now that nothing uses the PCI-to-PCI bridge device type, the compiler
warns that it is never constructed.  Mark the PciHeaderType enum to
allow this, since the enum is public and could be constructed outside
this file.

BUG=None
TEST=./build_test

Change-Id: I6832996c4e00a33cc1ba88d97fede65b226cbfc5
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691239
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-07-10 00:53:12 +00:00
Daniel Verkamp
9f86c7a221 seccomp: return error from socket for TPM device
The crosvm TPM process calls ssleay_rand_bytes(), which in some cases
attempts to acquire entropy through an EGD ("entropy gathering daemon")
- see OpenSSL's RAND_query_egd_bytes(). Attempting to communicate with
this daemon by creating a socket would cause the process to exit
currently because the syscall whitelist did not allow socket() or
connect().

Since we don't have an EGD and don't want to expose it to the sandboxed
TPM process anyway, modify the TPM seccomp policy to cause socket() to
return an error rather than aborting.

BUG=None
TEST=`vmc start --software-tpm termina`

Change-Id: Ib7c6bceced0f6cbe7199614ece8446aa300cec1e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1684411
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-07-09 23:34:57 +00:00
Dylan Reid
93b0c02227 qcow: limit the size of a qcow file
There are many corner cases when handling sizes that approach u64::max.
Limit the files to 16TB.

BUG=979458
TEST=Added unittest to check large disks fail

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I93a87c17267ae69102f8d46ced9dbea8c686d093
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679892
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-09 17:46:22 +00:00
Dylan Reid
eecbccc4d9 qcow: Avoid overflow when taking ceiling of division
The extra % operation will be slower, but none of these divisions are in
hot paths. They are only used during setup. Many of these operations
take untrusted input from the disk file, so need to be hardened.

BUG=979458
TEST=unit tests still pass

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I0e93c73b345faf643da53ea41bde3349d756bdc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679891
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-09 17:46:17 +00:00
Daniel Verkamp
bb5a4f1843 devices: remove use of mem::uninitialized
mem::uninitialized is unsafe, and we already replaced most instances of
it with alternate implementations; however, another one slipped in since
then.  Replace it with Default::default() as a safe alterantive.

BUG=None
TEST=./build_test

Change-Id: Idacdcb0ebe197cc93fba4b15c3dda774bb56e73e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691233
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-09 17:07:51 +00:00
Daniel Verkamp
da52468b34 tempfile: reimplement using libc::mkdtemp
POSIX provides a standard mkdtemp() function to securely create a
temporary directory; use it rather than reinventing the wheel.

This also drops the dependency of tempfile on rand_ish, which will allow
easier use of the tempfile implementation outside of crosvm.

BUG=chromium:974059
TEST=cargo test -p tempfile

Change-Id: I34a226b046dc6f272106988a78d121a24a377f44
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1659971
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-07-03 16:35:43 -07:00
Daniel Verkamp
5104b9641c build_test.py: test more packages
Add a number of packages to the build_test.py list so that they are
built and tested during local development. build_test.py doesn't run in
any automated tests currently, but it's still useful for checking
whether everything still builds for multiple architectures without the
overhead of a full portage build.

BUG=None
TEST=./build_test.py

Change-Id: I6d3300ae3189311fb6faffaf10c254636adba7c1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1682925
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-03 20:39:50 +00:00
Xiong Zhang
e09e470177 pci: Let device could trap pci config read/write
Currently device impliments PciDevice trait, it will return config
register to bus trait at pci cfg r/w, then BusDevice trait on behave
of device to do actual pci config r/w.

But vfio device need to handle the pci config r/w by itself, as
vfio device need to transfer this request to kernel.

For pci config read, this patch delete PciDevice->config_registers(),
and add PciDevice->read_config_register(), then BusDevice->
config_register_read() call PciDevice->read_config_register(), finally
Device could trap the PciConfig Read.

For pci config write, it is similiar with pci config read. But the
common code is moved into PciConfiguration.

BUG=none
TEST=none

Change-Id: Ie6bd3a8c94f523d6fb1ef3d1e97d087bb0407d9f
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1580457
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-07-03 16:56:46 +00:00
Gurchetan Singh
ad656a9d3a seccomp: whitelist read-only/write-only GPU mappings
minigbm sometimes maps buffer with only PROT_READ or only
PROT_WRITE, so allow this.

BUG=b:132939420
TEST=glxgears in container

Change-Id: Ie5ccd827dd14ee78b999d70287b7165d81c5c85e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1673533
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-07-03 15:41:58 +00:00
David Riley
996beb6499 virtio-gpu: Allocate buffers with shared bind flag using gbm.
BUG=chromium:972237
TEST=eglgears_wayland

Change-Id: If5a09c1ad95dfdbd47e7810c466c127c53413f21
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1657291
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Riley <davidriley@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-03 15:41:57 +00:00
David Riley
aa36a2923a gpu_renderer: update virglrenderer bindings
Results of:
  gpu_renderer/src/generated/generate --sysroot /build/$BOARD
  bin/fmt

BUG=chromium:972237
TEST=builds

Change-Id: I75063345a6cc77b54f51cfdaf244e5f73dffefcb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1657290
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Riley <davidriley@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-03 15:41:55 +00:00
Gurchetan Singh
33626056f4 devices: virtio: add bindings to a new capset
This is useful for prototyping new virtgpu features (zero copy, YUV, Vulkan)
without stepping on virglrenderer's capsets.

Initially, the plan is just to transparently support zero-copy in ARCVM.

The bindings were generated from the following header:

https://gitlab.freedesktop.org/gurchetansingh/virtio-gpu-test/blob/master/virtgpu_hw.h
Generated via:

bindgen --with-derive-default virtgpu_hw.h -o virtgpu_hw.rs --no-doc-comments --no-layout-tests \
        --whitelist-type=virtgpu_.+ --whitelist-var VIRTGPU_.+ --no-prepend-enum-name

BUG=chromium:924405
TEST=compile

Change-Id: I6000244faa0d619c3ac74105713e63a52d0d9cb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650289
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-03 05:42:27 +00:00
Gurchetan Singh
ab827ab177 gpu_buffer: add ability to get backend name
This is useful for letting the guest know about host-specific
features.

BUG=chromium:924405
TEST=compile

Change-Id: I0edc4280eec7235644c9ad8561dbe063276bb3bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650288
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-03 05:42:25 +00:00
Zach Reizner
44863792aa main: add seccomp-log-failures flag to command line
All cros-debug versions of crosvm enabled seccomp logging, which is now
broken on kernels <4.4 thanks to new minijail changes as explained in
the referenced BUG. This seems to be intended by the minijail folks as
the aim to improve the seccomp logging in part by changing its semantics
to logging failures without killing the violating process. In such a
world, crosvm should not as a compile time choice, enable logging, which
would amount to disabling some of the security. This change adds a
command line flag to emulate the old behavior for the purposes of
developer debugging, as long as that developer is running on a kernel
that supports the new minijail seccomp filter failure logging.

BUG=chromium:978998
TEST=USE=cros-debug emerge-eve crosvm && cros deploy eve crosvm
     then start crostini in UI

Change-Id: I98190a068a919929e466fe22d6d630b90a758336
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679380
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2019-06-27 20:51:15 +00:00
Daniel Verkamp
6160e479f6 usb: switch to new libusb_wrap_sys_device API
Replace use of our custom, patched libusb APIs with the new
libusb_wrap_sys_device() function, which has been submitted to libusb
upstream. This allows us to drop the bindings for the custom APIs (and
will also allow us to drop the libusb patch that introduces them).

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

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

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

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

Change-Id: I6a3dc9176bffdefe664139cb33bf3e65a751dbf2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679531
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-27 17:29:53 +00:00