Commit graph

474 commits

Author SHA1 Message Date
Chirantan Ekbote
6dfa1e4ce5 devices: fs: Implement copy_file_range
BUG=none
TEST=vm.Virtiofs

Change-Id: I2ed7137a901e6e506e6b1562b77fdb042bdc58ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105822
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-19 08:13:31 +00:00
Chirantan Ekbote
93a9877057 devices: fs: Support FOPEN_CACHE_DIR
Add support for FOPEN_CACHE_DIR so that the guest can cache directory
entries for longer.

BUG=b:150264964
TEST=vm.Virtiofs

Change-Id: Iade67b54084ed72378afa70af9e9e0f7f0bc03e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105821
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-19 08:13:30 +00:00
Chirantan Ekbote
a07d84ad68 devices: fs: Add support for fuse minor version 28
BUG=b:150264964
TEST=vm.Virtiofs

Change-Id: I544329b63352956647d07aefdfce3118947d0821
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105820
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-19 08:13:29 +00:00
Dylan Reid
8476d79a3c Fix warnings added in rust 1.42
rustc now warns about return statements that have an extra set of
parenthesis. Remove such instances so that the code is warning free.

TEST=cargo build completes without warnings

Change-Id: I55148f8aceca8ba90f6bead2b6929e2c843351aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2104767
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-03-17 00:05:44 +00:00
Chirantan Ekbote
752f9c2870 devices: Ignore O_DIRECT in 9p and fs devices
Specifying O_DIRECT in the 9p device doesn't actually work correctly and
leads to an error.  O_DIRECT handling in the fs device works correctly
but also makes it look much worse in disk I/O benchmarks because the
block device gets the benefit of the host cache while the fs device
depends on the performance of the actual storage device.

BUG=none
TEST=`tast run vm.Fio.*`

Change-Id: I738e4032081e331ef956c9d4c33616607e403d86
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2093967
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-03-16 15:12:52 +00:00
Jorge E. Moreira
cba39f2fef Allow all serial port types to read from stdin
Bug=b/148677254

Change-Id: I1fa38bc95ca303c7a2c38dbe4b938a6042c910c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2093800
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
2020-03-11 20:52:10 +00:00
Chirantan Ekbote
265967bcda descriptor_utils: Add iter method
Add an `iter` method to the `Reader` struct so that callers can iterate
over the objects in place rather than having to store them in a separate
collection.

BUG=none
TEST=unit tests

Change-Id: I29671910a4244a8d7786ca2eb241416ae72b8c9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2093966
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-10 03:35:05 +00:00
Keiichi Watanabe
9515b05c08 devices: virtio: resource_bridge: Transfer plane metadata
Transfer plane offsets and strides for exported GPU resource over resource
bridge as well as a resource itself.
These metadata will be required by virtio-video decoder and encoder.

BUG=b:120456557
TEST=Start ARCVM on atlas

Change-Id: Iaf539857c0f8525bd5be294521e75ad32cae05e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1787032
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-03-06 13:27:50 +00:00
Mattias Nissler
3f3c0a3f6a ac97: Mark pci::ac97_bus_master::test::start_playback ignored
The test is flaky and causes continuous build failures.

BUG=chromium:1058881
TEST=Tests run, offending test is listed as ignored.

Exempt-From-Owner-Approval: Sheriff action to silence flakes on builders

Change-Id: I204e6ef548e6f203b0c15b0d01fde3b88660bd44
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2090414
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Commit-Queue: Mattias Nissler <mnissler@chromium.org>
Tested-by: Mattias Nissler <mnissler@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-03-06 10:58:08 +00:00
Xiong Zhang
aee33b5862 virtio: Add VIRTIO_RING_F_EVENT_IDX test case
VIRTIO_RING_F_EVENT_IDX use Wrapping(u16) for irq suppressing, this
test case to avoid some corner case for Wrapping.

BUG=None
TEST=Run build_test.py

