Commit graph

324 commits

Author SHA1 Message Date
Chirantan Ekbote
9b81eb57f3 p9: protocol: Add message definitions
Add definitions for all the messages we expect to send and receive over
the wire.

BUG=chromium:703939
TEST=none

Change-Id: I6b48f3e2eb9779fca57f8b71120b7bb1e8ab4ab9
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1013201
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-05-22 21:56:58 -07:00
Chirantan Ekbote
800fcb060f Add low-level p9 protocol implementation
Implement encoding and decoding various primitives using the p9
protocol.  In addition, add a procedural macro to derive the encoding
and decoding implementation for structs built out of the primitives.

BUG=chromium:703939
TEST=unit tests
CQ-DEPEND=CL:1065063

Change-Id: I7256633fb7002da9ce8af03be2f24410b90ccf3f
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/969965
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-05-22 21:56:58 -07:00
Manoj Gupta
d8f10af6ae crosvm: Switch to cc crate.
We do not want to add dependencies on GCC. Switch to cc crate
instead of gcc to honor CC setting.

CQ-DEPEND=CL:1066462

BUG=chromium:814480
TEST=emerge-{eve,kevin} crosvm works.

Change-Id: I4e846b2080503e5617ed66e709f7af5263c98fba
Reviewed-on: https://chromium-review.googlesource.com/1066461
Commit-Ready: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-18 23:07:28 -07:00
Dylan Reid
2494ddefb1 qcow: Call fsync(2) when we want to flush to disk
Signal to the OS that we want these writes committed all the way to
disk.  Replace an existing call to flush as that's not sufficient.

Change-Id: I9df9e55d2182e283e15eebc02a54c1ce08434f42
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1060696
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-18 20:08:31 -07:00
David Reveman
fe0abe4a78 virtwl: Fix DMABuf support on when building for 32bit.
name/date/desc_len fields of drm_version struct are of type __kernel_size_t
and not unsigned long long.

BUG=chromium:837209
TEST=crosvm finds DRM device on kevin

Change-Id: If940b31cb730cbaa46ed781021cbe60189da9f65
Reviewed-on: https://chromium-review.googlesource.com/1064913
Commit-Ready: David Reveman <reveman@chromium.org>
Tested-by: David Reveman <reveman@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-18 20:08:22 -07:00
Dmitry Torokhov
bb65801679 plugin: allow retrieving and setting XCR VCPU states
Add crossvm plugin API to allow fetching and setting XCRs for VCPU.

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

Change-Id: I2a988279c08051a8d8865efc1e60f9692fa26272
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1062646
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-18 20:08:21 -07:00
David Reveman
f0656b661c virtwl: Fix wayland-dmabuf argument typo.
Remove "enable-" prefix from wayland-dmabuf argument. This prefix is not
used when specifying the argument in run_vm.

BUG=chromium:837209
TEST=crosvm usage output matches what is a valid argument

Change-Id: Ib9402842c6ce58b4b3d1646c0df3acb5c5de4b0c
Reviewed-on: https://chromium-review.googlesource.com/1064725
Commit-Ready: David Reveman <reveman@chromium.org>
Tested-by: David Reveman <reveman@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-18 10:05:19 -07:00
Dmitry Torokhov
10668e6387 kvm: fix test for getting and setting xcrs
The extension condition was reversed, also SSE is not enabled by default
in guest VCPU, so limit the test to setting the FP bit.

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

Change-Id: I2959fe7dfff79703777d6254deae817fea892b00
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1062645
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-17 03:24:28 -07:00
David Reveman
52ba4e5c64 virtwl: Add DMABuf allocation support.
This implements DMABuf allocation type in the virtio wayland
device.

We attempt to locate a supported DRM device prior to engaging
the device jail. If found, the DRM device is passed to the
wayland device code and used to serve DMABuf allocations.

DMABuf support can be disabled by not providing crosvm with
access to any DRM device nodes.

The guest is expected to handle the case when DMABuf allocation
fails and fall-back to standard shared memory.

This initial change uses DRM directly but is structured in a
way that would allow the allocator to be replaced by minigbm
with minimal effort.

BUG=chromium:837209
TEST=crosvm finds drm device and returns valid dmabufs to guest

