summary refs log tree commit diff
path: root/devices/src/virtio/gpu/mod.rs
Commit message (Collapse)AuthorAge
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* edition: Eliminate blocks superseded by NLLDavid Tolnay2019-04-17
| | | | | | | | | | | | | | | | | | | | Before the new borrow checker in the 2018 edition, we sometimes used to have to manually insert curly braced blocks to limit the scope of borrows. These are no longer needed. Details in: https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html TEST=cargo check --all-features TEST=local kokoro Change-Id: I59f9f98dcc03c8790c53e080a527ad9b68c8d6f3 Reviewed-on: https://chromium-review.googlesource.com/1568075 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>
* clippy: Resolve while_let_loopDavid Tolnay2019-04-17
| | | | | | | | | | | TEST=bin/clippy Change-Id: Iae447ec2c1b095286ab02cd153bd2daafe95fae1 Reviewed-on: https://chromium-review.googlesource.com/1566894 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>
* edition: Remove extern crate linesDavid Tolnay2019-04-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Rust 2018 edition, `extern crate` is no longer required for importing from other crates. Instead of writing: extern crate dep; use dep::Thing; we write: use dep::Thing; In this approach, macros are imported individually from the declaring crate rather than through #[macro_use]. Before: #[macro_use] extern crate sys_util; After: use sys_util::{debug, error}; The only place that `extern crate` continues to be required is in importing the compiler's proc_macro API into a procedural macro crate. This will hopefully be fixed in a future Rust release. extern crate proc_macro; TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=local kokoro Change-Id: I0b43768c0d81f2a250b1959fb97ba35cbac56293 Reviewed-on: https://chromium-review.googlesource.com/1565302 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* edition: Fill in macro importsDavid Tolnay2019-04-15
| | | | | | | | | | | | | | | | | | | | Macros were previously imported through `#[macro_use] extern crate`, which is basically a glob import of all macros from the crate. As of 2018 edition of Rust, `extern crate` is no longer required and macros are imported individually like any other item from a dependency. This CL fills in all the appropriate macro imports that will allow us to remove our use of `extern crate` in a subsequent CL. TEST=cargo check --all-features --tests TEST=kokoro Change-Id: If2ec08b06b743abf5f62677c6a9927c3d5d90a54 Reviewed-on: https://chromium-review.googlesource.com/1565546 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* gpu: Simplify imports from gpu_*David Tolnay2019-04-15
| | | | | | | | | | | | | | | | | The gpu_buffer, gpu_display, and gpu_renderer refer to crates outside of the devices crate. Typically importing from other crates is written as: use name_of_crate::path::to::ThingToImport; TEST=cargo check --features gpu Change-Id: Ic7b1a3fa6b4a06fca7f3e9ed09cbd2a9982279cc Reviewed-on: https://chromium-review.googlesource.com/1565726 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* edition: Use 2018-style paths in devices crateDavid Tolnay2019-04-09
| | | | | | | | | | | | | | | | These are import paths in new code added since CL:1513054 that need to be made compatible with 2018 edition's treatment of paths. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: Icb3ecf2fb2015332e0c03cdc22bff2ecab2c40df Reviewed-on: https://chromium-review.googlesource.com/1559264 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* devices: gpu: Silently accept empty command buffers.David Riley2019-04-03
| | | | | | | | | | | | | | Prior to this change empty command buffers would generate errors and syslogs. BUG=None TEST=glbench nop_virtgpu_execbuffer test Change-Id: I456fb342c945beebe121e22543bd93fe41cc5cbe Reviewed-on: https://chromium-review.googlesource.com/1532796 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: improve get_device_bars/caps interfaceDaniel Prilik2019-03-28
| | | | | | | | | | | | | | | | Removes an unnecessary Option from the return type. Also added a note about moving PCI methods out of the VirtioDevice trait, as the trait shouldn't be tied to any particular transport layer. BUG=chromium:936567 TEST=cargo build --features=gpu Change-Id: I2c75c830bbe2d2b4a15461e8497535c526775bbe Reviewed-on: https://chromium-review.googlesource.com/1536206 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* virtio-gpu: add a BAR for deviceGurchetan Singh2019-03-05
| | | | | | | | | | | | BUG=chromium:924405 TEST=compile Change-Id: I8a583df2a9db4ea7e066eb284eac54fc62580350 Reviewed-on: https://chromium-review.googlesource.com/1480744 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* error: Print errors using Display implDavid Tolnay2019-02-20
| | | | | | | | | | | | | | | | | | | | | | | | | I have been running into Debug-printed error messages too often and needing to look up in the source code each level of nested errors to find out from the comment on the error variant what the short name of the variant means in human terms. Worse, many errors (like the one shown below) already had error strings written but were being printed from the calling code in the less helpful Debug representation anyway. Before: [ERROR:src/main.rs:705] The architecture failed to build the vm: NoVarEmpty After: [ERROR:src/main.rs:705] The architecture failed to build the vm: /var/empty doesn't exist, can't jail devices. TEST=cargo check --all-features TEST=FEATURES=test emerge-amd64-generic crosvm Change-Id: I77122c7d6861b2d610de2fff718896918ab21e10 Reviewed-on: https://chromium-review.googlesource.com/1469225 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>
* devices: gpu: dup stdout to stderr to allow virglrenderer loggingDavid Riley2019-01-31
| | | | | | | | | | | | | | | | By default virglrenderer logs to stderr with VREND_DEBUG. dup stdout which is logged via logger to stderr so that virglrenderer logs can be seen. BUG=chromium:925590 TEST=cat /var/log/messages Change-Id: I3e1a5056dab9cfd895867b1835b421b144ee536b Reviewed-on: https://chromium-review.googlesource.com/1441352 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: gpu: preserve stdout and stderr for virglrender loggingDavid Riley2019-01-31
| | | | | | | | | | | | BUG=chromium:925590 TEST=tail -f /var/log/messages Change-Id: I1d2d3177f6a83d6631eab11ff455813f99f62406 Reviewed-on: https://chromium-review.googlesource.com/1440032 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: gpu: name gpu threadDavid Riley2019-01-30
| | | | | | | | | | | | BUG=chromium:925590 TEST=pstree Change-Id: I2f591894db2a40a812f1720e1fc8422049d85902 Reviewed-on: https://chromium-review.googlesource.com/1440031 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Riley <davidriley@chromium.org>
* devices: gpu: add resource bridge to fds to keep when jailedDavid Riley2019-01-09
| | | | | | | | | | | BUG=chromium:837073 TEST=vmc start --enable-gpu tatl; lxc start stretch-x; xterm && glxgears Change-Id: I3730fd8f2fc9d0ea4c0180d43f3253246fabd14a Reviewed-on: https://chromium-review.googlesource.com/1401111 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* toolchain: Update to Rust 1.31.0David Tolnay2018-12-13
| | | | | | | | | | | | | | | | | | We updated the production toolchain from 1.30 to 1.31 in CL:1366446. This CL does the same upgrade for the local developer toolchain and Kokoro. The relevant changes are in rust-toolchain and kokoro/Dockerfile. The rest are from rustfmt. TEST=cargo fmt --all -- --check TEST=as described in kokoro/README.md Change-Id: I3b4913f3e237baa36c664b4953be360c09efffd4 Reviewed-on: https://chromium-review.googlesource.com/1374376 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: allow virtio-wayland to use virtgpu resourcesZach Reizner2018-12-11
| | | | | | | | | | | | | | | | This change uses the resource bridge between virtio-gpu and virtio-cpu to send resources over the host wayland connection that originated from the virtio-gpu device. This will help support gpu accelerated wayland surfaces. BUG=chromium:875998 TEST=wayland-simple-egl Change-Id: I3340ecef438779be5cb3643b2de8bb8c33097d75 Reviewed-on: https://chromium-review.googlesource.com/1182793 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* lint: Resolve the easier clippy lintsDavid Tolnay2018-12-03
| | | | | | | | | | | | | | | | | | | | Hopefully the changes are self-explanatory and uncontroversial. This eliminates much of the noise from `cargo clippy` and, for my purposes, gives me a reasonable way to use it as a tool when writing and reviewing code. Here is the Clippy invocation I was using: cargo +nightly clippy -- -W clippy::correctness -A renamed_and_removed_lints -Aclippy::{blacklisted_name,borrowed_box,cast_lossless,cast_ptr_alignment,enum_variant_names,identity_op,if_same_then_else,mut_from_ref,needless_pass_by_value,new_without_default,new_without_default_derive,or_fun_call,ptr_arg,should_implement_trait,single_match,too_many_arguments,trivially_copy_pass_by_ref,unreadable_literal,unsafe_vector_initialization,useless_transmute} TEST=cargo check --features wl-dmabuf,gpu,usb-emulation TEST=boot linux Change-Id: I55eb1b4a72beb2f762480e3333a921909314a0a2 Reviewed-on: https://chromium-review.googlesource.com/1356911 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* devices: convert virtio features to a u64Daniel Verkamp2018-11-21
| | | | | | | | | | | | | | | | | | | | | The virtio specification only defines feature bits in the 0-63 range currently, so we can represent the features as a u64. The Linux kernel makes the same simplifying assumption, and very few features have been defined beyond the first 32 bits, so this is probably safe for a while. This allows the device models to be simplified, since they no longer need to deal with the features paging mechanism (it is handled by the generic virtio transport code). BUG=None TEST=build_test; boot termina on kevin Change-Id: I6fd86907b2bdf494466c205e85072ebfeb7f5b73 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1313012 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: pci: support level-triggered interruptsDaniel Verkamp2018-10-29
| | | | | | | | | | | | | | | | Register the irqfd with resample support so that we can correctly emulate level-triggered interrupts. This requires each PciDevice to listen for interrupt_resample events and re-assert the IRQ eventfd if it should still be active. BUG=None TEST=Boot crosvm on x86-64 and arm devices Change-Id: I5cf8d1d1705cf675b453962c00d2d606801fee91 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1298654 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* cargo fmt all source codeZach Reizner2018-10-09
| | | | | | | | | | | | | | Now that cargo fmt has landed, run it over everything at once to bring rust source to the standard formatting. TEST=cargo test BUG=None Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b Reviewed-on: https://chromium-review.googlesource.com/1259287 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* virtio-gpu: use the newest capsGurchetan Singh2018-10-05
| | | | | | | | | | | | | | | | | | | | | capset2 has many new features. We currently hardcode num_capsets to 1, however our Mesa/guest kernel/virglrenderer are new enough to support caps v2. We could attempt to do negotiation (see virtio_gpu_virgl_get_num_capset in QEMU), but virtio::gpu::Gpu::get_config actually comes before virtio::gpu::Gpu::activate. To support older Mesa/guest kernel/virglrenderer configurations, this must be refactored. BUG=none TEST=get a gles31 context on tatl Change-Id: I8d9ed54774a63da2ec5a4ba86187330521785566 Reviewed-on: https://chromium-review.googlesource.com/1258323 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
* gpu: add sandboxing via minijail for virtio gpu device.David Riley2018-09-17
| | | | | | | | | | | | | | | | | Sandboxing only works when started as chronos via concierge client. If started directly via crosvm as root, the jail will not have proper group permissions to access the Wayland socket. BUG=chromium:837073 TEST=build with --features=gpu; null_platform_test without --disable-sandbox CQ-DEPEND=CL:1213779 Change-Id: I6331f7ae1f5b99d31ad44cf158f72337294771f0 Reviewed-on: https://chromium-review.googlesource.com/1181168 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* virtio-gpu: fix reporting of VIRTIO_F_VERSION_1Daniel Verkamp2018-09-05
| | | | | | | | | | | | | | | The virtio 1.0 feature flag is defined as a shift count, not a mask. While we're at it, change the virtio gpu features() function to the avail_features style used in other devices for consistency. BUG=None TEST=None Change-Id: I704d9676cfe5f13d9a2f83eb9160937e94070d1e Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1198224 Reviewed-by: Zach Reizner <zachr@chromium.org>
* gpu: add force_ctx_0 calls prior to each gpu commandDavid Riley2018-07-30
| | | | | | | | | | | BUG=None TEST=build with --features=gpu; null_platform_test Change-Id: Ib7aab8b2f0d7e1523df49360ab99677b59ce6052 Reviewed-on: https://chromium-review.googlesource.com/1073960 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* gpu: add support for fencesDavid Riley2018-07-30
| | | | | | | | | | | BUG=None TEST=build with --features=gpu; null_platform_test Change-Id: Ib863c8ef3e85aa0f345c1f20be414979808b6a17 Reviewed-on: https://chromium-review.googlesource.com/1073959 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* gpu: make process_descriptor return OptionDavid Riley2018-07-30
| | | | | | | | | | | | | | | In preparation of adding fence support, allow process_descriptor to defer returning the descriptor until later by returning None. BUG=None TEST=build with --features=gpu; null_platform_test Change-Id: I57e4dc438e7f5a925c870e0bd596f89a2ed4e083 Reviewed-on: https://chromium-review.googlesource.com/1073957 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* gpu: fix parsing of third descriptor in chainDavid Riley2018-07-25
| | | | | | | | | | | | | | | Descriptor chains of three descriptors were not having the last descriptor parsed correctly which resulted in some commands not properly being responded to. BUG=None TEST=build with --features=gpu; null_platform_test Change-Id: Ia77c7ca485ded7cdcb71fd62e8f6be5c226df1bf Reviewed-on: https://chromium-review.googlesource.com/1073956 Commit-Ready: David Riley <davidriley@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* gpu_buffer: fix reading and writing to GPU buffersZach Reizner2018-07-25
| | | | | | | | | | | | | | | | | | | | The original methods for reading and writing to GPU buffers naively assumed that the mappings returned by GBM were to the first byte in the buffer. In fact, the returned mapping is to the first pixel of the mapped rectangle. This would lead to segaults when the copy routine would breeze past the end of the mapping into segault territory. This change fixes the read and write algorithms and adds lots more guard rails in to prevent future undefined behavior (hopefully). TEST=boot kernel with VT and VIRTIO_GPU BUG=None Change-Id: Ia7c968b6dd274551b6d218e2f0b255af6e55bd35 Reviewed-on: https://chromium-review.googlesource.com/1102110 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* gpu: implement virtio-gpuZach Reizner2018-07-20
Basic 2D and 3D support is there. The drm_cursor_test and null_platform_test in drm-tests should run to completion. The extra device is hidden behind both a build time feature called 'gpu' and the device is only added to a VM if the '--gpu' flag is given. TEST=build with --features=gpu; drm_cursor_test && null_platform_test BUG=chromium:837073 Change-Id: Ic91acaaebbee395599d7e1ba41c24c9ed2d84169 Reviewed-on: https://chromium-review.googlesource.com/1036862 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>