Change-Id: I47d377056fefcc36739bb197e30319deafb0faf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2073902
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
2020-03-06 07:28:23 +00:00
Xiong Zhang
ea6cf66ab5 Vfio: multi vfio group support
current one container contains one group only, but one container could
contain multi groups actually. The main gap that current code to
support multi groups is that container will be initialized multi times
when multi groups exist, as each group will initialize container one time.

This patch extracts the code which should run one time only on a
container, so when the first group is added into container, this
container initialize code will run once. The container once initialize
code contains:
a. Set iommu driver type as VfioType1V2
b. Setup Iommu table on each guest memory region
c. create vfio_kvm device, so kernel kvm and vfio is associated.

BUG=chromium:992270
TEST=passthrough two/three vfio devices into guest, these devices belong
to different vfio groups, then check these devices function in guest.

Change-Id: I94c9c86f70f49957a5e5c1dfd2c7d823ad042320
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2078970
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
2020-03-06 01:50:11 +00:00
Noah Gold
dc7f52bdb7 Use simple virtio_input_events where possible.
Previously, all input events in CrosVM were required to be linux
input_events, which have a timestamp field that is actually unused by
when we send/receive from the guest which are of type
virtio_input_event. This CL allows CrosVM to understand both types of input
events in a first class manner. It is a follow up on
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930405.

This CL also addresses some bugs with window driven input:
1. attach_event_device was being called before the surface was
created, so the devices were never attached.
2. The default touchpad size was not being set to the display window
size.

Additionally, it removes the unused event "filter" feature on event
sources.

Breaking change: from this point forward, CrosVM will treat input events sent
via a socket (e.g. SocketEventSource) to be virtio_input_events.

BUG=None
TEST=builds + manual

Change-Id: I7fec07c582e5a071a6f116975ba70d6e621bb483
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034046
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-03-06 01:00:39 +00:00
Zhuocheng Ding
b9f4c9bca3 crosvm: Add plumbing for split-irqchip interrupts
Devices use irqfd to inject interrupts, we listen to them in the main
thread and activate userspace pic/ioapic accordingly.

BUG=chromium:908689
TEST=lanuch linux guest with `--split-irqchip` flag

Change-Id: If30d17ce7ec9e26dba782c89cc1b9b2ff897a70d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945798
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2020-03-05 13:12:23 +00:00
Xiong Zhang
2f7dabbd6a Virtio: Add blk VIRTIO_RING_F_EVENT_IDX feature
Previous interrupt suppress patch only supply crude interrupt suppress,
VIRTIO_RING_F_EVENT_IDX feature supply a more performant alternative:
1) where the driver specifies how far the device can progress before a
notification is required
2) where the device specifies how far the driver can progress before a
interrrupt is required.

This patch add this feature into blk.
For gpu and network, this could be added also, but gpu and network
performance don't get better.

BUG=None
TEST=run benchmark for blk in guest

Change-Id: I73fe3f8b72a9e88fd6073890bc6ab2bee891d51d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2008341
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
2020-03-05 09:03:33 +00:00
Zhuocheng Ding
db4c70d215 devices: PIC: implement interrupt injection
TODO: Route irqfd to PIC, and use signal to kick vCPU thread when
interrupt is triggered.

BUG=chromium:908689
TEST=Unit tests in file.

Change-Id: I9a87502da57e725d3bb26d746a337d0ba44ef337
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945797
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2020-03-05 01:02:49 +00:00
Zhuocheng Ding
f2e90bf0b0 Add logic to setup PIC/IOAPIC.
TODO: Route irqfd to PIC/IOAPIC to make them fully work.

BUG=chromium:908689
TEST=None

Change-Id: I301287b1cf32cfccffce6c52ebbb5e123931178e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945796
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2020-03-05 01:02:48 +00:00
Xiong Zhang
80fb0753b3 Virtio: Add queue ack_features() interface
Virtio spec define some features like VIRTIO_F_RING_INDIRECT_DESC,
VIRTIO_F_RING_EVENT_IDX, VIRTIO_F_RING_PACKED. If one feature is enabled
in guest, device's queue will have corresponding behavior for this
feature. Queue's ack_features() interface let queue know which features
is enabled in guest.