Change-Id: Ic1fd776dfdfefae2d7b321d449273ef269e9cc62
Reviewed-on: https://chromium-review.googlesource.com/1034088
Commit-Ready: David Reveman <reveman@chromium.org>
Tested-by: David Reveman <reveman@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-16 08:34:40 -07:00
Dmitry Torokhov
0f1770d3ef crosvm/plugin: allow specifying root directory for plugin
Plugin often needs access to various objects on disk; let's allow caller
to prepare root filesystem for the plugin to pivot to.

BUG=None
TEST=cargo test --features=plugin

Change-Id: I4f91511c776a06e4c329fe5aa42df4bb613ab5ab
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1055666
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-16 05:08:31 -07:00
Dmitry Torokhov
6051e7593a kvm: plumb accessors for VCPU XCR state
Plumb in KVM_GET_XCRS and KVM_SET_XCRS to allow saving and restoring
extended control registers of VCPUs.

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

Change-Id: I77dcb2ac488bf73b7503f49875d91e7c0cb21003
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1060613
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-16 05:08:21 -07:00
Dmitry Torokhov
6526fbfd4f kvm: fix definition of KVM_SET_XCRS ioctl
The ioctl in question is defined as write ioctl, not read/write.

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

Change-Id: I6683291d38f170713b949a56251c970038f2652b
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1060612
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-16 05:08:21 -07:00
Zach Reizner
d913acb984 io_jail: fix missing null terminator for close_fds test
BUG=None
TEST=cargo test -p io_jail

Change-Id: Ib732daca97cb303ec5013e616e6a7037b11af589
Reviewed-on: https://chromium-review.googlesource.com/1056414
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-05-11 23:22:19 -07:00
Dmitry Torokhov
5e05a8331d crosvm: add a feature to disable sandbox by default
Add a build-time feature that allows having plugin and other parts of
crosvm to run outside of jailed environment. This is strictly a
development time feature and is not expected to be activated with
shipping code.

Sandbox can still be activated by passing -u (--multiprocess) option.

BUG=None
TEST=cargo test --feature=default-no-sandbox

Change-Id: If9ef1ce8ed0b5d23cef3ad193679baca94413360
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1054194
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-11 23:22:18 -07:00
Sonny Rao
0ac9254f9a crosvm: aarch64: fix truncate on wayland policy
Like block_device, also needs to use ftruncate64 instead of ftruncate.

BUG=chromium:840048
TEST=manual test of graphics on kevin

Change-Id: Ib24b12fd681c96ecc2fec796fe480e94a96a0626
Reviewed-on: https://chromium-review.googlesource.com/1050916
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-09 04:33:14 -07:00
Sonny Rao
17bd06f65b sys_util: SharedMemory: fix signature for memfd_create syscall
The signature for this system call was wrong, but somehow managed to
work on x86_64.  This should fix it to work on all architectures.

BUG=chromium:840048
TEST=build_test passes
TEST=virtio wayland works on ARM

Change-Id: I295548357f688be4772e65991fb65178ead3b1e8
Reviewed-on: https://chromium-review.googlesource.com/1050915
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-09 04:33:14 -07:00
Sonny Rao
5165cb7eec crosvm: aarch64: fix lack of shifting for base_dev_pfn
This is a pfn (page-frame number) not a raw address, so we need to
shift it right by 12.

BUG=chromium:840048
TEST=manual test on kevin with virtio wayland and --disable-sandbox,
should not get "failed to recv from vfd: VmBadResponse" message

Change-Id: I788712ec7b9b3e9b4ada481d62a5f2ae1624e929
Reviewed-on: https://chromium-review.googlesource.com/1049060
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-05-08 17:44:33 -07:00
Zach Reizner
6f6854312d gpu_buffer: create bindings to minigbm
These bindings are needed to allocate dmabufs that will be used for
accelerated rendering and zero-copy virtio-wayland support.

TEST=cargo test -p gpu_buffer
BUG=chromium:837073

Change-Id: I96d7bcdeaa1eda616a25fdcfedcbb734cd585ae7
Reviewed-on: https://chromium-review.googlesource.com/1029410
Commit-Ready: David Reveman <reveman@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-05-08 04:57:58 -07:00
Sonny Rao
e0823392f4 devices: add an emulated ARM pl030 RTC clock
This adds a very simple RTC device and implements reading the time of
day based on the host's time of day.  It currently doesn't support
setting the time or wake up alarms but could do so in the future.
Also instantiate it and add the appropriate nodes to the device-tree
for ARM guests.

