summary refs log tree commit diff
path: root/devices/src/virtio/wl.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>
* 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: 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>
* use `SharedMemory::{named, anon}` to replace `::new`Zach Reizner2019-09-11
| | | | | | | | | | | | | | | | The new constructors are shorter and omit the bare `None` in the `anon` call sites which gave no clues to the reader what the effect of that `None` was. This should improve readability. TEST=./build_test BUG=None Change-Id: I2e34e7df9a4ccc5da50edf4e963a6a42e3d84b22 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1797188 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* 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>
* eliminate mut from non-mut referencesZach Reizner2019-06-04
| | | | | | | | | | | | | | | | | | | | | | | This manifested itself in a couple places that were turning shared memory buffers into slices for the purposes of passing these slices to `Read` and `Write` trait methods. However, this required the removal of the methods that took `Read` and `Write` instances. This was a convenient interface but impossible to implement safely because making slices from raw pointers without enforcing safety guarantees causes undefined behaviour in Rust. It turns out lots of code in crosvm was using these interfaces indirectly, which explains why this CL touches so much. TEST=crosvm run BUG=chromium:938767 Change-Id: I4ff40c98da6ed08a4a42f4c31f0717f81b1c5863 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1636685 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org>
* crosvm: {WlDriverRequest, WlDriverResponse} --> {VmMemoryRequest, ↵Gurchetan Singh2019-05-24
| | | | | | | | | | | | | | | | | VmMemoryResponse} These type of requests are not necessarily specific to the virtio-wl, and other devices (virtio-gpu) may want to use them. BUG=chromium:924405 TEST=compile Change-Id: Iad0889da8ab3d23bb2378448fc05e3c840a93d93 Reviewed-on: https://chromium-review.googlesource.com/1626791 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: Removes used_desc_heads arrays from various virtio devices.Jakub Staron2019-05-23
| | | | | | | | | | | | BUG=None TEST=tast run ${IP} vm.CrostiniStartEverything Change-Id: I14bdc330bff23ef3397251a81bdf63e37c1e1dfd Reviewed-on: https://chromium-review.googlesource.com/1611014 Commit-Ready: Jakub Staroń <jstaron@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* wl: limit vfd recv size to leave room for VFDsZach Reizner2019-05-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The IN_BUFFER_LEN variable limits the amount of data that will be read into a single page sized descriptor. The old value for it left room for the 16 byte header but reserved no space for VFDs. This happens to work fine if the size of the read data and VFDs did not exceed the buffer size, but, in rare circumstance, the maximum amount of data would be read along with a FD getting received, spilling the descriptor and causing it to fail to write to it. The guest driver does not handle this gracefully and usually panics due to corruption. The new value reserves room for the max number of VFDs so that the descriptors will not end up with too much data. BUG=chromium:951576 TEST=while true; do (/opt/google/cros-containers/bin/wayland_demo&); pkill -f /opt/google/cros-containers/lib/ld-linux-x86-64.so.2; done Change-Id: Ic0c1c10f81a91b5e5cd076e3ded8d3cc0564b614 Reviewed-on: https://chromium-review.googlesource.com/1623558 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* crosvm: Extracts Wayland commands from from VmRequest.Jakub Staron2019-04-27
| | | | | | | | | | | | | | | BUG=None TEST=cargo test TEST=cargo test --package msg_socket TEST=cargo test --package devices TEST=cargo test --package vm_control TEST=tast -verbose run ${IP} vm.CrostiniStartEverything Change-Id: I07f034b1cc41e30b9deae68ea9c510b0923e17a8 Reviewed-on: https://chromium-review.googlesource.com/1565299 Commit-Ready: Jakub Staroń <jstaron@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* clippy: Iterate without calling .iter()David Tolnay2019-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | See: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop https://rust-lang.github.io/rust-clippy/master/index.html#explicit_into_iter_loop Before: for element in slice.iter() {...} After: for element in slice {...} TEST=grep -r '\.iter() {' TEST=grep -r '\.iter_mut() {' TEST=grep -r '\.into_iter() {' TEST=cargo check --all-features TEST=local kokoro Change-Id: I27f0df7cfa1064b2c8b162cba263513926a433a9 Reviewed-on: https://chromium-review.googlesource.com/1568525 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 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>
* clippy: Resolve option_map_unit_fnDavid Tolnay2019-04-17
| | | | | | | | | | | TEST=bin/clippy Change-Id: I814cfce68c147f63d96fce6d0c465488ad3e336a Reviewed-on: https://chromium-review.googlesource.com/1566744 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: 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>
* Wrap the UnixSeqpacket with a more descriptive type.Jakub Staron2019-04-10
| | | | | | | | | | | | | | | | Host/device sockets are now created as a pairs of MsgSockets instead of UnixSeqpacket sockets. BUG=chromium:950663 TEST=cargo check TEST=cargo test Change-Id: I8f61a711fe3c2547bf5d18fcfa23bfd0dc0ef5fd Reviewed-on: https://chromium-review.googlesource.com/1559041 Commit-Ready: Jakub Staroń <jstaron@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Jakub Staroń <jstaron@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* edition: Use dyn syntax for trait objectsDavid Tolnay2019-04-08
| | | | | | | | | | | | | | | | | | | | | Found by running: `cargo rustc -- -D bare_trait_objects` Bare trait objects like `&Trait` and `Box<Trait>` are soft-deprecated in 2018 edition and will start warning at some point. As part of this, I replaced `Box<Trait + 'static>` with `Box<dyn Trait>` because the 'static bound is implied for boxed trait objects. TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=local kokoro Change-Id: I41c4f13530bece8a34a8ed1c1afd7035b8f86f19 Reviewed-on: https://chromium-review.googlesource.com/1513059 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>
* error: Consistently use Display instead of error description()David Tolnay2019-03-02
| | | | | | | | | | | | | | | | The description method is deprecated and its signature forces less helpful error messages than what Display can provide. BUG=none TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I27fc99d59d0ef457c5273dc53e4c563ef439c2c0 Reviewed-on: https://chromium-review.googlesource.com/1497735 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* crosvm: use seqpacket rather than datagram socketsZach Reizner2019-02-28
| | | | | | | | | | | | | | | | | | | | The advantage of seqpacket is that they are connection oriented. A listener can be created that accepts new connections, useful for the path based VM control sockets. Previously, the only bidirectional sockets in crosvm were either stream based or made using socketpair. This change also whitelists sendmsg and recvmsg for the common device policy. TEST=cargo test BUG=chromium:848187 Change-Id: I83fd46f54bce105a7730632cd013b5e7047db22b Reviewed-on: https://chromium-review.googlesource.com/1470917 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@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: wl: 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: Id8890ce23ed4202ab1cc698ca00a9d8017f24113 Reviewed-on: https://chromium-review.googlesource.com/1401112 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: make all virtio devices report version 1Daniel Verkamp2018-11-26
| | | | | | | | | | | | | | | | | Our virtio devices are all "modern" (no legacy/transitional support). Add VIRTIO_F_VERSION_1 to the features() handler for all virtio devices that didn't already have it. This lets us remove the hack that forced VIRTIO_F_VERSION_1 on for all devices. BUG=None TEST=build_test; boot crosvm on kevin Change-Id: I008926a9075679aae46069aa37a14504f10e8584 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1313013 Reviewed-by: Zach Reizner <zachr@chromium.org>
* wl: silence unused code warningsDaniel Verkamp2018-11-21
| | | | | | | | | | | | When wl-dmabuf is not enabled, rustc complains about unused imports and enum values. Add compiler directives to silence the warnings. BUG=None TEST='cargo build', 'emerge-nami crosvm' Change-Id: Ib39735d329f8aa835c0b5842b10bfe78d0e578d9 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1327827
* 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>
* crosvm: use msg_socket in vm_controlJingkui Wang2018-11-19
| | | | | | | | | | | | | Refactor existing code to use msg_socket. BUG=None TEST=local build and run Change-Id: Iee72326b330e035303f679e1aedd6e5d18ad4f8a Reviewed-on: https://chromium-review.googlesource.com/1260260 Commit-Ready: Jingkui Wang <jkwang@google.com> Tested-by: Jingkui Wang <jkwang@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* cargo fmt with Rust 1.30.0Daniel Verkamp2018-10-31
| | | | | | | | | | | | | | | Rust 1.30.0 ships a new rustfmt that causes a few more formatting changes. BUG=None TEST=Run kokoro tests with updated Rust version Change-Id: I803765ec0f3d2447f627b1e990bce438512367f7 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1307816 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@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>
* sys_util: remove Scm struct and sock_ctrl_msg C libraryZach Reizner2018-09-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Scm object was made to reduce the number of heap allocations in the hot paths of poll loops, at the cost of some code complexity. As it turns out, the number of file descriptors being sent or received is usually just one or limited to a fixed amount that can easily be covered with a fixed size stack allocated buffer. This change implements that solution, with heap allocation as a backup in the rare case that many file descriptors must be sent or received. This change also moves the msg and cmsg manipulation code out of C and into pure Rust. The move was necessary to allocate the correct amount of buffer space at compile time. It also improves safety by reducing the scope of unsafe code. Deleting the code for building the C library is also a nice bonus. Finally, the removal of the commonly used Scm struct required transitioning existing usage to the ScmSocket trait based methods. This includes all those changes. TEST=cargo test BUG=None Change-Id: If27ba297f5416dd9b8bc686ce740866912fa0aa0 Reviewed-on: https://chromium-review.googlesource.com/1186146 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>
* Move gpu allocator to resourcesDylan Reid2018-07-09
| | | | | | | | | | Combine GPU buffer allocation with the system resource allocator making life easier as only one allocator needs to get passed to the execute function. Change-Id: I199eb0fd6b99b629aaec1ae3295e8a1942da5309 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1099856
* sys_util: move round_to_page_size to sys_utilZach Reizner2018-06-21
| | | | | | | | | | | | | This function will be used elsewhere in gpu_display. TEST=None BUG=None Change-Id: I58b820511ea5a55a53ad640fdfe7c96d2dbdc73b Reviewed-on: https://chromium-review.googlesource.com/1105481 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>
* virtwl: implement dmabuf sync supportDavid Reveman2018-06-19
| | | | | | | | | | | | | | | | | | | | | This provides proper synchronization for guest access to DMABufs. Virtio wayland device is given access to the DMA_BUF_SYNC ioctl in order to implement this. Being able to use this directly in the virtio wayland device process is important as these calls can sometimes be relatively expensive and they are frequent enough that avoiding another context switch is useful for good performance. TEST=cache-line artifacts no longer noticeable BUG=chromium:837209 Change-Id: Ibb8d7c01f70ed5b74afd69288015a65186fec52a Reviewed-on: https://chromium-review.googlesource.com/1076928 Commit-Ready: David Reveman <reveman@chromium.org> Tested-by: David Reveman <reveman@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* wl: do not close FDs that were hungupZach Reizner2018-06-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | Before this CL, the WlState object would close VFDs that had been hungup on the remote end as a means to removing the underlying FD from the PollContext. However, this has some unintended side-effects. For one, the guest would later try to delete the VFD after it was closed, which was a double-free. Another was that every pending message that was waiting to enter the virtio queue would get dropped if it was destined for the closed VFD. This was especially bad if the virtio queue became full because data would get dropped when a VFD was hungup before the guest had any chance to read it. This CL leaves the hungup VFDs (and therefore their pending message) as is, but removes it from the PollContext if there is nothing left to read. No data is removed until after the guest explicitly closes the VFD. TEST=paste 100k characters into a guest app from Chrome BUG=chromium:849317 Change-Id: I20e3bc7c32c3f654f88f6ef9cdfcb853f2d52f09 Reviewed-on: https://chromium-review.googlesource.com/1088308 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: David Reveman <reveman@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* virtwl: better multi-plane DMABuf supportDavid Reveman2018-05-26
| | | | | | | | | | | | | | | | | | | Multi-plane DMABufs are useful for efficient video playback. The guest can already use this but has to guess the stride and offsets for the second and third plane as they are not passed by virtwl to the guest kernel. This extracts the correct strides and offsets for each buffer and passes them back to the guest in the allocation response message. BUG=chromium:837209 TEST=sommelier can use nv12 buffers without guessing stride/offset Change-Id: I36ae2fad6605293c907802121676296cbc607a57 Reviewed-on: https://chromium-review.googlesource.com/1070799 Commit-Ready: David Reveman <reveman@chromium.org> Tested-by: David Reveman <reveman@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* virtwl: Add DMABuf allocation support.David Reveman2018-05-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements DMABuf allocation type in the virtio wayland device. We attempt to locate a supported DRM device prior to engaging the device jail. If found, the DRM device is passed to the wayland device code and used to serve DMABuf allocations. DMABuf support can be disabled by not providing crosvm with access to any DRM device nodes. The guest is expected to handle the case when DMABuf allocation fails and fall-back to standard shared memory. This initial change uses DRM directly but is structured in a way that would allow the allocator to be replaced by minigbm with minimal effort. BUG=chromium:837209 TEST=crosvm finds drm device and returns valid dmabufs to guest Change-Id: Ic1fd776dfdfefae2d7b321d449273ef269e9cc62 Reviewed-on: https://chromium-review.googlesource.com/1034088 Commit-Ready: David Reveman <reveman@chromium.org> Tested-by: David Reveman <reveman@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* wl: send HUP event when VFDs are hungupZach Reizner2018-04-27
| | | | | | | | | | | | | | | | | | It is essential that paste operations on the guest receive a hangup letting them know that there is no more data to read. This change fixes that behavior, which was broken by thew new PollContext based logic, which separates out the readable and hungup code paths. TEST=finished wayland pastes receive EOF BUG=chromium:835112 Change-Id: I764124ab2eabb32d8cc25a3a4c0dfbe49b26e799 Reviewed-on: https://chromium-review.googlesource.com/1031292 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: David Reveman <reveman@chromium.org> Reviewed-by: David Reveman <reveman@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* devices: use nested PollContext in wayland deviceZach Reizner2018-04-06
| | | | | | | | | | | | | The wl device was the last user of the old Poller. BUG=chromium:816692 TEST=run wayland under crosvm Change-Id: I6c1c1db2774a6e783b7bd1109288328d75ad2223 Reviewed-on: https://chromium-review.googlesource.com/1000102 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* wl: add pipe vfd supportZach Reizner2018-04-05
| | | | | | | | | | | | | | Pipe VFDs are used to send and recieve data offer bytes, often used for copy/paste and drag/drop operations. TEST=use copy/paste with wayland app BUG=chromium:793688 Change-Id: Ifc3f231dcdf90ce6791a98039405c7c404cf6942 Reviewed-on: https://chromium-review.googlesource.com/983037 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* wl: avoid inserting empty virtio queue entriesZach Reizner2018-03-22
| | | | | | | | | | | | | | | | | | The kernel driver currently short circuits the check for empty queue entries if the entry arrives empty. Ordinarily the check is run every time data is taken out of a queue entry and would recycle the entry once empty. The short circuiting is being fixed in the kernel, but this device change fixes the unnecessary empty queue entries from happening in the first place. BUG=chromium:791724 TEST=test code from the BUG Change-Id: I5b72aac843def052bfe1234dfbde236274ae02bb Reviewed-on: https://chromium-review.googlesource.com/974883 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* crosvm: change GuestAddress to always be a u64Sonny Rao2018-02-01
| | | | | | | | | | | | | | | We want to be able to run 64-bit ARM kernels using a 32-bit version of crosvm, to make it more consistent use a u64 to represent GuestAddress. BUG=chromium:797868 TEST=./build_test passes on all architectures TEST=crosvm runs on caroline Change-Id: I43bf993592caf46891e3e5e05258ab70b6bf3045 Signed-off-by: Sonny Rao <sonnyrao@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/896398 Reviewed-by: Dylan Reid <dgreid@chromium.org>
* wl: increase max FDs to send/recvZach Reizner2017-11-15
| | | | | | | | | | | | | | This change is to support a related kernel change but is backwards compatible with kernels without that change. BUG=chromium:782474 TEST=None Change-Id: Ic1224b65ed9685f246002f946cfc6bfa2dbb2856 Reviewed-on: https://chromium-review.googlesource.com/770593 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* crosvm/devices: set thread namesStephen Barber2017-10-30
| | | | | | | | | | | | | | | | crosvm spawns a lot of processes/threads, and having these all use the same name as the original process can be confusing. So at least in the instances where Rust threads are spawned (vs. minijail_fork()), use a thread::Builder to allow setting the thread name. BUG=none TEST=start crosvm, check thread names with top Change-Id: I6e55ff5fd60f258880bda8e656ab7f9da82c656e Reviewed-on: https://chromium-review.googlesource.com/742394 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* Move crosvm/hw to a new devices moduleDylan Reid2017-10-09
Moving the devices to their own module makes it easier to add tests that use them. Change-Id: I61bfef4037d16b20145b5fddce604835cdc4f67b Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/706559 Reviewed-by: Zach Reizner <zachr@chromium.org>