Commit graph

363 commits

Author SHA1 Message Date
Zach Reizner
bb493dd02b convert println logs to logging macros
TEST=build_test
BUG=None

Change-Id: Ia184e994e996eef427e1b50ce019403f4521f008
Reviewed-on: https://chromium-review.googlesource.com/693138
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2017-09-29 23:25:36 -07:00
Zach Reizner
26e1aef84f add usage information to README
TEST=None
BUG=None

Change-Id: Iab070c5788e19e63140643115af6e48421989f9b
Reviewed-on: https://chromium-review.googlesource.com/683798
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-09-27 12:57:59 -07:00
Zach Reizner
5e4ab46105 build_test: use command line arguments instead of enviroment variables
This change also includes bikeshed style fixes and adds doc strings.

TEST=build_test
BUG=None

Change-Id: I2fec9a3f4488ccf3629e70e5c507695c49389e0d
Reviewed-on: https://chromium-review.googlesource.com/679574
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2017-09-22 22:25:38 -07:00
Zach Reizner
ab839e293d fix dependency versions and add Cargo.lock
To ensure dependencies don't accidentally get updated, their versions are
fixed using the equals constraint. The Cargo.lock file is also checked in
so that the registry won't need to be downloaded by cargo.

These changes are needed so that the crosvm ebuild will not need to
download anything outside of its list of source packages.

TEST=./build_test
BUG=None

Change-Id: Iae8472de77e3589a453685717b26fb1ceb44e257
Reviewed-on: https://chromium-review.googlesource.com/674092
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>
2017-09-20 03:39:24 -07:00
Chirantan Ekbote
42b3e8da55 net_util: Remove unused import
The compiler was complaining about std::fmt::Debug being an unused
import.  Remove the import.

BUG=none
TEST=build_test and see no warnings about unused imports

Change-Id: I5e606982dffee575b3048b6c45cb5222e63ae3dc
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/669305
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-09-18 16:48:43 -07:00
Chirantan Ekbote
88f9cba448 Implement virtio-vsock
Implement the virtual sockets device using vhost subsystem of the host
kernel to handle data transfer.

BUG=chromium:708267
TEST=build and run maitred in guest VM without issue

Change-Id: I35b542c0fc7e0fd9296f7ba3e1dfce60bf524d15
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/638838
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-09-18 16:48:43 -07:00
Dylan Reid
270f7b6a16 Improve guest memory error handling
Pass better errors from mmap and guest_memory. These modules were
written before I understood errors. Now the errors passed back to block
can be propagated.

Change-Id: I1842808a4114a715321c555281aacc211f23511c
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/656837
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-09-11 22:47:10 -07:00
Jason D. Clinton
6f366b5460 vhost: Fix-up failing tests and add a little more coverage
This fakes out the underlying Net implementation with FakeNet to try
and get some of the code a little further along before it
explodes. Then, we test for known failures when running without a real
vhost file descriptors.

This allows us to pass without running as root as we would expect
running on Paladins.

This is also the final module that was failing at ToT.

Also adds vhost to the build_test test targets.

BUG=none
TEST=Run unit tests:
cargo test -p crosvm -p data_model -p syscall_defines -p kernel_loader -p net_util -p x86_64 -p virtio_sys -p kvm_sys -p vhost -p io_jail -p net_sys -p sys_util -p kvm
Also ran ./build_test

Change-Id: Ie12d05c044634a660a234483532cf783e2a7fe84
Reviewed-on: https://chromium-review.googlesource.com/656278
Commit-Ready: Jason Clinton <jclinton@chromium.org>
Tested-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
2017-09-09 13:48:49 -07:00
Zach Reizner
2bcf05b2af crosvm: add virtio wayland device
This adds the virtio wayland device which is activated by default. The wayland
device needs the XDG_RUNTIME_DIR env variable to be set and a running wayland
compositor to connect to in that directory.

