Commit graph

516 commits

Author SHA1 Message Date
David Tolnay
d32efefb7a macros: Format code inside of quote! invocations
Rustfmt currently does not touch the content of macro invocations. Also
it used to have a bug where if it changed indentation of a block of code
containing a multi-line macro invocation then the macro input would not
get correspondingly indented. That bug was visible across some of the
code here.

For example:

    // rustfmt decides to un-indent the surrounding block:
        let data_size_in_bytes = quote!(
            ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8
        );

    // poorly formatted resulting code:
    let data_size_in_bytes = quote!(
            ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8
        );

    // should have been:
    let data_size_in_bytes = quote!(
        ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8
    );

TEST=cargo check crosvm
TEST=cargo test each of the three proc-macro crates
CQ-DEPEND=CL:1338507

Change-Id: Id2d456a8d85d719fbc0a65624f153f0f9df6f500
Reviewed-on: https://chromium-review.googlesource.com/1338508
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-11-21 05:52:46 -08:00
David Tolnay
1d0b445be2 macros: Update syn to 0.15
This brings us onto the stable API surface area for procedural macros
that stabilized in Rust 1.30, rather than the string-based shim on
older compilers.

    https://blog.rust-lang.org/2018/10/25/Rust-1.30.0.html

Intervening release notes:

- https://github.com/dtolnay/syn/releases/tag/0.13.0
- https://github.com/dtolnay/syn/releases/tag/0.14.0
- https://github.com/dtolnay/syn/releases/tag/0.15.0

TEST=cargo check crosvm
TEST=cargo test each of the three proc-macro crates
TEST=build_packages
CQ-DEPEND=CL:1340766

Change-Id: Idcf14df0225ab41423b9a8639d0bba0a63513712
Reviewed-on: https://chromium-review.googlesource.com/1338507
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-11-21 05:52:45 -08:00
Daniel Verkamp
e81a3e66cc devices: convert virtio features to a u64
The virtio specification only defines feature bits in the 0-63 range
currently, so we can represent the features as a u64.  The Linux kernel
makes the same simplifying assumption, and very few features have been
defined beyond the first 32 bits, so this is probably safe for a while.

This allows the device models to be simplified, since they no longer
need to deal with the features paging mechanism (it is handled by the
generic virtio transport code).

BUG=None
TEST=build_test; boot termina on kevin

Change-Id: I6fd86907b2bdf494466c205e85072ebfeb7f5b73
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1313012
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-11-21 01:25:28 -08:00
Chirantan Ekbote
5c4ad02dd4 crosvm_plugin: Remove underscores in variable name
Remove the double underscore in front of `__has_extension` in crosvm.h.
Double underscores in identifiers are reserved for the compiler's
internal use and as it so happens, `__has_extension` is a macro that
clang defines for code to determine whether the compiler supports a
given feature.

We shouldn't be using double underscores in any of the variable names in
this header file but for now just fix the problematic one so that the
code can actually compile under clang.

BUG=b:80150167
TEST=Compile one of the test plugins with clang

Change-Id: Ibb59e72c968a7f245bd6cc693da99f9263eedf33
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1341100
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-11-20 18:27:40 -08:00
David Tolnay
cccbe6717c toolchain: The latest stable version is required
TEST=rustup update stable && cargo +stable check

Change-Id: I3f51132a6d3d5daac1f77924fd910b46aa4c6118
Reviewed-on: https://chromium-review.googlesource.com/1340657
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-11-20 05:52:41 -08:00
David Tolnay
298cf591ac toolchain: Add rust-toolchain file
The rust-toolchain file defines a local toolchain override that is
respected by rustup when running Cargo commands. This override applies
to the directory containing the rust-toolchain file as well as its
subdirectories. It makes it so that running `cargo check` or `cargo fmt`
always uses the intended toolchain, unless overridden by e.g. `cargo
+nightly check`, regardless of what toolchain the user has selected as
global default. No more accidentally running a too new or old version of
rustfmt!

We will need to bump this version number when rolling to a newer
toolchain in ebuild. When that happens, local Cargo commands by other
crosvm developers will automatically download the new toolchain.

For details on rust-toolchain:

    https://github.com/rust-lang-nursery/rustup.rs#the-toolchain-file
    https://github.com/rust-lang-nursery/rustup.rs#override-precedence

This file is ignored during emerge. Verified by setting rust-toolchain
to a bogus version number and emerge succeeded anyway.

