Commit graph

901 commits

Author SHA1 Message Date
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
Stephen Barber
219b1856eb net_sys: add crate for tap interface ioctl bindings
Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=chromium:738639
TEST=cargo test

Change-Id: Ic289419de96a2ba0791e8ce8b96d79745886cbfd
Reviewed-on: https://chromium-review.googlesource.com/538102
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
Stephen Barber
c4968f7de9 sys_util: add ioctl module
Factor out common ioctl wrappers and macros into their own module.

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

BUG=none
TEST=cargo test

Change-Id: Ibede8a853f5cc6c6d62565930f312b11024cc5b5
Reviewed-on: https://chromium-review.googlesource.com/566540
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-13 22:03:30 -07:00
Stephen Barber
8686d9ff5b crosvm: refactor mmio device setup
In preparation for adding a net device, factor out some of the common code
for setting up an mmio device and jailing it.

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

BUG=none
TEST=cargo test

Change-Id: I94f02e56a2b0938d860322b731d8b17a25357128
Reviewed-on: https://chromium-review.googlesource.com/543910
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
Dylan Reid
861d672430 crosvm: Remove obsolete help message
The cpus option is now used.

Change-Id: I64bcc7cf27427f20b093c70eec3b58cd2c55e290
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/569098
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-07-13 22:03:30 -07:00
Dylan Reid
e60336cc79 sys_util: syslog - Scope access from within macros
When syslog is used from another crate, the compiler needs a specific
place to look for the symbols.

Change-Id: I5ba1b7ae0e8f6825aaf2a0d0b6ff31dcab21aa0c
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/569360
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-13 19:46:09 -07:00
Stephen Barber
79d07c9727 sys_util: add signalfd module
Dealing with signals is unpleasant business. SignalFd wraps a kernel
signalfd for a signal, and blocks the default handling for the signal.

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

BUG=none
TEST=cargo test

Change-Id: I161c992b65b98ffa5c07d546f13efa6b56890df4
Reviewed-on: https://chromium-review.googlesource.com/557459
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-07-13 11:44:37 -07:00
Zach Reizner
f651357433 crosvm: use sys_util::clone_process to create proxy device
The `clone_process` function was created to safely encapsulate
fork/clone usage for the proxy device. This patch changes proxy device
to do utilize that.

TEST=cargo run -- -u <other crosvm args>...
BUG=None

Change-Id: I2d9f1794be61be31f3aae21037c7df14b7691172
Reviewed-on: https://chromium-review.googlesource.com/518935
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-13 11:44:36 -07:00
Zach Reizner
2b2952ff1f sys_util: add fork module for cloning process
This module is designed as a safe wrapper around clone for use by the
proxy device. It includes safe guards that prevent errors with typical
forking applications in rust.

TEST=cargo test
BUG=None

Change-Id: I09132a4cae61ebdaa97ec3b95d22567c36c5f15d
Reviewed-on: https://chromium-review.googlesource.com/518446
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-13 11:44:36 -07:00
Zach Reizner
fd3425db47 sys_util: add shared memory module
This CL adds the SharedMemory structure for managing memory attached to
a file descriptor, which can be sent to external processes.

TEST=cargo test
BUG=chromium:738638

Change-Id: I2b6a10e0e7275367ddb578831a73de6956d231bb
Reviewed-on: https://chromium-review.googlesource.com/562509
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-10 11:22:37 -07:00
Stephen Barber
f98d8f3ba6 sys_util: add with_regions_mut and make do_in_region pub
Add a new method to GuestMemory that allows running a FnMut over all
regions. This will allow the virtio module to generate a vhost memory
table.

Also make do_in_region public, so that VHOST_NET can find the host
userspace address of vrings (necessary for VHOST ioctls).

BUG=none
TEST=cargo build

Change-Id: I43611dcc56146ed4d160f0e189b9328ca0e6d87d
Reviewed-on: https://chromium-review.googlesource.com/543909
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-07 13:15:46 -07:00
Stephen Barber
e4c8c1463e crosvm: fix ordering of args for ack_features
BUG=none
TEST=cargo build

Change-Id: I58b475a4890d1d900c26b3d1c0598936f6f243ac
Reviewed-on: https://chromium-review.googlesource.com/538105
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2017-07-07 13:15:46 -07:00
Stephen Barber
6a4ca7556a crosvm: add device type for VirtioDevice
A VirtioDevice should expose its type so that the guest can probe it
correctly.

BUG=none
TEST=boot with block device

Change-Id: I6a8cae3afbdc5ae9f6af23eea928c83e67719c12
Reviewed-on: https://chromium-review.googlesource.com/538104
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-07-07 13:15:46 -07:00