Commit graph

251 commits

Author SHA1 Message Date
Zach Reizner
d1ab493672 fix some clippy errors that are default deny
Clippy only has 6 lints that are defaulted to deny, which this CL fixes.
The first step to running clippy and establishing our own set of default
deny lints, is to ensure we aren't running afoul of the most common
deny lints.

BUG=None
TEST=cargo clippy --all

Change-Id: I225801357d76a8a9e246e3842bc9bf550fcd7207
Reviewed-on: https://chromium-review.googlesource.com/952045
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-03-07 19:47:11 -08:00
Dmitry Torokhov
ab4994a646 plugin: only convert to negative errors on crosvm.h boundary
We have decided that API defined in crosvm.h should signal errors by
returning negative values derived from common errno error codes. To
avoid confusion within the rest of crosvm code that is using positive
erro codes, let's perform the conversion to negative on that crosvm API
boundary, so it is contained.

TEST=cargo test --features plugin
BUG=None

Change-Id: Icb1e719c8e99c95fdc32dce13a30d6ff8d3d9dc7
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/947563
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-07 16:55:32 -08:00
Zach Reizner
6c7ca93e28 REAPPLY: crosvm: allow control of running VM via socket
This change was overwritten yet again by a bad rebase. In this case it
was CL:942084.

TEST="crosvm run -s" with socket and then subsequent "crosvm stop"
causes the running VM to be shutdown
BUG=811749

Change-Id: I04d9b71b6eeef494eb0ffcd86c7bc71a86730a19
Reviewed-on: https://chromium-review.googlesource.com/951981
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Robert Bradford <robert.bradford@intel.com>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-03-07 16:55:08 -08:00
Zach Reizner
25c6bc137e sys_util: custom derive for PollToken
Using an enum implementing PollToken is the recommended way to use
PollContext, but writing the trait impls for each enum is mechanical yet
error prone. This is a perfect candidate for a custom derive, which
automates away the process using a simple derive attribute on an enum.

BUG=chromium:816692
TEST=cargo test -p sys_util

Change-Id: If21d0f94f9af4b4f6cef1f24c78fc36b50471053
Reviewed-on: https://chromium-review.googlesource.com/940865
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-03-07 16:54:46 -08:00
Zach Reizner
a5358e8ffd sys_util: add PollContext interface for using epoll
A common cause of silent 100% CPU usage on otherwise idle VMs is because
some poll loop is waiting on sockets that were hung up on. An unrelated
issue is that using the Poller interface requires dynamic allocation on
every poll call for dynamically sized poll lists.

The PollContext struct detects and warns about the first problem at runtime
and solves the latter problem.

TEST=cargo test -p sys_util
BUG=chromium:816692

Change-Id: I42a9c961db07191d25bcba77c5136f5729400ec9
Reviewed-on: https://chromium-review.googlesource.com/933870
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-03-07 16:54:45 -08:00
Dmitry Torokhov
5b6b192e34 plugin: use positive error values for errno-based errors
Errno-based error codes are positive and turning them into negatives is
Linxu kernel internal convention. Let's not do this so we do not confuse
the signedness of errors coming from crosvm code and system libraries.

TEST=cargo test --features plugin
BUG=None

Change-Id: Ia89f0b78ad1d2bb30a2f427593f13ebfb548b2b0
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/947562
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-06 20:19:27 -08:00
Sonny Rao
bb7da42d1e crosvm: linux: separate creating vcpus from running them
On ARM we need to set up all CPUs before we can initialize the
interrupt controller, which is unfortunately the opposite of the
required ordering on X86.  This separates out the creation of the
VCPUs and puts their FDs into a vector and then launches threads from
that vector later on in the setup sequence.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline

Change-Id: I108234efd6c53c4681531701c107a11e42c029f5
Reviewed-on: https://chromium-review.googlesource.com/947462
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-03-05 23:48:30 -08:00
Dmitry Torokhov
aa83c17359 sys_util: register_signal_handler should use SA_RESTART
On Linux, signal handlers installed with signal() will restart
interrupted system calls. When we moved to using sigaction() we forgot
to specify SA_RESTART and so we started experiencing returns from read
write system calls with EINTR, which throws off some of the code.
Instead of sprinkling "handle_eintr" everywhere, let's restore the old
behavior.