TEST=crosvm run <other args>
BUG=chromium:738638

Change-Id: Iaa417c6bb74739896042318451b4befcac0c1d0e
Reviewed-on: https://chromium-review.googlesource.com/559860
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-09-08 17:35:58 -07:00
Zach Reizner
22175fe368 crosvm: add uid_map/gid_map support to jailed devices
This CL includes a small tweak to sys_util so that cloned processes PIDs
are returned.

The proxy device CHILD_SIGNATURE check was removed because it would
deadlock with the synchronization that DeviceManager's post clone
callback uses to wait for the id maps to be set. The check wasn't that
useful to begin with.

This also bumps the libc version.

TEST=None
BUG=None

Change-Id: I881e08c9626e035044b0be1dd2e9fff3e7e61ec1
Reviewed-on: https://chromium-review.googlesource.com/634270
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-09-08 17:35:58 -07:00
Jason D. Clinton
d7f036281d net_util: Fix-up failing tests and add a little more coverage
We can't really mock out the underlying TAP ioctls unless we introduce
another layer of abstraction. Instead, this CL allows a test to pass
if the reason that it failed was a permission denial as we would
expect running on Paladins as non-root.

Also adds net_util to the build_test test targets.

BUG=none
TEST=Run unit tests:
cargo test -p crosvm -p data_model -p syscall_defines -p kernel_loader -p net_util -p x86_64 -p virtio_sys -p kvm_sys -p vhost -p io_jail -p net_sys -p sys_util -p kvm
Also ran ./build_test

Change-Id: I5c761bd75d3a6d5829f4dd07fb8031612944e912
Reviewed-on: https://chromium-review.googlesource.com/649958
Commit-Ready: Jason Clinton <jclinton@chromium.org>
Tested-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
2017-09-08 15:05:11 -07:00
Zach Reizner
1ea2f8ec34 crosvm: bump libc version to 0.2.29
This is so future changes can use getresuid/setresuid and similar
syscalls.

BUG=chromium:738638
TEST=./build_test

Change-Id: I47765fa1f45c549d8e148d02655dd61993a10f58
Reviewed-on: https://chromium-review.googlesource.com/655143
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-09-07 21:21:25 -07:00
Zach Reizner
bb2317033e io_jail: add ui_map/gid_map support to minijail
Change-Id: I6343e879ba75e8ac912590779c620bd0045e74d9
Reviewed-on: https://chromium-review.googlesource.com/634269
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-09-07 21:21:24 -07:00
Zach Reizner
1f77a0daa6 sys_util: use libc's openlog to connect to syslog
By using libc's openlog, we can ensure that the internal state of the
libc syslogger is consistent with the syslog module. Minijail will be
able to print to stderr and the syslog in the same way the logging
macros in crosvm do. The FD the syslog module uses is shared with libc
and via `syslog::get_fds`, jailed processes can inherit the needed FDs
to continue logging.

Now that `sys_log::init()` must be called in single threaded process,
this moves its tests to the list of the serially run ones in
build_test.py.

TEST=./build_test
BUG=None

Change-Id: I8dbc8ebf9d97ef670185259eceac5f6d3d6824ea
Reviewed-on: https://chromium-review.googlesource.com/649951
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-09-06 14:31:06 -07:00
Zach Reizner
d0a1fde1c1 crosvm: jailed child processes inherit stderr
By inheriting stderr, logs from minijail and the logging macros can be
seen in the stderr of crosvm, which is convenient for debugging.

BUG=None
TEST=None

Change-Id: I6d6506776add780b243da50e635c25d27a8976ce
Reviewed-on: https://chromium-review.googlesource.com/649952
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
2017-09-06 14:31:06 -07:00
Zach Reizner
35d4950c3f io_jail: implement Display for Error
Running crosvm in multiprocess mode includes setting up an io_jail for
each device and it can very often fail due to problems in the
enviroment, such as missing policy files or lack of privilege. The auto
generated debug error messages were not very good (based on initial user
feedback) and so this CL implements display to help make the errors more
understandable when they are printed.