TEST=rustc --version
TEST=rustc +nightly --version
TEST=cargo check
TEST=cargo fmt --all
TEST=cargo +nightly check
TEST=build_packages

Change-Id: Ia4d74a0c8c632bcd7b171f6c039b068fb30b5502
Reviewed-on: https://chromium-review.googlesource.com/1340728
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-11-20 05:52:35 -08:00
Jingkui Wang
e13b180f74 crosvm: use msg_socket in vm_control
Refactor existing code to use msg_socket.

BUG=None
TEST=local build and run

Change-Id: Iee72326b330e035303f679e1aedd6e5d18ad4f8a
Reviewed-on: https://chromium-review.googlesource.com/1260260
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-11-19 16:28:35 -08:00
Jingkui Wang
b23c091c8b Reland "devices: refactor proxy to use msg_socket"
This reverts commit 9d5e8f34ad.

Reason for revert: msg_socket was fixed to not call sendmsg/recvmsg

BUG=None
TEST=local build

Original change's description:
> Revert "devices: refactor proxy to use msg_socket"
>
> This reverts commit 142ce3efd9.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > devices: refactor proxy to use msg_socket
> >
> > Use msg socket in proxy.
> >
> > BUG=None
> > TEST=None
> >
> > Change-Id: Ia5ebc4410918a261fe525abc1051ebbbdc66a876
> > Reviewed-on: https://chromium-review.googlesource.com/1260259
> > Commit-Ready: Jingkui Wang <jkwang@google.com>
> > Tested-by: Jingkui Wang <jkwang@google.com>
> > Reviewed-by: Zach Reizner <zachr@chromium.org>
>
> Bug: None
> Change-Id: Ic7827969e9ad508cd1b65cb7b8747e81e0cd02d0
> Reviewed-on: https://chromium-review.googlesource.com/c/1313014
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
> Tested-by: Jingkui Wang <jkwang@google.com>

Bug: None
Change-Id: I27822d7572cab028ec6ed1f0f686fface0858a9a
Reviewed-on: https://chromium-review.googlesource.com/1315511
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-11-19 07:09:20 -08:00
Daniel Verkamp
ac2e50a6ce aarch64: report PCI interrupts as level triggered
This matches the x86 mptable change from commit ac242df107.

BUG=None
TEST=Boot termina on kevin

Change-Id: I370419f3edc1271df4ae7cdbe4b35241945c2757
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1333942
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-11-16 05:02:22 -08:00
Daniel Verkamp
f0fd764428 qcow: calculate refcount table size correctly
The refcount table needs to include not only the data clusters and
reftable clusters but also the L1 and L2 tables and main qcow2 header.

Also add sanity checking to prevent allocating a cluster that cannot be
indexed with the current reference count table size.

BUG=chromium:899273
TEST=cargo test -p qcow

Change-Id: I9da4515db3dccbabdeee4f60dc392b5b42d62cb2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1308833
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-11-16 05:02:06 -08:00
Zach Reizner
94923406ae qcow_utils: do not close given fds in convert_to_* functions
The `convert_to_*` functions take ownership of the passed FDs even
though they should not according to the function's contract. This change
clones the passed FDs so that the caller can retain ownership of its
FDs.

This change also wraps most of the implementations in catch_unwind so
that panics do not unwind past FFI boundaries, which is undefined
behavior.

BUG=chromium:905799
TEST=in crosh: `vmc export <vm name> <file name>`

Change-Id: I2f65ebff51243675d0854574d8fd02cec1b237a4
Reviewed-on: https://chromium-review.googlesource.com/1338501
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-11-16 05:01:42 -08:00
Zach Reizner
674504a3de move qcow_utils to members from dependencies
The qcow_utils crate is not a dependency of crosvm and should not be
built in the same phase as crosvm. Doing so was harmless before the
recent rustc/cargo changes, which seem to be triggering some kind of
race condition. This change works around the bug.

CQ-DEPEND=CL:1336738
TEST=cargo test --release
BUG=chromium:900366

