summary refs log tree commit diff
path: root/sys_util
Commit message (Collapse)AuthorAge
* crosvm: add cmdline flags for configuring serial outputs in guest machineTrent Begin2019-05-15
| | | | | | | | | | | | | | | | This change allows an output to be set for each serial device for a guest machine (stdout, syslog, or sink). BUG=chromium:953983 TEST=FEATURES=test emerge-sarien crosvm; cd sys_util; cargo test; ./build_test; manual testing on x86_64 and aarch_64 Change-Id: I9e7fcb0b296c0f8a5aa8d54b1a74ae801f6badc8 Reviewed-on: https://chromium-review.googlesource.com/1572813 Commit-Ready: Trent Begin <tbegin@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Trent Begin <tbegin@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* 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>
* sys_util: add size to mmap InvalidRange errorDaniel Verkamp2019-04-22
| | | | | | | | | | | | | | | | The current error doesn't provide sufficient information to debug InvalidRange errors; add the size of the region so that the bounds of the comparison can be determined from the error message. BUG=None TEST=cargo test -p sys_util Change-Id: I8e7fbd750ab84c43bbf0435230b7d3cf466783da Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1574964 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>
* clippy: Resolve cast_ptr_alignmentDavid Tolnay2019-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | This CL fixes four cases of what I believe are undefined behavior: - In vhost where the original code allocates a Vec<u8> with 1-byte alignment and casts the Vec's data pointer to a &mut vhost_memory which is required to be 8-byte aligned. Underaligned references of type &T or &mut T are always undefined behavior in Rust. - Same pattern in x86_64. - Same pattern in plugin::vcpu. - Code in crosvm_plugin that dereferences a potentially underaligned pointer. This is always undefined behavior in Rust. TEST=bin/clippy TEST=cargo test sys_util Change-Id: I926f17b1fe022a798f69d738f9990d548f40c59b Reviewed-on: https://chromium-review.googlesource.com/1566736 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@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>
* 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 assign_op_patternDavid Tolnay2019-04-17
| | | | | | | | | | | TEST=bin/clippy Change-Id: I1cb259f399f9aff2b9b745413f9a28e130688a2b Reviewed-on: https://chromium-review.googlesource.com/1566657 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>
* sys_util: Enable macros imported individuallyDavid Tolnay2019-04-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The syslog and ioctl macros in sys_util were originally written to be imported through `#[macro_use] extern crate sys_util` which is essentially a glob import of all macros from the crate. In 2018 edition, extern crate is deprecated and macros are imported the same as any other item. As these sys_util macros are currently written, importing an individual macro requires the caller to also import any other sys_util macros that the invocation internally expands to. Example: use sys_util::{error, log}; fn main() { error!("..."); } This CL adjusts all sys_util macros to invoke helper macros through a `$crate::` prefix so that the caller is not required to have the helper macros in scope themselves. use sys_util::error; fn main() { error!("..."); } TEST=kokoro Change-Id: I2d9f16dca8e7a4a4c0e63d9f10ead9f7413d9c3c Reviewed-on: https://chromium-review.googlesource.com/1565544 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>
* sys_util: add MemoryMappingArenaDaniel Prilik2019-04-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | There is a hard-limit to the number of MemoryMaps that can be added to a KVM VM, a arch-dependent number defined as KVM_USER_MEM_SLOTS. e.g: on x86 this is 509 (512 - 3 internal slots). For most purposes, this isn't too much of an issue, but there are some cases where one might want to share a lot of mmaps with a Guest. e.g: virtio-fs uses a large cache region for mapping in slices of file fds directly into guest memory. If one tries to add a new KVM memory region for each mmap, the number of available slots is quickly exhausted. MemoryMappingArena is a way to work around this limitation by allocating a single KVM memory region for a large slice of memory, and then using mmap with MAP_FIXED to override slices of this "arena" hostside, thereby achieving the same effect without quickly exhausting the number of KVM memory region slots. BUG=chromium:936567 TEST=cargo test -p sys_util Change-Id: I89cc3b22cdba6756b2d76689176d7147cf238f07 Reviewed-on: https://chromium-review.googlesource.com/1546600 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>
* main: add --cpu-affinity option to pin VCPUsDaniel Verkamp2019-04-09
| | | | | | | | | | | | | | | | | | This allows setting the affinity of the VCPU threads to specific host CPUs. Note that each individual CPU has its affinity set to the full set of CPUs specified, so the host kernel may still reschedule VCPU threads on whichever host CPUs it sees fit (within the specified set). BUG=chromium:909793 TEST=build_test Change-Id: I09b893901caf91368b64f5329a6e9f39027fef23 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1554865 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: Use expect_err instead of panickingChirantan Ekbote2019-04-09
| | | | | | | | | | | | | | Use expect_err in the unix_seqpacket_zero_timeout test instead of `#[should_panic]` as the panic is causing a memory leak. BUG=chromium:950576 TEST=`USE=asan FEATURES=test emerge-amd64-generic sys_util` Change-Id: I7a42bbbc741a84398989393e3294747cd01cee14 Reviewed-on: https://chromium-review.googlesource.com/1558933 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* cargo: Sort all dependency lists in Cargo.tomlDavid Tolnay2019-04-09
| | | | | | | | | | | | | | | This may help reduce cases of conflicts between independent CLs each appending a dependency at the bottom of the list, of which I hit two today rebasing some of my open CLs. TEST=cargo check --all-features Change-Id: Ief10bb004cc7b44b107dc3841ce36c6b23632aed Reviewed-on: https://chromium-review.googlesource.com/1557172 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: Update sys_util to 2018 editionDavid Tolnay2019-04-08
| | | | | | | | | | | | | | | | | | Separated out of CL:1513058 to make it possible to land parts individually while the affected crate has no other significant CLs pending. This avoids repeatedly introducing non-textual conflicts with new code that adds `use` statements. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: Ic57170776a9396bab54a8c7eb2b8b1436f63b57c Reviewed-on: https://chromium-review.googlesource.com/1520069 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@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>
* sys_util: sock_ctrl_msg: Make clippy cleanDylan Reid2019-04-03
| | | | | | | | | Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I1a81590b5bf80dce7d35a6005fff66ed45a2ebe6 Reviewed-on: https://chromium-review.googlesource.com/1510434 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: ioctl: Make clippy cleanDylan Reid2019-03-28
| | | | | | | | | Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Ic01c67f12be6b76887796beb73d1bd82077b87b3 Reviewed-on: https://chromium-review.googlesource.com/1510433 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: clock: Make clippy cleanDylan Reid2019-03-28
| | | | | | | | | Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I321af88908e14af08886fdfe5191bde5335c247a Reviewed-on: https://chromium-review.googlesource.com/1510432 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: net: Make clippy cleanDylan Reid2019-03-26
| | | | | | | | | Use from instead of as. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I02342bd352cd98417011ceb5a79ba5bde5551a07 Reviewed-on: https://chromium-review.googlesource.com/1510071 Tested-by: kokoro <noreply+kokoro@google.com>
* sys_util: shm: Make clippy cleanDylan Reid2019-03-26
| | | | | | | | | | clippy wants a default impl for `MemfdSeals` Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I3202037f7b82d7d4e63154a349c505fd7707bb9a Reviewed-on: https://chromium-review.googlesource.com/1510070 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: write_zeros: Make clippy cleanDylan Reid2019-03-26
| | | | | | | | | | | favor `if let` over `match` for destructing a single value. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I0c09d7ffc380e84d7413d6fed338d65a60563a8f Reviewed-on: https://chromium-review.googlesource.com/1510069 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* sys_util: poll: Make clippy cleanDylan Reid2019-03-25
| | | | | | | | | | u64 casts switched to from, add a Default impl. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I17757a081d41df465c74c7a6b410159b4023c70e Reviewed-on: https://chromium-review.googlesource.com/1510068 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* crosvm: add memfd for GuestMemoryDaniel Prilik2019-03-25
| | | | | | | | | | | | | | | | | Building off CL:1290293 Instead of having a seperate GuestMemoryManager, this adds SharedMemory as a Arc'd member of GuestMemory. This is nice since it removes the need to plumb the Manager struct throughout the codebase. BUG=chromium:936567 TEST=cargo test -p sys_util Change-Id: I6fa5d73f7e0db495c2803a040479818445660345 Reviewed-on: https://chromium-review.googlesource.com/1493013 Commit-Ready: Daniel Prilik <prilik@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: errno: Make clippy cleanDylan Reid2019-03-21
| | | | | | | | | | | Fix one warning about unnecessary ref. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I4a01d9762866d8eb7ed661e6c06fe3722d008ec4 Reviewed-on: https://chromium-review.googlesource.com/1510067 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: don't use hostname in syslog message headerChris Morin2019-03-20
| | | | | | | | | | | | | | | | | The putting the hostname in the syslog header of messages sent to /dev/log isn't widely supported. It isn't understood by rsyslogd by default, and it isn't understood by journald. Remove it as it provides no value to us. BUG=None TEST=Ensure journal properly parses the header from crosvm log messages Change-Id: I9bba78925f048f7d2ce6320b00b9fa52f070ce51 Reviewed-on: https://chromium-review.googlesource.com/1525139 Commit-Ready: Christopher Morin <cmtm@google.com> Tested-by: Christopher Morin <cmtm@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: timerfd: fix clippy lintsDylan Reid2019-03-20
| | | | | | | | | Use X::from() instead of as X. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Iefd412a4846d7f9bede57b68807e09cb43a5c579 Reviewed-on: https://chromium-review.googlesource.com/1510066 Tested-by: kokoro <noreply+kokoro@google.com>
* edition: Update absolute paths to 2018 styleDavid Tolnay2019-03-13
| | | | | | | | | | | | | | | | | | | | | | | | | | This is an easy step toward adopting 2018 edition eventually, and will make any future CL that sets `edition = "2018"` this much smaller. The module system changes in Rust 2018 are described here: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html Generated by running: cargo fix --edition --all in each workspace, followed by bin/fmt. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I000ab5e69d69aa222c272fae899464bbaf65f6d8 Reviewed-on: https://chromium-review.googlesource.com/1513054 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>
* sys_util: guest_address: take self by value in methodsDylan Reid2019-03-12
| | | | | | | | | | | clippy says that it is more efficient. Since self is a u64 in this case, it is correct. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Id7674db500a01640f650b239374fe9f83e2bc595 Reviewed-on: https://chromium-review.googlesource.com/1510065 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* data_model: ignore clippy error for mut from non-mutDylan Reid2019-03-09
| | | | | | | | | | | | | | | | A bug has been filed to fix this differently. Until then, add a TODO and a clippy disable so that clippy can be used to test for other issues without stopping on this error. BUG=928767 TEST=cargo clippy Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Ic264bc9101653c30354415c913e9ee3752985706 Reviewed-on: https://chromium-review.googlesource.com/1506308 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>
* Drop capabilities before spawning any vcpu threadDmitry Torokhov2019-03-08
| | | | | | | | | | | | | | | | | | In case crosvm starts with elevated capabilities (for example, we need to start with CAP_SETGID to be able to map additional gids into plugin jail), we should drop them before spawning VCPU threads. BUG=b:117989168 TEST=Start plugin via concierge_client and verify the process does not have any effective or permitted privileges. tast run [] 'vm.*' Change-Id: Ia1e80bfe19b296936d77fe9ffeda361211b41eed Reviewed-on: https://chromium-review.googlesource.com/1506296 Commit-Ready: Dmitry Torokhov <dtor@chromium.org> Tested-by: Dmitry Torokhov <dtor@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
* sys_util: remove deprecated functionspaulhsia2019-03-05
| | | | | | | | | | | | | | | | | Remove `write` and `read` after the only user in CL:1488597 change its usage. TEST=cargo test -p sys_util BUG=chromium:848187 CQ-DEPEND=CL:1488597 Change-Id: I15e03077f8970ea8350c7f64de9b64b16a08bfc1 Reviewed-on: https://chromium-review.googlesource.com/1488553 Commit-Ready: Chih-Yang Hsia <paulhsia@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Chih-Yang Hsia <paulhsia@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Reviewed-by: Zach Reizner <zachr@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>
* sys_util: add seqpacket featuresZach Reizner2019-02-28
| | | | | | | | | | | | | | | | This change adds the ability to make seqpacket pairs, and set the timeouts of the sockets. This also adds a TcpListener style api for accepting UnixSeqpacket sockets. TEST=cargo test -p sys_util BUG=chromium:848187 Change-Id: I9f9bb5224cdfaf257d8e4a1bdaac8128be874951 Reviewed-on: https://chromium-review.googlesource.com/1482371 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>
* Allow custom protection for mmap.Lepton Wu2019-02-27
| | | | | | | | | | | BUG=b:118408510 TEST=manual - build crosvm with/without crosvm-render-node-forward USE flag and run arcvm. Change-Id: I716fbd2f5daa0f109ef839b950ec6c88dc5a9c91 Reviewed-on: https://chromium-review.googlesource.com/1487774 Commit-Ready: Lepton Wu <lepton@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* fmt: Format sys_util and fuzz crates using rustfmtDavid Tolnay2019-02-21
| | | | | | | | | | | | | | | | | These are each their own workspace so I guess `cargo fmt` at the top level of the repo does not hit them. I checked that none of the other workspace roots currently need to be reformatted. TEST=cargo check Change-Id: I734cbc0f909fd3c2138513d9539b917bce80c0a8 Reviewed-on: https://chromium-review.googlesource.com/1477496 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>
* 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>
* Add IOCTL number functions that accept one parameterJorge E. Moreira2019-01-31
| | | | | | | | | | | | | | | Some IOCTL macros are define to accept a parameter, EVIOCGBIT is an example. This commit adds the ability to generate functions that accept any number of arguments to generate the IOCTL number. Bug=chromium:921271 Test=cargo test -p sys_util Change-Id: I966a3ac85e05764acff5d61cf85dc95b2b70ec20 Reviewed-on: https://chromium-review.googlesource.com/1406812 Commit-Ready: Jorge Moreira Broche <jemoreira@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: wait on specific pid in panic_safe testDaniel Verkamp2019-01-30
| | | | | | | | | | | | | | | | | | | | | | | | | The fork::tests::panic_safe unit test has been hanging intermittently in CQ runs. The root cause isn't understood yet, but the most likely explanation seems to be that the wait_process helper is hanging. There should be only two causes for that hang: either the cloned process is not exiting, or the wait() call in wait_process is not returning. The wait() should only hang if another thread has already reaped the cloned process. In order to help debug the issue, change the general wait() to a waitpid() on the specific cloned process ID. This will give us more information about what happens when the test fails - if the waitpid() returns ECHILD instead of hanging, this will indicate that something else is waiting on our child process and racing with our wait(). BUG=chromium:925725 TEST=cargo test --release -p sys_util panic_safe Change-Id: Ib25d88b35b16c75d4d8fe62fc779c9470303368a Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1444317 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Add FakeClock and FakeTimerFd for use in tests.Miriam Zimmerman2019-01-24
| | | | | | | | | | | | | | | | | Together, these allow tests to create a FakeTimerFd that they can trigger at a particular point in the test code, without having to rely on sleep()s or other racy methods. BUG=None TEST=Unit tests for FakeTimerFd + dependent CL. Change-Id: I14381272a6d75bebcdedb0a329a017a2131a3482 Reviewed-on: https://chromium-review.googlesource.com/1413830 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Miriam Zimmerman <mutexlox@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: Fix unit test error in armpaulhsia2019-01-23
| | | | | | | | | | | | | | | | | `libc::c_char` is `u8` instead of `i8` in arm, the test should use `libc::c_char` directly. Test unit tests with different architectures. BUG=chromium:907520 TEST=$ FEATURES=test emerge-{kevin,eve} sys_util Change-Id: Ie70da89470487d95675cb06b761e9ae9057bc38f Reviewed-on: https://chromium-review.googlesource.com/1430400 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Chih-Yang Hsia <paulhsia@chromium.org> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: refactor pollcontext to decouple events from epoll fd.Jingkui Wang2019-01-19
| | | | | | | | | | | | | | | | | PollContext is not thread safe while the underlying epoll is thread safe. This is because PollContext owns EpollEvents, to offer an easy to use interface. User of this package might want a thread safe version of Epoll. This CL decouples events from epoll fd, thus providing thread safe epoll. BUG=None TEST=cargo build and run Change-Id: I786b1d186664fdb4a95ce4d3062b044d27b74d40 Reviewed-on: https://chromium-review.googlesource.com/1320429 Commit-Ready: Jingkui Wang <jkwang@google.com> Tested-by: Jingkui Wang <jkwang@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* build: Restore ability to compile data_model and sys_util in isolationDavid Tolnay2019-01-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CL:1385972 breaks building these crates because they are not in the workspace of the top level Cargo.toml so the patch.crates-io setting of the top level Cargo.toml does not take effect. They end up looking for their dependencies on crates.io rather than in the parent directory. Being able to build just data_model and sys_util on their own is useful when iterating on a change in one of them and needing to run `cargo test` (as I tried to do today). The errors without this CL are like this: error: no matching package named `assertions` found location searched: registry `https://github.com/rust-lang/crates.io-index` required by package `data_model v0.1.0 (/path/to/crosvm/data_model)` BUG=chromium:916921 TEST=cargo check in data_model and sys_util TEST=cargo test as well TEST=emerge-amd64-generic crosvm TEST=FEATURES=test emerge-amd64-generic data_model, sys_util CQ-DEPEND=CL:1409854 Change-Id: I7bd34f38507c1cea72380f515ce2dd0835aec4fa Reviewed-on: https://chromium-review.googlesource.com/1403887 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
* memory: Add methods to return error on short writes and readsDavid Tolnay2019-01-13
| | | | | | | | | | | | | | | | | | | | Add GuestMemory::write_all_at_addr, GuestMemory::read_exact_at_addr which return error if the entire write or read cannot be completed. Also rename write_slice_at_addr to write_at_addr, read_slice_at_addr to read_at_addr to make the entire set of four methods consistent in naming with the methods of std::io::Write and std::io::Read. Context: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1387624/16/devices/src/virtio/tpm.rs#75 TEST=cargo test Change-Id: Ia0775b75281ccf8030c84b41f9018a511204b8c9 Reviewed-on: https://chromium-review.googlesource.com/1407156 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: Add net module includes UnixSeqpacketpaulhsia2019-01-10
| | | | | | | | | | | | | | | | | std::os::net only supprts UnixDatagram and UnixStream, so we need this to support the connection to socket opened with SOCK_SEQPACKET flag. It only supports public API connect, write, try_clone, and read now. BUG=chromium:907520 TEST=Use $ FEATURES=test emerge-eve sys_util to run unit tests. Change-Id: I61a9acd4fa2e601e93b1f76dc1758cb61a433205 Reviewed-on: https://chromium-review.googlesource.com/1390077 Commit-Ready: Chih-Yang Hsia <paulhsia@chromium.org> Tested-by: Chih-Yang Hsia <paulhsia@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Move validate_raw_fd to sys_utilChirantan Ekbote2019-01-07
| | | | | | | | | | | | | | validate_raw_fd is needed for the plugin crate. Move it into a common location so that it can be shared by both the linux and plugin code. BUG=b:80150167 TEST=manual Change-Id: I427e10716e75b2619fd0f4ba6725fa40446db4af Signed-off-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1341101 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* Add "Fd" wrapper for RawFd type.Miriam Zimmerman2019-01-05
| | | | | | | | | | | | | | This allows more type-safe usage of RawFds (preventing confusion with other c_ints) and provides a lightweight type that is usable in arguments to methods that take parameters of type AsRawFd. BUG=None TEST=Built. Change-Id: Ibdeb03b0e759577385b05acb25ce76d51f2188c6 Reviewed-on: https://chromium-review.googlesource.com/1396495 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Miriam Zimmerman <mutexlox@chromium.org> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add set_len() traitDaniel Verkamp2019-01-05
| | | | | | | | | | | | | | | | | Generalize file_sync into file_traits so that we can add another wrapper, this time for the set_len() method implemented directly on File. This will also be implemented on QcowFile. BUG=chromium:858815 TEST=build_test Change-Id: I43fbd1968a844c8cac359973a63babcc26942204 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1394148 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: Split sub-crates into independent workspacepaulhsia2019-01-03
| | | | | | | | | | | | | | | | | | | Split sub-crates under crosvm root directory into several independent workspaces for adding ebuild files for those crates. data_model and sys_util could only be built by emerge after creating their ebuilds. BUG=chromium:916921 TEST='emerge-eve crosvm' TEST=Run 'cargo build' under crosvm directory Change-Id: I2dddbbb7c7344e643183a5885e867f134b299591 Reviewed-on: https://chromium-review.googlesource.com/1385972 Commit-Ready: Chih-Yang Hsia <paulhsia@chromium.org> Tested-by: Chih-Yang Hsia <paulhsia@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>