Commit graph

31 commits

Author SHA1 Message Date
David Reveman
22272dd4b2 virtwl: implement dmabuf sync support
This provides proper synchronization for guest access to
DMABufs.

Virtio wayland device is given access to the DMA_BUF_SYNC ioctl
in order to implement this. Being able to use this directly in
the virtio wayland device process is important as these calls
can sometimes be relatively expensive and they are frequent
enough that avoiding another context switch is useful for good
performance.

TEST=cache-line artifacts no longer noticeable
BUG=chromium:837209

Change-Id: Ibb8d7c01f70ed5b74afd69288015a65186fec52a
Reviewed-on: https://chromium-review.googlesource.com/1076928
Commit-Ready: David Reveman <reveman@chromium.org>
Tested-by: David Reveman <reveman@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-06-19 14:38:53 -07:00
Chirantan Ekbote
a7b0a71204 virtio-queue: Add an iterator over a descriptor chain
Add a way to iterate over all the descriptors in a descriptor chain.
This is different from AvailIter, which iterates over all the descriptor
chain heads in a queue.

The new iterator struct provides readable() and writable() methods for
iterating over just the readable or writable descriptors, respectively.

BUG=chromium:703939
TEST=none

Change-Id: Iea3fa5bb7662146a2d156a49ce8bb8ef00c522da
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1065172
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-06-15 10:56:38 -07:00
Chirantan Ekbote
dd19b2e28a virtio-queue: Add an is_read_only() method for DescriptorChain
Add an is_read_only method to the DescriptorChain struct.  This is
easier to read at a glance than `!is_write_only()`, which looks almost
the same as `is_write_only()`.

BUG=chromium:703939
TEST=none

Change-Id: I0cb3b17c30e38804a21d3e63e975157c96879cb4
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1067703
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-06-15 10:56:38 -07:00
Chirantan Ekbote
6452eaf902 virtio: Derive Clone for DescriptorChain
Allow DescriptorChain to be cloned.  This will enable devices to
maintain a read head and write head in the same DescriptorChain.

BUG=chromium:703939
TEST=clone the DescriptorChain in a method

Change-Id: I1d775a9e0b7ed42052272f22a9b308ad4d108e45
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1065171
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-06-15 10:56:37 -07:00
Chirantan Ekbote
5f787217cc net: Allow passing in a configured tap fd on the command line
Allow the process that spawned crosvm to pass in a configured tap file
descriptor for networking.  If this option is provided then crosvm will
ignore the other networking related command line flags (like mac
address, netmask, etc).

Passing in a configured tap device allows us to run crosvm without
having to give it CAP_NET_ADMIN.

BUG=none
TEST=Start a container and verify that networking still works

Change-Id: I70b9e6ae030d66c4882e4e48804dc2f29d9874ba
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1081394
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-06-12 00:36:27 -07:00
Zach Reizner
92068bca00 wl: do not close FDs that were hungup
Before this CL, the WlState object would close VFDs that had been hungup
on the remote end as a means to removing the underlying FD from the
PollContext. However, this has some unintended side-effects. For one,
the guest would later try to delete the VFD after it was closed, which
was a double-free. Another was that every pending message that was
waiting to enter the virtio queue would get dropped if it was destined
for the closed VFD. This was especially bad if the virtio queue became
full because data would get dropped when a VFD was hungup before the
guest had any chance to read it.

This CL leaves the hungup VFDs (and therefore their pending message) as
is, but removes it from the PollContext if there is nothing left to read.
No data is removed until after the guest explicitly closes the VFD.

TEST=paste 100k characters into a guest app from Chrome
BUG=chromium:849317

Change-Id: I20e3bc7c32c3f654f88f6ef9cdfcb853f2d52f09
Reviewed-on: https://chromium-review.googlesource.com/1088308
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: David Reveman <reveman@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-06-07 16:52:39 -07:00
David Reveman
5f5e7ec3ba virtwl: better multi-plane DMABuf support
Multi-plane DMABufs are useful for efficient video playback. The
guest can already use this but has to guess the stride and offsets
for the second and third plane as they are not passed by virtwl
to the guest kernel.

This extracts the correct strides and offsets for each buffer and
passes them back to the guest in the allocation response message.

BUG=chromium:837209
TEST=sommelier can use nv12 buffers without guessing stride/offset

Change-Id: I36ae2fad6605293c907802121676296cbc607a57
Reviewed-on: https://chromium-review.googlesource.com/1070799
Commit-Ready: David Reveman <reveman@chromium.org>
Tested-by: David Reveman <reveman@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-26 10:19:50 -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
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
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
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
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
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
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
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
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
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
Stephen Barber
308ff60601 net_util: add tap support for mac address
Allow get/set for the host mac on the tap interface. Also add read accessors
for the host IP address and netmask, and make using IFF_VNET_HDR optional.

