Commit graph

273 commits

Author SHA1 Message Date
Sonny Rao
00549b04a9 crosvm: fix documentation for SystemEvent
The documentation for the SystemEvent exit reason needs to specify
the positions for the two fields.

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

Change-Id: Ida98ba4a6b383a1c10fa48356decc1c5264999ec
Reviewed-on: https://chromium-review.googlesource.com/986721
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-29 19:51:34 -07:00
Dylan Reid
45753529ba x86_64: Set EFER.LMA
We were setting LME (Long Mode Enabled) but not LMA (Long Mode Active).
New kernels have a check in the kvm code that disallows this brokenness.

Change-Id: Ic8950c8748ead81201223c19404fdd2c8d80f7dc
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/985733
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-29 17:02:43 -07:00
Sonny Rao
6ce158fb86 crosvm: support VM shutdown via SystemEvent
ARM systems don't have an exit event fd like x86, instead one of the Vcpus
will exit with the SystemEvent reason and put a code into the kvm run
union of either shutdown, reboot, or crash.  We currently don't handle
reboot or crash differently but can do so in the future.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on kevin - manually test shutdown via maitred

Change-Id: I455cbe1ac653f61a1e9eae1ce22922d14cff4e3c
Reviewed-on: https://chromium-review.googlesource.com/982531
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-03-29 13:32:59 -07:00
Sonny Rao
62a4063aa6 crosvm: guest_memory: add memory_size method
This is useful to get the total size of memory without having to write
something that iterates over the regions explicitly.

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

Change-Id: Iac9a341b4c41d6462cf731f6267b92a0169578e4
Reviewed-on: https://chromium-review.googlesource.com/977565
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-27 18:01:43 -07:00
Dmitry Torokhov
ca3a4822cc kvm: plumb accessors for IRQCHIP and PIT state
Plumb in KVM_GET_IRQCHIP/KVM_SET_IRQCHIP and KVM_GET_PIT2/KVM_SET_PIT2
to allow saving and restoring irqchip and PIT state.

BUG=b:76083711
TEST=cargo test -p kvm

Change-Id: I45a0beb3315f67af7cd9deee80dce0ca25f05001
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/981592
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-03-27 18:01:42 -07:00
Mike Frysinger
064696f4fa x86_64: use project name in cpuid vendor
The official name is "crosvm", not "CrOSVM".

BUG=None
TEST=None

Change-Id: I21f200d8224c9a8fee53011a63ff4ad165128904
Reviewed-on: https://chromium-review.googlesource.com/976941
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-03-22 20:53:31 -07:00
Dylan Reid
1776c645c9 x86_64: Add separate error for getting sregs
Re-using the set error could cause confusion.

BUG=none
TEST=none

Change-Id: I47445b28946484028bf96cff9ee0bc8c89b6f3e5
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/974741
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-22 18:16:57 -07:00
Zach Reizner
5fc80ebd71 wl: avoid inserting empty virtio queue entries
The kernel driver currently short circuits the check for empty queue
entries if the entry arrives empty. Ordinarily the check is run every
time data is taken out of a queue entry and would recycle the entry once
empty. The short circuiting is being fixed in the kernel, but this
device change fixes the unnecessary empty queue entries from happening
in the first place.

BUG=chromium:791724
TEST=test code from the BUG

Change-Id: I5b72aac843def052bfe1234dfbde236274ae02bb
Reviewed-on: https://chromium-review.googlesource.com/974883
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-03-22 05:14:49 -07:00
Mike Frysinger
63be8cb9d3 x86_64: improve documentation for cpuid vendor
BUG=None
TEST=None

Change-Id: Id274c361d10be00d5d7279765a2e90ad5ecb4112
Reviewed-on: https://chromium-review.googlesource.com/974314
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-21 20:48:40 -07:00
Dmitry Torokhov
e4fc0fecad crosvm/plugin: create PIT for plugin VMs
Create PIT for VMs services by the plugin.

TEST=cargo test --features plugin
BUG=b:75598821

Change-Id: Ifc03aaf6bfee2f6e60dea057132f5ed24145ffbf
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/969887
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-20 16:53:35 -07:00
Chirantan Ekbote
fec86cc3ae poll_token_derive: Calculate variant bits without sizeof_val
Calculate the number of bits necessary to represent the enum variant
using the next_power_of_two() and trailing_zeros() functions from the
primitive usize type.

Also add a test to ensure that the returned value is correct when there
is only one variant in the enum.

BUG=none
TEST=unit tests

Change-Id: Ibd15efd4f06e17a74489fee04ff19aca0dde68b2
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/959624
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-20 00:00:28 -07:00
Sonny Rao
ed517d1bfe crosvm: create a LinuxArch trait and use it for x86
This creates a trait that different architectures can implement to
support running Linux VMs.