BUG=None
TEST=./build_test

Change-Id: If51c00e60abb9b0d482515fa1e401f2fa6fb9e8f
Reviewed-on: https://chromium-review.googlesource.com/649950
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-09-06 14:31:06 -07:00
Zach Reizner
efe957849b crosvm: argument parsing without clap
This removes the clap dependency by replacing that functionality with a
custom written parser. Binary size is reduced by about 60% in optimized
and stripped mode.

TEST=cargo run -- run -h
BUG=None

Change-Id: I2eaf6fcff121ab16613c444693d95fdf3ad04da3
Reviewed-on: https://chromium-review.googlesource.com/636011
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-09-02 00:18:25 -07:00
Zach Reizner
e932102386 data_model: add copy functions for copying slices in VolatileSlice's
These copy functions are functionally similar to read_from and write_to,
but have stronger guarantees because they are copying to/from concrete
slices. In particular, the volatile access pattern is specified and the
copy operation never returns an error.

TEST=cargo test
BUG=chromium:738638

Change-Id: Ie10152e10bc8a36058f5d5001ff392ff8975ee36
Reviewed-on: https://chromium-review.googlesource.com/599043
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-09-01 14:41:52 -07:00
Zach Reizner
451dd3bdab add build_test script to automate crosvm test running
TEST=./build_test && cros lint build_test.py
BUG=None

Change-Id: I11de92ab1c854264b762c3bb2e3ebda9d3f4b007
Reviewed-on: https://chromium-review.googlesource.com/644409
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-09-01 12:39:19 -07:00
Zach Reizner
3cbded2c51 fix armv7a and aarch64 build errors and warnings
BUG=None
TEST=cargo build --target=armv7a-cros-linux-gnueabi &&
     cargo build --target=aarch64-cros-linux-gnu

Change-Id: I954c152f3c8086e24c4809dd5aabb5043fdd63af
Reviewed-on: https://chromium-review.googlesource.com/644408
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-09-01 12:39:18 -07:00
Chirantan Ekbote
86fb9567b5 Refactor the VhostNet virtio device
Split the VhostNet virtio device into generic and specific bits.  Almost
the entire Worker implementation is generic between all vhost devices.
The only non-generic bit is a device-specific ioctl to activate a
virtqueue.

To deal with this add a callback to the Worker's Run function to
activate all the virtqueues after they have been set up.

BUG=chromium:708267
TEST=build and run with a vhost-net enabled kernel and see that
     everything still works

Change-Id: I262c07e4d2c289f9528924ba708d0b88bd0379bb
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/636121
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-08-30 13:04:22 -07:00
Zach Reizner
ee73bf34a8 crosvm: unlink control sockets bound to files
This is a regression from the control socket refactoring. The removal of
the control socket receiver class, whose drop impl handled the removal
of the socket's files, meant that no code took care of cleaning them up.

BUG=None
TEST=Run with `-s./` and after a clean exit, make sure there is no
     *.sock files in the current directory.

Change-Id: I0064900f4eec6d054d174d59a4aefdf36ab4d3b3
Reviewed-on: https://chromium-review.googlesource.com/642510
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-30 13:04:16 -07:00
Zach Reizner
56077cf863 fix compiler errors and warnings
Problems that were fixed:
  - gcc crate deprecated compile_library
  - `cargo test -p kvm` had a compile error
  - `cargo test -p kvm_sys` failed to link with libc
  - main.rs failed to include `getpid` and had dead code
  - fork.rs had a warning in `cargo test -p sys_util`
  - unused const in serial.rs

BUG=None
TEST=sudo cargo test -p data_model -p io_jail -p kernel_loader -p kvm \
     -p kvm_sys -p net_sys -p net_util -p syscall_defines -p sys_util \
     -p virtio_sys -p vhost -p x86_64 -p crosvm