BUG=chromium:833825
TEST=manual test on kevin, date is properly set when VM is started

Change-Id: I032ec7df2cba9e9016966eb4160b413fec9a40ba
Reviewed-on: https://chromium-review.googlesource.com/1038801
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-04 03:03:00 -07:00
Sonny Rao
caaeb04460 devices: block: add sector info to block errors
This would have been useful in figuring out recent bugs in the block
sub system.

BUG=chromium:837453
TEST=manual test on kevin with qcow device

Change-Id: I3e3360bb0226e3cd7052e0431ce555cfef5e091b
Reviewed-on: https://chromium-review.googlesource.com/1034013
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-04 03:02:42 -07:00
Slava Malyugin
5622f12584 plugin: measure max/avg latencies of all plugin API
A simple stat collecting. Uses RAII to gather latency on all exit
paths from function/block. The underscore in "let _u = STATS.u(...)" is
to pacify "unused variable" warning. Using "let _ = " makes compiler
optimize out the call.

Rust makes it particularly hard to convert enums from integers, so I had
to add a hack that stores Enum on every invocation of the STATS.u. Looking
at disassembly, it added one move of constant to the field of STATS.entries;
no heap operations or cloning. A clever alternative using macros was
suggested by semenzato@, but I decided saving an instruction was not
worth the complexity.

The output is currently printed on the destruction of crosvm, so tests
print out stats on exit. We probably should find a better place for it
though.

BUG=None
TEST=cargo test --release --features plugin

Change-Id: I78a8920e9896b717af3aaea14f8ed6013be6b94f
Reviewed-on: https://chromium-review.googlesource.com/1036473
Commit-Ready: Slava Malyugin <slavamn@chromium.org>
Tested-by: Slava Malyugin <slavamn@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-04 03:02:39 -07:00
Zach Reizner
b749af91fe crosvm/linux: remove unusued error variants
These error variants are leftovers from the old initialization path for
virtio-wayland.

TEST=./build_test
BUG=None

Change-Id: I3dd55a10b923c4be300a72dfc36aeeb3bb02570b
Reviewed-on: https://chromium-review.googlesource.com/1033499
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-05-01 02:13:36 -07:00
Dylan Reid
832fc3cde5 qcow: avoid truncation if usize is 32 bits
The u64 offsets could be truncated when running on a 32 bit machine.
Do the math in 64 bit, limit to usize::MAX, then truncate.

BUG=837453
TEST=run crosvm and read/write files

Change-Id: If44ec94cf730ca7c1e580eeddd202e54e2de1081
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1031301
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-04-27 12:22:49 -07:00
Zach Reizner
71aedde5af wl: send HUP event when VFDs are hungup
It is essential that paste operations on the guest receive a hangup
letting them know that there is no more data to read. This change fixes
that behavior, which was broken by thew new PollContext based logic,
which separates out the readable and hungup code paths.

TEST=finished wayland pastes receive EOF
BUG=chromium:835112

Change-Id: I764124ab2eabb32d8cc25a3a4c0dfbe49b26e799
Reviewed-on: https://chromium-review.googlesource.com/1031292
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: David Reveman <reveman@chromium.org>
Reviewed-by: David Reveman <reveman@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-27 12:22:37 -07:00
Sonny Rao
dafdbc01cb crosvm: aarch64: fix seccomp entry for ftruncate on aarch64
Aarch64 seems to use ftruncate64 rather than ftruncate.

BUG=chromium:816692
TEST=run VM on kevin using concierge

Change-Id: I944f52d75fb9f5a3aaf5fe9e85708c48f249bb1a
Reviewed-on: https://chromium-review.googlesource.com/1031175
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-26 21:10:10 -07:00
Zach Reizner
28be0c6812 crosvm/plugin: fmt plugin module and remove negative error code
This is fixes the last remaining negative error code returned by a Rust
function.

TEST= cargo test --features plugin
BUG=None

Change-Id: Ideee89b0f0b1effecc9b5880bcf400c82d9b96f9
Reviewed-on: https://chromium-review.googlesource.com/1026938
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
2018-04-26 17:00:37 -07:00
Zach Reizner
da3f64c8fe crovm/plugin: fix PerVcpuState to be per vcpu
Because resize was used to grow a vec, each Arc<Mutex<PerVcpuState>> was
cloned from the original Default, merely increasing the ref count on the
same default data.