Change-Id: I01048128b20cf06580e809f6701688ab72e7756d
Reviewed-on: https://chromium-review.googlesource.com/1336737
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-11-16 05:01:41 -08:00
Zach Reizner
2fb61f77fe msg_socket: return io:Error from pair() instead of Option
Change-Id: I8733794bca7a9510d5508941cbe3297a78e9923b
Reviewed-on: https://chromium-review.googlesource.com/1314210
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-11-15 08:11:28 -08:00
Zach Reizner
e0305c6533 msg_socket: implement AsRawFd for UnixDatagram wrappers
Change-Id: I0589c6b88b4922db422771dc5930ca3f00b91736
Reviewed-on: https://chromium-review.googlesource.com/1314209
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2018-11-15 08:11:28 -08:00
Zach Reizner
c527c1a7e8 fix formatting in msg_on_socket_derive.rs unit test
Turns out my cargo-fmt binary was being sourced from ~/.cargo/bin, which
was very out of date. Hopefully less formatting issues come out of my
chroot now.

TEST=cargo fmt --all -- --check
BUG=None

Change-Id: I50592e2781835840dc5d589c681b3438d6de3370
Reviewed-on: https://chromium-review.googlesource.com/1324669
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-11-09 07:20:12 -08:00
Zach Reizner
f741098251 kokoro: make output slightly more verbose
This change includes relevant toolchain versions and some echos
announcing the stages of testing. This should make kokoro's logs a bit
easier to diagnose.

TEST=kokoro_simulator.sh
BUG=None

Change-Id: I6d51d8ae6618a244338605d61882eeedcb1f5b79
Reviewed-on: https://chromium-review.googlesource.com/1324689
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-11-09 07:20:06 -08:00
Zach Reizner
3c71bb953e msg_socket_on_derive: use fully qualified types
The types from msg_socket were assumed to be in scope for the custom
derive implementation, which would cause mysterious compiler errors if
the custom derive was invoked in a module without msg_socket types in
scope.

This CL uses fully qualified types in the generated output to avoid
these errors.

This change also uses `extern crate msg_socket` in case the call site
doesn't have it in scope.

BUG=None
TEST=cargo test -p msg_on_socket_derive

Change-Id: Ie6443cd4ffc070d27e71de123090a58f19846472
Reviewed-on: https://chromium-review.googlesource.com/1314208
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2018-11-07 06:35:06 -08:00
Daniel Verkamp
60f55da937 devices: balloon: define features as shift counts
This matches the definitions from the virtio specification and makes
balloon consistent with the other virtio devices in crosvm.

BUG=None
TEST=build_test.py

Change-Id: I9dd6b6ec981944e28eaf6bc92332db5ec326433b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1313011
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-11-07 01:21:20 -08:00
Jingkui Wang
994e418039 msg_socket: avoid send_msg/recv_msg call if it's not necessary
This patch avoids sendmsg/recvmsg if there is no fd.

BUG=chromium:900962
TEST=build local image and test

Change-Id: I3a5fd52232dc7d98dacd78aa0b383a436056ffb7
Reviewed-on: https://chromium-review.googlesource.com/1313656
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-11-02 14:50:47 -07:00
Jingkui Wang
9d5e8f34ad Revert "devices: refactor proxy to use msg_socket"
This reverts commit 142ce3efd9.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> devices: refactor proxy to use msg_socket
> 
> Use msg socket in proxy.
> 
> BUG=None
> TEST=None
> 
> Change-Id: Ia5ebc4410918a261fe525abc1051ebbbdc66a876
> Reviewed-on: https://chromium-review.googlesource.com/1260259
> Commit-Ready: Jingkui Wang <jkwang@google.com>
> Tested-by: Jingkui Wang <jkwang@google.com>
> Reviewed-by: Zach Reizner <zachr@chromium.org>

Bug: None
Change-Id: Ic7827969e9ad508cd1b65cb7b8747e81e0cd02d0
Reviewed-on: https://chromium-review.googlesource.com/c/1313014
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
2018-11-02 16:59:10 +00:00
Jingkui Wang
142ce3efd9 devices: refactor proxy to use msg_socket
Use msg socket in proxy.

BUG=None
TEST=None

Change-Id: Ia5ebc4410918a261fe525abc1051ebbbdc66a876
Reviewed-on: https://chromium-review.googlesource.com/1260259
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-31 21:59:23 -07:00
Daniel Verkamp
aac28134d2 main: merge VirtIoDeviceInfo back into Config
This was split to allow the virtio PCI transition. Now that everything
is moved over, we can put the virtio configuration back into Config.

BUG=None
TEST=Boot crosvm on kevin and verify virtio devices still work

