summary refs log tree commit diff
path: root/src/linux.rs
Commit message (Collapse)AuthorAge
* crosvm: fix balloon and USB sockets HEAD masterAlyssa Ross2020-06-15
| | | | | | | | | | | | | | | | | | | | 5bd2e7f606b726b598fdc26fe26a9b4029fab6d3 introduced queued_device_reqs to accomodate devices that are not ready to receive messages until they are activated in response to an event. But, devices that are ready immediately were not added to the map. When an event came in to one of these sockets (balloon and USB), the socket file descriptor would be looked up in queued_device_reqs, and crosvm would then crash because it wouldn't be found. The correct behaviour, which this patch implements, is to treat a missing entry the same as a Ready entry. An alternative would have been to add all other sockets to queued_device_reqs, and set them to Ready up front, but that would be more difficult to keep up to date than having a default. This way, only devices that need queueing need to be added to queued_device_reqs. Fixes: 5bd2e7f606b726b598fdc26fe26a9b4029fab6d3
* crosvm: fix deadlock on early VmRequestAlyssa Ross2020-06-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a DiskCommand was received on the crosvm socket before the virtio-block device was activated, the Token::VmRequest case in the main event loop would forward the request to the block device socket, and then wait syncronously for a response. That response would never come because the device hadn't been activated, and it would never be activated because the event loop would never continue, and therefore never be able to respond to the event that causes the device to be activated. crosvm would therefore just hang forever, waiting for a response that would never come. This patch fixes this deadlock by keeping track of whether devices that send a response in this way have been activated yet. If they have already been activated, messages are sent and responses are received as normal. If they have not been activated, messages are instead put into a per-device queue. Once the device is activated, queued messages are processed all at once, and then the device is marked as ready, and the queue is dropped. Future messages are processed immediately as they come in, with no further queueing. A device indicates that it is ready by sending a message on its socket. The main crosvm event loop can then poll the socket, to be notified when the device is ready. This poll event will only trigger once -- once it has been received, it is removed from the poll context. Currently, the only device type that responds to external control messages AND needs to be activated by an event is the block device. The balloon device does not respond to messages, and the xhci controller device is activated up front. The code is nevertheless structured so that it should be very easy to drop another kind of device in to the queuing system, should that be required. Message-Id: <20200614114344.22642-3-hi@alyssa.is> Notes: Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
* Merge remote-tracking branch 'origin/master'Alyssa Ross2020-06-14
|\
| * kvm: use MappedRegion traitGurchetan Singh2020-06-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Reduces code duplication between MMIO and mmap arenas - Makes adding future types easier - Makes upcoming deprecation of kvm crate easier - Use BTreeMap instead of HashMap since it's more efficient BUG=chromium:924405 TEST=compile and test Change-Id: I520abed0926489e64aac046e0dc0cfeb72fae7b2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2216446 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Steven Richman <srichman@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
* | Merge remote-tracking branch 'origin/master'Alyssa Ross2020-06-14
|\|
| * acpi: support user provided ACPI SDTs.Tomasz Jeznach2020-06-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Enable support for user provided ACPI tables with supplementary system description. Argument --acpi-table shall point to exsting file or pseudo-file with valid ACPI table content. BUG=None TEST=boot Linux kernel with generated SSDT tables. Change-Id: I8eac21da070dcc325884ed888cc7bcb01bc086ce Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2212501 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Tomasz Jeznach <tjeznach@chromium.org> Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
| * devices: virtio: Initial implementation of virtio-video deviceKeiichi Watanabe2020-05-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This CL adds a fundamental part of the virtio video device, which will be shared between the encoder and the decoder. Both devices uses the virtio-video protocol proposed as RFC v3 [1,2]. The corresponding driver code is at CL:2060327 and its children CLs. The actual decoding and encoding logic will be implemented in different CLs. [1]: mail: https://markmail.org/thread/wxdne5re7aaugbjg [2]: PDF: https://drive.google.com/file/d/1jOsS2WdVhL4PpcWLO8Zukq5J0fXDiWn-/view BUG=b:147465619, b:140082257 TEST=cargo check --features=video-decoder,video-encoder TEST=ARCVM started with --video-decoder --video-encoder Cq-Depend: chromium:2203997 Change-Id: I01999eea218ba0f3aaed1558ca2311a57d0c6819 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1973973 Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
* | crosvm: fix file_to_i64 commentAlyssa Ross2020-05-22
|/ | | | This was missed in 0bf8a5590f3556d8ec05c182cb612f254fd416e5.
* linux.rs: Set MS_SLAVE mount propagation for virtio-fsChirantan Ekbote2020-04-28
| | | | | | | | | | | | | | Allow mounts from the parent namespace to propagate into the virtio-fs device's mount namespace. BUG=b:123377807 TEST=vm.Fio.virtiofs_stress_rw and manual Change-Id: I1b8f1b411bd72a8cf5d5b4b30fa5dad466f1e48f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2156327 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* Remove redundant single-component importsDaniel Verkamp2020-04-26
| | | | | | | | | | | | | Fix clippy 1.43.0 clippy::single-component-path-imports warnings. BUG=None TEST=bin/clippy Change-Id: I3f4f54138bedce16dc1ca937bb8bc00a94594f69 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2163203 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* Apply same permissions to pmem-region alignments.Iliyan Malchev2020-04-23
| | | | | | | | | | | | | | | | | | | https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1979257 created a padding of read-only pages between the end of the pmem region and padding up to the next multiple of 2MiB. However, on ARM systems, kvm_arch_prepare_memory_region does not permit read-only pages on a write-able memory region. BUG=b:148706939 TEST=Tested on x86_64 and arm64 board with pmem image < 2MiB Tested-by: Iliyan Malchev <malchev@google.com> Change-Id: If06c2e0f74fdcd7db1b7d56e1a8d732d17f352bf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2153103 Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: timerfd: Methods don't need to me mutDylan Reid2020-04-23
| | | | | | | | | | | | | | Because TimerFd is a wrapper around a 'File' that is never modified there isn't a need for a mutable borrow. The kernel already handles the interior mutability of the underlying file descriptor. Change-Id: I7ae068cc54050b0021d00620b561335b2ae0ba16 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2161625 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* arch, main: add virtio-console parsing and creationDaniel Verkamp2020-04-23
| | | | | | | | | | | | | | | | | | | | | | This allows the creation of virtio-console devices using the new hardware=virtio-console parameter to the --serial option. Also add support for the serial earlycon option, which allows using virtio-console as the main console device with a traditional serial device as the early console. This allows logging during early boot before PCI device discovery (when virtio-console devices are set up). BUG=chromium:1059924 TEST=crosvm run -r vm_rootfs.img \ --serial hardware=serial,type=stdout,console=false,earlycon=true \ --serial hardware=virtio-console,type=stdout,console=true,stdin=true \ vm_kernel Change-Id: Iff48800272b154d49b1da00f3914799089268afe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2127322 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* crosvm: Apply cargo fix for some clippy errorsKeiichi Watanabe2020-04-15
| | | | | | | | | | | | | | | | | Executed the following command to fix trivial style problems automatically. $ rustup run nightly cargo fix -Z unstable-options --clippy \ --all-features --all-targets BUG=chromium:908640 TEST=build Change-Id: I8a42806dc573b25d4ca918112e7b420793261d37 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145537 Tested-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* msg_socket: add specialized error for zero sized recvZach Reizner2020-04-14
| | | | | | | | | | | | | | | | | | | | Receiving no data can be considered a special case for MsgOnSocket. It doesn't necessarily indicate EOF because usually messages are sent over a datagram channel and some fixed sized messages are actually zero sized. This change handles this by adding a specific result for receiving no data when at least some was expected. This will also simplify some error handling that had to unpack the `BadRecvSize` variant. TEST=cargo test -p msg_socket BUG=None Change-Id: I16feeabc1481de93a2b189989d095434b5b417b5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2079178 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Auto-Submit: Zach Reizner <zachr@chromium.org>
* devices: pmem: implement flush using msync()Daniel Verkamp2020-04-08
| | | | | | | | | | | | | | | | | | | | | | | Previously, writable pmem devices implemented the flush command using fsync(); however, this does not guarantee synchronization of memory mappings via mmap() to the file on disk. What we actually need is msync() on the pmem file mapping, but we don't have access to that mapping in the pmem child process, and it isn't trivial to pass it along since it is owned by the Vm object once it has been added as a mmap_arena. In order to call msync() on the mapping, add a new VmControl socket so that the pmem device can request that the main process issues an msync() on the MemoryMappingArena identified by its slot number. BUG=chromium:1007535 TEST=mount filesystem on /dev/pmem0 and sync; verify msync in strace Change-Id: Id0484757c422cf81d454fd54012a12dbcc1baaf6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2044365 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* crosvm balance available memoryCharles William Dick2020-04-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Poll available memory from the host and guest every second. Resize the balloon so that available memory in the guest is the same as in the host. balancemem_timer adds a Token::BalanceMemory to poll_ctx every second which creates a balloon stats request. When the stats results come back from the guest, we compute how much the balloon should change to balance available memory between the guest and host. If this new balloon size is > 5% different than the current balloon size, we make a BalloonControlCommand::Adjust to resize the balloon. BUG=b:147334004 TEST=tast run <DUT> arc.MemoryChomeOSPerf*, .vm shows memory use similar to the base arc test. tast run <DUT> arc.MemoryShiftingPerf.vm, both chromeos and android counters report high numbers. Switch LOWMEM_AVAILABLE constant to non-existing file, check the ARCVM reports not running in ChromeOS, but still boots. Change-Id: I8a581f86bf4881541d2f5f26dc541b35b862d244 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2061518 Reviewed-by: Lepton Wu <lepton@chromium.org> Reviewed-by: Charles Dueck <cwd@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Charles Dueck <cwd@chromium.org>
* Virtio-net: Let queue-num could configurableXiong Zhang2020-04-04
| | | | | | | | | | | | | | | | Virtio-net multi queue feature need multi queue pairs, this patch change queue-num configurable instead of static. --net-vq-pairs parameter could config virtio net device virtual queue pairs. BUG=chromium:1064482 TEST=Test virtio net function in guest with --net-vq-pairs=1 and --net-vq-pairs=2 Change-Id: I75202c8ae52a83b8087b52149ec6d2138d8831cb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2120312 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* Virtio-net: Add multi queues in multi threadsXiong Zhang2020-04-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to support 2 vq pairs for virtio-net, this patch create 2 sockets in one tap interface, 2 vq pairs(rx/tx) and 2 threads in device model, So one vq pair has one thread and one socket in tap corresponding. On my SkyLake desktop with crosvm and ubuntu 18.04 guest: If run one iperf server on host and one iperf client in guest, 2 vq pairs has the same netwrok bandwidth as 1 vq pair, the bandwidth is 5.99Gbits/sec If run two iperf server on host and two iperf client in guest, In 1 vq pair mode, two iperf cliens bandwidth are 3.19Gbits/sec and 3.18Gbits/sec. In 2 vq pairs mode, two iperf clients bandwidth are 4.87Gbits/sec and 4.86Gbits/sec. So 2 vq pairs improve net bandwidth 52.7% compared with 1 vq pair in this case. BUG=chromium:1064482 TEST=Run iperf test in guest Change-Id: I1fa14d7e24085552dc828a89a883d4a2ada34789 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2099754 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* crosvm virtio balloon statsCharles William Dick2020-03-31
| | | | | | | | | | | | | | | Introduces the ability to request BalloonStats from a BalloonControlCommand. BUG=b:147334004 TEST=tast run <DUT> arc.Boot.vm, and the balance available changes based on this. Change-Id: I808c4024f8c644c9cc4e30cc455ceda5f477bff3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2061517 Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Charles Dueck <cwd@chromium.org>
* audio: Create AC97 device with --ac97 optionJudy Hsiao2020-03-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Replace --cras-audio, --cras-capture, null-audio options by --ac97 option to create audio devices. 2. "--ac97 backend=BACKEND\ [capture=true,capture_effect=EFFECT]" is comma separated key=value pairs for setting up Ac97 devices. It can be given more than once to create multiple devices. Possible key values are: backend=(null, cras) - Where to route the audio device. `null` for /dev/null, and cras for CRAS server. capture=true - Enable audio capture. capture_effects - | separated effects to be enabled for recording. The only supported effect value now is EchoCancellation or aec. BUG=b:140866281 TEST=1.crosvm run -r ./vm_rootfs.img -c 4 -m 1024 -s /run --cid 5 --host_ip\ 100.115.92.25 --netmask 255.255.255.252 --ac97\ backend=cras,capture=true,capture_effect=aec\ --mac d2:47:f7:c5:9e:53 ./vm_kernel 2. Record with the vm by: arecord -D hw:0,0 -d5 -fS16_LE -c2 -r48000 /tmp/test.mp3 3. Verify that AEC is enabled within the recording stream by cras_test_cleint. Cq-Depend: chromium:2053654 Cq-Depend: chromium:2095644 Cq-Depend: chromium:2038221 Change-Id: Ia9e0e7cda1671a4842ec77a354efaa4a2dc745eb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2038413 Tested-by: Judy Hsiao <judyhsiao@chromium.org> Commit-Queue: Judy Hsiao <judyhsiao@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Auto-Submit: Judy Hsiao <judyhsiao@chromium.org>
* Fix into_iter() usage where iter() sufficesDaniel Verkamp2020-03-10
| | | | | | | | | | | | | | | | | Fixes warnings of the form: warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added. BUG=None TEST=emerge-nami crosvm Change-Id: I2b46b55f0e967d985d04678c240604b542e27e07 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2093287 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* Vfio: Multi vfio device supportXiong Zhang2020-03-09
| | | | | | | | | | | | | | | Current one vm could have one vfio device only, this patch let one vm could have multi vfio devices by changing the vfio parameter into vec<>. BUG=chromium:992270 TEST=passthrough two/three devices into guest, these devices are in the same vfio group, then check these devices function in guest. Change-Id: I366d24d750a199d7862fb907fa44f9be429c5944 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2080111 Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
* Vfio: multi vfio group supportXiong Zhang2020-03-06
| | | | | | | | | | | | | | | | | | | | | | | | | current one container contains one group only, but one container could contain multi groups actually. The main gap that current code to support multi groups is that container will be initialized multi times when multi groups exist, as each group will initialize container one time. This patch extracts the code which should run one time only on a container, so when the first group is added into container, this container initialize code will run once. The container once initialize code contains: a. Set iommu driver type as VfioType1V2 b. Setup Iommu table on each guest memory region c. create vfio_kvm device, so kernel kvm and vfio is associated. BUG=chromium:992270 TEST=passthrough two/three vfio devices into guest, these devices belong to different vfio groups, then check these devices function in guest. Change-Id: I94c9c86f70f49957a5e5c1dfd2c7d823ad042320 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2078970 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
* Use simple virtio_input_events where possible.Noah Gold2020-03-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, all input events in CrosVM were required to be linux input_events, which have a timestamp field that is actually unused by when we send/receive from the guest which are of type virtio_input_event. This CL allows CrosVM to understand both types of input events in a first class manner. It is a follow up on https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930405. This CL also addresses some bugs with window driven input: 1. attach_event_device was being called before the surface was created, so the devices were never attached. 2. The default touchpad size was not being set to the display window size. Additionally, it removes the unused event "filter" feature on event sources. Breaking change: from this point forward, CrosVM will treat input events sent via a socket (e.g. SocketEventSource) to be virtio_input_events. BUG=None TEST=builds + manual Change-Id: I7fec07c582e5a071a6f116975ba70d6e621bb483 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034046 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Noah Gold <nkgold@google.com>
* crosvm: Add plumbing for split-irqchip interruptsZhuocheng Ding2020-03-05
| | | | | | | | | | | | | | | Devices use irqfd to inject interrupts, we listen to them in the main thread and activate userspace pic/ioapic accordingly. BUG=chromium:908689 TEST=lanuch linux guest with `--split-irqchip` flag Change-Id: If30d17ce7ec9e26dba782c89cc1b9b2ff897a70d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945798 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
* devices: PIC: implement interrupt injectionZhuocheng Ding2020-03-05
| | | | | | | | | | | | | | TODO: Route irqfd to PIC, and use signal to kick vCPU thread when interrupt is triggered. BUG=chromium:908689 TEST=Unit tests in file. Change-Id: I9a87502da57e725d3bb26d746a337d0ba44ef337 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945797 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
* Add logic to setup PIC/IOAPIC.Zhuocheng Ding2020-03-05
| | | | | | | | | | | | | TODO: Route irqfd to PIC/IOAPIC to make them fully work. BUG=chromium:908689 TEST=None Change-Id: I301287b1cf32cfccffce6c52ebbb5e123931178e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945796 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
* linux: fix unused code warning without gpu featureDaniel Verkamp2020-03-02
| | | | | | | | | | | | | | | | When the gpu feature is not enabled, the compiler warns about unused imports of DEFAULT_TOUCH_DEVICE_HEIGHT and DEFAULT_TOUCH_DEVICE_WIDTH. Put these imports behind a cfg check to silence the warning. BUG=None TEST=cargo build TEST=emerge-nami crosvm # test with gpu feature enabled Change-Id: Ib60072cc78a8ffd0ac39dcb4d3a60ba4c9d424b5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2080645 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* ac97: switch to ShmStreamSourceFletcher Woodruff2020-02-28
| | | | | | | | | | | | | | | | | | | | | Convert playback and capture for the AC97 device to use the zero-copy ShmStreamSource instead of the old StreamSource. In the process, rework start_playback and start_capture unit tests so they rely less on sleep statements. BUG=chromium:968724 BUG=chromium:1006035 TEST="sox -n -r 48000 -b 16 output.raw synth 5 sine 330 && aplay -f dat output.raw" within a VM, check that sine wave is played accurately. Change-Id: Ie9cddbc5285a9505872c9951a8a1da01de70eb88 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749950 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
* linux: add disk path to open error messageDaniel Verkamp2020-02-27
| | | | | | | | | | | | | | | | | | | Previously, if a disk could not be opened, the error message did not include the path of the disk, e.g.: The architecture failed to build the vm: error creating devices: failed to load disk image: Read-only file system (os error 30) To make debugging easier, add the path to Error::Disk. BUG=b:150181514 TEST=crosvm run --rwdisk ro.img vm_kernel Change-Id: I7b319c419b889334ecadbb0497dc4b3dc5115aa6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2070844 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* linux.rs: Don't pivot_root when using host's root directoryChirantan Ekbote2020-02-22
| | | | | | | | | | | | | | | pivot_root(2) will fail with EBUSY if we try to pivot_root to "/". Check for this case and skip the pivot_root if necessary. BUG=b:147258662 TEST=`tast run <dut> vm.Virtiofs` Change-Id: I1d7645844e183222a561578677fc5f59c080d58c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2067823 Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* linux.rs: Refactor 9p device jailChirantan Ekbote2020-02-21
| | | | | | | | | | | | | | | | | Give the 9p device the same jail as the fs device. In particular it needs a higher max open file limit and should map the current euid/egid in its user namespace rather than always using the crosvm user. BUG=b:147258662 TEST=`tast run <dut> vm.Blogbench.p9` Change-Id: I12e7ba7b651da4bae1435e0598b62fe2c35ff1bf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2065254 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* linux.rs: unify jail creationMatt Delco2020-02-19
| | | | | | | | | | | | | | | | This change unifies two substantially similiar segments of code used to create a jail. BUG=none TEST=Ran 'build_test'. Local build, deployed to DUT, and verified that termina VM could still be used. Change-Id: Ib1f2f9bc5cfe1e6c9f3633af7e23f52e5eafe3c7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2057744 Tested-by: Matt Delco <delco@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Matt Delco <delco@chromium.org>
* acpipm: implement suspend and resume mechanismChuanxiao Dong2020-02-19
| | | | | | | | | | | | | | | | | | | For suspend request from VM, will write suspend event and notify crosvm main process to pause VCPUs. For resume request, it is not from VM itself but by the resume command through crosvm socket. Resume request will notify the PM device to fill its wakeup registers with wakeup event so that when VCPUs start to run, VM can know there is wakeup from outside. BUG=chromium:1018674 TEST=cargo test -p devices Change-Id: I4724ffee10150065a62bf520076c16cbc70b7749 Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035169 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
* Use display size as the default size for single touchKaiyi Li2020-02-12
| | | | | | | | | | | | | | | When the user specifies the display size through the gpu argument but not specifies the size of the single touch device, the display size will be used as the size of these touch devices. Use default() to initialize the GpuParameters. Allow initialize the GpuParameters dynamically in the future. Change-Id: I9fa04f8ff479732370514fbaeb062d737adba319 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2043072 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Kaiyi Li <kaiyili@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Allow mounts to propagate into 9p device jailChirantan Ekbote2020-02-04
| | | | | | | | | | | | | | | | | Allow mounts from the parent namespace to propagate into the mount namespace of the 9p device process. BUG=none TEST=none Change-Id: Iff455c8967949bd3e0f2990c947d45bbbc541d45 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2018305 Reviewed-by: Yusuke Sato <yusukes@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: Yusuke Sato <yusukes@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Chirantan Ekbote <chirantan@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* crosvm: pstore works for ARCVM on x86_64Kansho Nishida2020-02-03
| | | | | | | | | | | | | | | | Adds support for pstore on ARCVM on x86_64. The backend file of the buffer will be passed via argument of the crosvm. BUG=b:144962428 TEST=kernel crash on eve-arcvm, check /sys/fs/pstore/console-ramoops-0 Launch crostini manually on eve-arcvm Change-Id: I29492ac7a9067aa2ae23eb03fbb942ab7dd3aa8d Signed-off-by: Kansho Nishida <kansho@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1973391 Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Kansho Nishida <kansho@chromium.org>
* linux: use ScopedEvent to trigger the `exit_evt` in vcpu threadsZach Reizner2020-02-01
| | | | | | | | | | | | | | | | The VCPU thread can panic when there is a bug, and this should trigger an exit in crosvm instead of hanging the VCPU thread forever. BUG=None TEST=run crosvm with kernel, trigger a vcpu exit using guest Change-Id: I1df0e04eda73ad67fec20adeff893f6c00699318 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2029929 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org>
* crosvm: add support for bpf policy filesMatt Delco2020-01-22
| | | | | | | | | | | | | | | | | | | | Change adds supports for providing pre-compiled bpf files as the policy file for jailing. In short it's more effient to compile once on the build machine than each time at runtime. Additionally libminijail's support for more efficient bpfs (which use a binary tree instead of a linear search) is currently only available via tools that are based around pre-compiled use. BUG=None TEST=Ran build_test and verified that tests can pass with both bpf and policy files (though the tests might only exercise the jail for the plugin). Change-Id: Idd93e3c802fc79da93850d6bad1db660576bc9ba Signed-off-by: Matt Delco <delco@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1914416 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* MsgSocket: Don't implement DerefChirantan Ekbote2020-01-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Deref trait is usually only implemented by smart pointers or by trivial wrappers around the underlying type. MsgSocket does not fit into either category because it wraps a `UnixSeqPacket` to provide new functionality. Having it implement can lead to confusing error messages, especially for people who are new to rust and are not familiar with the Deref trait and Deref coercion. For example, calling `sock.send()` on a MsgSocket without first adding `use msg_socket::MsgSender` leads to the compiler complaining about mis-matched types for the `send` method. `UnixSeqPacket::send` expects a `&[u8]` while `MsgSocket::send` expects a `&M`. The compiler also gives no clues that it is implicitly coercing the socket to a `&UnixSeqPacket` and using the `send` method from there. Drop the `Deref` implementation. `MsgSocket` already implements `AsRef<UniqSeqPacket>` so anything that _needs_ to access the underlying `UnixSeqPacket` should just use that. BUG=none TEST=unit tests Change-Id: If02ef7173ae21d85d517e808489ed4d6d09ae90b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2002997 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* 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>
* 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>
* crosvm: align pmem region size to 2MiBStephen Barber2020-01-07
| | | | | | | | | | | | | | | | | Linux commit 7ea6216049ff9cf250a6722cd766d99c8d1424e5 "mm/sparsemem: prepare for sub-section ranges" added validation of memory region sizes for hotplugging. This requires alignment of the region to 2MiB, which can be done with a MemoryMappingArena that will pad the end of the region with read-only pages. BUG=chromium:1031408 TEST=crostini.Sanity.artifact with 5.4 guest kernel Change-Id: I526f23a5ef32edd3268cd23f010e2bc20f9c305a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1979257 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: 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>
* Cast refernces of libc::RLIMIT_NOFILE to i32 for newer libc crate.Allen Webb2019-12-26
| | | | | | | | | | | | BUG=chromium:1021609 TEST=emerge-sand crosvm Change-Id: I9658d3816cc846be2b6320f2f03036375de67cbe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1979532 Tested-by: Allen Webb <allenwebb@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Commit-Queue: Allen Webb <allenwebb@google.com>
* crosvm: treat FailEntry as fatal to a vcpuStephen Barber2019-12-20
| | | | | | | | | | | | | | | | | FailEntry indicates an arch-specific failure to enter a VM. Treat this as fatal to the vcpu. Pass the u64 hardware failure reason from the kvm_run struct up to the client. BUG=chromium:1036009 TEST=crosvm on hatch nested VM dies immediately instead of infinite looping Change-Id: Iecb279b5b08ae1edc085717dce65e3ca46cbd30e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1977221 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* 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>
* Remove render node forward codeLepton Wu2019-12-10
| | | | | | | | | | | | | We don't use it for ARCVM now. BUG=None TEST=`emerge-eve crosvm` Change-Id: I14343a2eb24c24a0216950b7c4eeb56ac482973e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1958569 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Lepton Wu <lepton@chromium.org> Auto-Submit: Lepton Wu <lepton@chromium.org>