This change manually pushes a unique set of data per vcpu.

BUG=chromium:835916
TEST=None

Change-Id: I7116c764effd0f33f706f912bcf4d5d28ba1e08e
Reviewed-on: https://chromium-review.googlesource.com/1024504
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Aleksandr Kartashov <regmka@gmail.com>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-26 17:00:36 -07:00
Philipp Kern
a894f53439 Fix a typo: virtio::NOITFY_REG_OFFSET -> virtio::NOTIFY_REG_OFFSET
TEST=compiled crosvm successfully

Change-Id: Idabf81b8600fa2772e6e315d08d3c853e511a8cd
Reviewed-on: https://chromium-review.googlesource.com/1023415
Commit-Ready: Philipp Kern <pkern@google.com>
Tested-by: Philipp Kern <pkern@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-04-23 15:36:33 -07:00
Mark Ryan
6ed5aea011 Fix signal handling in VCPU threads
This commit addresses a number of issues with the way in which the
SIGRTMIN() + 0 signal is used to kick VCPU threads.  It

1. Moves the registration of the signal handler to the main thread.
   There's no need to register the handler once for each VCPU as
   there's one handler per process, rather than one per thread.
2. Ensures expect is not called in the VCPU thread before
   start_barrier.wait() is called.  In the current code,
   failure to register the signal handler causes crosvm to hang
   rather than to exit as the VCPU thread panics before calling
   start_barrier.wait().  The main thread then blocks forever while
   waiting on the barrier.
3. Uses the KVM_SET_SIGNAL_MASK ioctl to remove a race condition in
   the current code.  In the current code, a SIGRTMIN() + 0 signal,
   received during a vm exit, would be consumed before the next call
   to KVM_RUN, which would execute as normal and not be interrupted.
   This could delay the VM from stopping when requested to do so.
   Note that the new code doesn't unblock all signals during
   the call to KVM_RUN.  It only unblocks SIGRTMIN() + 0.  This is
   important as SIGCHILD is blocked at the start of run_config, and
   we probably don't want this unblocked periodically in each of the
   VCPU threads.

TEST=run crosvm and stop it in both single and multi-process mode.
BUG=none

Signed-off-by: Mark Ryan <mark.d.ryan@intel.com>
Change-Id: Ibda7d6220482aa11b2f5feee410d1d2b67a7e774
Reviewed-on: https://chromium-review.googlesource.com/1019443
Commit-Ready: Mark D Ryan <mark.d.ryan@intel.com>
Tested-by: Mark D Ryan <mark.d.ryan@intel.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-04-23 10:50:01 -07:00
Zach Reizner
d14c41a81f sys_util: handle EINTR return from epoll_wait
The PollContext::wait returns Error on EINTR, which often happens during
suspend/resume cycles. Because this Error is transient, this should be
handled internally with a retry until a fatal error is encountered.

BUG=chromium:834558
TEST=run crosvm, suspend, resume, observe crosvm still running

Change-Id: I75469e261ddf28f025a3b3b93612538ccf1230b9
Reviewed-on: https://chromium-review.googlesource.com/1018527
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-19 01:13:09 -07:00
Sonny Rao
7a7268faf0 crosvm: aarch64: add epoll syscalls to seccomp policy for wayland
Match the configuration for x86_64

BUG=chromium:816692
TEST=run wayland under crosvm on kevin

Change-Id: If21bccddba362656fc02b213b9f30166f2c4be13
Reviewed-on: https://chromium-review.googlesource.com/1006488
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-11 18:08:32 -07:00
Zach Reizner
4fcd1af11e sys_util: remove deprecated Poller/Pollable interface
Now that there are no users of that interface, we should remove it.

TEST=./build_test
BUG=chromium:816692

Change-Id: Ifdbde22984f557b945e49559ba47076e99db923b
Reviewed-on: https://chromium-review.googlesource.com/1000103
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-06 19:50:33 -07:00
Zach Reizner
d86e698ec8 devices: use nested PollContext in wayland device
The wl device was the last user of the old Poller.

BUG=chromium:816692
TEST=run wayland under crosvm