Change-Id: I2411f5131729f84b6820aac67a92d07346f64021
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1281833
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-31 21:59:16 -07:00
Daniel Verkamp
402d53bba8 devices: virtio: remove virtio MMIO transport
All devices have been converted to PCI, so we don't need MmioDevice.

BUG=chromium:854766
TEST=Boot crosvm on kevin and verify virtio devices still work

Change-Id: Ib6400e15bdb2153d14795de3cb0bfbf1845a8891
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1281832
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-31 21:59:16 -07:00
Daniel Verkamp
5656c124af devices: block: fix seccomp failures from free()
It looks like free() will sometimes try to open
/proc/sys/vm/overcommit_memory in order to decide whether to return
freed heap memory to the kernel; change the seccomp filter to fail the
open syscalls with an error code (ENOENT) rather than killing the
process.

Also allow madvise to free memory for the same free() codepath.

BUG=chromium:888212
TEST=Run fio loop test on kevin

Change-Id: I1c27b265b822771f76b7d9572d9759476770000e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1305756
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-31 12:42:43 -07:00
Daniel Verkamp
eeebe63c43 cargo fmt with Rust 1.30.0
Rust 1.30.0 ships a new rustfmt that causes a few more formatting
changes.

BUG=None
TEST=Run kokoro tests with updated Rust version

Change-Id: I803765ec0f3d2447f627b1e990bce438512367f7
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1307816
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-31 12:42:26 -07:00
Daniel Verkamp
f28a864fd9 kokoro: update to Rust 1.30.0
Also add g++ to the apt package list, since minijail now requires it.

BUG=None
TEST=Rebuild Docker container and run tests

Change-Id: I3d5cee0fa626e840037ae83537bdf891b4489a49
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1307815
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-31 12:42:25 -07:00
Stephen Barber
49dd2e219d main: increase child wait timeout to 1 second
BUG=chromium:899302
TEST=vm.CrostiniStartTime

Change-Id: Ie434bc8ec2df7a7e8d1102feab5b84ebcdbb113d
Reviewed-on: https://chromium-review.googlesource.com/1306821
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-30 20:59:50 -07:00
Daniel Verkamp
ac242df107 Revert "mptable: mark PCI interrupts as edge triggered"
Legacy PCI interrupts should be level triggered, not edge triggered.

The reverted change was done as part of a series of patches during
debugging of virtio-pci differences from virtio-mmio, but this was not
the actual root cause of the problems.

BUG=None
TEST=Boot crosvm on x86-64 and verify virtio devices still work

This reverts commit 9357ceab6a.

Change-Id: If1bf6e48d63fe352f0b914f5bdb2e346ab210369
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1297840
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-29 21:18:14 -07:00
Daniel Verkamp
120d95e031 devices: pci: support level-triggered interrupts
Register the irqfd with resample support so that we can correctly
emulate level-triggered interrupts.  This requires each PciDevice to
listen for interrupt_resample events and re-assert the IRQ eventfd if it
should still be active.

BUG=None
TEST=Boot crosvm on x86-64 and arm devices

Change-Id: I5cf8d1d1705cf675b453962c00d2d606801fee91
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1298654
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-29 21:18:14 -07:00
Daniel Verkamp
510c783c84 sys_util: add trait to fsync File and QcowFile
File exposes sync_all() and sync_data() functions, which map to fsync()
and fdatasync(), but these functions are not in a trait (they are just
implemented directly on File), so they can't be implemented and used in
a generic way for QcowFile.

Add a new trait, FileSync, that exposes a fsync() function that may be
used in the virtio block model.  Previously, we were translating a block
flush request into a call to File's flush() function, but this just
flushes internal Rust library buffers to the file descriptor; it didn't
actually result in a fsync() call.  Using the new trait, we can cause an
actual fsync() to occur for raw files, as intended.  QcowFile was
already safe, since its flush() function actually calls sync_all() under
the hood.

BUG=None
TEST=sync with raw disk and verify fsync() in strace output

Change-Id: I9bee2c0d2df3747aac1e7d9ec7d9b46a7862dc48
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1297839
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-26 17:19:10 -07:00
Daniel Verkamp
ac699881f2 kokoro: add rustfmt check
Also add the standard Chromium copyright header to make the pre-submit
check happy.

BUG=None
TEST=Run manually with docker and verify it catches incorrect formatting

Change-Id: I85b7736e9efe97e56bde99eee0f23b213d3b7523
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1296984
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-25 15:19:02 -07:00
Zach Reizner
56ec644e09 main: remove unused wayland-group option
This command line option was unwired a while back, so this option is not
needed.

