summary refs log tree commit diff
path: root/devices/src
Commit message (Collapse)AuthorAge
...
* 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>
* devices: pci: make get_bar_addr work for all BAR typesDaniel Verkamp2019-11-17
| | | | | | | | | | | | | | | Previously, PciConfiguration::get_bar_addr would only correctly return the value of a 32-bit memory region; implement support for the other valid BAR types as well. BUG=None TEST=cargo test -p devices Change-Id: I221187dfb96b31d7fead73eccf605a0886021d8b Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1880164 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* devices: virtio: add missing virtio type IDsZach Reizner2019-11-16
| | | | | | | | | | | | | TEST=./build_test BUG=None Change-Id: I52dd8ca64287a93eb89c045cb0418aefc9e9ba23 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1912777 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Auto-Submit: Zach Reizner <zachr@chromium.org>
* devices: net: remove rx_buf from receive pathStephen Barber2019-11-16
| | | | | | | | | | | | | | | Performance-wise this about breaks even, but greatly simplifies the virtio-net handling for processing received frames. BUG=chromium:753630 TEST=crostini.NetworkPerf Change-Id: Ie7b576020ecfe2a6cc41b7f72bd7143795a9a457 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1906996 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* devices: fs: Allow running as users other than rootChirantan Ekbote2019-11-12
| | | | | | | | | | | | | | | | | Don't assume the file system is running as the root user when changing credentials. Instead keep track of the thread euid/egid and use those when restoring thread credentials. BUG=b:136128319 TEST=`tast run vm.VirtioFs` Change-Id: I37d59def99cd71de68aa7f94941031a86df54329 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1890584 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* devices: virtio: ensure all block data is transferredDaniel Verkamp2019-11-11
| | | | | | | | | | | | | | | | | | Add _exact/_all variants of the FileReadWriteAtVolatile functions on descriptor Reader/Writer, and use them in the block device to replace the short read/short write error cases. This ensures all data is read/written even if the underlying implementation (in particular, qcow2) does not transfer the full amount of data in one read_vectored_at_volatile/write_vectored_at_volatile call. BUG=chromium:1023422 TEST=`mkfs.btrfs /dev/vdb` with a qcow2 disk Change-Id: Ia37a333947f6f63faf3d4a06cfcc297309d5aff6 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1907443 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* Vfio: Suitably allocate bar for vfio deviceXiong Zhang2019-11-11
| | | | | | | | | | | | | Use 64bit flag in vfio device's bar to get correct mmio allocator. BUG=chromium:992270 TEST=none Change-Id: I8f3dab48eb6dc0b92071803aa3526cadda8034c7 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581143 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* resource: Rename device memory to mmioXiong Zhang2019-11-10
| | | | | | | | | | | | | | Since unified allocator is used to allocate mmio, this patch remove the device memory name, and rename device to mmio. BUG=chromium:992270 TEST=this patch doesn't change function, run build_test Change-Id: I234b0db4b3c5de8cfee372ace5212a980564d0c7 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895234 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* Resource: Unify mmio allocatorXiong Zhang2019-11-10
| | | | | | | | | | | | | | | | | | | | | | | | | | Current mmio and device two allocators exist, the purpose to define two allocator is: Accessing to gpa from mmio allocator cause vm exit, while gpa from device allocator doesn't cause vm exit. Whether vm exits exist or not, dependency on whether vm->add_device_memory() is called with gpa from allocator or not.Even if gpa is from mmio alloator, and vm->add_device_memory() is called with this gpa, accessing this gpa won't cause vm exit. So mmio allocator and device allocator couldn't guarantee the original purpose. This patch unify mmio allocator and device allocator into one mmio allocator. BUG=chromium:992270 TEST=this patch doesn't change function, so just run build_test Change-Id: If87d5c2838eb122ef627fa45c394b1b3ccfafeb0 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895233 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* devices: virtio: add peek operation to queueDaniel Verkamp2019-11-09
| | | | | | | | | | | | | | | | This allows the caller to grab a buffer without committing to using it, which can be used in the case where two resources (a virtio buffer plus some other resource) need to be acquired simultaneously. BUG=None TEST=build_test.py Change-Id: Icb61de99db807648ff02c41f95b3128ecce41501 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1904638 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* devices: virtio: wl: use descriptor reader/writerDaniel Verkamp2019-11-08
| | | | | | | | | | | | | | | | Convert the virtio wayland device to use the descriptor_util Reader/Writer helpers to simplify the code and allow support of arbitrary descriptor layouts. BUG=chromium:966258 TEST=./build_test.py Change-Id: Ic854b76d378be261db4f21cba475bd0abc4af80e Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1815418 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* Remove unneeded return statementsDaniel Verkamp2019-11-08
| | | | | | | | | | | BUG=None TEST=bin/clippy Change-Id: I2cf3b961baefd21fedaa6b545c1c7ecfb25a9efc Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896088 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: block: advertise seg_maxDaniel Verkamp2019-11-08
| | | | | | | | | | | | | | | | | | | | | | The virtio-blk configuration space has a `seg_max` field that lets the device inform the driver of the maximum number of segments allowed within a single request. The Linux virtio block driver assumes that if the corresponding feature (VIRTIO_BLK_F_SEG_MAX) is not advertised, then only one segment can be used. Add a segment limit based on sysconf(_SC_IOV_MAX) to allow the Linux block stack to make use of multiple segments in a single request, which will get translated into a single readv/writev call in the crosvm block device. BUG=None TEST=strace crosvm virtio-blk process and note preadv with iov_cnt > 1 Change-Id: Ia14ebebb85daa21e2d43437bb74886f32e6e8187 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1876806 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: fs: Disable HANDLE_KILLPRIV when writeback caching is enabledChirantan Ekbote2019-11-08
| | | | | | | | | | | | | | | | | | | | | | | The HANDLE_KILLPRIV feature tells the kernel that the file system will take care of clearing the setuid and setgid bits when a file is written to by someone other than the owner. However, this doesn't work when writeback caching is enabled as the write may be buffered and flushed later, which would prevent the bits from being cleared on write. Remove the HANDLE_KILLPRIV feature when writeback caching is enabled. BUG=b:136128319 TEST=`tast run vm.VirtioFs` Change-Id: Icef98e878603cc428f83db37857d69bc6da4486c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1890582 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* fuzz: Add virtio-fs server fuzzerChirantan Ekbote2019-11-08
| | | | | | | | | | | | | | | | Add a fuzzer for the virtio-fs server, which is responsible for decoding a byte stream into FUSE messages. BUG=none TEST=run it with cros_fuzz Change-Id: Ic7695f2106d3f81e6cf09b98ffedc51831238f1e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865272 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* Remove duplicated semicolonsDaniel Verkamp2019-11-08
| | | | | | | | | | | | | This will be checked by Rust 1.39.0's rustfmt. BUG=None TEST=bin/fmt --check Change-Id: I8f037207af39f7de1c346365259a10dbe044450b Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1904162 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: proxy: print failed command on errorDaniel Verkamp2019-11-06
| | | | | | | | | | | | | | Add some context for debugging failures so it is possible to determine which register read is failing. BUG=None TEST=./build_test.py Change-Id: I6084971bc6dbd1f7b5d46e6c5d7ba017bb32edc6 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1893637 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: factor out interrupt signal functionDaniel Verkamp2019-11-06
| | | | | | | | | | | | | | | | This will be used for configuration interrupts as well. No functional change. BUG=chromium:854765 TEST=./build_test.py Change-Id: Iacccfd0a93a5c90783033a8e37598c2683704351 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898267 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: do not trigger MSI-X with no vectorDaniel Verkamp2019-11-06
| | | | | | | | | | | | | | | | The virtio specification allows the driver to configure a queue's MSI-X vector to the magic NO_VECTOR value (0xffff); in this case, if MSI-X is enabled, no interrupt should be delivered (neither MSI-X nor INTx). BUG=chromium:854765 TEST=./build_test.py Change-Id: Icb5e82bf9a57ded60fc8c022c4d8630b5ab70dcf Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898266 Reviewed-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: simplify interrupt status updateDaniel Verkamp2019-11-06
| | | | | | | | | | | | | | | | | | | | The first interrupt_status.fetch_or() operation already sets the appropriate bit; calling fetch_or() again with the same value is unnecessary. In addition, if the interrupt_status field has any bit set (not just the USED_RING bit), then the interrupt is already pending and we don't need to trigger it again. BUG=chromium:854765 TEST=./build_test.py Change-Id: Iba7fb9b934d062db801f8ba0e743618f9db580ee Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898045 Reviewed-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: initialize config MSI-X vectorDaniel Verkamp2019-11-06
| | | | | | | | | | | | | | | | | | | The virtio specification says that the device must have all queue and configuration change events unmapped upon reset. The queue MSI-X vector configuration was already initialized to VIRTIO_MSI_NO_VECTOR (0xffff), but the device configuration change notification vector was initialized to 0. Move the constant to the virtio module so it can be used to initialize the config vector to the correct value. BUG=chromium:854765 TEST=./build_test.py Change-Id: Ife1117e54196a898782238a2b81e69b20ac79784 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898044 Reviewed-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: Add virtio-fs deviceChirantan Ekbote2019-11-06
| | | | | | | | | | | | | | | | | | | | | | | | Add a new virtio-fs device for sharing files between the host and the guest. This change adds all the device infrastructure necessary for the driver probe to succeed but doesn't currently handle the actual fuse protocol. Additionally, shared memory support is not currently implemented. The device is not hooked up to the command line. Testing this device requires a kernel with the virtio-fs patches. To test with a standard crostini setup, use https://user.git.corp.google.com/chirantan/virtiofs/+/refs/heads/chromeos-5.1 which is the 5.1 kernel with the virtio-fs and chromium-specific virtio-{gpu,wl} patches applied. BUG=b:136128319 TEST=`tast run vm.VirtioFs` Change-Id: I09dcefafaf0d2a7e13d54df11384dfcee3b85ba6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1705654 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* devices: fix fuse compilation on 32-bit platformsDaniel Verkamp2019-11-06
| | | | | | | | | | | | | | | | | | | | struct stat64 uses different types on 32-bit platforms like arm; cast to the types used there to allow compilation on both x86-64 and arm. In addition, a 64-bit offset was being passed to libc::ftruncate, but this API takes a 32-bit off_t on 32-bit platforms; switch to ftruncate64 to allow the full range of offsets. BUG=b:136128319 TEST=emerge-kevin crosvm TEST=emerge-nami crosvm Change-Id: I382aef8509ca723efcf5024b22e140265636dc10 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1899218 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: net: use FileReadWriteVolatile trait for txStephen Barber2019-11-05
| | | | | | | | | | | | | | | | | This removes the unnecessary copy on the tx path. On nami, this increases tx throughput by ~60%. BUG=chromium:753630 TEST=crostini.NetworkPerf Cq-Depend: chromium:1873142 Change-Id: I58be5a7acef5d118d34b3c42ffb5a34e90070bf4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1881419 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
* devices: add into_iovec() for DescriptorUtilsDaniel Verkamp2019-11-05
| | | | | | | | | | | | | | This allows the conversion of (part of) a descriptor chain into an iovec suitable for use with sys_util functions like send_with_fds(). BUG=None TEST=./build_test.py Change-Id: I4e3f7d9c1175c1173661b0661d3fa15d1da72d1a Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1815417 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: fs: Fix available_bytes() callChirantan Ekbote2019-11-01
| | | | | | | | | | | | | | | | This call was changed to not return a Result in "7f64f50 descriptor_utils: check for size overflow in new()". BUG=b:136128319 TEST=build and run pjdfstests Change-Id: Ibdc786b26ff35977723ba61c51e8cdf1b631edc8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1890581 Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* devices: fs: Add a passthrough file systemChirantan Ekbote2019-11-01
| | | | | | | | | | | | | | | Add a "passthrough" file system implementation that just forwards it's requests to the appropriate system call. BUG=b:136128319 TEST=`tast run vm.VirtioFs` Change-Id: I802c91dd0af8cdd8b9e761d9f04f874ae41ec033 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1758103 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: virtio: disable MSI-X for block and netDaniel Verkamp2019-10-31
| | | | | | | | | | | | | | | | | | | | | | | | | Temporarily turn off MSI-X support in the block and net devices since it seems this is responsible for some test flakiness that manifests as timeouts/hangs in the ProxyDevice read handler, e.g.: [devices/src/proxy.rs:238] failed read from child device process virtio-pci (virtio-block): failed to receive request or response: Resource temporarily unavailable (os error 11) This is a minimally-invasive change to disable MSI-X without a full revert of the relevant patches by just changing the relevant devices so that they no longer request MSI-X vectors. BUG=chromium:1019986 BUG=chromium:854765 TEST=check /proc/interrupts inside crosvm does not contain "PCI-MSI" Change-Id: Ib37b503e609e2b9e22265370bcfe5804f04057ef Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1891643 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
* virtio: Convert ring index to u64 earlier in Queue::popChirantan Ekbote2019-10-29
| | | | | | | | | | | | | | | | | | | | | | The `next_avail` field is a Wrapping<u16> but we pull out the underlying u16 when calculating the descriptor index address offset in Queue::pop and only convert the result to a u64 after applying all the operations. This can cause a u16 overflow if the queue size is the max allowed (2^15). Instead, convert to a u64 immediately after calculating the index so that the rest of the operations are carried out as u64s and will not overflow. BUG=chromium:1018319 TEST=`cros_fuzz reproduce` and unit tests Change-Id: I49743e239e2a407498d862c5137930f3f0cdf72a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1884404 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
* devices: virtio: block: use FileReadWriteAtVolatileDaniel Verkamp2019-10-29
| | | | | | | | | | | | | | | | | | | Use the "at" variants of the read/write functions in the block device. This reduces the number of syscalls on the host per I/O to one (pread64/pwrite64) rather than two (lseek + read/write). The CompositeDiskFile implementation is also updated in this commit, since it's both a producer and consumer of DiskFile, and it isn't trivial to update it in a separate commit without breaking compilation. BUG=None TEST=Start Crostini on kevin, banon, and nami Change-Id: I031e7e87cd6c99504db8c56b1725ea51c1e27a53 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1845948 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* vfio: Add vfio msi routing information into kvmXiong Zhang2019-10-29
| | | | | | | | | | | | | | | | When vfio device msi is enabled, use VmIrqRequest->AllocateOneMsi() to allocate one gsi for a msi vector, and link gsi with irqfd through vm->register_irqfd, use VmIrqRequest->AddMsiRoute() to add msi routing info into kvm route table. BUG=chromium:992270 TEST=none Change-Id: I5e2d2347e5e26f0ef6e12554dae4b12934b65e82 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581146 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* descriptor_utils: Use copy_nonoverlappingChirantan Ekbote2019-10-28
| | | | | | | | | | | | | | | | | | | | Replace the copy_{to,from} calls for VolatileSlice with ptr::copy_nonoverlapping. The copy_{to,from} implementations were doing a volatile read/write per byte, which is significantly slower than just using a memcpy. Using copy_nonoverlapping should be safe here as that's how this was implemented before the refactor. BUG=chromium:1014999 TEST=unit tests Change-Id: Iad29e76056ff3064a5fe7e816b517b4ac75eaaef Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1866894 Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Tested-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* vfio: Intx supportXiong Zhang2019-10-28
| | | | | | | | | | | | | | | | | | When hw reports it could support INTX, this patch enable it by passing irqfd into vfio kernel. Then once hw intx happens, the vfio kernel irq handler receives and handles it, the handler will trigger irqfd and kvm injects the interrupt into guest. BUG=chromium:992270 TEST=None Change-Id: I8b200174a91183b7324b0044fde13b44c751d4d7 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1813457 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* devices: fs: Add multikey moduleChirantan Ekbote2019-10-27
| | | | | | | | | | | | | | | | | The multikey module provides a BTreeMap implementation that can use one of 2 different kinds of keys to look up a value. This is needed by the virtio-fs server since it needs to be able to look up keys either by u64 or by a (ino_t, dev_t) pair. BUG=b:136127316 TEST=`tast run vm.VirtioFs` Change-Id: I3a22331e7a15b2316c31ac803bf2813a14bf948f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1837025 Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: Chirantan Ekbote <chirantan@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* devices: fs: Implement virtio-fs serverChirantan Ekbote2019-10-27
| | | | | | | | | | | | | | | | Add a `Server` type that links the FUSE protocol with the virtio transport. It parses messages sent on the virtio queue and then calls the appropriate method of the `Filesystem` trait. BUG=b:136128319 TEST=`tast run vm.VirtioFs` Change-Id: I7d6fb521f6c620efe1bdb4fa0fa8fb8c42a82f45 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1757242 Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Tested-by: Chirantan Ekbote <chirantan@chromium.org>
* devices: fs: Add Filesystem traitChirantan Ekbote2019-10-27
| | | | | | | | | | | | | | | Add the `Filesystem` trait, which is the main interface between the transport and the actual file system implementation. BUG=b:136128319 TEST=`tast run vm.VirtioFs` Change-Id: Ic8bc9e231652020501e10ad0be810a9f66e90b8e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1757241 Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: Chirantan Ekbote <chirantan@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* devices: implement dedicated Interrupt struct for virtio WorkerZide Chen2019-10-25
| | | | | | | | | | | | | | | | | | | | | | The code to inject interrupt to the guest can be generic to all virtio devices. This patch: - move those guest interrupt related fields out of Worker structure and put in a separate file, making the worker code cleaner. - remove redandant functions across virtio devices: signal_used_queue(), signal_config_changed(), etc. BUG=chromium:854765 TEST=sanity test on eve and Linux TEST=cargo test -p devices Change-Id: I8e9f760f2057f192fdc74d16a59fea2e6b08c194 Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1869553 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* devices: enable MSI-X for virtio-net and viotio-block devicesXiong Zhang2019-10-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - signal_used_queue(): trigger MSI-X interrupts to the guest if MSI-X is enabled, otherwise trigger INTx interrupts - enable MSI-X on vhost-net: allocate one vhost_interrupt for every MSI-X vector. Performance wise, fio random R/W test on eve pixelbook: INTx MSI-X delta fio write 8.13MiB/s 9.79MiB/s +1.66MiB/s (+20%) fio read 24.35MiB/s 29.3MiB/s +4.95MiB/s (+20%) For networking performance (TCP stream), test results on eve pixelbook: INTx MSI-X delta iperf3 5.93Gbits/s 6.57Gbits/s +0.64Gbits/s (+10.7%) iperf3 -R 5.68Gbits/s 7.37Gbits/s +1.30Gbits/s (+22.8%) iperf test results on VM launched from Ubuntu host (client sends only): INTx MSI-X delta virtio-net 9.53Gbits/s 11.4 Gbits/s +1.87Gbits/s (+19.5%) vhost 28.34Gbits/s 44.43Gbits/s +16.09Gbits/s (+56.7%) BUG=chromium:854765 TEST=cargo test -p devices TEST=tested virtio-net and block on Linux VM and eve pixelbook Change-Id: Ic4952a094327e6b977f446def8209ea2f796878c Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1828340 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* descriptor_utils: check for size overflow in new()Daniel Verkamp2019-10-25
| | | | | | | | | | | | | | | | | | | Move the check for length overflow that was in available_bytes() into Reader::new() and Writer::new(). This simplifies callers, since they can assume that once a valid Reader or Writer has been constructed, available_bytes() cannot fail. Since we are walking the descriptor chain during new() anyway, this extra check should be essentially free. BUG=None TEST=cargo test -p devices descriptor_utils Change-Id: Ibeb1defd3728e7b71356650094b0885f3419ed47 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1873142 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* devices: implement MSI control socketXiong Zhang2019-10-24
| | | | | | | | | | | | | | | | | Allocate per device VmMsi msg_socket for communication between virtio devices and main VM process, which owns the KVM fd and issues ioctl to KVM for KVM_IRQFD and KVM_SET_GSI_ROUTING. BUG=chromium:854765 TEST=None Change-Id: Ie1c81534912eaab7fbf05b5edef7dca343db301c Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1828339 Tested-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* devices: finish the functions to enable MSI-XZide Chen2019-10-24
| | | | | | | | | | | | | | | | | | | | | | | - add a new field "vector" to struct Queue, which represents the entry number to the MSI-X Table. This can be used to find out the desired irqfd to inject MSI-X interrupts to the guest. - enable MSI-X when MSI-X Enable bit of the Message Control word is being set: allocate irqfd per MSI-X vector; register the irqfd to KVM; update GSI routing to KVM. - update GSI routing if the Message Data or Message Addr of individual MSI-X table Entry is being changed in run time. BUG=chromium:854765 TEST=cargo test -p devices Change-Id: I81533999ab6cd9ec5f111b256caf34077a4a7d1a Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com> Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1828338 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* devices: implement MsixConfig struct and generic MSI-X functionsZide Chen2019-10-24
| | | | | | | | | | | | | | | | | | | | The MsixConfig struct is responsible for all the operations of MSI-X Capability Structure and MSI-X Table. A msix_config object is created for each virtio device. BUG=chromium:854765 TEST=cargo test -p devices Change-Id: Ide7c34d335d49a201f20b0a4307bcda97d1d61b7 Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com> Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1828337 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* devices: implement msix capability structureZide Chen2019-10-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | The MSI-X feature is ported from Cloud-hypervisor commit 69e27288a2e. (https://github.com/intel/cloud-hypervisor.git) In this commit: - add a new "msix" module to the pci crate. - implement the MSI-X Capability Structure. - implement per virtio device msix_vectors() function which represents the supported MSI-X vector for this device. BUG=chromium:854765 TEST=launch Crosvm on eve and Linux TEST=cargo test -p devices TEST=./bin/clippy TEST=./build_test.py --x86_64-sysroot /build/eve Change-Id: I5498b15a3bf115e34764e6610407b3ba204dae7f Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com> Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1873356 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* descriptor_utils: Consume all buffers when reading or writingChirantan Ekbote2019-10-23
| | | | | | | | | | | | | | | | | | | The consume function in both the read and write methods should consume all the VolatileSlices that are given to it rather than just the first one. The previous implementation was not wrong, just inefficient. This should fix that. Also add a test to make sure that this doesn't regress in the future. BUG=none TEST=unit tests Change-Id: I02ec22269cdd6cdc329dd62367b99352a4dc1245 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865271 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* virtio-net: reduce number of virtual interrupts to the guestZide Chen2019-10-22
| | | | | | | | | | | | | | | | | | | | | It's quite costly to inject virtual interrupt to the guest, especially in INTx case. To reduce the number of interrupts, in process_rx(), we don't have to inject interrupt on every frame, but wait until process_rx() finishes processing all frames. On eve, iperf3 gets ~15% improvement, "iperf3 -R" gets ~30% improvement. BUG=chromium:854765 TEST=iperf3 on eve and Linux Change-Id: Ie0560d8f42235d2371addb6de34c5f93d11a405f Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865021 Reviewed-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org>
* ac97: add sample format to create_*_streamFletcher Woodruff2019-10-22
| | | | | | | | | | | | | | | The audio_streams interface now supports specifying a sample format. Update call sites to indicate that the desired format is S16LE. BUG=chromium:1010667 TEST=aplay within vm Cq-Depend: chromium:1856646 Change-Id: Ib69ff9b39196905f0f429eaf771f6f92901bfc71 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1856586 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
* devices: vhost: simplify vhost importsDaniel Verkamp2019-10-21
| | | | | | | | | | | | | | | | | | | | Rather than using `use ::vhost::...` to disambiguate the imports, remove the conflicting `use virtio_sys::vhost` and add `virtio_sys::` to each location that used `vhost::...` previously. The `use ::vhost::...` syntax confuses rustfmt when run directly on these two files, causing it to rewrite the imports into something that doesn't actually compile. BUG=None TEST=rustfmt --check devices/src/virtio/vhost/net.rs TEST=rustfmt --check devices/src/virtio/vhost/vsock.rs Change-Id: I8483f5327a1e2b3ae4887f0b3cef20a917d7410e Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865370 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>