Commit graph

343 commits

Author SHA1 Message Date
Zach Reizner
20d71f8928 gpu_display: provides wayland based output for virtio-gpu
This provides virtual display style output, useful for debugging
virtio-gpu. Although using virtio-gpu for display purposes clashes with
the more integreated virtio-wayland support, it is nonetheless helpful
for debugging virtio-gpu, and is technically required to fully implement
that device.

TEST=cargo build -p gpu_display
BUG=chromium:837073
CQ-DEPEND=CL:1096300

Change-Id: I59f895e951ef593d4119e7558168dd34223519ee
Reviewed-on: https://chromium-review.googlesource.com/1043446
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-09 15:48:21 -07:00
Slava Malyugin
ac5a8dbe50 x86_64: fill cache info in cpuid, stop spoofing CPU vendor id
The fix passes through cache-related CPU entries 2, 4, 0x80000005
and 0x80000006 similar to how QEMU does it.

Note passing this cpuid info itself is not sufficient unless
CPU vendor is something Linux kernel recognizes. Therefore, I am
removing cute spoofing of the vendor id, allowing host value to
pass through.

I believe it is generally a bad idea to spoof vendor id as lots of
kernel and user space code gets confused and may take unoptimized paths.
The corollary is that removing the spoofing may have unintended
consequences correctness- and performance-wise. I would appreciate
recommendation on additional testing.

BUG=chromium:859678
TEST=lscpu in Guest, 'cargo test'

Change-Id: I6963b00d9eecf49fb4578bcc75ad744c3099f045
Reviewed-on: https://chromium-review.googlesource.com/1125529
Commit-Ready: Slava Malyugin <slavamn@chromium.org>
Tested-by: Slava Malyugin <slavamn@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-07-09 12:42:42 -07:00
Dylan Reid
ef7352f208 Remove the device manager and use the new resource allocator
Allow IRQs to be assigned before creating device manager.

For PCI, we need to add devices with interrupts before MMIO setup. Add
the ability to tell the architecture device manager about IRQs that we
have stolen.

There was only one function in device_manager and all of its state is
now delegated to the resource allocator, remove it.

Change-Id: I9afa0e3081a20cb024551ef18ae34fe76a1ef39d
Reviewed-on: https://chromium-review.googlesource.com/1089720
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-06-29 17:50:17 -07:00
Dylan Reid
473ae270d0 resources: Add system resource allocator
Start a system resource allocator that will be able to manage the
resources specific to each architecture.

Change-Id: I98cf35c280fefd7b0000801eb7405a236373b753
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1089719
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-06-29 01:08:56 -07:00
Dylan Reid
dea77cef92 resources: Add address allocation helper
Add the AddressAllocator module that will be used by both architectures
to manage distributing address ranges to devices. This will make the
addition of PCI devices easier as now both MMIO and PCI will need to
share address space. Add this to a new resources crate.

Change-Id: I6a971dd795f2118bd6cfec7dc34a65b0d4a32f9b
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1072570
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-06-29 01:08:55 -07:00
Chirantan Ekbote
d678784ae1 p9: Fix file and directory creation mode
Don't allow clients to create files and directories that are writable by
anyone other than the user.  This is equivalent to having a umask of
022.

BUG=chromium:703939
TEST=change the umask in the container, mkdir, and see that it has 0755

Change-Id: I0622fcd89935512969bcd25a9b1fece1e72e1f38
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1112869
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-06-27 22:07:22 -07:00
Chirantan Ekbote
f2fb37e669 p9: Fix unsafe block in read function
We calculate the size of the buffer to allocate for a read message by
finding the minimum of the requested size and the number of bytes left
in the response message buffer.

However, we then turned around and used an unsafe block to set the
length of the allocated buffer to the requested size rather than the
calculated size.  This could lead to memory corruption if the file we
were trying to read had enough bytes to fill up the whole buffer and the
requested size was larger than the max message size.

Replace both unsafe blocks with a resize function instead.  The
compiler is smart enough to turn this into a memset and
zero-initializing a few KB of memory is not that expensive.

BUG=chromium:703939
TEST=none

Change-Id: Ia9911d4176322bc9af0753541bd29d7a4723503b
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1110479
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-06-21 19:56:34 -07:00
Zach Reizner
298b41cf82 sys_util: move round_to_page_size to sys_util
This function will be used elsewhere in gpu_display.

TEST=None
BUG=None

Change-Id: I58b820511ea5a55a53ad640fdfe7c96d2dbdc73b
Reviewed-on: https://chromium-review.googlesource.com/1105481
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-06-21 16:31:43 -07:00
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
b657603f10 p9: Add server implementation
Implement all the server methods for the 9P protocol.

BUG=chromium:703939
TEST=bonnie++ -r 256

Change-Id: I6b1b5fe4fea4d4941db42e5c1a364a54d0827054
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1013203
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-06-15 10:56:39 -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
Sonny Rao
72fa671f6c virtwl: exclude "pvr" drm devices for mediatek systems
On Mediatek systems like hana we see there's are three drm renderer
devices including vgem, pvr, and mediatek.  We should exclude the pvr
device along with the vgem device for crosvm usage.

BUG=none
TEST=manual test on hana
TEST=build_test passes on all architectures

Change-Id: I834c231a08a7193bd358b3543ed0ed81a6d8bd84
Reviewed-on: https://chromium-review.googlesource.com/1087250
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: David Reveman <reveman@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-06-14 05:38:36 -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
Sonny Rao
90c50419d4 crosvm: aarch64: whitelist gettimeofday for error messages
It looks like on ARM we use the real gettimeofday system call when
we're outputting error messages, so we need to whitelist this to avoid
crashing instead of seeing the error messages.

BUG=chromium:843807
TEST=run vm_CrosVmStart and make sure there are no crashes for crosvm

Change-Id: I9f47da8dabe31f0677bcaa1d431e56545e20c9c9
Reviewed-on: https://chromium-review.googlesource.com/1081390
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-06-01 17:44:30 -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
Chirantan Ekbote
8608eb044b Update libc version to 0.2.40
The p9 crate needs the libc::DT_UNKNOWN constant, which isn't available
in version 0.2.34 but is available in version 0.2.40.

BUG=chromium:703939
TEST=none
CQ-DEPEND=CL:1065064

Change-Id: If1451d5bcc2737abc2a14d2b81005c6318165e1f
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1013202
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-05-23 01:25:36 -07:00
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