Change-Id: I6c1c1db2774a6e783b7bd1109288328d75ad2223
Reviewed-on: https://chromium-review.googlesource.com/1000102
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-06 19:50:33 -07:00
Zach Reizner
c1b74eb8b1 sys_util: add method for copying PollEvents
Making a copy of PollEvents is useful to drop the PollEvents structure
which borrows from a PollContext. Even though immutably borrowing from a
PollContext does not prevent any operations on a PollContext, it does
prevent mutable method calls on any structure that owns PollContext.

TEST=None
BUG=chromium:816692

Change-Id: I9527fd5c122a703933deb973ad549b792226e4c6
Reviewed-on: https://chromium-review.googlesource.com/1000101
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-06 19:50:32 -07:00
Sonny Rao
7951f16b87 crosvm: aarch64: add seccomp policy for wl_wayland
Add a seccomp policy for virtio wayland devices on aarch64.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on kevin built with USE="kvm_host" with a
  wayland socket passed in

Change-Id: I89e9904b48598d78be0721ba8b3242d1b43f7aa3
Reviewed-on: https://chromium-review.googlesource.com/999169
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-04-06 14:44:10 -07:00
Zach Reizner
129bc9c2c8 wl: add pipe vfd support
Pipe VFDs are used to send and recieve data offer bytes, often used for
copy/paste and drag/drop operations.

TEST=use copy/paste with wayland app
BUG=chromium:793688

Change-Id: Ifc3f231dcdf90ce6791a98039405c7c404cf6942
Reviewed-on: https://chromium-review.googlesource.com/983037
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-04-05 22:12:32 -07:00
Zach Reizner
fc62c45dab devices: use PollContext for all virtio deivces
BUG=chromium:816692
TEST=run any VM

Change-Id: I4219050fdb7947ca513f599f1ac57cde6052d397
Reviewed-on: https://chromium-review.googlesource.com/996917
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-04-05 15:20:42 -07:00
Dylan Reid
2056644c7d crosvm: Allow disks to be specified as /proc/self/fd/X
Concierge needs to be able to pass open file descriptors to crosvm when
crosvm is executed. Use /proc/self/fd to communicate that a file is
already open. This will allow passing open FDs to concierge over D-BUS
and avoid giving the crosvm user permission to open files in different
parts of the system.

BUG=827705
TEST=Start VM with persistent storage on a USB device.

Change-Id: I1c56eeb11f95f32e235f3486eb04581851c41d90
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/991094
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-04-04 22:53:28 -07:00
Zach Reizner
5bed0d2ffa crosvm/linux: switch to using PollContext in control loop
This avoids the pitfalls of Poller, which required dynamic allocation on
every loop for the dynamically added Pollables. Using PollContext also
makes busy poll loops less silent.

TEST=run a linux vm
BUG=chromium:816692

Change-Id: If44e47bcbbd7c889399f957ad5bcca66eca57b8e
Reviewed-on: https://chromium-review.googlesource.com/983038
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-04-04 22:53:27 -07:00
Zach Reizner
f96be03cad devices: block: use PollContext in block device
Switching to PollContext so that there is one less user of Poller, which
will be removed.

TEST=run any vm with a block device
BUG=chromium:816692

Change-Id: I2e1301ea9d66012262f1fcb69eaeee9f7464f3b3
Reviewed-on: https://chromium-review.googlesource.com/983036
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-04-04 22:53:22 -07:00
Zach Reizner
043ddc5c0d crosvm: enable seccomp logging in debug builds
This will be useful for diagnosing crosvm crashes which are most often
caused by seccomp killing a device process.

TEST=delete a seccomp filter, run crosvm, check for blocked syscall in
     /var/log/messages
BUG=None

Change-Id: I1e01a0794f0349e6ad9b101eb2e32320f60b1283
Reviewed-on: https://chromium-review.googlesource.com/994737
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-04-04 22:53:21 -07:00
Sonny Rao
a7fae252b0 crosvm: aarch64: get kernel's preferred target type for vcpus
This fixes an issue on kevin where if we start on a little core, the
kernel doesn't like the generic ARMv8 target cpu type for some reason.  To
fix this we must query the preferred type from the vm device first and
supply that to the vcpu init ioctl.