TEST=cargo test --features plugin; cargo test -p sys_util
BUG=chromium:800626

Change-Id: I24c23069ad4c9e7be8c484ee4c57f67451a2944d
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/944848
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-02 22:22:43 -08:00
Sonny Rao
43724a239b crosvm: move x86_64 arch specific stuff into the x86_64 crate
This is in preparation to make different architectures implement a
trait, but for now it's just moving code out of linux.rs and into
x86_64 trait.  A few new functions were required which will become
part of the trait interface.  There's still a lot of ugly ifdefs
everywhere that should go away in subsequent CLs.

BUG=chromium:797868
TEST=./build_test
TEST=run crosvm on caroline

Change-Id: Ifc95d4eb84f64ebacb4481a172524d94dc96b7bb
Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/942084
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-02 22:22:29 -08:00
Sonny Rao
0a404b8a0e sys_util: fix issue in ppoll on 32-bit architectures
I ran into an issue on ARM where ppoll() was returning EINVAL and it
was becuase our timespec value sent to ppoll contained a negative
value for tv_sec.  We need to use the correct type when determining
the max value.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline

Change-Id: I7f8818e5f93e0327fd9facefb5032f7c5fb00ea0
Reviewed-on: https://chromium-review.googlesource.com/945111
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-02 15:47:18 -08:00
Dmitry Torokhov
505c6f9888 vm_control: more error signedness fixes
Fix a couple more spaces where we used negative errno values.

TEST=cargo test -p vm_control
BUG=None

Change-Id: Id622192d025d0ac733419411492ca53a50f957f3
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/942087
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-01 16:13:07 -08:00
Dmitry Torokhov
cb47da4910 sys_util: fix handling EINTR of C system functions
System functions have 2 ways of signalling errors, either via returning
-1 as result, and setting errno, or directly returning error code, and
we can not distinguish automatically between the 2 options when using
InterruptibleResult trait for i32 values.

Let's remove this trait for i32 and create 2 explicit macros:
handle_eintr_rc and handle_eintr_errno.

TEST=cargo test --features plugin; cargo test -p sys_util
BUG=None

Change-Id: I1dc8e3c023e7bf7875ac3536703eb71fa3206b7b
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/940612
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-01 16:13:07 -08:00
Dmitry Torokhov
3cbbbe6884 sys_util: do not treat EINTR as negative in handle_eintr
System error codes are positive, we should not try to use the negative
(kernel) form when working with it.

TEST=cargo test --features plugin; cargo test -p sys_util
BUG=None

Change-Id: I8dea773e6148d1814ca0ea5019d5fb7824dc80ac
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/940611
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-01 16:13:05 -08:00
Dmitry Torokhov
8b32d55ae2 sys_util: properly convert errors in sock_ctrl_msg
scm_sendmsg() and scm_recvmsg() return negative errors derived from
errnos that are normally positive. When constructing errno::Error from
these error codes we should convert them back into positive values for
error codes to make proper sense.

TEST=cargo test --features plugin; cargo test -p sys_util
BUG=None

Change-Id: Ibf9065b72602e43cb6badd06f85044329d714276
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/940562
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-01 16:13:05 -08:00
Dmitry Torokhov
9c7508593d kvm: fix a couple of typos in comments
BUG=None
TEST=cargo test --features plugin; cargo test -p kvm

Change-Id: If3408984ebb4f9212aaaae6084353a411a7f902b
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/938845
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-28 21:30:22 -08:00
Dmitry Torokhov
9786573e07 allow plugin to query KVM for supported/emulated CPUIDs
This plumbs calls to KVM_GET_SUPPORTED_CPUID and KVM_GET_EMULATED_CPUID
to be available to plugins.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=chromium:800626

