summary refs log tree commit diff
path: root/devices
Commit message (Collapse)AuthorAge
* devices: virtio/gpu: support PCI shared mem capGurchetan Singh2020-01-25
| | | | | | | | | | | | | | 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>
* devices: virtio: block: keep disk allocated on resizeDaniel Verkamp2020-01-24
| | | | | | | | | | | | | | | | 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>
* devices: xhci: use get_bar_addr() to find BAR 0Daniel Verkamp2020-01-23
| | | | | | | | | | | | | | 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>
* Remove warning for VIRTIO_INPUT_CFG_UNSET.Noah Gold2020-01-21
| | | | | | | | | | | | | | | | 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>
* vhost: impl on_device_sandboxed for virtio deviceChuanxiao Dong2020-01-19
| | | | | | | | | | | | | | | | | 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>
* vhost: add cleanup_vqs to do some cleanup stuffChuanxiao Dong2020-01-19
| | | | | | | | | | | | | | | | | | | | 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>
* gpu_display: implement stub displayJason Macnak2020-01-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* virtio: resolve some new introduced clippy warningsChuanxiao Dong2020-01-10
| | | | | | | | | | | | BUG=None TEST=./bin/clippy TEST=cargo test -p devices Change-Id: Ic5183ef887a85bc14357fd29bc7ea70caded61a8 Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1988704 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: remove user_command from proxy deviceZach Reizner2020-01-09
| | | | | | | | | | | | | | | | | | The only device that used user_command was Serial. This change makes Serial device use a thread to read from its input instead of using user_command. BUG=chromium:1033787 TEST=./build_test run crosvm with stdio serial with and without sandbox Change-Id: Ia0f2ee83d94ad2fee3f1f4f89aa734b976e33507 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1966435 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Auto-Submit: Zach Reizner <zachr@chromium.org>
* devices: net: add control queue for enabling/disabling offloadsStephen Barber2020-01-08
| | | | | | | | | | | | | | | | | | | | | | Add a control queue for virtio_net, and implement the command to set available networking offloads. Set offloads initially when acking features from the guest. We previously set offloads on unconditionally. Add TUNSETOFFLOAD to the allowed ioctls for virtio_net. BUG=chromium:1031413 TEST=boot 5.4 guest, check vmtap offloads enabled with ethtool TEST=enable ip_forward in guest, check vmtap offloads disabled with ethtool Change-Id: I4129aa03419798906bd95cf65a6a4ab63069f50b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1968200 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: gpu: log hung-up displayGurchetan Singh2020-01-08
| | | | | | | | | | | | | | This could be useful for debugging feedback reports. BUG=chromium:1027379 TEST=compile Change-Id: I520dedb0d0639f27cd5c2f81b09271bc4a243850 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1986298 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* devices: virtio: wl: Support multiple socketsRyo Hashimoto2020-01-07
| | | | | | | | | | | | | | | | | | | Guest can specify which socket it wants to connect by passing a parameter to VIRTWL_IOCTL_NEW_CTX_NAMED. Even after this CL, only the unnamed wayland socket is used for composition. Additional sockets are used for IPC purpose (e.g. camera). BUG=b:146100044 TEST=Camera works Cq-Depend: chromium:1962108 Change-Id: Ibd8efbae1b2177cc0381d88d151643183c31b519 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963412 Tested-by: Ryo Hashimoto <hashimoto@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
* Vfio: Ignore vfio device's multifunction flagXiong Zhang2020-01-07
| | | | | | | | | | | | | | | | | | PciRoot doesn't support multifunciion which forward pci config r/w from function > 0 to function 0, so if the vfio device have multifunction flag, guest will find the existence of all the other functions, actually it is from the function 0. In order to fix these extra functions, this patch clear the multifunction flag, so guest won't probe the other functions. BUG=chromium:992270 TEST=pass through a device with multifunction into guest Change-Id: I395636411e0d7d2a3729de16e638d7f6b2dde552 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954221 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* Vfio: Add igd Opregion supportXiong Zhang2020-01-07
| | | | | | | | | | | | | | | | | | | | | | | | | | igd opregion is used by igd driver to get vbt info and exhange info between bios and driver, but it isn't a standard pci resource, host bios allocate, reserve its memory, and report the memory base address through cfg_register 0xFC on native. As crosvm doesn't have bios, it is hard to allocate and reserve opregion for guest. Here opregion is faked as mmio memory, and let crosvm allocate guest memory from mmio space, report its base to cfg_register 0xFC also. guest driver read cfg_register 0xFC to get opregion base address, then rw it throgh this address. Read is forwarded to vfio kernel and write is ignored. BUG=chromium:992270 TEST=crosvm --vfio /sys/devices/pci0000:00/0000:00:02.0, pass through host igd into linux guest, the physical local display lightup and show linux desktop. Change-Id: I1cc3618e99313fc1f88b96dcbc635f090b19340c Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1688689 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* gpu_display: add X11 input bindings.Noah Gold2020-01-03
| | | | | | | | | | | | | | | | Adds bindings to the X11 display window to capture keyboard & mouse input & send it to the guest via an EventDevice. Original implementation by zachr@chromium.org. BUG=chromium:1023975 TEST=None Change-Id: I33156a8ca0b8c610a2080e3b6891cca2a865734b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971121 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Noah Gold <nkgold@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* virtio: implement reset for balloon/rng/blk/netChuanxiao Dong2020-01-03
| | | | | | | | | | | | | | | | | | | | The reset method will be called when guest virtio driver is resetting the device. Currently the balloon/Rng/block/net virtio drivers will re-configure the virt queue during the reset so they required to be re-activated for using the new virt queue configurations. To support this, need these device models to return back the moved ownership of the important variables so that they can do the re-activate. BUG=chromium:1030609 TEST=Launch linux guest and follow the reproduce steps in BUG#1030609 to check if balloon/Rng/block/net driver still complain failure. Change-Id: I5b40fd303ea334484c590982e3e0874ea4e854ee Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971097 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* virtio: call virtio device reset method for resetChuanxiao Dong2020-01-03
| | | | | | | | | | | | | | | | | | | | | | | | It refers to the implementation of the Cloud-hypervisor commit: - vm-virtio: Reset underlying device on driver request If the driver triggers a reset by writing zero into the status register then reset the underlying device if supported. A device reset also requires resetting various aspects of the queue. The reset method of a virtio device might return false if it is failed to reset the device or it is not implemented. In this case, we don't reset the queues. Otherwise the queues will also be reset together with a successful device reset. BUG=chromium:1030609 TEST=cargo test -p devices Change-Id: Iad2be38149e423a79d8366dc72e570a1d6eb297c Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971096 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: fix warning about extra parensDylan Reid2019-12-23
| | | | | | | | | | | rust 1.40 has a new warning when there are extra parens, soRemove them. Change-Id: Ibb565cac41ba8d72879f4cb8b949f2be30e55167 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1978140 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* devices: gpu: remove hung display from PollEventsGurchetan Singh2019-12-20
| | | | | | | | | | | | | | | | | | | This display isn't typically used when the virt-wl device is available and it can lead to hung fds during plug/unplug with external displays and docks. BUG=chromium:1027379, chromium:1027447 TEST= Tested five times each on R79-12607.47.0 sarien: => without patch --> CPU usage goes to 100% after unplug => with patch --> CPU usages remains normal Change-Id: Iea57f05002acc661f36b180e9e88c37b1f1b9047 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1977100 Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* vfio: Disable igd stolen memoryXiong Zhang2019-12-17
| | | | | | | | | | | | | | | | igd stolen memory isn't a standard pci resource, so guest couldn't access it. Once guest i915 driver see its size is zero, i915 won't use it. Here sotlen memory's size register PciCfg 0x51 is forced to zero. BUG=chromium:992270 TEST=crosvm run --vfio=/sys/devices/pci0000:00/0000:00:02.0, pass through host igd into linux guest. The physical local display lightup and show linux desktop. Change-Id: I1a0a6edda5d92d32307ea8025ef96677ca62c125 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1688368 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* devices: virtio: add support for VIRTIO_PCI_CAP_SHARED_MEMORY_CFGDaniel Prilik2019-12-12
| | | | | | | | | | | | | | | | | Could be used by virtio-fs and virtio-gpu. (cherry picked from crrev.com/c/1493014) [took out PCI portions and modified commit message -- @gsingh] BUG=chromium:924405 TEST=build and run Change-Id: I47fd4482aa7c11e08bfb4f6c990221ae7a11a11d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963333 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>
* Makes gpu renderer flags configurable via command lineJason Macnak2019-12-11
| | | | | | | | | | | | BUG=b:134086390 TEST=built crosvm and booted cuttlefish locally with gpu Change-Id: I4d816ddb52a2eadd06088d204d95118289a3f587 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927873 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Jason Macnak <natsu@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jason Macnak <natsu@google.com>
* ac97: bus_master: Check pi_info before warm resetpaulhsia2019-12-11
| | | | | | | | | | | | | | | According to ac97 spec, warm reset is specified to no-op when the device is running. We should ignore it while the device is recording audio as well. BUG=chromium:1026538 TEST=Build Change-Id: I64be922149c90be9a7a8669ef6d56591e6de632b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1960058 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
* ac97: extract moving to next buffer into functionFletcher Woodruff2019-12-11
| | | | | | | | | | | | | | | | | | | Create a function move_to_next_buffer which handles incrementing civ and piv properly. Set the PICB register when that function is called, not when we read a guest buffer. BUG=chromium:968724 TEST=playback on-device Change-Id: Ib384efceeac4be0e056c20591d93fe32b7305db6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954207 Reviewed-by: Fletcher Woodruff <fletcherw@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* crosvm: move vec_with_array_field to data_modelGurchetan Singh2019-12-11
| | | | | | | | | | | | | | Move it to the newly created flexible array file. BUG=chromium:892806 TEST=compiles Change-Id: I6c423a885cec17e376b0da87a4adbd17c71ff6f0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1325510 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* utilize EventDevices to make virtio-input devicesZach Reizner2019-12-11
| | | | | | | | | | | | BUG=chromium:1023975 TEST=./build_test Change-Id: I10267e535d4d1dae90b2b5f30db046c388791a16 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930409 Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: block: add block_size option for disksDaniel Verkamp2019-12-10
| | | | | | | | | | | | | | | This allows overriding the default logical block size (512 bytes) with other values, such as 4096 for 4K block size disks. BUG=chromium:942700 TEST=crosvm run -r vm_rootfs,block_size=4096 vm_kernel TEST=verify block size with lsblk --output-all Change-Id: Ia6db05f369a76557a2afb8b48b5cc2b66cf84b01 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954220 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* crosvm: PIT: use full address and avoid conflictZhuocheng Ding2019-12-10
| | | | | | | | | | | | | | | | The PIT implementation has the assumption that addresses are I/O port numbers, so we should use full address mode. i8042 is also changed to full address mode to avoid the conflict on port 0x61. BUG=chromium:908689 TEST=None Change-Id: Ibbb851e3a46ac7fc71576990a1618196de92e33c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945794 Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: IOAPIC: ignore interrupt polarityZhuocheng Ding2019-12-10
| | | | | | | | | | | | | | | | Interrupt polarity is ignored by kvm since 3.15, and the irqfd interface does not support polarity. We should not consider polarity either. BUG=chromium:908689 TEST=Unit tests in file. Integration testing is blocked on rest of split-irqchip being implemented. Change-Id: Ibae23b81274f867bbf56009854611628dbb4c154 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945793 Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* Support configurable screen sizesJason Macnak2019-12-10
| | | | | | | | | | | | | | | | | | This change enables Cuttlefish to run with a user specified display size on top of virtio gpu accelerated graphics rendering. This change makes the width and height an argument/flag and adds the necessary plumbing to pass this width and height through the gpu backend. BUG=b:134086390 TEST=built crosvm and booted cuttlefish locally Change-Id: Idabf7ef083b2377e3ebf3b50dd0296f4bf7e8ddc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927872 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Jason Macnak <natsu@google.com>
* devices: fs: Support fs crypto ioctlsChirantan Ekbote2019-12-10
| | | | | | | | | | | | | | | | | | Add support for FS_IOC_{GET,SET}_ENCRYPTION_POLICY. Unfortunately, since the I/O direction is encoded backwards in the ioctl definitions, these will only work with on a kernel that's compiled with a patch to mark them as unrestricted FUSE ioctls. BUG=b:136127632 TEST=Compile and run the vfs_crypto.c program on a virtio-fs mount inside a VM Change-Id: I124c5a943111b453dd44921a079a2baa1036dfd4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1952570 Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* devices: clone the EventFds before activateChuanxiao Dong2019-12-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The interrupt_evt/interrupt_resample_evt/queue_evts were move to activate so the reset method has to return them back (although there is no virtio device implemented the reset method yet). Instead of move, another way is just clone these EventFds so that they don't need needed to be returned. The advantage of doing this can avoid changing every virtio device reset method (again, currently there is no virtio device implemented the reset method yet, but this method is going to used when needs to support the reset of a virtio device) for returning them, which can simplify the code. And reset method just needs to take care their own specific resources. The disadvantage is that, the clone of an EventFd is try_clone which might return error code (although this shouldn't happen). If in such case, the virtio device won't be activated. BUG=None TEST=launch crosvm guest with virtio devices(rng/balloon/blk/net). Change-Id: I6e55782c3ecc46bfa878aff24b85a58a7ed66365 Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925682 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* vfio: Implement bar mappableXiong Zhang2019-12-06
| | | | | | | | | | | | | | | | | | if device bar is mappable, map bar's gpa to hpa in EPT, guest vcpu could access this bar directly through EPT without trapping. This could improve performance. vm.add_mmio_memory could help do this, here vfio_pci send RegisterMmapMemory request through vm_control socket to do this. BUG=chromium:992270 TEST=none Change-Id: I3b4274372f7dcd32e18084d55f037b6fe45ed422 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581147 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* devices: use File rather than shm in testsDaniel Verkamp2019-12-06
| | | | | | | | | | | | | | | | | | | | | | | | | Two virtio descriptor_utils tests were using SharedMemory to stand in for I/o targets with a fixed size; replace these with File to avoid needing the FileReadWriteVolatile impl for SharedMemory, which isn't used anywhere else in the crosvm code base. This slightly changes the behavior under test in the reader_failing_io test, since it was previously using the SharedMemory seal functionality to make the region ungrowable; this is an unusual corner case, and (as mentioned in the comment that was previously at the end of the test) it is testing implementation details of write() on shared memory on Linux. Instead, just use a read-only file so that write() to it will fail and cause the same observable result. BUG=None TEST=./build_test.py Change-Id: I6d62cd70791f1dec625b750ecd01cc51e307f971 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1939783 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: enable MSI-X for all devicesDaniel Verkamp2019-12-06
| | | | | | | | | | | | | | | | | | All virtio devices can use the same generic calculation for number of MSI-X vectors required: number of queues plus one for configuration changes. Move this calculation to the VirtioPciDevice implementation and remove the Option to unconditionally enable MSI-X support for all PCI virtio devices. BUG=chromium:854765 TEST=Verify all virtio interrupts in /proc/interrupts are PCI-MSI Change-Id: I5905ab52840e7617b0b342ec6ca3f75dccd16e4d Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925169 Reviewed-by: Zide Chen <zide.chen@intel.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* ac97: combine PlaybackError and CaptureErrorFletcher Woodruff2019-12-04
| | | | | | | | | | | | | | PlaybackError and CaptureError encode the same error cases. Combine the two into one Error type, AudioError. BUG=None TEST=builds Change-Id: I44259227d67a0284c9a11c4aafd86fafe1006f8b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925727 Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
* disk: add get_len() to eliminate need for SeekDaniel Verkamp2019-11-27
| | | | | | | | | | | | | | | This new trait allows DiskFile implementors to provide the length of the file directly rather than using SeekFrom::End with seek(). BUG=None TEST=./build_test TEST=Boot Termina in crosvm Change-Id: I9447ebb43dbd5fbb32a3a6b6d2fc969b9406cdbc Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913961 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* disk: switch from WriteZeroes to WriteZeroesAtDaniel Verkamp2019-11-27
| | | | | | | | | | | | | | | | This eliminates an extra seek per guest write zeroes request. Additionally, it allows us to stop depending on the file cursor and pass the offset directly, making multi-queue implementation easier. BUG=chromium:858815 TEST=Boot Termina in crosvm Change-Id: I8b15a39752a1b68597a2b1e1fd72382a484a3cb2 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913521 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* devices: fs: Use 32-bit uid/gid values on armChirantan Ekbote2019-11-22
| | | | | | | | | | | | | | | | | | | | | The setres{u,g}id and the gete{u,g}id system calls on arm use 16 bit values for uid_t and gid_t. This causes the kernel to interpret a uid/gid of 65535 as -1, which means do nothing. Use the 32-bit variants of these system calls instead so that we can use 32-bit values. Normally, libc would take care of hiding these kinds of implementation details but since we can't use the libc wrappers for these system calls, we have to do it ourselves. BUG=b:136128319 TEST=`tast run vm.Virtiofs` on kevin Change-Id: I6c0fda42c131e059139000828b3a53d4a73f340c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1923569 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* devices: fs: Only resample interrupts on one threadChirantan Ekbote2019-11-22
| | | | | | | | | | | | | | | | | | | | | | | | Having more than one thread watch the interrupt resample event meant that the threads would race to acknowledge the event: if thread B called epoll_wait after thread A got a readable event for the resample eventfd but before thread A called `read()` on the eventfd, then thread B would also get a readable event for that eventfd. Both threads would then attempt to acknowledge the event but only one would succeed. This would leave the other thread blocked on the `read()` call until the resample event became readable again. Fix this by having only one worker watch the resample event. BUG=b:136128319 TEST=`tast run vm.Virtiofs` on kevin Change-Id: I5cd781a9c79ac718207a944433ea20a967735237 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1923568 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* ac97: bus_master: Sync SR_CELV with civ == lvipaulhsia2019-11-21
| | | | | | | | | | | | | | | | | | | | | From ac97 spec, SR_CELV should be synced with civ == lvi in bus_master. intel8x0 is not using the bit but some other driver or system might be using it. Remove checking if new_sr equals to old_sr since update_sr will do nothing if the input value equals to the old sr value. Add unit tests steps to test the expected results. BUG=chromium:1026538 TEST=Unit tests Change-Id: I3dc9f42e2beed8e635a65dbefba44677c73fcc5b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925917 Tested-by: Chih-Yang Hsia <paulhsia@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* ac97: bus_master: CR: Clean up reset registers optpaulhsia2019-11-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In bus_master control register (CR), reset registers (RR) operation is refactored by: - Don't call stop_audio(), since the bus master should always be in stop state while getting this control. (From AC'97 spec: Setting it when the Run bit is set will cause undefined consequences."). And the driver will always disable the audio first by setting 0 to CR_RPBM bit. - While doing the registers reset, clean up sr by using update_sr since assigning 0 to sr directly won't unset the interrupt bit in global status register and the driver might go into snd_intel8x0_update() with a stopped substream. - Introduce helper function - reset_func_regs() Add steps in unit tests which - Start the bus masters with "Interrupt on Completion Enable" (CR_IOCE) bit. - Verify if the interrupt bit in global status register is set / unset. BUG=chromium:1026538 TEST=Unit tests Change-Id: Ie90ca4c82cc3c867992ecaeb61ef4b3e9dd0d079 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925916 Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Tested-by: Chih-Yang Hsia <paulhsia@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* devices: block: add option to control sparsenessDaniel Verkamp2019-11-18
| | | | | | | | | | | | | | | | | | Extend the --disk option and other related options to allow a particular disk to have the sparse operations (virtio-blk's discard command) enabled or disabled. By default, the sparse flag will be enabled for virtio-blk devices, matching current behavior. BUG=chromium:858815 TEST=Run `crosvm with --rwdisk file.img,sparse=false` and try to discard Change-Id: Ib72c949711fbe869a3f444d7f929a80d0e039f72 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1906750 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* vfio: Don't exit at get_region_info failureXiong Zhang2019-11-18
| | | | | | | | | | | | | | | | At vfio device initialization, it will probe all the defined regions, most device don't have vga region, then when crosvm probe vga region info, kernel vfio will return -EINVAL. So when error happens, it should continue getting the next region info, instead of exit. BUG=None TEST=passthrough non graphic device into guest Change-Id: If4d2f723df45f58ccd733e03c854cdcef3530bdb Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1918486 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* Revert "devices: virtio: disable MSI-X for block and net"Daniel Verkamp2019-11-18
| | | | | | | | | | | | | | | | | Re-enable MSI-X for virtio-blk and virtio-net now that the underlying issue causing hangs at startup has been fixed (CL:1917495). BUG=chromium:1019986 TEST=Boot Termina on nami This reverts commit 85858f580eada8dd85c8c798ef3e98f18d92dc1e. Change-Id: I5a5e197243a16aee2b2aaf3145a1180749b097b2 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1918261 Reviewed-by: Zide Chen <zide.chen@intel.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: remove unused VirtioPciDevice functionsDaniel Verkamp2019-11-18
| | | | | | | | | | | | | | The queue_evts() and interrupt_evt() functions were public, but nothing was calling them. Remove them to clean up the unused code. BUG=None TEST=./build_test Change-Id: Id36e78343869746c733bba04383ab93c9d377601 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898270 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: virtio: use signal helper for config changesDaniel Verkamp2019-11-18
| | | | | | | | | | | | | | | | Add handling of the virtio device MSI-X configuration change vector by using the signal function that was previously factored out. BUG=chromium:854765 TEST=./build_test TEST=trigger disk config change with `crosvm disk resize ...` Change-Id: I462c23e10d152f896586bb70b95634a53088d480 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898269 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: virtio: pass Interrupt to activate()Daniel Verkamp2019-11-18
| | | | | | | | | | | | | | Factor out the common creation of struct Interrupt. No functional change. BUG=chromium:854765 TEST=./build_test Change-Id: Idf8804771ba1af5181818f643e15e1b42918258a Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898268 Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: block: refactor status_writer setupDaniel Verkamp2019-11-18
| | | | | | | | | | | | | | | | | | | | | | | This consolidates the status byte manipulation in process_one_request() instead of requiring both that function and execute_request() to deal with it. The tests are modified to run the full process_one_request() function instead of just execute_request() to exercise the full descriptor parsing logic, and they are adapted to read the status of the request from the status byte in the buffer from the descriptor since process_one_request() returns successfully as long as the descriptor parsing succeeded, even if the requested I/O failed. BUG=None TEST=./build_test Change-Id: I17affabc2d3c30c810643ce260152cf34893b772 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1918479 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: update the msix route table regardless msix mask statusChuanxiao Dong2019-11-18
| | | | | | | | | | | | | | | | | | | The msix entries might be changed by guest during msix maksed. The current implementation won't update the MSIX route table in this case which can cause KVM still inject the IRQ according to the old routing. To fix this, we should update the msix route regardless the msix mask status. BUG=chromium:1023692 TEST=cargo test -p devices Change-Id: Ifa356b3834ff454ecfca1dbdd97a7ca940d1f2b6 Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1911721 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Tested-by: kokoro <noreply+kokoro@google.com>