Change-Id: Iaf0389013fbcdfbfaa7cf37ea1a1fc045f480ada
Reviewed-on: https://chromium-review.googlesource.com/642509
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-08-30 13:04:16 -07:00
Chirantan Ekbote
195457e484 Refactor VhostNet into separate vhost and net pieces
A large portion of the VhostNet implementation is common to all vhost
devices.  Create a new Vhost trait that encapsulates this behavior and
split the network specific bits into a new Net type and implement the
Vhost trait for it.

BUG=chromium:708267
TEST=build and run with a VHOST_NET enabled kernel and see that
     everything still works fine

Change-Id: Ia6b7591f9428c1fba1e13b11791fe40e1bd3942b
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/630060
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-08-28 21:15:36 -07:00
Zach Reizner
56158c873a sys_util: add safe wrappers getpid,geteuid,getguid,waitpid,kill
These functions are trivially safe and by adding them to sys_util, we
can remove some unsafe blocks from crosvm. This CL also replaces the
unsafe call sites with the safe alternatives.

There are no previous usages of gete{g,u}id(2), but they will be needed
in a future change.

TEST=None
BUG=None

Change-Id: Ief8787b298cfaa5b7fd1b83f0eba6660369e687d
Reviewed-on: https://chromium-review.googlesource.com/634268
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-28 18:21:37 -07:00
Chirantan Ekbote
41d5b5b12a Put seccomp policy files in a common directory
We will almost certainly require different seccomp policy files for
different architectures.  Move all the existing secommp policy files
into a common directory grouped by architecture.

This will make it easier to install them via the ebuild later.

BUG=none
TEST=none

Change-Id: I0495789cd4143dc374ee6ebe083dc20ce724edbb
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/630058
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-25 19:54:16 -07:00
Zach Reizner
29ad3c7d0f crosvm: refactor and expand vm control socket IPC
This CL adds VM request capabilities to the control socket. These
requests include the basic exit as well as the essential ioeventfd and
irqfd requests. For virtio wayland, the register/unregister device
memory request was added.

TEST=cargo test
BUG=chromium:738638

Change-Id: I0cbf62d85a299cf454bcf6924a4e1d52d5b7183f
Reviewed-on: https://chromium-review.googlesource.com/602593
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-25 19:54:11 -07:00
Stephen Barber
5e77e88062 crosvm: add pure virtio net device
While vhost_net can provide better performance than a userspace
virtio device, it also requires a kernel module to function. This
also prevents jailing the virtio device, since virtqueue operations
(which necessarily touch guest memory) will be running directly
in the kernel.

Add a userspace virtio net device that can be jailed and works
without vhost support in the kernel.

BUG=chromium:703920
TEST=networking works

Change-Id: I468114b48abd8e30e967ff16329a5dce6a75018f
Signed-off-by: Stephen Barber <smbarber@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/604937
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-08-16 07:48:27 -07:00
Dylan Reid
d527d85da6 crosvm: Add barrier before updating used_ring index
We have to guarantee that all the descriptor writes are visible to the
guest before the index update is.

Change-Id: I35f1c8d3f5fc9a6ac54de1eb4be66e1c5ac81fc8
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/611215
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-08-14 18:24:55 -07:00
Dylan Reid
c28f6a67b1 crosvm: Add virtio random
Provide the guest OS with /dev/random.

Change-Id: I1323836392f3f1d59a6be276ce495e0d78ea9669
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/603531
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-08-10 20:24:09 -07:00
Stephen Barber
d579e3cd49 crosvm: rename Net virtio device to VhostNet
BUG=chromium:703920
TEST=networking still works

Change-Id: I28517cc61a572998cd57868c2dbccec247140a58
Signed-off-by: Stephen Barber <smbarber@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/604936
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-08-09 11:47:55 -07:00
Stephen Barber
604d989d7e net_util: implement Read, Write, and Pollable for Tap
BUG=none
TEST=none

