Commit graph

484 commits

Author SHA1 Message Date
Lingfeng Yang
22964eab88 gfxstream: fix build
API for export_resource changed

Bug: b/146066070
Change-Id: I614880704658bbe7aae2f7ad8b10c76555d99c1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2102760
Tested-by: Lingfeng Yang <lfy@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-03-26 02:52:58 +00:00
Chuanxiao Dong
45a94bedae vhost-net: implement direct msix irq fd
The current vhost-net msix irq injection flow is from vhost-kernel
to crosvm vhost-net, then to the KVM for irq injection. It still need
crosvm vhost-net to trigger irq, which is because the set_vring_call
is not directly using the msix irq fd.

To optimize this flow to be from vhost-kernel to KVM directly, need:
1. if the msix is enabled and unmasked, use the misx irq fd for the
vring_call directly so that all the misx injection can directly to
KVM from vhost-kernel.
2. if the msix is disabled or masked, use the indirect vhost_interrupt
fd to let the crosvm to control the irq injection.

BUG=None
TEST=cargo test -p devices
TEST=start crosvm with vhost-net, and run the iperf3 on the network
without any issue

Change-Id: Idb3427f69f23b728305ed63d88973156a03e7c6b
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2046452
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-03-25 17:41:42 +00:00
Chuanxiao Dong
57b8201eeb vhost: pass response_socket to activate thread
Pass the Option of the response socket should be used by the
activate thread, to communicate with its device model.

BUG=None
TEST=cargo test -p devices

Change-Id: I929f4c901468e920116f2a744ec73571d91080e3
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2046451
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-03-25 01:33:59 +00:00
Chuanxiao Dong
02f58e6d74 vhost-net: add control socket basic support
Add a pair of control socket for vhost net. This pair can be
used for the vhost-net device model to control and
communicate with its activate thread.

BUG=None
TEST=cargo test -p devices

Change-Id: I8bacdb9132787dc499ef00eea1df26ff3b35028d
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2046450
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-03-25 01:33:57 +00:00
Daniel Verkamp
0dcbfa1176 usb: avoid setting configuration when unnecessary
On devices with only one configuration, skip the code that attempts to
change the device's active configuration, since it must always be the
single available configuration.

This works around an issue observed with some USB devices (e.g. Servo
Micro) where the initial Get Configuration control request fails with
-EPIPE.

BUG=chromium:1061382
BUG=b:151408644
TEST=Attach servo micro, see /dev/ttyUSB[012], screen /dev/ttyUSB0

Change-Id: Ic3333e1d70a0c57b090de64e4d3b7932ce2cf81d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2108871
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: George Engelbrecht <engeg@google.com>
Commit-Queue: George Engelbrecht <engeg@google.com>
2020-03-24 11:29:57 +00:00
Gurchetan Singh
83fc5c49ba devices: gpu: complete resource V2 rebase
* Remove RESOURCE_V2_UNREF
* Add RESOURCE_MAP/RESOURCE_UNMAP to enable resources without guest
  storage that don't need to be mapped directly either

BUG=chromium:924405
TEST=compile and test

Change-Id: I10d6cd120d86131fa7ed8917ddad25cdb99ae50c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015587
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-03-23 20:37:12 +00:00
Gurchetan Singh
151af70ac9 devices: gpu: modify resource v2
Rebase of zero-copy virtio-gpu flow:

    * Removes guest_memory_type/guest_caching_type in favor of a bitmask
    * Removes ALLOCATION_METADATA, since ideally we'd just read from
      guest memory to get guest responses
    * Renames HOST_COHERENT to HOST_VISIBLE
    * Adds a few more feature flags

BUG=chromium:924405
TEST=compile

Change-Id: I0d5a84b66cfa6d09f7e2d07ed8e761e7ba850284
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2013767
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-03-23 20:37:11 +00:00
Judy Hsiao
d5c1e968c9 audio: Create AC97 device with --ac97 option
1. Replace --cras-audio, --cras-capture, null-audio options by --ac97
option to create audio devices.
2. "--ac97 backend=BACKEND\
[capture=true,capture_effect=EFFECT]" is comma
separated key=value pairs for setting up Ac97 devices.
It can be given more than once to create multiple devices. Possible
key values are:
backend=(null, cras) - Where to route the audio device.
`null` for /dev/null, and  cras for CRAS server.
capture=true - Enable audio capture.
capture_effects - | separated effects to be enabled
for recording. The only supported effect value now is EchoCancellation
or aec.

BUG=b:140866281
TEST=1.crosvm run -r ./vm_rootfs.img -c 4 -m 1024 -s /run --cid 5 --host_ip\
100.115.92.25 --netmask 255.255.255.252 --ac97\
backend=cras,capture=true,capture_effect=aec\
--mac d2:47:f7:c5:9e:53 ./vm_kernel
2. Record with the vm by:
arecord -D hw:0,0 -d5 -fS16_LE -c2 -r48000 /tmp/test.mp3
3. Verify that AEC is enabled within the recording stream by
cras_test_cleint.

Cq-Depend: chromium:2053654
Cq-Depend: chromium:2095644
Cq-Depend: chromium:2038221
Change-Id: Ia9e0e7cda1671a4842ec77a354efaa4a2dc745eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2038413
Tested-by: Judy Hsiao <judyhsiao@chromium.org>
Commit-Queue: Judy Hsiao <judyhsiao@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Auto-Submit: Judy Hsiao <judyhsiao@chromium.org>
2020-03-20 15:26:02 +00:00
Daniel Verkamp
e5113047d5 devices: virtio: add virtio-console device
This is a virtio device that provides a serial console.  It has
constructors matching the existing Serial device (new_in_out, new_out,
and new_sink) that take generic io::Read and io::Write streams.

This change just adds the device code; additional changes are required
to add the console device to the command-line parsing and device setup
code.

BUG=chromium:1059924
TEST=boot linux with console=hvc0

Change-Id: I917157d5ecb5160c9b00b499eabe6fb08486776c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2095534
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-03-19 19:47:10 +00:00
Chirantan Ekbote
5b2447ceaf devices: fs: Bump fuse minor version to 31
Add new definitions and constants to support fuse minor version 31.
These include the FUSE_SETUPMAPPING and FUSE_REMOVEMAPPING opcodes used
by the virtio-fs driver for implementing DAX support.

BUG=b:147341783
TEST=vm.Virtiofs

Change-Id: Ie59ec1a44e555910f2ee2c5ba7afccb8bd435db9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105823
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-19 08:13:32 +00:00
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