Change-Id: I98879599b5f970c6c2720772658689a505d8abe1
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/938674
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-28 21:30:20 -08:00
Slava Malyugin
d1c761354f crosvm: put devices right after RAM in Guest physical address space
Small core CPUs have limited physical address space, e.g. 16GB. This
affects both "real" physical address space as well as "virtual"
physical address space implemented by extended page tables.

Any page table entry addressing memory beyond physical address limit
will produce page fault. The change avoids these faults for
memory-mapped devices (e.g. Wayland shared buffers) by moving them
next to physical RAM.

BUG=none
TEST=verified Xwayland boots fine on N3150 (Braswell)

Change-Id: I178aa53eb511a98507b2cb28d28ccf422a08b107
Reviewed-on: https://chromium-review.googlesource.com/940191
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Slava Malyugin <slavamn@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-28 21:30:15 -08:00
Dmitry Torokhov
cd6a187de6 plugin_proto: add helpers to convert CPUID data between KVM and protobuf
We need to convert between protobuf and KVM format of cpuid data in
several places, so let's add helpers to plugin_proto crate.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=chromium:800626

Change-Id: Ida7b59825d2146b0d02711e441f477d90dd4263a
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/939660
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-27 22:26:14 -08:00
Sonny Rao
59cdd83fda sys_util: implement error trait for sys_util::Error
This is helpful in passing up low-level errors from system calls.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline

Change-Id: Ic2d8a23240a1449ac78877d37a074fd97a29a065
Reviewed-on: https://chromium-review.googlesource.com/933375
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-02-27 22:26:10 -08:00
Sonny Rao
d33407aa99 guest_memory: implement error trait
This implements the error trait so we can get more useful error
information back on failures.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline

Change-Id: Ia131b1eb14d24709c10f2ba752a962e822134a42
Reviewed-on: https://chromium-review.googlesource.com/938312
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-02-27 22:26:09 -08:00
Sonny Rao
765deaafb4 kernel_loader: implement error trait
This implements the error trait so we can get more useful error
information back on failures.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline

Change-Id: I888cbe6fca8bc3885eeb4ff747f7b9dc51e0b587
Reviewed-on: https://chromium-review.googlesource.com/938311
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-02-27 22:26:08 -08:00
Sonny Rao
1aa03e00a0 x86_64: implement error trait for sub-modules in x86_64 crate
Implement the std::error::Error Trait for Error types within the
x86_64 crate.  We will make use of these implementations later on when
we are using the architecture Trait to pass architecture-specific
errors up with meaningful descriptions.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline

Change-Id: I7a30db69437990608e3a0f5e6e3a200ef6c2d0c3
Reviewed-on: https://chromium-review.googlesource.com/932976
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-02-27 22:26:07 -08:00
Dmitry Torokhov
c73d390522 kvm: plumb in KVM_GET_EMULATED_CPUID
This plumbs in KVM_GET_EMULATED_CPUID to allow userspace to figure out
whether a certain feature(s) can be used or whether they are too
expensive.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=chromium:800626

Change-Id: I914415a311f40d079b1703efb5129fd91b0d24ad
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/933243
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-27 20:17:42 -08:00
Slava Malyugin
ae5878bef1 crosvm: make port 0x61 return 0x20, preventing Guest kernel hang
Harmonize small 8042 implementation with kvmtool by making read from
port 0x61 return 0x20. This prevents infinite loop in
pit_calibrate_tsc() on small Intel cores.

BUG=none
TEST=reproduced problem on Celeraon N3150 (Braswell), verified
     VM boots further with the fix

Change-Id: Ifbee2bc72c4f5acd2551d8dcab466dc5f4907975
Reviewed-on: https://chromium-review.googlesource.com/938759
Commit-Ready: Slava Malyugin <slavamn@chromium.org>
Tested-by: Slava Malyugin <slavamn@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-27 20:17:37 -08:00
Dmitry Torokhov
93b00ecca7 kvm: do not use negative error coded for errno-based errors
Errors derived from sysem errors delivered via -1 return code/errno
should use positive error codes, not negative, in order for them to be
recognized by other components. I.e. we should use
errno::Error::new(EINVAL) and not -EINVAL.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=None

