summary refs log tree commit diff
path: root/devices/src/virtio/gpu
Commit message (Collapse)AuthorAge
* Fix VolatileSlice calls in all modulesDaniel Verkamp2020-05-27
| | | | | | | | | | | | | | | | | | The VolatileSlice API changed, but some callers were not updated to match. Fix them up so that builds with additional features enabled (e.g. kokoro) pass again. BUG=None TEST=cargo test -p disk --features=composite-disk TEST=docker/wrapped_smoke_test.sh Change-Id: I97b3cd04549af30b7dc1515245f025d9439669bc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2216399 Tested-by: Daniel Verkamp <dverkamp@chromium.org> Auto-Submit: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* Make VolatileSlice ABI-compatible with iovecChirantan Ekbote2020-05-25
| | | | | | | | | | | | | | | | | | | | | | Change VolatileSlice so that it is ABI-compatible with iovec. This allows us to directly pass in a VolatileSlice for a C function that expects an iovec without having to create temporaries that convert from one to the other. Also change all the parameters from u64 to usize. It's not possible to address more memory than fits into a usize so having u64 here didn't really provide much benefit and led to a lot of tedious casting back and forth all over the place. BUG=none TEST=unit tests Cq-Depend: chromium:2206621 Change-Id: I258f9123c603d9a4c6c5e2d4d10eb4aedf74466d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2203998 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* devices: gpu: random cleanupGurchetan Singh2020-05-22
| | | | | | | | | | | | | | | | - Remove unused phantom data - scannout --> scanout BUG=none TEST=compile Change-Id: I5054833025eef5be766b547fa3e61d2ca46e226f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2211154 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* Extract the DisplayBackend build process into BackendKind build functionKaiyi Li2020-05-08
| | | | | | | | | | | | | | | | All 3 different virtio gpu backends share the same process of creating the GpuDisplay instance, so move that process out of their separate build functions and put it in the shared BackendKind build function. BUG=None TEST=build_test Change-Id: Ie15bae48c8f1b75df49ba066a677020ec5dbf744 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2182041 Reviewed-by: Jason Macnak <natsu@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Kaiyi Li <kaiyili@google.com>
* devices: pci: refactor PCI devices to use PciAddress.Tomasz Jeznach2020-05-01
| | | | | | | | | | | | | | Simple refactor of PCI device addressing to use PciAddress type providing bus:device.function number. BUG=None TEST=build_test & tast run crostini.Sanity Change-Id: I7755ad6b31aa8c882475cd8212630e1cc86ef49e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2172766 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
* Remove unnecessary parentheses in constsDaniel Verkamp2020-04-26
| | | | | | | | | | | | | Fix clippy "error: unnecessary parentheses around assigned value." BUG=None TEST=bin/clippy Change-Id: I31e61c770c62d7ff2ca8525bf754bd615e24c349 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2163204 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* virtio-gpu: add support for exporting virtgpu resourcesDavid Stevens2020-04-04
| | | | | | | | | | | | | BUG=b:136269340 TEST=boot ARCVM and launch play store Change-Id: I2d78ffb15dcf2dc0f245916485f5ebb636ef6e78 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2014680 Reviewed-by: David Stevens <stevensd@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: David Stevens <stevensd@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
* gfxstream: fix buildLingfeng Yang2020-03-26
| | | | | | | | | | | | | | API for export_resource changed Bug: b/146066070 Change-Id: I614880704658bbe7aae2f7ad8b10c76555d99c1f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2102760 Tested-by: Lingfeng Yang <lfy@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Lingfeng Yang <lfy@google.com> Reviewed-by: Jason Macnak <natsu@google.com> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: gpu: complete resource V2 rebaseGurchetan Singh2020-03-23
| | | | | | | | | | | | | | | | * Remove RESOURCE_V2_UNREF * Add RESOURCE_MAP/RESOURCE_UNMAP to enable resources without guest storage that don't need to be mapped directly either BUG=chromium:924405 TEST=compile and test Change-Id: I10d6cd120d86131fa7ed8917ddad25cdb99ae50c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015587 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* devices: gpu: modify resource v2Gurchetan Singh2020-03-23
| | | | | | | | | | | | | | | | | | | | Rebase of zero-copy virtio-gpu flow: * Removes guest_memory_type/guest_caching_type in favor of a bitmask * Removes ALLOCATION_METADATA, since ideally we'd just read from guest memory to get guest responses * Renames HOST_COHERENT to HOST_VISIBLE * Adds a few more feature flags BUG=chromium:924405 TEST=compile Change-Id: I0d5a84b66cfa6d09f7e2d07ed8e761e7ba850284 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2013767 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Lingfeng Yang <lfy@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: virtio: resource_bridge: Transfer plane metadataKeiichi Watanabe2020-03-06
| | | | | | | | | | | | | | | | | Transfer plane offsets and strides for exported GPU resource over resource bridge as well as a resource itself. These metadata will be required by virtio-video decoder and encoder. BUG=b:120456557 TEST=Start ARCVM on atlas Change-Id: Iaf539857c0f8525bd5be294521e75ad32cae05e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1787032 Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Reviewed-by: David Stevens <stevensd@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
* 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>
* virtio-gpu: gfxstream backendLingfeng Yang2020-02-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds a new backend type, gfxstream, that calls out to a C library implementing the actual rendering. The purpose is to allow the Cuttlefish and Android Studio Emulator teams to use crosvm with the current API-forwarding style of rendering employed in the Android Studio Emulator. Also, introduces a new key to the --gpu command line interface, backend=, which selects from different backends. Note that the previous behavior is now deprecated and will be removed after some time (when all clients switch over to backend=). The gfxstream backend itself implements a subset of 3d-related resource and context creation/transfer/execbuffer commands. Their meaning is specific to the way in which they are interpreted in the backend library. To interface with display, gfx stream backend takes a callback that is run on guest vsync. The callback is responsible for repainting the display's contents. gfx stream provides a callback, get_pixels, that can be used asynchronously. The asyncness is not taken advantage of currently but will be useful for cases where the client attached to the VMM might want to update at a different rate than guest vsync. The guts of the stream backend library is currently defined here: https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/android-qemu2-glue/emulation/virtio-goldfish-pipe.cpp The linking of the library is controlled via the feature "gfxstream". If the feature is turned off, we use a default do-nothing stub impl. Next steps: - integrate virtio-gpu-next so as to have host coherent memory for vulkan - Figure out low latency command submit/response with SUBMIT_CMD_3DV2 BUG=b:146066070 Change-Id: If647381c15e5459cec85e2325f97e2f0a963b083 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2033305 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Lingfeng Yang <lfy@google.com> Reviewed-by: Lingfeng Yang <lfy@google.com> Reviewed-by: Jason Macnak <natsu@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Auto-Submit: Lingfeng Yang <lfy@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org>
* 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>
* virtio-gpu: implement 2D GPU BackendJason Macnak2020-02-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... which does not require virglrenderer (or any renderer). This will allow the Cuttlefish team to use minigbm as its gralloc implementation when both hardware acceleration is available and unavailable. Adds a GPU `Backend` trait with all of the existing methods of the current backend and converts the existing `Backend` into `Virtio3DBackend` which implements the new trait. Adds a `Virtio2DBackend` which creates resources with byte vectors on the host and implements transfers via the old code from gpu_buffer/src/lib.rs. Adds a runtime flag to select between 2D and 3D mode with 3D mode as the default. Moves the process_resource_bridge() function to the `Frontend` and instead expose a export_resource() function on the `Backend` to avoid some code duplication. BUG=b:123764798 TEST=build + launch cuttlefish w/ 2D mode (minigbm + custom hwcomposer) TEST=built + launch cuttlefish w/ 2D mode (minigbm + drm_hwcomposer) TEST=built + launch cuttlefish w/ 3D mode (minigbm + drm_hwcomposer) Change-Id: Ie5b7a6f80f7e0da72a910644ba42d2f34b246be8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1993913 Commit-Queue: Jason Macnak <natsu@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Lingfeng Yang <lfy@google.com>
* devices: virtio/gpu: support PCI shared mem capGurchetan Singh2020-01-25
| | | | | | | | | | | | | | The plan is to use shared mem cap for virtio-gpu. BUG=chromium:924405 TEST=build Change-Id: Id2829c2cd9883aca19641eff625c65a8db335e7a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963334 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* 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: gpu: log hung-up displayGurchetan Singh2020-01-08
| | | | | | | | | | | | | | This could be useful for debugging feedback reports. BUG=chromium:1027379 TEST=compile Change-Id: I520dedb0d0639f27cd5c2f81b09271bc4a243850 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1986298 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* devices: gpu: remove hung display from PollEventsGurchetan Singh2019-12-20
| | | | | | | | | | | | | | | | | | | This display isn't typically used when the virt-wl device is available and it can lead to hung fds during plug/unplug with external displays and docks. BUG=chromium:1027379, chromium:1027447 TEST= Tested five times each on R79-12607.47.0 sarien: => without patch --> CPU usage goes to 100% after unplug => with patch --> CPU usages remains normal Change-Id: Iea57f05002acc661f36b180e9e88c37b1f1b9047 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1977100 Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* Makes gpu renderer flags configurable via command lineJason Macnak2019-12-11
| | | | | | | | | | | | BUG=b:134086390 TEST=built crosvm and booted cuttlefish locally with gpu Change-Id: I4d816ddb52a2eadd06088d204d95118289a3f587 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927873 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Jason Macnak <natsu@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jason Macnak <natsu@google.com>
* 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>
* Support configurable screen sizesJason Macnak2019-12-10
| | | | | | | | | | | | | | | | | | This change enables Cuttlefish to run with a user specified display size on top of virtio gpu accelerated graphics rendering. This change makes the width and height an argument/flag and adds the necessary plumbing to pass this width and height through the gpu backend. BUG=b:134086390 TEST=built crosvm and booted cuttlefish locally Change-Id: Idabf7ef083b2377e3ebf3b50dd0296f4bf7e8ddc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927872 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Jason Macnak <natsu@google.com>
* devices: 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: 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>
* 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 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: Refactor DescriptorChainConsumer, Reader, and WriterChirantan Ekbote2019-10-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactor the Reader and Writer implementations for DescriptorChains. This has several changes: * Change the DescriptorChainConsumer to keep a VecDeque<VolatileSlice> instead of an iterator. This delegates the fiddly business of sub-slicing chunks of memory to the VolatileSlice implementation. * Read in the entire DescriptorChain once when the Reader or Writer is first constructed. This allows us to validate the DescriptorChain in the beginning rather than having to deal with an invalid DescriptorChain in the middle of the device operating on it. Combined with the check that enforces the ordering of read/write descriptors in a previous change we can be sure that the entire descriptor chain that we have copied in is valid. * Add a new `split_at` method so that we can split the Reader/Writer into multiple pieces, each responsible for reading/writing a separate part of the DescriptorChain. This is particularly useful for implementing zero-copy data transfer as we sometimes need to write the data first and then update an earlier part of the buffer with the number of bytes written. * Stop caching the available bytes in the DescriptorChain. The previous implementation iterated over the remaining descriptors in the chain and then only updated the cached value. If a mis-behaving guest then changed one of the later descriptors, the cached value would no longer be valid. * Check for integer overflow when calculating the number of bytes available in the chain. A guest could fill a chain with five 1GB descriptors and cause an integer overflow on a 32-bit machine. This would previously crash the device process since we compile with integer overflow checks enabled but it would be better to return an error instead. * Clean up the Read/Write impls. Having 2 different functions called `read`, with different behavior is just confusing. Consolidate on the Read/Write traits from `std::io`. * Change the `read_to` and `write_from` functions to be generic over types that implement `FileReadWriteVolatile` since we are not allowed to assume that it's safe to call read or write on something just because it implements `AsRawFd`. Also add `*at` variants that read or write to a particular offset rather than the kernel offset. * Change the callback passed to the `consume` function of `DescriptorChainConsumer` to take a `&[VolatileSlice]` instead. This way we can use the `*vectored` versions of some methods to reduce the number of I/O syscalls we need to make. * Change the `Result` types that are returned. Functions that perform I/O return an `io::Result`. Functions that only work on guest memory return a `guest_memory::Result`. This makes it easier to inter-operate with the functions from `std::io`. * Change some u64/u32 parameters to usize to avoid having to convert back and forth between the two in various places. BUG=b:136128319 TEST=unit tests Change-Id: I15102f7b4035d66b5ce0891df42b656411e8279f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1757240 Auto-Submit: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* virtio-gpu: handle VIRTIO_GPU_CMD_RESOURCE_CREATE_V2Gurchetan Singh2019-10-01
| | | | | | | | | | | | BUG=chromium:924405 TEST=compile Change-Id: I57379452f6805aaf429c268b95ddd3aecd07e90e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591463 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* virtio-gpu: handle VIRTIO_GPU_CMD_ALLOCATION_METADATAGurchetan Singh2019-10-01
| | | | | | | | | | | | | | Designed to return metadata to the guest. BUG=chromium:924405 TEST=compile Change-Id: Ic04a0bbb6b0a5bb6d08314371181f256eb7230df Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591464 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* devices: modify get_device_bars(..) interfaceGurchetan Singh2019-09-20
| | | | | | | | | | | | | | | Alloc::PciBar {..} is used as a key in the AddressAllocator's hashmap, so inform the device about the pci bus/dev numbers. BUG=chromium:924405 TEST=compile Change-Id: Ib9d94e516269c1dc9a375c2ceb9775cf5a421156 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1811585 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
* virtio-gpu: Use new + proposed virtio-gpu featuresGurchetan Singh2019-09-20
| | | | | | | | | | | | | BUG=chromium:924405 TEST=compile Change-Id: If7f2d35f66664a1a4e9a6e0883ea981b0ac3e87c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591462 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org>
* virtio-gpu: add new + proposed kernel protocolsGurchetan Singh2019-09-20
| | | | | | | | | | | | | BUG=chromium:924405 TEST=compile Change-Id: I550d5e60e8bde1378c226fc9da61eb60f1293811 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591461 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org>
* devices: gpu: Use descriptor_utils helpers for virtio processing.David Riley2019-09-17
| | | | | | | | | | | | | | | | | Switch to using Reader/Writer which allows buffers to be passed from the guest as scatter gathers instead of requiring a single contiguous buffer. BUG=chromium:993452 TEST=apitrace replay Change-Id: Ibe212cfa60eae16d70db248a2a619d272c13f540 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1775365 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: David Riley <davidriley@chromium.org>
* devices: join worker threads in drop()Daniel Verkamp2019-09-17
| | | | | | | | | | | | | | Make sure all devices join any threads they spawn before returning from the drop() handler after signaling the exit event. BUG=chromium:992494 TEST=crosvm exits without errors Change-Id: I6bc91c32a08f568b041765044caa9aff6f7cf4a9 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1802156 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: gpu: remove BackedBuffer/GpuRendererResource distinctionGurchetan Singh2019-08-20
| | | | | | | | | | | | | | | | | | | | | | | | | | We always advertise VIRTIO_GPU_F_VIRGL and don't activate the worker thread if Renderer::init fails. We're unlikely to encounter an platform where we can initialize a GBM device, but can't initialize virglrenderer. Since our virtio-gpu implementation depends on virglrenderer, we can pipe 2D hypercalls to virglrenderer (QEMU does this too, when built with the --enable-virglrenderer option). Also remove virgl_renderer_resource_info since it's unlikely to work with non-Mesa drivers. BUG=chromium:906811 TEST=kmscube renders correctly (though there's a prior bug in closing the rendering window -- see chromium:991830) Change-Id: I7851cd0837fd226f523f81c5b4a3389dc85f3e4f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1743219 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
* gpu_renderer: remove EGL related functionsGurchetan Singh2019-08-20
| | | | | | | | | | | | | | | | Now that we're not creating EGL images anymore, we can remove EGL logic. BUG=chromium:906811 TEST=freecad works without any local Mesa patches Change-Id: I09db1c828ae1a331eaeae7c66653a49fe42a04bf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1725451 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* gpu_renderer: use GBM inside virglrendererGurchetan Singh2019-08-20
| | | | | | | | | | | | | | | | | | | | | | With YUV support + modifier support coming up, it makes sense to move GBM allocation inside virglrenderer so we can upstream our use cases. In addition, this allows us to use gbm_bo_map(..) for the freecad issue, which would otherwise be resolved through local patches in our graphics drivers. BUG=chromium:906811 TEST=freecad works without Mesa patches Change-Id: I61db5c58a5bc5a79fda3cec8ad6c322fae6acc9e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1725450 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
* devices: virtio: add copy_config() helper functionDaniel Verkamp2019-08-16
| | | | | | | | | | | | | | | | | | | | | | | Add a new virtio configuration copying function to replace all of the slightly varying read_config() and write_config() implementations in our virtio devices. This replaces a lot of tricky bounds-checking code with a single central implementation, simplifying the devices to a single call to copy_config() in most cases. The balloon device is also changed to represent its config space as a DataInit struct to match most other devices and remove several unwrap() calls. BUG=None TEST=./build_test TEST=Boot vm_kernel+vm_rootfs in crosvm TEST=Start Crostini on nami Change-Id: Ia49bd6dbe609d17455b9562086bc0b24f327be3f Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749562 Reviewed-by: Dylan Reid <dgreid@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_display: add X11 backendZach Reizner2019-07-25
| | | | | | | | | | | | | | This change adds an X11 backend to the gpu_display crate. With this addition, the virtio-gpu device can display to traditional linux desktops that only have X11 output. Change-Id: I86c80cac91ca5bdc97588194a44040273ae69385 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591572 Reviewed-by: Stéphane Marchesin <marcheu@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Zach Reizner <zachr@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>
* devices: gpu: advertise support for capset 3Gurchetan Singh2019-07-16
| | | | | | | | | | | | | | | Useful for prototyping new features. BUG=chromium:924405 TEST=compile Change-Id: Ibdc4a70761493939ca96b92540b9e0cca88c17a8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650290 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
* virtio-gpu: Allocate buffers with shared bind flag using gbm.David Riley2019-07-03
| | | | | | | | | | | BUG=chromium:972237 TEST=eglgears_wayland Change-Id: If5a09c1ad95dfdbd47e7810c466c127c53413f21 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1657291 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: David Riley <davidriley@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
* gpu_renderer: make Box3 less error prone with constructorZach Reizner2019-06-24
| | | | | | | | | | | | | | | | | | | The argument order of the new_2d constructor was very odd. That has been changed to the ordinary x,y,w,h order. Also, each Box3 is checked by is_empty() before being used, which prevents some degenerate operations on zero area boxes. TEST=cargo run -- run --gpu BUG=None Change-Id: I6954fa4846f20353517fe81028058b639752d8ea Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670549 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: 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>
* 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>
* 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>
* devices: gpu: Fallback to allocating with virgl if no fourcc mapping.David Riley2019-05-16
| | | | | | | | | | | | | BUG=chromium:963559 TEST=freecad starts and displays Change-Id: I0d7a6ad5622b46a3fb0792eafd3dad1ed850e01d Reviewed-on: https://chromium-review.googlesource.com/1613842 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: David Riley <davidriley@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
* crosvm: add license blurb to all filesStephen Barber2019-04-24
| | | | | | | | | | | | | | A few files were missing license blurbs at the top, so update them all to include them. BUG=none TEST=none Change-Id: Ida101be2e5c255b8cffeb15f5b93f63bfd1b130b Reviewed-on: https://chromium-review.googlesource.com/1577900 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* edition: Eliminate ref keywordDavid Tolnay2019-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As described in: https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/default-match-bindings.html which also covers the new mental model that the Rust Book will use for teaching binding modes and has been found to be more friendly for both beginners and experienced users. Before: match *opt { Some(ref v) => ..., None => ..., } After: match opt { Some(v) => ..., None => ..., } TEST=cargo check --all-features TEST=local kokoro Change-Id: I3c5800a9be36aaf5d3290ae3bd3116f699cb00b7 Reviewed-on: https://chromium-review.googlesource.com/1566669 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>