summary refs log tree commit diff
path: root/crosvm_plugin
Commit message (Collapse)AuthorAge
* sys_util: Refactor IntoIovecChirantan Ekbote2020-05-28
| | | | | | | | | | | | | | | | | | | | | The original stated purpose of this trait was to reduce memory allocations but having the `into_iovec` method return a Vec kind of defeats that purpose. Refactor the trait so that it can either convert a T into an iovec or convert a &[T] into a &[iovec]. Implement the trait for VolatileSlice, IoSlice, and IoSliceMut and update all the callers. BUG=none TEST=unit tests Cq-Depend: chromium:2210272 Change-Id: I9d0d617a23030d241d50411f4a5a16e7cba4bcee Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2208527 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Tested-by: Chirantan Ekbote <chirantan@chromium.org>
* crosvm: add handling for hyperv exitsMatt Delco2020-03-05
| | | | | | | | | | | | | | | | | When features for Hyper-V are enabled there's a another type of exit that can be triggered. This change attempts to add support for those types of exits. BUG=b:150151095 TEST=ran build_test Change-Id: I3131a2c8d9c610576ac177dbfe82f78e8d5dbfb1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2073254 Reviewed-by: Matt Delco <delco@chromium.org> Tested-by: Matt Delco <delco@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Matt Delco <delco@chromium.org> Auto-Submit: Matt Delco <delco@chromium.org>
* crosvm: add ability to enable caps on vcpuMatt Delco2020-02-20
| | | | | | | | | | | | | | | | | This change primarily adds functionality to allow kvm features to be enabled on a vcpu (most of the current infra only supporst the ioctl for the vm fd). BUG=b:144746965 TEST=ran 'build_test' and verified that the added tests passed. Change-Id: I30c00b6f462377c21d477602ceba5853df953b37 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2055883 Tested-by: Matt Delco <delco@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Matt Delco <delco@chromium.org>
* crosvm: support kvm's hyper-v cpuid ioctlMatt Delco2020-02-20
| | | | | | | | | | | | | | | | | | | | | Kvm can emulate the hyper-v paravirt interface. Newer versions of kvm can advertise the features they support via an ioctl() that reports the cpuid leafs for this interface. This change adds some support for the ioctl() and plumbs it through the plugin interface so that plugins can determine the level of support available in kvm. BUG=b:144746965 TEST=Ran build_test on kernel that supports the ioctl. Added temporary code to print the cpuid leafs and verified that the output is as expected. Instrumented failure as expected from older kernels and verified that results still passed. Change-Id: I6cd7dade1793e4edb52b331d5b960685541f7ba3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2037919 Tested-by: Matt Delco <delco@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Matt Delco <delco@chromium.org>
* Remove unneeded return statementsDaniel Verkamp2019-11-08
| | | | | | | | | | | BUG=None TEST=bin/clippy Change-Id: I2cf3b961baefd21fedaa6b545c1c7ecfb25a9efc Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896088 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* crosvm: add plugin API for async writesMatt Delco2019-11-06
| | | | | | | | | | | | | | | | | | | | | | | A plugin might care to be immediately notified when a write is made to a port, but it doesn't care to have the VM stopped while the plugin calls back to resume the VM. Unfortunately this means that multiple messages can be queued up in the pipe and read() together by the plugin API. Protobuf's parsing function doesn't report how many bytes it read, so I've resorted to having crosvm prefix every message with a length and then have the plugin lib parse this number. Impact on performance has not been measured. BUG=b:143294496 TEST=Local build and run of build_test. Verified that new unit test was executed, exercised the case where multiple msgs are received together, and completed successfully. Change-Id: If6ef463e7b4d2e688e649f832a764fa644bf2d36 Signed-off-by: Matt Delco <delco@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896376 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* crosvm: compile out statsMatt Delco2019-11-02
| | | | | | | | | | | | | | | The stats are typically alive in the plugin library, but we typically don't care about or use these stats. BUG=None. TEST=Compiled and ran test. Verified release binary size got smaller by 25KB and debug by 50KB. Change-Id: I2469ff83f91a3aebf86d70807088bba3edce6641 Signed-off-by: Matt Delco <delco@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1835034 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: pre-cache answers to plugin get callsMatt Delco2019-10-31
| | | | | | | | | | | | | | | | This change tries to improve the performance of a plugin-based VM by adding a hint API that allows crosvm to proactively push cpu state to the plugin when certain ports for hypercalls are accessed by the VM. BUG=None TEST=build and run. See performance increase significantly. Change-Id: I71af24ebc034095ffea42eedb9ffda0afc719cd6 Signed-off-by: Matt Delco <delco@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1873005 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: defer IPC on set callsMatt Delco2019-10-23
| | | | | | | | | | | | | | If a plugin makes a set call on vcpu registers then we can improve performance by deferring the IPC and instead conbining the request with the next resume call. BUG=None TEST=build and run. Change-Id: I4eb54a3f6eb30c98971aa2f099e3ea5899767eed Signed-off-by: Matt Delco <delco@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1825262 Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: use pipe instead of socket for vcpu communicationMatt Delco2019-04-24
| | | | | | | | | | | | | | | | | | | | | Pipes have better performance than sockets, so switch the vcpu communication over to pipes. The vm communication channels will continue to use sockets since that communication isn't performance critical (and those messages sometimes exchange file descriptors, and that functionality requires sockets). TEST=local compile and confirmed that my diagnostic plugin is still happy. The time it takes to run my benchmark plugin has decreased by 20%. This combined with my prior commit results in a net wall-clock time reduction of 32%. BUG=None Change-Id: I44c198d62a3bbe3b539ff6ac79707d02488876e3 Signed-off-by: Matt Delco <delco@google.com> Reviewed-on: https://chromium-review.googlesource.com/1572873 Commit-Ready: Matt Delco <delco@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: reduce excess chatter with pluginMatt Delco2019-04-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change helps to improve performance in plugin communications by removing unnecessary communication exchange. The existing protocol basically requires the plugin to send a request msg and wait for a reply msg. Prior to this change a plugin had to send a wait request before it got a wait reply (which typically contains an IO event notication). Similarly, when the plugin sends a resume request there's also a resume reply that's sent. The reply to the resume message serves no worthwhile purpose and can be removed. In the common case there's also no need for the plugin to send a wait request message--the prior operation was a resume so both sides know that the only next legal operation is a wait. Thereforce, crosvm can send a wait reply message without waiting for the plugin's request. Another way to look at the situation is that a resume request message is now answered by a wait reply message, and the overall message exchange pattern looks less like http and more like async I/O. The plugin's first call to wait is the one time that a wait request is sent. This in turn will receive an wait-init reply. TEST=Ran my diagnostic plugin and confirmed that it still passes (after working around an 8-byte limitation in crosvm). Run my benchmarking plugin and observed the time it takes to complete go down by 16.5%. BUG=None Change-Id: I9c93ba1d3a8f7814ca952f3dc7239d48675192e2 Signed-off-by: Matt Delco <delco@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1571066 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Matt Delco <delco@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 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 toplevel_ref_argDavid Tolnay2019-04-17
| | | | | | | | | | | TEST=bin/clippy Change-Id: Iad8145deb3d96eb53ca8109636f2e04bca29f853 Reviewed-on: https://chromium-review.googlesource.com/1566890 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>
* protos: Merge plugin_proto crate under protos::pluginDavid Tolnay2019-04-12
| | | | | | | | | | | | | | | | | | | | | | | | | This de-duplicates the two separate build.rs files dealing with proto compilation. The trunks interface.proto will be exposed under protos::trunks and the plugin proto will be exposed under protos::plugin. BUG=none TEST=cargo check TEST=cargo check --features tpm TEST=cargo check --features plugin TEST=cargo check --features tpm,plugin TEST=FEATURES=test emerge-nami crosvm TEST=FEATURES=test USE=crosvm-tpm emerge-nami crosvm TEST=FEATURES=test USE=crosvm-plugin emerge-nami crosvm TEST=FEATURES=test USE='crosvm-tpm crosvm-plugin' emerge-nami crosvm TEST=local kokoro CQ-DEPEND=CL:1553971 Change-Id: I203b654a38e9d671a508156ae06dfb6f70047c4f Reviewed-on: https://chromium-review.googlesource.com/1556417 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>
* protos: Update to protobuf 2.3David Tolnay2019-04-12
| | | | | | | | | | | | | | | | | | | | | This matches the version already used by crostini_client. The newer protobuf version depends on the tempfile crate rather than tempdir, the latter being now deprecated. So I replaced our immitation tempdir crate with one that matches the API of tempfile instead. As a reminder, we use this crate as a patch to avoid pulling in all of the rand crate and its many dependencies. TEST=cargo check --features plugin CQ-DEPEND=CL:1553971 Change-Id: I28eed3ceadb1013f015400b4c582aaf8dc89eee1 Reviewed-on: https://chromium-review.googlesource.com/1562924 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: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* edition: Update crosvm_plugin crate to 2018 editionDavid Tolnay2019-04-09
| | | | | | | | | | | | | | | | | | 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: I78a8e95199da47843bf75bb9b2f0f3dd9899ac19 Reviewed-on: https://chromium-review.googlesource.com/1519703 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>
* 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>
* require protobuf version match that of top-level Cargo.tomlZach Reizner2019-03-25
| | | | | | | | | | | | | | | | | | When compiling unit tests in the pre-cq, the Cargo.lock file is deleted. Testing a sub-crate without a lock file will cause the protobuf dependency to resolve to the latest version of protobuf, which varies based on whatever other cros-rust.eclass based ebuilds have been run beforehand. This change fixes that source of flake. BUG=None TEST=pre-cq Change-Id: Ief951391c08b0f0cc9ff035437824d89860455e2 Reviewed-on: https://chromium-review.googlesource.com/1534962 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* plugin: allow retrieving and setting VM clockDmitry Torokhov2019-01-22
| | | | | | | | | | | | | Add crossvm plugin API to allow reading and setting guest clock. BUG=b:122878975 TEST=cargo test -p kvm; cargo test --features=plugin Change-Id: I3fd656c06b0e7e43ac88a337ac5d0caec8c59dba Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1419373 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm_plugin: Remove underscores in variable nameChirantan Ekbote2018-11-20
| | | | | | | | | | | | | | | | | | | | | Remove the double underscore in front of `__has_extension` in crosvm.h. Double underscores in identifiers are reserved for the compiler's internal use and as it so happens, `__has_extension` is a macro that clang defines for code to determine whether the compiler supports a given feature. We shouldn't be using double underscores in any of the variable names in this header file but for now just fix the problematic one so that the code can actually compile under clang. BUG=b:80150167 TEST=Compile one of the test plugins with clang Change-Id: Ibb59e72c968a7f245bd6cc693da99f9263eedf33 Signed-off-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1341100 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@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>
* plugin: do not fail crosvm_vcpu_get_msrs() if we failed to fetch someDmitry Torokhov2018-08-31
| | | | | | | | | | | | | | KVM_GET_MSRS may return less MSRs that were requested; do not fail but instead let callers to know how many were fetched. BUG=None TEST=cargo test --features plugin Change-Id: Ie14a3d38b66bfe34f5279543bea9c6c78423527e Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1192232 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* plugin: return number of supported MSRS even if buffer is too smallDmitry Torokhov2018-08-29
| | | | | | | | | | | | | | | | | | | | | Userspace is interested in number of supported MSRs even if supplied buffer is too small, as then it can intelligently [re]allocate the buffer and repeat the call instead of doing this blindly. So let's always populate 'out_count'in crosvm_get_msr_index_list() call. Obviously if there is hard error we will not be able to supply a meaningful number, so 0 will be returned, but in case of E2BIG error we can return the real number. Also let's do the same for get_supported_cpuids() and get_emulated_cpuids() calls. BUG=b:111083877 TEST=cargo test -p kvm; cargo test --features=plugin Change-Id: I37a8d719103fac44597b88ddecb6b8af2dd54ac8 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1185293 Reviewed-by: Zach Reizner <zachr@chromium.org>
* plugin: allow retrieving list of supported MSRsDmitry Torokhov2018-07-31
| | | | | | | | | | | | Add crossvm plugin API to allow fetching list of supported MSRs. BUG=b:111083877 TEST=cargo test -p kvm; cargo test --features=plugin Change-Id: I178c7bc33d606bef10422faac6bb9afb3fe0a014 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1152229 Reviewed-by: Zach Reizner <zachr@chromium.org>
* plugin: allow retrieving and setting VCPU eventsSlava Malyugin2018-07-11
| | | | | | | | | | | | | Add crosvm plugin API to allow fetching and setting VCPU events. BUG=b:110056268 TEST=cargo test --features plugin -p kvm Change-Id: Id66230f180f4bdb95bd1850ed050e439083701cc Reviewed-on: https://chromium-review.googlesource.com/1128045 Commit-Ready: Slava Malyugin <slavamn@chromium.org> Tested-by: Slava Malyugin <slavamn@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* plugin: allow retrieving and setting XCR VCPU statesDmitry Torokhov2018-05-18
| | | | | | | | | | | | | Add crossvm plugin API to allow fetching and setting XCRs for VCPU. BUG=b:79692549 TEST=cargo test -p kvm Change-Id: I2a988279c08051a8d8865efc1e60f9692fa26272 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1062646 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* plugin: measure max/avg latencies of all plugin APISlava Malyugin2018-05-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | A simple stat collecting. Uses RAII to gather latency on all exit paths from function/block. The underscore in "let _u = STATS.u(...)" is to pacify "unused variable" warning. Using "let _ = " makes compiler optimize out the call. Rust makes it particularly hard to convert enums from integers, so I had to add a hack that stores Enum on every invocation of the STATS.u. Looking at disassembly, it added one move of constant to the field of STATS.entries; no heap operations or cloning. A clever alternative using macros was suggested by semenzato@, but I decided saving an instruction was not worth the complexity. The output is currently printed on the destruction of crosvm, so tests print out stats on exit. We probably should find a better place for it though. BUG=None TEST=cargo test --release --features plugin Change-Id: I78a8920e9896b717af3aaea14f8ed6013be6b94f Reviewed-on: https://chromium-review.googlesource.com/1036473 Commit-Ready: Slava Malyugin <slavamn@chromium.org> Tested-by: Slava Malyugin <slavamn@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* plugin: allow retrieving and setting VM and VCPU statesDmitry Torokhov2018-03-30
| | | | | | | | | | | | | This change allows plugin to retrieve and set various VM and VCPU states: interrupt controller, PIT, LAPIC and MP state. BUG=b:76083711 TEST=cargo test -p kvm Change-Id: Ie32a67b0cd4a1f0a19ccd826a6e1c9dc25670f95 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/986511 Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm_plugin: be more RustyDmitry Torokhov2018-03-08
| | | | | | | | | | | | | | Instead of writing "if let Some(x) = ret.ok()" let's write more idiomatic "if let Ok(x) = ret". BUG=none TEST=sudo cargo test --features plugin Change-Id: Id8c4d0fd2a05783759b5699b65d2333b2a1a6776 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/956229 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* plugin: add crosvm_net_get_configStephen Barber2018-03-08
| | | | | | | | | | | BUG=none TEST=sudo cargo test --features plugin Change-Id: Ib38fad250295d73529dff0451345b4274a261073 Reviewed-on: https://chromium-review.googlesource.com/911943 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* plugin: only convert to negative errors on crosvm.h boundaryDmitry Torokhov2018-03-07
| | | | | | | | | | | | | | | | We have decided that API defined in crosvm.h should signal errors by returning negative values derived from common errno error codes. To avoid confusion within the rest of crosvm code that is using positive erro codes, let's perform the conversion to negative on that crosvm API boundary, so it is contained. TEST=cargo test --features plugin BUG=None Change-Id: Icb1e719c8e99c95fdc32dce13a30d6ff8d3d9dc7 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/947563 Reviewed-by: Zach Reizner <zachr@chromium.org>
* allow plugin to query KVM for supported/emulated CPUIDsDmitry Torokhov2018-02-28
| | | | | | | | | | | | | This plumbs calls to KVM_GET_SUPPORTED_CPUID and KVM_GET_EMULATED_CPUID to be available to plugins. TEST=cargo test --features plugin; cargo test -p kvm BUG=chromium:800626 Change-Id: I98879599b5f970c6c2720772658689a505d8abe1 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/938674 Reviewed-by: Zach Reizner <zachr@chromium.org>
* plugin_proto: add helpers to convert CPUID data between KVM and protobufDmitry Torokhov2018-02-27
| | | | | | | | | | | | | We need to convert between protobuf and KVM format of cpuid data in several places, so let's add helpers to plugin_proto crate. TEST=cargo test --features plugin; cargo test -p kvm BUG=chromium:800626 Change-Id: Ida7b59825d2146b0d02711e441f477d90dd4263a Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/939660 Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm_plugin: fix errno conversionsDmitry Torokhov2018-02-27
| | | | | | | | | | | | | | | The raw_os_error() and errno() return positive values (errno values are all positive), but the rest of crosvm plugin C API works with negative return codes, so we need to convert raw_os_error()/errno() into negatives as well. TEST=cargo test --features plugin; cargo test -p kvm BUG=None Change-Id: I8bd72c2e67cb227a638e5c9478cd2f781f0783d0 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/939865 Reviewed-by: Zach Reizner <zachr@chromium.org>
* allow plugin to query for KVM extensionsZach Reizner2018-02-12
| | | | | | | | | | | | | | The guest may need to check for KVM extensions before blindly using them. TEST=cargo test --features plugin; cargo test -p kvm; ./build_test BUG=chromium:800626 Change-Id: If87b928753cd71adeabac4fc7732c3fce7265834 Reviewed-on: https://chromium-review.googlesource.com/906008 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* add plugin support for configuring CPUIDZach Reizner2018-02-12
| | | | | | | | | | | | | | The guest expects to be able to read the CPUID, so the plugin process needs to specify what the CPUID for each VCPU will have. TEST=cargo test --features plugin; ./build_test BUG=chromium:800626 Change-Id: I9258540ab2501126c3d8cadbd09b7fc01d19f7a9 Reviewed-on: https://chromium-review.googlesource.com/906006 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* allow non-dirty log memory regions from the plugin processZach Reizner2018-02-12
| | | | | | | | | | | | | | | Dirty logging is not necessary for every memory region, so the plugin process should be able to specific exactly which regions it would like dirty logging enabled for. TEST=cargo test --features plugin BUG=chromium:800626 Change-Id: I28b8285357e7de1c8c3a1392bdfdb4853ec5a654 Reviewed-on: https://chromium-review.googlesource.com/900294 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* add plugin support for model specific registersZach Reizner2018-02-12
| | | | | | | | | | | | | | The MSRs are useful for booting a full operating system that requires them. TEST=cargo test --features plugin; cargo test -p kvm; ./build_test BUG=chromium:800626 Change-Id: I817fbf3e6868c85b373808bd48e568b5b2b458eb Reviewed-on: https://chromium-review.googlesource.com/897412 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* add support for accessing debug registers in the plugin processZach Reizner2018-02-12
| | | | | | | | | | | | | | The debug registers are useful to access for the plugin process in some cases. TEST=cargo test --features plugin; cargo test -p kvm; ./build_test BUG=chromium:800626 Change-Id: I8f3f6c31c6989061a43cef948cf5b4e64bd52d30 Reviewed-on: https://chromium-review.googlesource.com/896945 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* add crosvm_plugin dynamic library crateZach Reizner2018-02-07
| | | | | | | | | | | | | | This is the shared library used by the plugin process to speak to a crosvm main process that spawned it. TEST=cargo build --features plugin BUG=chromium:800626 Change-Id: I100e7ddfc1099fbdf1462c171785a861e075d5d7 Reviewed-on: https://chromium-review.googlesource.com/869356 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* add crosvm plugin C header fileZach Reizner2018-01-26
This header file defines the C API used to interface with crosvm as a plugin process. TEST=None BUG=chromium:800626 Change-Id: Ie06b833e25dab8f31f64d8bc8b4b521b61d1ca04 Reviewed-on: https://chromium-review.googlesource.com/764267 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>