BUG=None
TEST=build_test

Change-Id: I865f93940a1f4db8ca6da8829136127353cc1c6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2008340
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-03-01 05:09:59 +00:00
Fletcher Woodruff
7eae7735ee ac97: switch to ShmStreamSource
Convert playback and capture for the AC97 device to use the zero-copy
ShmStreamSource instead of the old StreamSource.

In the process, rework start_playback and start_capture unit tests so
they rely less on sleep statements.

BUG=chromium:968724
BUG=chromium:1006035
TEST="sox -n -r 48000 -b 16 output.raw synth 5 sine 330 &&
     aplay -f dat output.raw" within a VM, check that sine wave is played
     accurately.

Change-Id: Ie9cddbc5285a9505872c9951a8a1da01de70eb88
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749950
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2020-02-28 01:07:56 +00:00
Chuanxiao Dong
020fbf04c2 x86_64: generate ACPI tables
Add acpi_rsdp_addr in boot_params to allow crosvm to pass
a physicall address of RSDP to the Linux guest kernel, so
that the linux guest kernel can parse the constructed ACPI
tables and enable the ACPI.

Although there is ACPI tables but as we still have "acpi=off"
in command line parameter, there is still no ACPI in guest kernel.

The ACPI construction refers to the implementation of the
Cloud-hypervisor commit:
- arch: x86_64: Generate basic ACPI tables

BUG=chromium:1018674
TEST=None

Change-Id: Ibcb2ae98c43da8ef8c07a07eda9213f61570d14c
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035351
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
2020-02-28 00:11:19 +00:00
Daniel Verkamp
7673338200 devices: block: let resize convert to non-sparse
Change the behavior of the resize operation on virtio-block devices so
that it causes a disk to become fully allocated (non-sparse) even if it
had previously been sparse.

This means that we could have a disk that was previously sparse and is
now non-sparse, so treat discard requests for sparse disks as a no-op
instead of an error.  This is acceptable since discard is a hint and
doing nothing is a valid implementation.

BUG=chromium:858815
TEST=`crosvm disk resize` a sparse disk

Change-Id: I8b79e460e5432cc71bed98172527fe1cd2e726ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2070846
Reviewed-by: David Munro <davidmunro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-27 22:22:26 +00:00
Daniel Verkamp
1f9c1bb88b devices: pci: add error handling for msix_enable
This more gracefully handles failure of msix_enable; in particular, if
it fails, the self.enabled state is returned to false so that future
device operations won't try to access uninitialized parts of
self.irq_vec.

In addition, the AddMsiRoute response is now checked (previously, it was
just ignored), and errors are bubbled up via MsixError rather than just
printing a message.

BUG=chromium:1041351
TEST=Boot Crostini on nami

Change-Id: I9999f149817bc9f49176487446b52e74fb8be9a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2067964
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-27 21:50:51 +00:00
Xiong Zhang
2647a1916d Vfio: Disable msix bar's mmap
If vfio device's bar is mmappable, vcpu could access it directly through
ept without trapping. But msix's table and pba exist on pci bar, they must
be trapped and emulated by crosvm, so these bars mmappable must be
disabled.

BUG=chromium:992270
TEST=pass through a device with msix cap to guest, then test device
function in guest.

Change-Id: If7504a924902c940e00cc759c1ca64a116bbca17
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987815
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-21 11:45:16 +00:00
Zhuocheng Ding
04b44e3df0 devices: IOAPIC: implement interrupt routing
This change implements MSI routing and injection, so that service_irq
can actually inject an interrupt into guest.

BUG=chromium:908689
TEST=Unit tests in file.

Change-Id: I2db4f00f569db56f5765c707faaa87c64fd3da9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945795
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2020-02-21 09:33:19 +00:00
Xiong Zhang
521646a401 Vfio: Emulate MSI-x
When VFIO device have msix capability, vfio kernel doesn't emulate msix,
so all the msix emulation are handled by crosvm. This include
msix capability register read/write, msix table read/write, msix pba
table read/write.

BUG=chromium:992270
TEST=passthrough a device with msix capabilty to guest, and check device
msix function in guest