Change-Id: I1baf242a605ee6ff8e3bcc26e49042c3c2dd8cbb
Signed-off-by: Stephen Barber <smbarber@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/604935
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-09 11:47:55 -07:00
Stephen Barber
2fb1969902 sys_util: add read_slice_at_addr to GuestMemory
BUG=none
TEST=cargo test

Change-Id: Ifeda91de37bf83a2e5a00f5e308db786fa5d49d5
Signed-off-by: Stephen Barber <smbarber@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/604934
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-09 11:47:55 -07:00
Zach Reizner
09a95f5e74 kvm: add device memory interface to Vm
This interface is to dynamically add and remove memory mappings to guest
physical address space.

TEST=cargo test
BUG=chromium:738638

Change-Id: I695775289d56686ef16a1e3cf7640c97d5da2662
Reviewed-on: https://chromium-review.googlesource.com/599040
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-05 22:07:53 -07:00
Zach Reizner
7a9de27c36 sys_util: allow sock_ctrl_msg to be more flexible with iovecs
Because there are more than one kind of slice (typical &[T] and
VolatileSlice), the trait IntoIovec is added that any linear memory
region-like type can implement. This helps to reduce the number of
copies needed when dealing with volatile memory.

TEST=cargo test
BUG=chromium:738638

Change-Id: I86bbb693cb7a10ec85bafccf562c078167121c03
Reviewed-on: https://chromium-review.googlesource.com/599042
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-03 01:11:01 -07:00
Zach Reizner
3eddedd005 sys_util: add Pollable impls for UnixDatagram and UnixStream
UnixDatagram and UnixStream are both wrappers around unix domain sockets
which are often polled.

TEST=None
BUG=chromium:738638

Change-Id: Ib5572faf1d601b89b9fdd323f654ba04650b7600
Reviewed-on: https://chromium-review.googlesource.com/599041
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-03 01:11:01 -07:00
Zach Reizner
174ce13e55 crosvm: fix queue wrapping behavior over u16
The queue's next index, as set by the kernel, will increase
monotonically to the limit of a u16 and then wrap back to zero. In
contrast, Rust will panic when its internal counter reaches the limit.
This change enables the wrapping behavior that we want.

TEST=run a kernel that uses a queue >0xffff times
BUG=None

Change-Id: I24101dfb137a1350fd93d1b378840b72431764ea
Reviewed-on: https://chromium-review.googlesource.com/598502
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-08-03 01:11:01 -07:00
Dylan Reid
f463bc139d crosvm: main - Allow read/write block devices
Add an option for allowing a writable disk.
Allow specifying multiple disks.
Don't assume the path to the root device, force the user to specify a
correct command line option.

Change-Id: I87dea1152e1f81c0cde45ad47e2c4cf0f187918e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/569450
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-31 04:12:33 -07:00
Stephen Barber
5ad8bc5e08 io_jail: Add InvalidPath error
parse_seccomp_filters in libminijail will unhelpfully abort() if the
path doesn't exist. Check that the policy file exists so that there's
a semi-useful error message.

BUG=none
TEST=crosvm run without seccomp policy in current directory; no abort

Change-Id: Ie1123e8cae3f6a27bbd5a3128161364401e8d4b2
Signed-off-by: Stephen Barber <smbarber@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/585829
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-26 16:46:53 -07:00
Stephen Barber
ce3a3e8f00 sys_util: fix include in sock_ctrl_msg
close() is from unistd.h.

BUG=none
TEST=cargo build

Change-Id: I62730c374b016118dececcfd7e2cd009f12611a7
Signed-off-by: Stephen Barber <smbarber@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/583904
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-24 22:54:04 -07:00
Zach Reizner
bf36bcbc4a sys_util: add sock_ctrl_msg module for transmitting messages with FD
This CL also includes the gcc build time dependency for building the
sock_ctrl_msg.c helper code.