Change-Id: Ibe91745c36765c64aeab2f6aae5cd0ca8f243a42
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/939868
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-27 20:17:08 -08:00
Dmitry Torokhov
8283248a60 vm_control: do not use negative error coded for errno-based errors
Errors derived from sysem errors delivered via -1 return code/errno
should use positive error codes, not negative, in order for them to be
recognized by other components. I.e. we should use
errno::Error::new(EINVAL) and not -EINVAL.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=None

Change-Id: I10d5992cb1e1750aa9b8a7269c4f574d7c753683
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/939866
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-27 20:17:07 -08:00
Dmitry Torokhov
5ba068f9a4 crosvm_plugin: fix errno conversions
The raw_os_error() and errno() return positive values (errno values are
all positive), but the rest of crosvm plugin C API works with negative
return codes, so we need to convert raw_os_error()/errno() into
negatives as well.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=None

Change-Id: I8bd72c2e67cb227a638e5c9478cd2f781f0783d0
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/939865
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-27 20:17:06 -08:00
Dmitry Torokhov
cda18d757b kvm: do not pass max number of cpuid entries in get_supported_cpuid()
It does not make sense to have users of the API limit number of cpuid
entries retrieved. Just have KVM select reasonable upper limit and
return the true number.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=chromium:800626

Change-Id: I8ab7e8d901bc408d17c23bfe798d89f921488673
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/933242
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-27 17:33:20 -08:00
Slava Malyugin
4567a281a5 crosvm: disable reliance on support of 1GB pages
The initalization code in crosvm used two-level page table
    in long mode, with last entry covering 1GB. This assumed
    presence of 1GB pages support ('pdpe1gb' in /proc/cpuinfo).
    Some CPUs don't have it.

    BUG=none
    TEST=reproduced bug on Celeron N3150 (Braswell), verified
         VM boots on it with fix

Change-Id: I6014c7ea236d8daf95e9f09b68beb7935a267aa3
Reviewed-on: https://chromium-review.googlesource.com/936323
Commit-Ready: Slava Malyugin <slavamn@chromium.org>
Tested-by: Slava Malyugin <slavamn@chromium.org>
Reviewed-by: Slava Malyugin <slavamn@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-26 22:07:23 -08:00
Sonny Rao
8836bb51a2 crosvm: move device_manager to it's own crate
I will be refactoring this code to mostly live in the architecture
code, but for now it's simpler to move it out into it's own crate.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline

Change-Id: I85c12696fcd5cbef6a72a6dcbc484a443e0b0784
Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/933084
2018-02-26 22:07:15 -08:00
Dmitry Torokhov
42d194de3f kvm: plumb in KVM_SET_SIGNAL_MASK ioctl
We need this ioctl to implement race-free support for kicking/pausing VCPUs.

TEST=cargo test --features plugin; cargo test -p kvm; ./build_test
BUG=chromium:800626

Change-Id: I5dcff54f7eb34568a8d8503e0dde86b6a36ac693
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/932443
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-26 22:07:11 -08:00
Dmitry Torokhov
b7bb00297c sys_util: use sigaction() instead of signal() when installing handler
Use of signal(2) is only portable with SIG_DFL or SIG_IGN, it should not
be used to set real signal handler. sigaction(2) should be used for this
purpose.

TEST=cargo test --features plugin; cargo test -p kvm; ./build_test
BUG=chromium:800626

Change-Id: I5a8d1f68c7f285b489e08f74f63b573f263e09d1
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/930463
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-26 22:07:10 -08:00
Dmitry Torokhov
2cd14a1e46 sys_util: allow clearing given pending signal
We are planning on using KVM_SET_SIGNAL_MASK and have the signal that we
use to kick VCPU permanently masked to close the race around handling
pause requests, so we need a way to clear pending interrupts, otherwise
VM will never run again.

TEST=cargo test --features plugin; cargo test -p kvm; ./build_test
BUG=chromium:800626