Change-Id: Ic39737662a5051ac6b9e29aad227d3d4946190a8
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987814
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-20 06:42:13 +00:00
Xiong Zhang
de92ad05c7 Vfio: Enable multi vectors in irq_enable()
When msix is enabled, msix will have multi vectors, this patch enable
mutlti vectors in vfio_device.irq_enable() function.

BUG=chromium:992270
TEST=passthrough a device with msix capability to guest, and check
device msix function in guest

Change-Id: I5f8265e7badec8551ff9a974462f08425ee93ab2
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987813
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-19 19:31:56 +00:00
Xiong Zhang
9f7e38de57 Virtio: Add virtio block irq suppress
The flag in avail descriptor supplies irq suppress, it could reduce irq
injection from device, so many redundant interrupts could be removed
from guest, then improve guest performance.

BUG=None
TEST=run fio read and fio write in guest

Change-Id: I68789d8ca24d0e84d0b446db65057f4da2fac56f
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2008339
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-19 17:31:39 +00:00
Chuanxiao Dong
546f01cb96 acpipm: implement suspend and resume mechanism
For suspend request from VM, will write suspend event and notify
crosvm main process to pause VCPUs.

For resume request, it is not from VM itself but by the resume
command through crosvm socket. Resume request will notify the PM
device to fill its wakeup registers with wakeup event so that
when VCPUs start to run, VM can know there is wakeup from outside.

BUG=chromium:1018674
TEST=cargo test -p devices

Change-Id: I4724ffee10150065a62bf520076c16cbc70b7749
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035169
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2020-02-19 10:38:04 +00:00
Charles William Dick
80a8d52fac devices: virtio: Implement Reader::collect() and Writer::consume()
Adds a method Reader::collect() to read a collection of DataInit types,
and a method Writer::consume() to write a collection of DataInit types.

BUG=b:147334004
TEST=cargo test -p devices

Change-Id: Ib5947d30b44b74dc6cf0474e5b87778aad6f08a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2061516
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-02-19 10:25:23 +00:00
Lingfeng Yang
ddbe8b7e8e virtio-gpu: gfxstream backend
Adds a new backend type, gfxstream, that calls out to a C library
implementing the actual rendering.

The purpose is to allow the Cuttlefish and Android Studio Emulator teams
to use crosvm with the current API-forwarding style of rendering
employed in the Android Studio Emulator.

Also, introduces a new key to the --gpu command line interface,
backend=, which selects from different backends. Note that the previous
behavior is now deprecated and will be removed after some time
(when all clients switch over to backend=).

The gfxstream backend itself implements a subset of 3d-related resource
and context creation/transfer/execbuffer commands. Their meaning is
specific to the way in which they are interpreted in the backend
library.

To interface with display, gfx stream backend takes a callback that is
run on guest vsync. The callback is responsible for repainting the
display's contents. gfx stream provides a callback, get_pixels, that can
be used asynchronously. The asyncness is not taken advantage of
currently but will be useful for cases where the client attached to the
VMM might want to update at a different rate than guest vsync.

The guts of the stream backend library is currently defined here:

https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/android-qemu2-glue/emulation/virtio-goldfish-pipe.cpp

The linking of the library is controlled via the feature "gfxstream".
If the feature is turned off, we use a default do-nothing stub impl.

Next steps:
- integrate virtio-gpu-next so as to have host coherent memory for
vulkan
- Figure out low latency command submit/response with SUBMIT_CMD_3DV2

BUG=b:146066070

Change-Id: If647381c15e5459cec85e2325f97e2f0a963b083
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2033305
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Lingfeng Yang <lfy@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-02-19 06:18:37 +00:00
Xiong Zhang
79f10170da virtio: Inject virtio-blk interrupt quickly
Current blk interrupt is injected into guest after device handle a
batch of requests. While this patch injects interrupt at the end of each
request. So guest block will get much more interrupts and could handle
request more quickly.

With this patch, the guest fio read test improves 13%, while fio write
doesn't get better.