TEST=./build_test
BUG=None

Change-Id: Ie5a8e305958fd710fc8edc67e33772ed38c7711c
Reviewed-on: https://chromium-review.googlesource.com/1058713
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-24 13:03:09 -07:00
David Riley
64cc43d2b8 devices: gpu: Have BackBuffer use renderer resource when attaching backing.
If a BackBuffer has some gpu_renderer_resource, attach the backing
through to virgl to allow resources to be transfered in the future.

BUG=chromium:892261
TEST=eglgears_x11, xterm, xeyes

Change-Id: I9c4310da8eba73ec69dbaeba340b362c22fb21a0
Reviewed-on: https://chromium-review.googlesource.com/1288960
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-23 22:50:43 -07:00
Daniel Verkamp
4ad6de0dbc aarch64: remove unused UnixDatagram import
BUG=None
TEST=emerge-kevin crosvm

Change-Id: I0d0197002d1d048a19139da9a11f6426c55f7f87
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1295349
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-23 13:01:49 -07:00
Yunlian Jiang
31c20fdcce crosvm: add getpid and prlimit to seccomp
This is needed to make sure seccomp work with glibc 2.27

BUG=chromium:897477
TEST=None

Change-Id: I101aa07bffd8db2b449be1a697dafcd7d6f1cb58
Reviewed-on: https://chromium-review.googlesource.com/1294729
Commit-Ready: Yunlian Jiang <yunlian@chromium.org>
Tested-by: Yunlian Jiang <yunlian@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2018-10-23 02:55:29 -07:00
Zach Reizner
15503e236e gpu_display: use syslog for display_wl
Change-Id: I8275d0f3f7ed31b9f53a533c0d2fbda62977a1b7
Reviewed-on: https://chromium-review.googlesource.com/1292756
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
2018-10-22 17:38:06 -07:00
Yunlian Jiang
a70445aa3b crosvm: add openat to seccomp
This adds openat to a seccomp policy file if open is already there.
We need this because glibc 2.25 changed it system call for open().

BUG=chromium:894614
TEST=None

Change-Id: Ie5b45d858e8d9ea081fd7bfda81709bda048d965
Reviewed-on: https://chromium-review.googlesource.com/1292129
Commit-Ready: Yunlian Jiang <yunlian@chromium.org>
Tested-by: Yunlian Jiang <yunlian@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2018-10-21 05:25:01 -07:00
Daniel Verkamp
8eceba31c0 devices: make PCI work in --disable-sandbox mode
Make the Minijail part of the PCI device tuple optional so that an empty
jail is not created for --disable-sandbox.

BUG=None
TEST=Boot crosvm in both --multiprocess and --disable-sandbox modes

Change-Id: Ibb3f2dbf33ca19910ee7448ea823b2772e09ecc5
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1290289
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-19 15:07:43 -07:00
Daniel Verkamp
f02fdd1f66 main: autodetect disk image type
Make --disk and --rwdisk automatically distinguish between qcow2 and raw
disk images.  --qcow and --rwqcow are kept as aliases for compatibility.

BUG=chromium:893380
TEST=Boot crosvm with both raw and qcow2 disk images.

Change-Id: I5b572626ca5ab894c78454f59355f27d552cbf7d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1275185
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-19 12:19:52 -07:00
Daniel Verkamp
de198cc9be devices: virtio: block: ignore Discard failures
Our branch of the 3.18 kernel has FALLOC_FL_PUNCH_HOLE disabled for the
ext4 filesystem, which means that systems running that kernel always
take the fallback path of writing buffers full of zeroes.  This is not
necessary for the Discard command, since it is just a hint and is not
required to actually zero the blocks.

Split the WriteZeroes trait up into a new PunchHole trait, which
corresponds to fallocate() with FALLOC_FL_PUNCH_HOLE, and use the new
trait to implement the virtio block Discard command.

BUG=chromium:896314
TEST=`mkfs.btrfs /dev/vdb` and verify the desired fallocate() is used
     and no write() calls are issued when inducing a failure