Change-Id: I2dfe6fcb129e4b8156f6a7ff842e171661c56440
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/930462
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-26 22:07:09 -08:00
Dmitry Torokhov
cd4053364d sys_util: factor out signal manipulation from signalfd into signal
Move creating sigsets and blocking/unblocking signals form signalfd
module to signal module so they are usable by other parties as well.

BUG=chromium:800626
TEST=cargo test --features=plugin

Change-Id: I281ce784ed6cb341cc1e7cf2784f6fb1e8cc894d
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/930461
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-26 22:07:08 -08:00
Dylan Reid
328bfd2959 qcow: check more address addition for overflow
Check that two address calculations don't overflow. Return an error if
they do. Thanks cargo fuzz.

Change-Id: I9dd301c4e08516cea8456f1ea313d62582979da0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/932646
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-02-23 03:37:10 -08:00
Stephen Barber
c79de2d0b2 crosvm: add advisory locking for disk images
Disk images should never be mounted as writable by multiple VMs at once.
Add advisory locking to prevent this.

BUG=chromium:810576
TEST=run crosvm twice with same rwdisk, check that second VM fails to start

Change-Id: I5e6c178515eafa570812a093449eef5a4edc1740
Reviewed-on: https://chromium-review.googlesource.com/929994
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-21 22:26:53 -08:00
Stephen Barber
859b5d9d14 net_util: use sys_util::Error instead of std::io::Error
sys_util errors always have a backing errno. Use these to allow
clients to always get access to the underlying errno when using
ioctl-based operations.

BUG=none
TEST=cargo test

Change-Id: I8853eeb2b9b38e5509c0ef01f507e461d5d36267
Reviewed-on: https://chromium-review.googlesource.com/927804
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-21 14:20:01 -08:00
Stephen Barber
308ff60601 net_util: add tap support for mac address
Allow get/set for the host mac on the tap interface. Also add read accessors
for the host IP address and netmask, and make using IFF_VNET_HDR optional.

BUG=none
TEST=./build_test

Change-Id: I9999bf5aa8aa35b8cae702d9bc6f94602d6fe32e
Reviewed-on: https://chromium-review.googlesource.com/918406
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-21 01:06:42 -08:00
Rob Bradford
8f002f5c4a crosvm: add flag to enable vhost networking
crosvm supports using vhost for improved networking peformance however
there is no runtime control to enable it. Add a flag to the command line
arguments to enable vhost networking.

This defaults to off, as before, since /dev/vhost-net may not be
accessible to the current user.

TEST=With permissions to open /dev/vhost-net check that running with
--vhost-net shows significantly improved performance. Tested with and
without sandbox.
BUG=none

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
Change-Id: Idfd3f59cc7ff68a3cab7d1855c7d6b8f046f7cec
Reviewed-on: https://chromium-review.googlesource.com/925361
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-19 17:23:41 -08:00
Dmitry Torokhov
0db8f41245 Ensure we are not holding per-cpu data lock when pausing VCPU
We may want to issue additional crosvm_pause_vcpu() requests while VCPUs
are waiting to be resumed, so we need to make sure we are not holding
lock while waiting.

TEST=cargo test --features plugin
BUG=chromium:800626

Change-Id: Ia74836a567fc565fbd868abdcaa6d0174a4341ad
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/917426
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-16 15:12:24 -08:00
Stephen Barber
ee0d67cc5e crosvm: fix run_vm return values for plugin
BUG=none
TEST=crosvm builds with plugin enabled

Change-Id: Ic54550e59d3d3b0e7b09cd3f18496ca790d29f7d
Reviewed-on: https://chromium-review.googlesource.com/922281
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-15 21:43:45 -08:00
Rob Bradford
8091a2a525 crosvm: with vcpus > 1 cleanly shutdown jailed processes
When creating a new vcpu, setup_vcpu() returns a JoinHandle which allows
the main thread to wait for the vcpu threads to complete. Put this
handle into a vector from which it will be later join()ed with to wait
for its execution to complete. By ensuring that the thread's completion
is waited for all the references to the ProxyDevice will be dropped and
thus the jailed processes will be sent a shutdown message and they will
cleanly exit.