BUG=none
TEST=run fio_read and fio_write in guest

Change-Id: Ib0bd23e624dfc5d940d6cc124468b898d8ba128e
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2008338
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-19 06:09:41 +00:00
Chuanxiao Dong
ed6c972994 devices: add acpi device emulation code in devices
Add ACPI PM resource emulation code in devices, so that it can support
the ACPI PM requestion from guest OS.

BUG=chromium:1018674
TEST=cargo test -p devices

Change-Id: I7b82b1c3a6f609136e493b55420b947afd1d5cfc
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035168
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2020-02-17 04:57:26 +00:00
Keiichi Watanabe
7c43b32a36 crosvm: virtio: Use larger IDs for crosvm-specific devices
Stop using 30 and 31 as device IDs of virtio-wl and
virtio-tpm, as these numbers were reserved for virtio-video devices
in the upstream [1].

Instead, use integers from 63, which is the largest
number we can use for a virtio device ID.

Note that this CL must be merged after kernels with CL:2024135 landed.

[1]: https://github.com/oasis-tcs/virtio-spec/issues/67

BUG=chromium:1031512
TEST=Check if /dev/wl0 exists on ARCVM with CL:2024135

Change-Id: I267c7702d3c28642492f560170a0d1d9d6523c31
Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2025127
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Fergus Dall <sidereal@google.com>
2020-02-15 09:18:09 +00:00
Kaiyi Li
bccb4ebb85 Use display size as the default size for single touch
When the user specifies the display size through the gpu argument but
not specifies the size of the single touch device, the display size
will be used as the size of these touch devices.

Use default() to initialize the GpuParameters. Allow initialize the
GpuParameters dynamically in the future.

Change-Id: I9fa04f8ff479732370514fbaeb062d737adba319
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2043072
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-02-12 19:01:12 +00:00
Xiong Zhang
c13648b444 Vfio: Create Msix capability for vfio device
Loop vfio device config register, then find out the msi and msix
pci capability.

both msi and msix need IrqRequestSocket for adding its routing info
into kvm routing table, but vfio device has one IrqRequestSocket only,
and only msi or msix is enabled at runtime, so Arc is used to let msi
and msix share one device IrqRequestSocket.

BUG=chromium:992270
TEST=pass a device with msix capability to guest, and check device msix
function in guest

Change-Id: I008ccd0e98507dc4d587418fbe00aa23029bdbad
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987812
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-12 14:16:39 +00:00
Xiong Zhang
5c51e05282 Virtio: Add fence(Acquire) after avail_index read
Driver use virtio_wmb() before avail_index updating, here fence() is
compared with it, this guarantee that the descriptor_index is read after
avail_index.

BUG=none
TEST=run fio_read and fio_write in guest

Change-Id: I6a5e1bc7c915effd433b05aca246302c5a3e313c
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035079
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-07 15:27:25 +00:00
Chuanxiao Dong
c65a406abd vhost-net: implement the reset method
Vhost-net reset method can stop the activate thread and let it to
return the ownership of eventfds and tap back to the device, so that
it is possible to be activated again.

BUG=None
TEST=launch Crosvm guest with vhost-net. It works fine with iperf test.
TEST=cargo test -p devices

Change-Id: I8f3cb6939595b4dffa0e95bcffbf9fcc8fcf71ba
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009665
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-06 14:34:57 +00:00
Chuanxiao Dong
fab42c86ed virtio-input: implement the reset method
the event_source needs to be returned through the reset method to allow
the virtio-input device model reactivated again.

BUG=None
TEST=cargo test -p devices

Change-Id: I07a4add40b1c233e1ed328ccef1a1abd453ea0f7
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2032351
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-06 12:31:56 +00:00
Chuanxiao Dong
3eb7927bcd vhost: put kill eventfd to Worker
worker.run might encounter error when running but we still need it
to give the ownerships of the kill eventfd back so that it
can have a second round activate. And Worker structure also contains
several other eventfds which will be needed for a second round activate
so change to put this eventfd into Worker as well.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them work fine.
TEST=cargo test -p devices