In the implementation on X86 we remove some error and return errors
from lower-level modules as appropriate.  These modules now implement
the Error trait so we can get meaningful descriptions without an extra
error from the calling function. This still keeps all the ifdefs in
linux.rs for now until we have another implementation to use for ARM.

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

Change-Id: If24bcc83e25f9127d6aea68f9272e639296aad8b
Reviewed-on: https://chromium-review.googlesource.com/952368
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-15 17:58:33 -07:00
Sonny Rao
8f73ccc45d x86_64: implement error trait
This is useful for describing errors that we pass up.

BUG=chromium:797868
TEST=build_tests passes on all architectures
TEST=crosvm runs on caroline

Change-Id: Ied456015e74830d3f1f465fca1151682c9148eb5
Reviewed-on: https://chromium-review.googlesource.com/961603
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-14 11:55:56 -07:00
Sonny Rao
657c1850ab kvm: silence a warning on non-x86 builds
We don't use this particular constant on non-x86 builds, so let's
leave it out if when it's not needed.

BUG=chromium:797868
TEST=build_test passes
TEST=crosvm runs on caroline

Change-Id: Ic752f9ae33d577d78c7df282e9803936aa181504
Reviewed-on: https://chromium-review.googlesource.com/952166
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-03-12 12:52:39 -07:00
Zach Reizner
d604dbbab4 crosvm/plugin: refactor poll loop to use PollContext
This change simplifies plugin processing by removing the awkward
run_until_started loop. This also switches to use PollContext instead
of the Poller/Pollable interface, which required reallocating a Vec
every loop to satisfy the borrow checker.

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

Change-Id: Iedf26a32840a9a038205c4be8d1adb2f1b565a5c
Reviewed-on: https://chromium-review.googlesource.com/938653
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-08 19:28:52 -08:00
Dmitry Torokhov
7c2238bd15 crosvm_plugin: be more Rusty
Instead of writing "if let Some(x) = ret.ok()" let's write more
idiomatic "if let Ok(x) = ret".

BUG=none
TEST=sudo cargo test --features plugin

Change-Id: Id8c4d0fd2a05783759b5699b65d2333b2a1a6776
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/956229
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-08 19:28:40 -08:00
Dylan Reid
609d0f041b qcow: Fix clippy warnings
Having qcow clippy clean will make us more likely to see important
warnings.

Change-Id: I3ce08f50eb73f2291c56dc8fe06dd378eb3dcf93
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/954404
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-08 00:37:54 -08:00
Stephen Barber
a10b2d20a8 plugin: add crosvm_net_get_config
BUG=none
TEST=sudo cargo test --features plugin

Change-Id: Ib38fad250295d73529dff0451345b4274a261073
Reviewed-on: https://chromium-review.googlesource.com/911943
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-08 00:37:50 -08:00
Dmitry Torokhov
8da6543e74 kvm: add tests for get_supported_cpuid() and get_emulated_cpuid()
TEST=cargo test -p kvm
BUG=None

Change-Id: I2af245cb94d68faf091bf6788842c1932240df3d
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/947320
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-08 00:37:34 -08:00
Dmitry Torokhov
532a94c1c8 Fix race between un-pausing vcpu and requesting vcpu pause
To ensure that we do not miss pause request sent while we were in paused
state, or were exiting paused state, let's start using
KVM_SET_SIGNAL_MASK. SIGRTMIN() + 0 signal will be blocked and thus is
not delivered, and it will only be checked when KVM_RUN is being
executed, reliably interrupting KVM_RUN.

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

Change-Id: Iae67a411c23c2b14fbfcbc7d53d0bc86ec4b67d9
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/944850
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-08 00:37:33 -08:00
Dmitry Torokhov
e423460238 kvm: fix invocation of KVM_SET_SIGNAL_MASK ioctl
Linux kernel expects size of sigset passed in through KVM_SET_SIGNAL_MASK
ioctl to be exactly 8, but Rust's sigset size is 128 bytes, so we can
not use sizeof to set up the size.

Also let's add test set_signal_mask().

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

Change-Id: Ica757ad63d6754d5c8008ba1735982c7ca026f33
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/944849
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-08 00:37:32 -08:00
Dylan Reid
818afd6eb0 qcow: Fix refcount_bytes
This should be the number of bits (1 << order) divided by bits per byte.

BUG=none
TEST=cargo test

Change-Id: I201dbaf21d13a82af6bcb493ba5f3b62c89286fa
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/954348
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-07 22:08:20 -08:00
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