summary refs log tree commit diff
path: root/src/linux.rs
Commit message (Collapse)AuthorAge
...
* Add runnable vcpuDylan Reid2019-12-10
| | | | | | | | | | | | | Add a new type `RunnableVcpu` for a vcpu that is bound to a thread. This adds type safety to ensure that vcpus are only ever run on one thread because RunnableVcpu can't `Send`. It also ensures multiple vcpus can't run on the same thread. Change-Id: Ia50dc127bc7a4ea4ce3ca99ef1062edbcaa912d0 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898909 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@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>
* linux.rs: Don't use /proc/sys/fs/file-maxChirantan Ekbote2019-12-09
| | | | | | | | | | | | | | | | | | | | | | | | | | Don't use /proc/sys/fs/file-max when setting the max open file limit for the virtio-fs device. This will fail when the value is larger than the hard limit set for the crosvm process, unless it also has CAP_SYS_ADMIN in the initial namespace. Instead, just use the hard limit as returned by `prlimit64`. Increasing the soft limit up to the hard limit is allowed even for completely unprivileged processes. It is up to the process that spawned crosvm to ensure that the hard limit is high enough that the virtio-fs server will not run out of fds. BUG=b:142344095 TEST=Start a termina VM with a virtio-fs device after applying CL:1939193 Change-Id: I4fb4c33ffe6378ed3109fddcb0fc2bf3da850252 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1957767 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* linux: check memory size calculation overflowDaniel Verkamp2019-12-06
| | | | | | | | | | | | | | | | | | | | | | | | | | On systems where usize is 32 bits wide (e.g. 32-bit arm), the calculation of memory_size in bytes based on the -m configuration option in megabytes would silently overflow when the resulting value was wider than 32 bits. Change the shift that converts megabytes to bytes into a checked_mul so that a suitable error is produced if the size overflows. Additionally, change the cfg.memory type to u64 instead of usize; this is representing a size in megabytes, so its maximum value isn't related to the size of an object in memory anyway, and this avoids the need for a cast in the memory_size calculation. Requesting a memory size larger than the crosvm process can map will still result in an error at a later stage in guest startup. BUG=chromium:1028747 TEST=`crosvm run -m $((5 * 1024)) ...` on kevin Change-Id: I8fef7070bab4dafff70ed54738b26d0bb7632150 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1937551 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* 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: 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>
* linux.rs: Set open file limits for all devicesChirantan Ekbote2019-11-28
| | | | | | | | | | | | | | | | | | | | | | | | | The virtio-fs device opens a lot of fds and needs to have a pretty high open file limit. In order for this to be successful on Chrome OS, the parent process (concierge) also needs to have a very high open file limit. This unfortunately has the side-effect of raising the open file limit for _all_ crosvm devices. Deal with this by setting the open file limit back down to a reasonable value (1024) for all devices that use `create_base_minijail`. This was the value of the open file limit for concierge before the increase. BUG=b:142344095 TEST=Check /proc/<pid>/limits for various crosvm device processes and see that they have the proper value for "Max open files". Change-Id: I87e3fe62fe22e68bff5ba5b60d85d39060a111dd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1939527 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Commit-Queue: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* linux.rs: Remove references to chronosChirantan Ekbote2019-11-26
| | | | | | | | | | | | | | | | | | | | | | | Even when run on Chrome OS, the crosvm process does not have enough privilege to add the chronos user/group to the {u,g}idmap of the 9p device process. This was never cleaned up because we don't use the 9p device in crostini VMs (seneschal spawns 9s servers in a separate process tree). Remove all references to the chronos user/group and just do what the other devices do: use the crosvm user/group if it exists or fall back to the current euid/egid. BUG=chromium:1028442 TEST=Add `--shared-dir` to the command line flags of a termina VM and see that it starts properly Change-Id: Iad4927d37c35709aee6e15f79b316eb88483458f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1935581 Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* io_jail: Replace rlim_t with rlim64_tChirantan Ekbote2019-11-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | rlim_t is defined as an unsigned long but importantly, it is defined as what the _kernel_ thinks is an unsigned long. This means that when you have a 32-bit userspace and a 64-bit kernel (like we do for arm64 chromebooks), rlim_t is 64 bits. This isn't really a problem for C and C++ code because they use the headers from the kernel where rlim_t is properly sized but it doesn't really work for rust. The libc crate defines rlim_t as an alias for ::std::os::raw::c_ulong, which leads to the rust compiler thinking that it has a 32 bit width. Hilarity ensues when you attempt to cross the rust -> C FFI barrier with these conflicting definitions. The rust compiler thinks the parameters can fit in 32 bit registers so it puts the `cur` parameter in r2 and the `max` parameter in r3. On the other hand, the C code knows that the parameters are 64-bit values and combines r2/r3 to create the 64-bit `cur` value and uses the first 8 bytes on the stack as the `max` value. This leads to a `cur` value that is way too large and a nonsensical `max` value that depends on whatever happened to be on the stack at the time. Fix this by changing the library bindings to u64 and the Minijail::set_rlimit parameters to rlim64_t. Once we add a method to minijail that accepts rlim64_t's we can switch the library bindings to use that as well. BUG=b:136128319 TEST=`tast run vm.Virtiofs` on kevin Change-Id: I8f58923c4768ecfe827d2a5d73c72dc778fe419c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1916560 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>
* Enable seccomp for virtio-fsChirantan Ekbote2019-11-19
| | | | | | | | | | | | | | Add x86_64 and arm seccomp policy files for the virtio-fs device. BUG=b:136128319 TEST=Run a vm with a sandboxed virtio-fs device Change-Id: I8ea7c5d3e90696077f0c2b1f942cb286a0b36cf4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1916559 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* Add fs device to --shared-dirChirantan Ekbote2019-11-19
| | | | | | | | | | | | | | Expand the `--shared-dir` option to allow callers to select between 9p and virtio-fs for sharing directories. BUG=b:136128319 TEST=start a VM with a virtio-fs based shared directory Change-Id: Ie8afc1965b693805dd6000f0157786317aab060d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1705656 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@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>
* main: remove EPOLLHUP epoll item from host kernel synchronouslyZide Chen2019-11-17
| | | | | | | | | | | | | | | | | | | control_sockets.swap_remove() could cause host kernel to invoke ep_remove() to remove the epoll item. But it's called from the task work, and it could be deferred after next poll_ctx.wait() which could unexpectedly pick up epoll events from the already closed fd. BUG=chromium:1019986 TEST=launch Crosvm guest from heavy loaded Linux host Change-Id: I474a7a47a484e3acfae4383d61601e1553bd674f Signed-off-by: Zide Chen <zide.chen@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1917495 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* 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>
* crosvm: Linux VM use immediate exitMatt Delco2019-10-30
| | | | | | | | | | | | Use immediate exit when avaialable to improve performance. BUG=None TEST=Local build and test. Change-Id: I5a4fb3dc310f3b2969113f6d57290099f84a0187 Signed-off-by: Matt Delco <delco@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1847861 Reviewed-by: Zach Reizner <zachr@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>
* 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: vfio: fix clippy warningsDaniel Verkamp2019-10-17
| | | | | | | | | | | | | | | | | | | | | Fix boxed_local, const_static_lifetime, useless_format, and redundant_closure clippy warnings in the VFIO code. This fixes all clippy warnings except a single instance of let_and_return in VfioPciDevice::keep_fds(), since that code is modified in an upcoming patch. BUG=None TEST=./build_test.py TEST=bin/clippy Change-Id: I548adbc6b92448fc0db82ed72214d73b0eabaf5c Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1822697 Reviewed-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Tested-by: kokoro <noreply+kokoro@google.com>
* vm_control: Add VmIrqRequest SocketXiong Zhang2019-10-15
| | | | | | | | | | | | | | | | | | | | | | | | | When vfio device's msi/msi-x or virtio device's msi-x is enabled, its irq routing info should be notified to kvm. But this is a runtime vm service call, so vm_control is used to call vm service. VmIrqRequest->AllocateOneMsi() is used to allocate one gsi for a msi and a msi-x vector, and link gsi with irqfd through vm->register_irqfd. The orignal interrupt_evt and interrupt_resample_interrupt is used for INTX only. VmIrqRequest->AddMsiRoute is used to add msi routing info into kvm route table. BUG=chromium:992270 TEST=none Change-Id: I4f1beeb791943e09d957573dd2a58d55bf895d16 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1846603 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
* devices: jail serial deviceZach Reizner2019-10-10
| | | | | | | | | | | | | | | | | | This change plumbs the jail throughout the arch specific device creation process. It also adds a custom callback support for the ProxyDevice so that the main process can interrupt the child serial process when it has incoming bytes. TEST=crosvm run BUG=None Change-Id: I6af7d2cb0acbba9bf42eaeeb294cee2bce4a1f36 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1752589 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org>
* sys_util: allow adding handlers for all signalsFletcher Woodruff2019-10-03
| | | | | | | | | | | | | | | | | | Currently, sys_util's register_signal_handler only permits handlers for real-time signals. Rename that function to register_rt_signal_handler and add a new register_signal_handler that supports all signals, then update references to the old name. BUG=chromium:1008990 TEST=builds Change-Id: I455e14c562cd1f2ca4b308b4e38c503845321926 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1836185 Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
* vfio: Setup dma map for vfio deviceXiong Zhang2019-10-01
| | | | | | | | | | | | | | | | | For each guest memory region, setup the corresponding gpa to hva map in the kernel vfio iommu table. Then the kernel vfio driver could get the hpa through gpa. Device could use this gpa for dma also. BUG=chromium:992270 TEST=none Change-Id: I04008d68ab2ed182a789d6ee8c97a0ed9e1e4756 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581141 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* vfio: Integrate VFIO device into pci device modelXiong Zhang2019-10-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Create VFIO device and VFIO PCI device in create_devices() function, and intergrate it into PciRootBridge, so guest could see this vfio device. Add a vfio config parameter, this config point to passthrough or mdev device sysfs path. For passthrough case, first user unbind host device from its driver, then bind host device to vfio-pci. Like: echo 0000:00:02.0 > /sys/bus/pci/devices/0000:00:02.0/driver/unbind ech0 8086 1912 > /sys/bus/pci/drivers/vfio-pci/new_id Finally pass the sysfs to crosvm through --vfio=/sys/bus/pci/devices/0000:00:02.0 For mdev case, user create a mdev device through echo $UUID > mdev_type/create, then pass this mdev device to crosvm like --vfio=/sys/bus/pci/devices/0000:00:02.0/$UUID BUG=chromium:992270 TEST=none Change-Id: I0f59d6e93f62f9ab0727ad3a867d204f4ff6ad2d Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581140 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* linux: drop VM before exiting to allow cleanupDaniel Verkamp2019-09-17
| | | | | | | | | | | | | | | | Clean up the `linux` object (which contains the devices) before the control sockets passed to `run_control` are closed. This allows crosvm to shut down cleanly without any error messages about short reads from the control sockets. BUG=chromium:992494 TEST=exit crosvm without errors Change-Id: I1040c2f9ecbd03f820c7082da3327962ecc445f1 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1802155 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* Extract disk creation logic out of qcow and src.Cody Schuffelen2019-08-28
| | | | | | | | | Bug: b/133432409 Change-Id: Iba25d5f6bb5f60619bb2f5a3d72ddfd3a81650b4 Signed-off-by: Cody Schuffelen <schuffelen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691460 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* crosvm: silence unused code warning for NonZeroU8Daniel Verkamp2019-08-22
| | | | | | | | | | | | | | | | After a recent refactoring of display support, this import is only used when building with the "gpu" feature enabled. Put it behind a cfg check to avoid a warning when building without gpu support. BUG=None TEST=cargo build TEST=emerge-nami crosvm Change-Id: I4e407e09daa93c74203f3472dad5a3713b99d122 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1762448 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* crosvm: add x-display argument for choosing the X11 gpu displayZach Reizner2019-08-08
| | | | | | | | | | | | TEST=cargo run -- run --gpu --x-display :0 BUG=None Change-Id: I76b4b33a6b14cb6fad322ffa95f00cce976f81a3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670550 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>
* gpu: Add sandboxing support for pvr.David Riley2019-08-01
| | | | | | | | | | | | | BUG=chromium:892280 TEST=glxgears with virtio-gpu on hana Change-Id: Ib92b21c124e30eacb3fc28558e2eb5d8d4a92567 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1717739 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: David Riley <davidriley@chromium.org> Commit-Queue: David Riley <davidriley@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Auto-Submit: David Riley <davidriley@chromium.org>
* gpu: Add sandboxing support for mali/ARM.David Riley2019-08-01
| | | | | | | | | | | | | | | | ARM platforms have different library locations and also required GPU devices to be availble to the GPU process. BUG=chromium:892280 TEST=glxgears with virtio-gpu on kevin and nami Change-Id: If1baeb1edda76d057e88ab5e88ce22f02e5d30a0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1717738 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: David Riley <davidriley@chromium.org> Commit-Queue: David Riley <davidriley@chromium.org> Auto-Submit: David Riley <davidriley@chromium.org>
* tree-wide: use PollContext::build_with where possibleZach Reizner2019-07-24
| | | | | | | | | | | | | | | | | | The old method of creating a PollContext and calling `add` inside of `and_then` chains was an ugly way handle the Results that can crop up after each call. The `build_with` function is equivalent but operates on a slice which has way less boilerplate. TEST=./build_test BUG=None Change-Id: I8b0d6532680e04c501187397bd211014a2363c25 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715581 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org>
* main: add seccomp-log-failures flag to command lineZach Reizner2019-06-27
| | | | | | | | | | | | | | | | | | | | | | | | | | All cros-debug versions of crosvm enabled seccomp logging, which is now broken on kernels <4.4 thanks to new minijail changes as explained in the referenced BUG. This seems to be intended by the minijail folks as the aim to improve the seccomp logging in part by changing its semantics to logging failures without killing the violating process. In such a world, crosvm should not as a compile time choice, enable logging, which would amount to disabling some of the security. This change adds a command line flag to emulate the old behavior for the purposes of developer debugging, as long as that developer is running on a kernel that supports the new minijail seccomp filter failure logging. BUG=chromium:978998 TEST=USE=cros-debug emerge-eve crosvm && cros deploy eve crosvm then start crostini in UI Change-Id: I98190a068a919929e466fe22d6d630b90a758336 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679380 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: Zach Reizner <zachr@chromium.org>
* gpu: Allow more than one resource bridge socketChirantan Ekbote2019-06-24
| | | | | | | | | | | | | | | | | | | | | | | | Currently the wayland device accesses buffers allocated by the gpu device via a dedicated socket connection. Upcoming virtual devices like vdec and camera will also need access to these buffers. Modify the gpu device so that it can process requests on multiple resource_bridge sockets. Each future device that needs access to gpu device buffers should create a new resource bridge socket pair and add it to the list of sockets that the gpu device monitors. The actual interface between the devices is unchanged. BUG=b:133381367 TEST=run glxgears in a crostini container with and without gpu enabled Change-Id: I58693881945965071a53653bf4f86681725267d0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1652876 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
* devices: Add separate seccomp policy for pmem deviceJakub Staron2019-06-21
| | | | | | | | | | | | | | | This change adds separate seccomp policy for pmem device. Previously, pmem device was using block device seccomp policy. BUG=None TEST=Boot VM and run xfstests on pmem device Change-Id: I3f25d64d4da6ad8f0ff22b285e1a7e958f545c55 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1652441 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jakub Staroń <jstaron@google.com>
* src/linux.rs: Modify socket instead of add socket when remove other socketsXiong Zhang2019-06-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an ill socket is detected, it will be removed from poll_context and control_sockets, then the remaining good sockets should change their indices, So modify should be used instead of add, as all of them have been added into poll_context already, the add will return an error. This change is merge of another change at I977be57ea0898cc8226505f7d3da103a46ea626c that was identical to this one except it contained the following similar commit message: linux: when renumbering control sockets, use modify instead of add In some circumstances, a VM control socket will get removed from the list of control sockets in the run_control loop. Usually, the last control socket in the list gets removed, but if that is not the case, the control sockets will get reordered to fill in the gap in the list. The `add` method of `PollContext` was used to change the token used for a given control socket, when `modify` should have been used instead. The problem with using `add` when a control socket is already part of a `PollContext` is that it will return an error and terminate crosvm. This CL fixes that issue. BUG=none TEST="crosvm run --vfio=$GVT_UUID", then run many gpu workloads in guest TEST=crosvm run --gpu Change-Id: Ic00a781d8839e652e2a8fd54ccd8e55849fa20bb Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Signed-off-by: Zach Reizner <zachr@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581151 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: fix clippy warningsJakub Staron2019-06-08
| | | | | | | | | | | | | | | | | | | Resolve a couple of minor clippy warnings: - unneeded return statement - use `if let` instead of `match` for single pattern destruction - use `values()` function to iterate over map values - supress warning about `ptr::null()` as expressed by the comment BUG=None TEST=./bin/clippy TEST=cargo build Change-Id: Ic4cea94cd3a25a9edf6ef38119de8c46dcfec563 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1646739 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Jakub Staroń <jstaron@google.com>
* crosvm: virtio-pmem deviceJakub Staron2019-06-05
| | | | | | | | | | | | | | | | | | | | Adds support for virtio-pmem device as an alternative for virtio-blk. Exposing disk image to guest as virtio-blk device results in both guest and host independently caching the disk I/O. Using virtio-pmem device allows to mount disk image as direct access (DAX) in the guest and thus bypass the guest cache. This will reduce memory foodprint of the VMs. BUG=None TEST=cargo test TEST=Boot patched termina kernel in crosvm; mount virtio-pmem device as DAX and run xfstests. Change-Id: I935fc8fc7527f79e5169f07ec7927e4ea4fa6027 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1605517 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Jakub Staroń <jstaron@google.com>
* Initial BIOS support.Cody Schuffelen2019-05-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The --bios argument is added as an alternative to the kernel positional argument. The BIOS runs in unreal mode (16-bit cs selector set to the end of 32-bit address space), which matches the default state KVM puts the segment and data registers into. Example usage: Build u-boot with "make qemu-x86_defconfig && make" Run crosvm with "crosvm_wrapper.sh run --bios=u-boot.rom" This produces the following message: """ U-Boot 2019.01-00017-gdc76aabe6a-dirty (May 21 2019 - 12:17:02 -0700) CPU: DRAM: 16 MiB unable to get online cpu number: -19 Warning: MP init failure Model: QEMU x86 (I440FX) Net: No ethernet found. error: can't find etc/table-loader Hit any key to stop autoboot: 0 => """ At this point the u-boot shell works with stdin/stdout, but virtual disks passed with --rwdisk weren't immediately visible from running "virtio scan" and "virtio info". This change puts the bios loading together with the linux kernel loading code since there is a lot of overlap in functionality. Bug: b/133358982 Test: ./crosvm_wrapper.sh run --mem=4097 --bios=u-boot.rom Change-Id: I65b0e1044233af662a642c592d35b106217f3c13 Reviewed-on: https://chromium-review.googlesource.com/1622648 Commit-Ready: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* linux: Add cras-capture option for cras-audio devicepaulhsia2019-05-31
| | | | | | | | | | | | | | | | | | | | The flag can enable capturing audio from CRAS server to the cras-audio device. We'll re-enable capture function on Crostini after finishing capture permission works. BUG=chromium:932268 TEST=Boot vm with crosvm --cras-audio --cras-capture to check recording functionality. Cq-Depend: chromium:1628633 Change-Id: I7502cbd668cbc722224164d9f69e50a16b0ab86b Reviewed-on: https://chromium-review.googlesource.com/1628687 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Chih-Yang Hsia <paulhsia@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
* crosvm: fix unused variable warning in create_virtio_devicesDmitry Torokhov2019-05-29
| | | | | | | | | | | | | | | The gpu_device_socket is not used when GPU support is disabled. BUG=chromium:967436 TEST=cargo build --no-default-features Change-Id: I5c0ef0ecf27349bcfbc19474879a282c9f6fb8ef Reviewed-on: https://chromium-review.googlesource.com/1631292 Commit-Ready: Dmitry Torokhov <dtor@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Dmitry Torokhov <dtor@chromium.org> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
* virtio-gpu: add gpu control socketGurchetan Singh2019-05-28
| | | | | | | | | | | | | | | The GPU process will need access to KVM. BUG=chromium:924405 TEST=compile Change-Id: I9e454d79a36a40a20c6c4b3a62ea367f339e526b Reviewed-on: https://chromium-review.googlesource.com/1626793 Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org>
* linux.rs: create a socket between gpu device and hostGurchetan Singh2019-05-24
| | | | | | | | | | | | | | | The GPU process needs to access KVM from host coherent memory. BUG=chromium:924405 TEST=compile Change-Id: I3db9dce044e2a5cc816f48f28d943024dad7e7eb Reviewed-on: https://chromium-review.googlesource.com/1626792 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: {WlDriverRequest, WlDriverResponse} --> {VmMemoryRequest, ↵Gurchetan Singh2019-05-24
| | | | | | | | | | | | | | | | | VmMemoryResponse} These type of requests are not necessarily specific to the virtio-wl, and other devices (virtio-gpu) may want to use them. BUG=chromium:924405 TEST=compile Change-Id: Iad0889da8ab3d23bb2378448fc05e3c840a93d93 Reviewed-on: https://chromium-review.googlesource.com/1626791 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: add cmdline flags for configuring serial outputs in guest machineTrent Begin2019-05-15
| | | | | | | | | | | | | | | | This change allows an output to be set for each serial device for a guest machine (stdout, syslog, or sink). BUG=chromium:953983 TEST=FEATURES=test emerge-sarien crosvm; cd sys_util; cargo test; ./build_test; manual testing on x86_64 and aarch_64 Change-Id: I9e7fcb0b296c0f8a5aa8d54b1a74ae801f6badc8 Reviewed-on: https://chromium-review.googlesource.com/1572813 Commit-Ready: Trent Begin <tbegin@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Trent Begin <tbegin@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* linux: handle margin file with multiple valuesSonny Rao2019-04-29
| | | | | | | | | | | | | | | | | We're changing the content of the low_mem margin file to handle multiple values to support notification for multiple memory pressure levels. The values will be from most critical to least, so we need to handle this by fetching the first value. BUG=chromium:736538 TEST=run vm.CrostiniStartEverything with and put memory pressure on the system Change-Id: I0278ed492ddda1594d53750e0d4024a878210c9f Reviewed-on: https://chromium-review.googlesource.com/1584644 Commit-Ready: Sonny Rao <sonnyrao@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Sonny Rao <sonnyrao@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* crosvm: Fix misleading field name in VmComponents struct.Jakub Staron2019-04-29
| | | | | | | | | | | | | | | Renames field memory_mb to memory_size. All usages of this field treat it as a memory size in bytes, not megabytes. BUG=None TEST=cargo check TEST=cargo check --package aarch64 --target aarch64-unknown-linux-gnu Change-Id: I7b1aefe4f0b612d5eeb2987dc2a0fce6db0dd228 Reviewed-on: https://chromium-review.googlesource.com/1585617 Commit-Ready: Jakub Staroń <jstaron@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: Extracts Wayland commands from from VmRequest.Jakub Staron2019-04-27
| | | | | | | | | | | | | | | BUG=None TEST=cargo test TEST=cargo test --package msg_socket TEST=cargo test --package devices TEST=cargo test --package vm_control TEST=tast -verbose run ${IP} vm.CrostiniStartEverything Change-Id: I07f034b1cc41e30b9deae68ea9c510b0923e17a8 Reviewed-on: https://chromium-review.googlesource.com/1565299 Commit-Ready: Jakub Staroń <jstaron@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Extracts BalloonAdjust from VmRequest.Jakub Staron2019-04-25
| | | | | | | | | | | | | | | | | Extracts BalloonAdjust from VmRequest into BalloonControlCommand. BUG=None TEST=cargo test TEST=cargo test --package msg_socket TEST=cargo test --package devices TEST=cargo test --package vm_control TEST=tast -verbose run ${IP} vm.CrostiniStartEverything Change-Id: Ia9f5778c37c8fd4fa560df413134d1b441142f64 Reviewed-on: https://chromium-review.googlesource.com/1565298 Commit-Ready: Jakub Staroń <jstaron@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* resources+pci: allocator rework (allocation tags)Daniel Prilik2019-04-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | AddressAllocator now maintains a HashMap<Alloc, (u64, u64, u64)>, which uniquely maps a Allocation enum (e.g: PciBar(bus, dev, bar), GpuRenderNode, etc...) to it's address, size, and human-readable tag / description. The interface has also been modified to use Error instead of Option. Aside from improving debugging, tracking allocations will have numerous uses in the future. For example, when allocating guest memory over VmControl sockets, it will be possible to restrict allocations to pre-allocated slices of memory owned by the requesting device. To plumb through PCI information to PCI devices, this CL necessitated the addition of a PciDevice method called `assign_bus_dev`, which notifies PCI devices of their uniquely assigned Bus and Device numbers. BUG=chromium:936567 TEST=cargo test -p resources && cargo build --features="gpu gpu-forward" Change-Id: I8b4b0e32c6f3168138739249ede53d03143ee5c3 Reviewed-on: https://chromium-review.googlesource.com/1536207 Commit-Ready: Daniel Prilik <prilik@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Extracts DiskResize from VmRequest to a new type.Jakub Staron2019-04-19
| | | | | | | | | | | | | | | BUG=None TEST=cargo test TEST=cargo test --package msg_socket TEST=cargo test --package devices TEST=cargo test --package vm_control TEST=tast -verbose run ${IP} vm.CrostiniStartEverything Change-Id: Icf26f53d3fd813ab43b8f14079f90628d245eed7 Reviewed-on: https://chromium-review.googlesource.com/1565297 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>