TEST=cargo test
BUG=chromium:738638

Change-Id: I4adc2360b7fab4ed7d557603aa7bad2e738b69b4
Reviewed-on: https://chromium-review.googlesource.com/562574
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-20 21:21:29 -07:00
Dylan Reid
3a4cca14a0 crosvm: block - Fill upper 4 bytes of disk size
Fill the upper for bytes of the disk size configuration.  The size is a
64bit value accessed with two 32bit reads.

The guest is permitted to read at any byte offset in the config space.
Allow it to do so, even if it doesn't make much sense.

Change-Id: I5d02620a8751b31784e419ae6a57173a2e212b8f
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/569359
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-20 15:00:37 -07:00
Stephen Barber
2cfc2056aa crosvm: add vhost_net virtio device
vhost_net is an in-kernel implementation of a virtio_net device. This device
implementation is responsible only for negotiating features and setting up
vhost_net to point to the virtqueues in the guest.

Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=chromium:738639
TEST=boot with networking enabled and ping host

Change-Id: I9192765b9348528a8a7a7f273e9522c2373d22fb
Reviewed-on: https://chromium-review.googlesource.com/538106
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-20 03:05:17 -07:00
Stephen Barber
d02ae30698 vhost: add crate for interacting with vhost net
Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=chromium:738639
TEST=cargo test

Change-Id: I83ef1657a90c3946db296c2e743397dbd1947de4
Reviewed-on: https://chromium-review.googlesource.com/538101
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-20 03:05:17 -07:00
Zach Reizner
648a58d248 crosvm: mmio register and queue check fixes
According to the Virtio specification, all MMIO register access must be
32-bit wide and aligned. However, this restriction is not true in
general for the config space. This change relaxes the restriction for
accesses to config space.

This change also checks that each queue is valid before activating a
device.

TEST=crosvm run
BUG=None

Change-Id: I10228d99992576837ff505aad56fefbc4d8eff78
Reviewed-on: https://chromium-review.googlesource.com/578314
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-20 00:37:00 -07:00
Stephen Barber
5b5574471b sys_util: add get_host_address for GuestMemory
Add a method get_host_address for converting a
GuestAddress to a (usize) pointer in crosvm's address
space.

Change-Id: I6dc09e942c95204f4e53218b3250664782c8f8f9
Signed-off-by: Stephen Barber <smbarber@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/575439
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-19 16:26:59 -07:00
Stephen Barber
a00753ba37 crosvm: clean up waiting for children
Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=none
TEST=run and kill block device process

Change-Id: I1a4e98cb1985bfeb2303428f95f3bae27dccf803
Reviewed-on: https://chromium-review.googlesource.com/576463
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-18 23:48:37 -07:00
Stephen Barber
56fbf09eac crosvm: add signalfd support
Use signalfd to catch SIGCHLD, which will notify the main process when a
device process has died, e.g. it crashed or violated seccomp policy. The
main process will then exit gracefully.

Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=none
TEST=block a syscall and run with multiprocess; ensure no defunct
processes are hanging around

Change-Id: Ief8a94576ad9eeb032f45ce8491fcfe23a971473
Reviewed-on: https://chromium-review.googlesource.com/557460
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-18 02:36:14 -07:00
Stephen Barber
99bed77967 virtio_sys: add crate for virtio/vhost ioctl bindings
Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=chromium:738639
TEST=cargo test

Change-Id: I93eac65910e7f4f7c786cc0de3bb28c07b1be268
Reviewed-on: https://chromium-review.googlesource.com/538100
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-13 22:03:31 -07:00
Stephen Barber
253ac89d91 net_util: add crate for creating/configuring tap interfaces
Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=chromium:738639
TEST=cargo test

Change-Id: Iddf715d40164abeeb6923e8e5a84c02233e0ab64
Reviewed-on: https://chromium-review.googlesource.com/538103
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-13 22:03:30 -07:00