We need to change the signature of the configure_vcpu method to pass
in the vm object even though we aren't using it on x86.

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

Change-Id: I460cb9db62a8805bb88f838956aa4f1c69183961
Reviewed-on: https://chromium-review.googlesource.com/982996
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-04-03 12:50:39 -07:00
Sonny Rao
2ffa0cbe5b crosvm: aarch64 guest support
- removes old ARMv7a (32-bit) bindings as we're only supporting aarch64
  guests right now
- switches both ARMv7 and aarch64 builds to use aarch64 kvm bindings
- adds support for ARMv8 Linux guest with dynamic flattened-device-tree

CQ-DEPEND=990894
BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline
TEST=crosvm runs on kevin built with USE="kvm_host"

Change-Id: I7fc4fc4017ed87fd23a1bc50e3ebb05377040006
Reviewed-on: https://chromium-review.googlesource.com/969987
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-04-03 12:50:37 -07:00
Zach Reizner
5d586b73a4 sys_util: use MADV_DONTDUMP for new mmaps
The mmaps made through the sys_util API are usually for guest memory or
other large shared memory chunks that will pollute the file system with
huge dumps on crash. By using MADV_DONTDUMP, we save the file system
from storing these useless data segments when crosvm crashes.

TEST=./build_test
BUG=None

Change-Id: I2041523648cd7c150bbdbfceef589f42d3f9c2b9
Reviewed-on: https://chromium-review.googlesource.com/890279
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-03-30 21:53:32 -07:00
Dmitry Torokhov
3e40b51a62 plugin: allow retrieving and setting VM and VCPU states
This change allows plugin to retrieve and set various VM and VCPU states:
interrupt controller, PIT, LAPIC and MP state.

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

Change-Id: Ie32a67b0cd4a1f0a19ccd826a6e1c9dc25670f95
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/986511
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-30 00:07:07 -07:00
Dmitry Torokhov
eda8b21536 kvm: fix fetching irqchip state for PICs other than the first one
The KVM API to fetch interrupt controller state expects caller to supply
number (id) of the interrupt controller number in which state the caller
is interested. To allow crosvm to fetch the correct state and to improve
type safety we split the API into one that handles the PIC (primary and
secondary) and the one that handles IOAPIC.

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

Change-Id: Ia45b51cb218072a275c244af2de1b4a73a1d3352
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/986510
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-30 00:07:07 -07:00
Dmitry Torokhov
4757cf164b kvm: plumb accessors for VCPU MP state
Plumb in KVM_GET_MP_STATE and KVM_SET_MP_STATE to allow saving and
restoring "multiprocessing state" of VCPUs.

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

Change-Id: Ia6e98a09c12dcc859196908f865fac57d48b2ddd
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/982372
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-03-29 22:00:14 -07:00
Zach Reizner
b2e528b575 sys_util: impl Pollable for File
Files are Pollable because they have an FD. Whether this makes sense for
any specific `File` is not enforced, but it will never be unsafe or
undefined when used with Poller.

BUG=chromium:793688
TEST=None

Change-Id: I2ce7ffd1b408bcee5ffbb3738d26339aa0c466e0
Reviewed-on: https://chromium-review.googlesource.com/985617
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-03-29 21:59:45 -07:00
Zach Reizner
1028f53ed2 sys_util: have Poller return token on POLLHUP
If POLLHUP is filtered out of the returned tokens, the caller of
Poller::poll will likely just put the same (token, fd) in the next call
to poll which will return instantly. This degrades into a busy poll loop
without the chance for the caller to change the poll list.

Instead, this change changes the filter to return tokens on POLLHUP so
that the caller will hopefully notice the FD associated with the token
has been hungup and will close it.

BUG=chromium:816692
TEST=None

Change-Id: Ie36d8a647a5fd7faabfd57a562205f75c77991e7
Reviewed-on: https://chromium-review.googlesource.com/985616
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-29 21:59:45 -07:00
Zach Reizner
3afab33a8d sys_util: add type to get open file flags
The only instance of libstd getting file flags is the debug formatter
for `File` which would be hacky to depend on. This change adds a type
and method to directly get open file flags.

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

Change-Id: I9fe411d8cb45d2993e2334ffe41f2eb6ec48de70
Reviewed-on: https://chromium-review.googlesource.com/985615
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-03-29 21:59:44 -07:00