BUG=none
TEST=./build_test

Change-Id: I9999bf5aa8aa35b8cae702d9bc6f94602d6fe32e
Reviewed-on: https://chromium-review.googlesource.com/918406
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-21 01:06:42 -08:00
Dylan Reid
c3579e0c35 block: Put more info in Read and Write errors
Adding the size and offset of a read or write makes errors easier to
reproduce.

Change-Id: Ia1c07f831dc6fb6f08acb87a30459713d0f706c0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/907420
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-02-12 22:42:42 -08:00
Jason D. Clinton
865323d0ed hw/virtio/vhost: Add simple tests backed by fakes
This slightly advances the use of fakes to test higher level
application logic. The fakes are rudimentary at this point, but I
wanted to get feedback on the addition of generics in order to
facilitate swaping concrete implementations out with fakes in higher
level code.

BUG=none
TEST=./build_test and
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

Change-Id: Ib64581014391f49cff30ada10677bbbcd0088f20
Reviewed-on: https://chromium-review.googlesource.com/689740
Commit-Ready: Jason Clinton <jclinton@chromium.org>
Tested-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-02-02 16:32:12 -08:00
Sonny Rao
29cd40a1d6 crosvm: change GuestAddress to always be a u64
We want to be able to run 64-bit ARM kernels using a 32-bit version of
crosvm, to make it more consistent use a u64 to represent
GuestAddress.

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

Change-Id: I43bf993592caf46891e3e5e05258ab70b6bf3045
Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/896398
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-01 18:08:55 -08:00
Dylan Reid
7a084f4ab1 devices: virtio - Limit avail_iter iterations
Don't allow AvailIter to loop forever if there is malformed input.
Making sure that the queue has less than queue_len entries prevents
array out of bounds panics when fuzzing.

Change-Id: Ibceadff19a1026bf5d68e05008c48ce9c85c52a3
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/882618
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-01-31 03:36:24 -08:00
Mike Frysinger
e56e045b18 rng: switch to /dev/urandom
There's no need to provide direct access to /dev/random to all guests,
and we don't want them to be able to drain entropy from other VMs and
from the host itself.

BUG=chromium:800520
TEST=precq passes

Change-Id: I94ea0755123ee7479ca83c07525ca870d42c637f
Reviewed-on: https://chromium-review.googlesource.com/872890
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-01-18 17:40:52 -08:00
Dylan Reid
c2051921b5 devices: block: require traits not a file
Allow block to take anything that satisfies the traits it uses. This
will allow for different backends to be used in addition to normal
files. The first new backend will be qcow2 added in subsequent commits.

Change-Id: I571ffc8ad4b5d56f286e134f47a60261d639b160
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/862627
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-01-16 21:26:24 -08:00
Dylan Reid
295ccac1f3 devices: Add balloon
The balloon device is used to take regions of unused memory from the
guest and allow other host processes to use that memory.

Change-Id: I06c821365a58672d605fc7555beaec599cae1b15
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/759306
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-12-18 17:54:57 -08:00
Zach Reizner
4e7feeec3e wl: increase max FDs to send/recv
This change is to support a related kernel change but is backwards
compatible with kernels without that change.

BUG=chromium:782474
TEST=None

Change-Id: Ic1224b65ed9685f246002f946cfc6bfa2dbb2856
Reviewed-on: https://chromium-review.googlesource.com/770593
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-11-15 16:07:28 -08:00
Stephen Barber
ce374793bf crosvm/devices: set thread names
crosvm spawns a lot of processes/threads, and having these all use the same
name as the original process can be confusing. So at least in the instances
where Rust threads are spawned (vs. minijail_fork()), use a thread::Builder
to allow setting the thread name.

BUG=none
TEST=start crosvm, check thread names with top

Change-Id: I6e55ff5fd60f258880bda8e656ab7f9da82c656e
Reviewed-on: https://chromium-review.googlesource.com/742394
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-10-30 23:21:37 -07:00
Dylan Reid
b3bfbde1db Use minijail_fork
Using minijail_fork removes the need to manage user and pid namespace
explicitly in crosvm and removes some parent/child synchonization
requirements too.

Change-Id: I47f9d39527d0a3ccf625600e9bfc2cccc3cb27ca
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/719443
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-10-25 05:52:43 -07:00
Dylan Reid
d169a8d9ed Move crosvm/hw to a new devices module
Moving the devices to their own module makes it easier to add tests that
use them.

Change-Id: I61bfef4037d16b20145b5fddce604835cdc4f67b
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/706559
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-10-09 17:39:05 -07:00