TEST="crosvm run --cpus=2 ..." and observe that the jailed processes are
cleanly shutdown and not forcefully killed.
BUG=812234

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
Change-Id: I771251ff1cdf762ca68c0781dc7de9f95cc1fcfe
Reviewed-on: https://chromium-review.googlesource.com/919165
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-14 17:05:23 -08:00
Rob Bradford
30ebd272d6 crosvm: allow control of running VM via socket
Remove control_sockets definition that shadows earlier one which
contains the opened socket for receiving messages for controlling the
running VM. This shadowing meant that the messages sent over the socket
were not handled.

TEST="crosvm run -s" with socket and then subsequent "crosvm stop"
causes the running VM to be shutdown
BUG=811749

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
Change-Id: If5a82ec10c29ab037cbedcf7acea23a49b4cfeb6
Reviewed-on: https://chromium-review.googlesource.com/916264
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-13 17:40:53 -08:00
Dylan Reid
bfba99376a main: Exit with non-zero exit code on failure
Writing tests that see if crosvm succeeds is difficult if it doesn't
indicate when it fails. Return 1 when something goes wrong so that the
exit code of crosvm can be used in autotest.

Change-Id: Iaaa526bf78da19b73f786f7bbfa8e2f16eb39ca1
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/902779
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-13 17:40:44 -08:00
Dylan Reid
72dd367aa8 qcow: Calculate correct refcount table size and zero it
The reference count table must be continuous in the file, not
preallocating it when creating a file causes errors when setting
reference counts for new blocks later.

BUG=809847
TEST=Replay formatting and downloading container events.
Add unit test that catches error with default files.

Change-Id: I08840958a1180a73f32f42d520517bcf88a158b0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/909915
2018-02-12 22:42:42 -08:00
Dylan Reid
c3579e0c35 block: Put more info in Read and Write errors
Adding the size and offset of a read or write makes errors easier to
reproduce.

Change-Id: Ia1c07f831dc6fb6f08acb87a30459713d0f706c0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/907420
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-02-12 22:42:42 -08:00
Zach Reizner
dadb7625ea allow plugin to query for KVM extensions
The guest may need to check for KVM extensions before blindly using
them.

TEST=cargo test --features plugin; cargo test -p kvm; ./build_test
BUG=chromium:800626

Change-Id: If87b928753cd71adeabac4fc7732c3fce7265834
Reviewed-on: https://chromium-review.googlesource.com/906008
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-12 22:42:40 -08:00
Zach Reizner
1d4a70029c crosvm/plugin: allow plugins to exit early succesfully
A plugin that exits without sending the start message would cause the
main process to exit with a failure code, which made some forms of
unit testing have false negatives.

BUG=chromium:800626
TEST=cargo test --features plugin

Change-Id: I14803ed3d2c933b8591c5370756a5caaa93b97e6
Reviewed-on: https://chromium-review.googlesource.com/906007
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-12 22:42:39 -08:00
Zach Reizner
7ca9f771e7 add plugin support for configuring CPUID
The guest expects to be able to read the CPUID, so the plugin process
needs to specify what the CPUID for each VCPU will have.

TEST=cargo test --features plugin; ./build_test
BUG=chromium:800626

Change-Id: I9258540ab2501126c3d8cadbd09b7fc01d19f7a9
Reviewed-on: https://chromium-review.googlesource.com/906006
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-12 22:42:38 -08:00
Zach Reizner
ce8961d1fc allow non-dirty log memory regions from the plugin process
Dirty logging is not necessary for every memory region, so the plugin
process should be able to specific exactly which regions it would like
dirty logging enabled for.

TEST=cargo test --features plugin
BUG=chromium:800626

Change-Id: I28b8285357e7de1c8c3a1392bdfdb4853ec5a654
Reviewed-on: https://chromium-review.googlesource.com/900294
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-12 22:42:37 -08:00