Change-Id: I67fd9a132758d8d766531ccca8358c7fe67b0460
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1286224
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-19 12:19:41 -07:00
Daniel Verkamp
7f9b9ea344 qcow: add convert API and export it in qcow_utils
This will be used in vm_concierge's ExportDiskImage function in order to
allow a minimal qcow2 image to be written on the fly (containing only
the required clusters in a tightly-packed image file). It also allows
future flexibility to change the underlying disk image file format while
still exporting qcow2 images (e.g. via `vmc export`).

For testing, add a qcow_img `convert` command, which can convert
between raw and qcow2 as both source and destination.

BUG=None
TEST=Use qcow_img to convert a raw image to qcow2 and back and verify
     its contents are the same as the original.

Change-Id: I74167aca9a9c857d892e24adf5ee17afc0f6e6b5
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1272060
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-18 19:01:06 -07:00
Daniel Verkamp
2167ae9535 sys_util: add SeekHole trait
Allow seeking to the next hole or data region in File and QcowFile.

BUG=None
TEST=None

Change-Id: I16e77e4791aa85b4cc96f38327026cd93f02b7e1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1274147
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-18 19:01:06 -07:00
Daniel Verkamp
c1f08277f9 cargo fmt aarch64 and kvm
A few non-rustfmt changes slipped in since the tree-wide formatting
pass.

BUG=None
TEST=Re-run `cargo fmt` and verify that it makes no further changes.

Change-Id: Ic5afb20dabc1087e5d6f54862e6b8b47c5f5608d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1287369
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-18 14:53:32 -07:00
Zach Reizner
f6b58e4cf2 enable integer overflow checks on release profile
This will harden crosvm against potential integer overflow leading to
unsafe behavior in unsafe blocks.

TEST=cargo test --release
BUG=None

Change-Id: Ie750906d04c6ef8cb9400b976827c2abeab2ab56
Reviewed-on: https://chromium-review.googlesource.com/1282064
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-16 02:57:36 -07:00
Daniel Verkamp
6b28917b83 qcow: create BufWriter with exact capacity
Rather than using the default BufWriter capacity (currently 8K),
calculate the exact size required to contain the table.  This further
consolidates the write() system calls to the minimum required.

BUG=chromium:891335
TEST=Manually verify expected write() calls with strace

Change-Id: I9ade77024e60a92d30b65beb07c2385e5dacc167
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1250035
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-13 14:55:25 -07:00
Daniel Verkamp
abbe0c8cf0 sys_util: use PUNCH_HOLE to implement write_zeroes
Some filesystems do not support FALLOC_FL_ZERO_RANGE; in particular,
encrypted files on ext4 fail this request with -EOPNOTSUPP.  Use
fallocate with FALLOC_FL_PUNCH_HOLE instead, which is more widely
supported.

BUG=None
TEST=strace crosvm using qcow files on encrypted ext4 and verify that
     fallocate(FALLOC_FL_PUNCH_HOLE) is issued when required.

Change-Id: Idffabc75ea0e1153efbb13cec8b4a25570427235
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1250022
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-13 14:55:24 -07:00
Daniel Verkamp
6c765fd2ac aarch64: remove reboot=k kernel cmdline option
The "reboot" option is specific to x86 (reboot=k forces use of the i8042
keyboard controller to initiate a reset).  Remove the unnecessary option
from the aarch64 command line.

BUG=None
TEST=Stop and restart VM on Kevin

Change-Id: Ic91c9a03491a6620d6f88ea0ada12f637f402840
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1279268
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-10-12 23:07:17 -07:00
Daniel Verkamp
56f283b297 Revert "Revert "linux: Convert all virtio devices to PCI""
This reverts commit c8986f14a8.

Re-land the virtio PCI conversion after the preceding fixes.

BUG=chromium:854766
TEST=Boot crosvm on nami and kevin

Change-Id: I3699e3ed1a45cecc99c51e352d0cf0c32bc4116f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1265862
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-12 23:07:16 -07:00
Zach Reizner
ed31137fd0 kvm: fix clippy error about mis-aligned pointer casts
BUG=None
TEST=cargo test -p kvm

Change-Id: I43321d01a02821495fb8a8f0f03df21eacc688ee
Reviewed-on: https://chromium-review.googlesource.com/1277873
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-12 23:07:10 -07:00
Zach Reizner
7c78a3c948 kvm: fix clippy error about multiple mut references
TEST=cargo test -p kvm
BUG=None

Change-Id: I2d4552b693f253f8411199ecf4583553c80e37a6
Reviewed-on: https://chromium-review.googlesource.com/1277874
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-12 23:07:10 -07:00