Change-Id: I34477cfa3de23d7ab849f741d0ffb098c720a629
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009664
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
2020-02-06 03:25:33 +00:00
Daniel Verkamp
f054de59b3 devices: pci: fix writable_bits for 64-bit BARs
The high 32 bits of writable_bits was set incorrectly when adding 64-bit
memory BARs to PciConfiguration: it would effectively always be all
zeroes (no writable bits) instead of all ones (all writable bits).

The writable_bits field is used to determine which bits to force to 0
when reading the BAR, which is used by the guest to determine the size
of a BAR: write an all-ones value to the BAR, read it back, and the
resulting value has only the writable bits still set.  Since PCI BARs
must be a power of two in size, the effective size of the BAR is the
bitwise inverse of the resulting value plus one.

For 64-bit BARs, this process is the same, except that two contiguous
32-bit registers are combined, so for a 4096-byte 64-bit BAR, the
writable_bits field should be 0xFFFFFFFF_FFFFF000; however, with the
previous (buggy) code, it was 0x00000000_FFFFF000.

Add checks to the unit tests to verify that the writable_bits field is
correctly calculated as well.

BUG=None
TEST=cargo test -p devices pci_configuration
TEST=Boot Linux 4.19 kernel in crosvm

Change-Id: Ib97aa5dccf9bf042328c0fc9defe1797fc67bb05
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2033620
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-05 09:18:36 +00:00
Daniel Verkamp
df2bfe30f3 devices: xhci: support TRB Immediate Data bit
Transfer TRBs have a flag that indicates that data is transferred within
the TRB itself instead of as a separate buffer.  Add support for this
type of transfer in the ScatterGatherBuffer implementation.

This fixes USB support when using Linux 5.1+ as the guest kernel, since
it now uses immediate data transfers.

BUG=chromium:1046564
TEST=`adb root` to connected phone on Linux 5.4 guest kernel

Change-Id: I6c37db422ac8e65d10e1a91807b15e903ad614de
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2026262
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-03 18:12:01 +00:00
Keiichi Watanabe
392b73cdbc devices: virtio: Add a function to get a FD via resource_bridge
Add a function to get a resource FD via resource_bridge by extracting code from
the wayland device implementation.
This function will be used by virtio-video devices.

BUG=b:147465619
TEST=Run ARCVM and check that a window is displayed

Change-Id: I7b064c9a04bd082e30dd488d0b14731228e6047d
Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2014520
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-02-03 12:33:52 +00:00
Jason Macnak
327fc2454c virtio-gpu: implement 2D GPU Backend
... which does not require virglrenderer (or any renderer).

This will allow the Cuttlefish team to use minigbm as its gralloc
implementation when both hardware acceleration is available and
unavailable.

Adds a GPU `Backend` trait with all of the existing methods of the
current backend and converts the existing `Backend` into
`Virtio3DBackend` which implements the new trait.

Adds a `Virtio2DBackend` which creates resources with byte vectors on
the host and implements transfers via the old code from
gpu_buffer/src/lib.rs.

Adds a runtime flag to select between 2D and 3D mode with 3D mode as
the default.

Moves the process_resource_bridge() function to the `Frontend` and
instead expose a export_resource() function on the `Backend` to avoid
some code duplication.

BUG=b:123764798
TEST=build + launch cuttlefish w/ 2D mode (minigbm + custom hwcomposer)
TEST=built + launch cuttlefish w/ 2D mode (minigbm + drm_hwcomposer)
TEST=built + launch cuttlefish w/ 3D mode (minigbm + drm_hwcomposer)

Change-Id: Ie5b7a6f80f7e0da72a910644ba42d2f34b246be8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1993913
Commit-Queue: Jason Macnak <natsu@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Lingfeng Yang <lfy@google.com>
2020-02-03 11:14:22 +00:00
Chuanxiao Dong
bc499ec278 vhost-net: set backend to null when activate fn quit
Set the backend with null fd can reset the vq in vhost, which
can allow the activate fn to run again.

BUG=None
TEST=launch Crosvm guest with vhost-net. It works fine with iperf test.
TEST=cargo test -p devices

Change-Id: Ida952409147fd6fbd1d8f69b3a88a7ef03051d65
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009523
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-03 09:47:41 +00:00
Gurchetan Singh
8b8c01e1ad devices: virtio/gpu: support PCI shared mem cap
The plan is to use shared mem cap for virtio-gpu.

BUG=chromium:924405
TEST=build

Change-Id: Id2829c2cd9883aca19641eff625c65a8db335e7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963334
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-01-25 02:28:10 +00:00
Daniel Verkamp
3c62aac88f devices: virtio: block: keep disk allocated on resize
When a non-sparse disk is resized, we should allocate storage for the
newly-expanded space when the disk is grown to maintain the
non-sparseness.  To accomplish this, add a call to allocate in the
resize function in the block device.

BUG=chromium:858815
TEST=`crosvm disk resize ...` and verify disk image is fully allocated

Change-Id: If263aa2b5c9da11b8bfc0586e4ac1575f2bd7084
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015829
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-01-24 20:22:49 +00:00
Daniel Verkamp
e43d300aef devices: xhci: use get_bar_addr() to find BAR 0
Don't store the BAR value, as it can potentially be updated by the
guest. (This is not supported by our PCI device model just yet, but this
is still the correct thing to do and matches other crosvm PCI devices.)

BUG=None
TEST=Add USB device on nami

Change-Id: Ie42d08429e7ff124178c818877b4cee83003d66f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1924782
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-01-23 20:11:06 +00:00
Noah Gold
90878fb30e Remove warning for VIRTIO_INPUT_CFG_UNSET.
As indicated in the comments, it seems that this warning is unnecessary.
We've added explicit handling for the UNSET case, and left the warning
intact to handle any out of range values.

BUG=chromium:1041054
TEST=builds.

Change-Id: I2d41159f2d4ccbb4d75d2a8f4bab54586ec65442
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1995308
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Auto-Submit: Noah Gold <nkgold@google.com>
2020-01-21 17:16:59 +00:00
Chuanxiao Dong
1375c284b7 vhost: impl on_device_sandboxed for virtio device
vhost set_owner fn only needs to be called once. Put it in activate
fn will block the vhost devices to be activated again in future.
on_device_sandboxed is a good place to put the set_owner as it only
run once. So put it there.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them can work
TEST=cargo test -p devices

Change-Id: I45308e26b026c9141e4426d8b1bbe1944612a915
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954173
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-19 09:24:42 +00:00
Chuanxiao Dong
92ee1489ce vhost: add cleanup_vqs to do some cleanup stuff
Activate_vqs is used to do the queue preparation before really
running. The virtio-vhost device might need to do some cleanup
to allow a second round activate in the future. How to do the
cleanup is depending on how the vhost virtio devices.

Just add an interface called cleanup_vqs to allow the vhost virtio
devices to do their own cleanup stuff.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them can work
TEST=cargo test -p devices

Change-Id: I2472e79a8b63c9336f886cde55ffef6a78008ad8
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954172
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-19 09:24:40 +00:00
Jason Macnak
60eb1fbe89 gpu_display: implement stub display
Adds a stub display that emulates a display without actually
displaying contents anywhere.

This is needed for transitioning Cuttlefish to always using minigbm
as its gralloc implementation. Cuttlefish currently uses a custom
gralloc and hwcomposer implementation when running without hardware
acceleration. The Cuttlefish team would like to start with removing
our custom gralloc implementation and use minigbm. For this, we need
to add a virtio 2D backend to crosvm. Our hwcomposer implementation
currenlly sends framebuffers from the guest to the host via sockets.
The gpu backend still requires a display so we need a stub display
to use with the 2D backend for the period of time while we are
either still using our hwcomposer implementation or until our
hwcomposer implementation is updated to use the virtio backend for
display.

BUG=b:123764798
BUG=chromium:1033787
TEST=built and launched with Cuttlefish locally

Change-Id: I1a7e259d914a53252200c59589c4142e76c6b96b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1993947
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2020-01-14 00:31:00 +00:00