Commit graph

40 commits

Author SHA1 Message Date
Daniel Verkamp
aef7f5f5a6 hypervisor: add gvm feature to Cargo.toml
This doesn't build upstream, but cfg(feature = "gvm") is checked in
various places in upstream code, which becomes a warning in Rust 1.80.

BUG=b:365852007

Change-Id: Ib13f8b6ce965f790b292db1cf827472a292473da
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5894665
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-10-01 02:17:20 +00:00
Noah Gold
1d6be0f345 hypervisor: TLB flush test
We need to verify that a hypervisor is flushing a TLB on region
removal. This test removes a region in the middle of the VM running,
which allows us to verify that MMIO occurs on the next instruction,
rather than a read from an unmapped region.

BUG=b:333728516
TEST=presubmit

Change-Id: I215520ecfd4181a1e1ebd3cb5d784b3db94e799a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5690379
Reviewed-by: Idan Raiter <idanr@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
2024-07-10 20:42:34 +00:00
Daniel Verkamp
383ae1a6bf Replace memoffset with std::core::offset_of
offset_of!() is available in the standard library as of Rust 1.77.

Also update intrusive-collections 0.9.4 -> 0.9.6, which drops an
indirect dependency on memoffset 0.5.6:

  cargo update -p intrusive-collections

BUG=b:344974550
TEST=tools/dev_container tools/presubmit

Change-Id: I37a9bf0aee5f5f55bdea1e17d71889e8a3badb36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5667936
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-28 22:07:50 +00:00
Daniel Verkamp
52b8e42869 Cargo.toml: avoid "*" versions for external crates
Ensure that every Cargo.toml dependency on a third-party crates.io crate
specifies at least a major version, or a minor version for 0.x crates,
to ensure that if a new major version is published, it cannot cause API
breaks.

The versions are selected to match the ones already in Cargo.lock, so
this should have no functional change, but it will help prevent new "*"
versions from being introduced via copy-and-paste.

For rationale, see the Cargo FAQ:
<https://doc.rust-lang.org/cargo/faq.html#can-libraries-use--as-a-version-for-their-dependencies>

`minijail`, `audio_streams`, and `cras` are left as "*" for now, since
they have unusual situations (imported from a submodule and/or replaced
at build time with ebuild magic).

BUG=None
TEST=tools/dev_container tools/presubmit
TEST=verify Cargo.lock is unchanged

Change-Id: Ifa18199f812f01d2d10bfb4146b3353c1a76527c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5555656
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-22 01:01:42 +00:00
Kaiyi Li
31c24b551e hypervisor: add a simple interruption injection test
This test:
* sets the IDT
* sets one register in the ISR
* uses hlt to VMEXIT
* inject an interrupt through the hypervisor
* check if the ISR has executed by checking the register

TEST= cargo nextest run --workspace --features=all-msvc64_product_debug_test,whpx --profile=default -E 'package(hypervisor) & test(/.*test_minimal_interruption_injection/)'
BUG=b:334055761

Change-Id: Id082d5b48434745e12ac3467f37de45bdb22b669
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5548947
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-05-22 00:53:35 +00:00
Kaiyi Li
d43e8bd092 hypervisor: convenient macro to generate an array from inline assemblies
The new global_asm_data macro allows to embed the compiled assembly as an array, which makes it easier to modify and write new integration tests for the hypervisor.

A proc-macro is needed to generate random symbols and forward arbitrary arguments to the global_asm! macro.

TEST=cargo test --doc --package hypervisor_test_macro
TEST=cargo nextest run --workspace --features=all-msvc64_product_debug_test,whpx --profile=default -E 'package(hypervisor) & test(/.*test_minimal_virtualization/)'
BUG=b:334055761

Change-Id: I83b4b5f46bdd39adbfd279fefabbf275eb6127ea
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5549033
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Judson Powers <judsonp@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-05-21 19:31:17 +00:00
Daniel Verkamp
7bfa80063b hypervisor: remove kvm crate dependency
Duplicate the KvmCap enum and KvmCpuId type alias that were imported
from the top-level `kvm` crate in order to drop the hypervisor -> kvm
dependency.

The `kvm` crate is otherwise only used by the plugin feature, so this
removes it from the build in the usual non-plugin case.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: If710c547619f7c2bbff7e0a6eeca7a6aaf19e63c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5517747
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-07 19:55:57 +00:00
Daniel Verkamp
a41473f813 hypervisor: remove gdb feature and gdbstub deps
The gdb support is implemented outside of the hypervisor crate now,
aside from two debug-specific VcpuAarch64 functions, which don't depend
on the gdbstub crate for their API. Drop the cfg checks and make these
APIs always available (the compiler will optimize them out if they are
not called anyway) and remove the unused gdbstub dependencies.

BUG=b:323354478
TEST=tools/dev_container tools/presubmit

Change-Id: Ieb313a1098239e9d764207c9cb6cc18c8a376795
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5500375
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-04-30 01:43:02 +00:00
Stanislaw Kardach
3363fb9fe7 Cargo.toml: add noncoherent-dma feature flag
Add a top level noncoherent-dma feature flag as well as its
counterparts in devices and hypervisor modules.
This flag enables the MemCacheType::CacheNonCoherent handling,
ensuring that behavior introduced in the previous commit can be
selectively enabled.

BUG=b:316337317
TEST=emerge-rex chromeos-base/crosvm
TEST=USE=crosvm-noncoherent-dma emerge-rex chromeos-base/crosvm

Change-Id: I13f50547b21ce804c5fa4b8f6328931f558b717e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5237126
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Zhenyu Z Wang <zhenyuw@linux.intel.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stanisław Kardach <skardach@google.com>
2024-01-26 23:27:58 +00:00
Ludovic Barman
cd04b6198d Upgrade gdbstub and gdbstub_arch.
gdbstub 0.6.3 -> 0.7.0
gdbstub_arch 0.2.4 -> 0.3.0

There is small change in API, see src/crosvm/gdb.rs. `read_addrs` now returns a `usize` instead of a `()`.

This change is needed to submit this AOSP topic: https://android-review.git.corp.google.com/c/platform/external/crosvm/+/2879249

BUG=b:286979636

TEST=tools/presubmit --all

Change-Id: I124d65e673c5943070c2bb5e39e3a7e5506e5528
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5146447
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-01-04 02:06:22 +00:00
A. Cody Schuffelen
97dff044f8 Replace #[cfg(unix)] with #[cfg(any(target_os = "android", target_os = "linux"))]
Updates are made to source and documentation.

This more accurately represents the currently supported platforms of
Android/Linux and Windows, without unexpectedly including other
unix-like operating systems.

Command to reproduce:
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -i 's/cfg(unix)/cfg(any(target_os = "android", target_os = "linux"))/g' {}
$ cargo fmt

md files manually updated to fix line lengths.

Renaming `unix` modules to `linux` will be done in a later CL.

Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I42c1bf0abf80b9a0df25551613910293217c7295
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909059
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-10-11 00:43:29 +00:00
Andrew Walbran
1661dfca89 Update bitflags dependency to 2.2.1.
This is a new major version, and requires some code changes.

Change-Id: I294ce3604aad6e6dc5f50e33246b690e883c1e36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4481294
Auto-Submit: Andrew Walbran <qwandor@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-04-27 17:22:36 +00:00
Noah Gold
526922ac76 hypervisor: implment get/set xsave for WHPX.
Adds implementations for get/set xsave for WHPX. This is needed for
snapshotting on WHPX.

BUG=b:270734340
TEST=unit test.

Change-Id: I6496b257dc7ef374a1c972e9b1179a6692541ae8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4409919
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Steven Moreland <smoreland@google.com>
2023-04-10 23:31:45 +00:00
Elliot Berman
3cfc7c260b Cargo.toml: Enable Gunyah only for all-aarch64
Enable gunyah feature for all-aarch64. all-x86_64 inherits all-aarch64
and Gunyah does not support x86_64, so create a new meta-feature,
all-default to support the common features that need to be enabled in
aarch64 and x86_64.

Cherry-pick notes: This commit now adds the "gunyah" feature and is
moved earlier in the series so that changes later in the series can be
properly tested by presubmits.

BUG=b:232360323

Change-Id: Ibb3b0ad48017c2480498634d766aea162114b385
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4404216
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-04-05 18:32:18 +00:00
Elliot Berman
9b2ea4f8a6 hypervisor: Allow for hypervisor-specific DT additions
Gunyah hypervisor requires some VM configuration to be described on the
devicetree. Add a trait to VmAArch64 to allow a hypervisor
implementation to provide the needed info.

BUG=b:253416076
Change-Id: I07091518b856add0c1644bf6a857460da7ff2b3b
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4379521
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-29 00:52:24 +00:00
Elie Kheirallah
9d214c1843 hypervisor: Add snapshot to vCPU x86_64
Add snapshot to vCPU for x86 and x86_64 arch.

BUG=b:266515147
BUG=b:232437513
Test=crosvm run && crosvm snapshot take img_name socket

Change-Id: I65d059a7537c713e9ef6c1456a7aeae2b6bc4728
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237759
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
2023-03-23 17:15:47 +00:00
Yi-De Wu
65d98b04f6 aarch64: MTK GenieZone hypervisor enablement as Crosvm backend
To support GenieZone (gz) hypervisor as a crosvm hypervisor backend:
- Implement GenieZone hypervisor
- Implement GenieZone’s irqchip
- Create config and feature for GenieZone
- Probe proper hypervisor backend with naive logic
- Inject virtual interrupts
- Bootup guest VM with linux kernel to shell

We still have other todos:

- Integrate with protected VM and pvmfw
- Support multi-core VM

Fixed bugs:
- Replace gz with geniezone in most cases for clarity
- Replace KVM’s ioctl number with GZVM’s ioctl in bindings

Bug: 264630327
TEST:
$ taskset 10 ./crosvm run --disable-sandbox -m 512 -s s1 \
  --rwroot alpine-rootfs.img -p 'init=/bin/sh rodata=off' \
  --display-window-keyboard Image_515_41_no_numa_20230130 \
  --serial type=stdout,hardware=serial,earlycon \
  --serial type=stdout,hardware=virtio-console,console,stdin

Change-Id: Ia5d92ba5cbb4198ab7f9f2a778da03b2199892cd
Signed-off-by: Ze-yu Wang <ze-yu.wang@mediatek.com>
Signed-off-by: Yi-de Wu <yi-de.wu@mediatek.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4170415
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-03-22 18:04:47 +00:00
Daniel Verkamp
ac0fc378a3 Fix remaining Chrome/Chromium OS instances
These should be written as ChromeOS and ChromiumOS (without the space)
to match the updated branding. The copyright headers were already
migrated to the new style (https://crrev.com/c/3894243), but there were
some more instances left over.

BUG=None
TEST=tools/cargo-doc

Change-Id: I8c76aea2eb33b2e370ab71ee9b5cc0a4cfd00585
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4129934
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-01-03 22:14:30 +00:00
Pierre-Clément Tosi
7737c533db gdb: Add basic support for AArch64
Enable the "gdb" feature on AArch64 (KVM) builds and add support for:

 - reading & writing guest memory (only guest IPAs, for now)
 - getting & setting core registers
 - getting & setting the few system registers from kvm_regs
 - setting hardware breakpoints (no software breakpoints, for now)
 - enabling single-step mode

BUG=b:222222882
BUG=b:240711627
BUG=chromium:1141812
TEST=tools/dev_container ./tools/run_tests

Change-Id: I0ae38c1065002d55a569b1575b1637110694e6db
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3785467
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Takaya Saeki <takayas@chromium.org>
2022-09-28 11:25:50 +00:00
Daniel Verkamp
19fc097eb8 crosvm: replace lazy_static with once_cell
We depend on both lazy_static and once_cell, which do basically the same
thing.

The once_cell crate has a few advantages:
- once_cell is on track to be included into libstd.
  (https://github.com/rust-lang/rust/issues/74465)
- once_cell doesn't require macro magic.

Replace the uses of lazy_static with their once_cell equivalents so we
don't need to pull in both crates.

BUG=b:236191006
TEST=tools/presubmit --all
TEST=tools/run_tests --target=host --arch=win64 --build-only
TEST=cargo test --features=plugin

Change-Id: I7cabcd837ef4878e8e8ae635bb4f235a58e4cae3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707624
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-21 23:40:55 +00:00
Vaibhav Nagarnaik
ea7132e158 hypervisor: Add whpx support
Add `whpx` and `whpx_sys` modules that allow using Hyper-V platform as a
hypervisor on Windows. This has been tested running on Windows 19H1 and
above.

BUG=b:213151419
TEST=Compiled and tested on Windows.

Change-Id: If91ea6337876b85c9fdafe6ae4ad39fba40c4979
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3700983
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-16 01:05:36 +00:00
Vaibhav Nagarnaik
478c7104f8 hypervisor: Update Cargo.toml dependencies
The `haxm` implementation depends on `win_util` and `winapi` crates
which are only required on Windows. The `tempfile` crate is used in
testing.

Move `kvm` and `kvm_sys` dependencies for non-windows builds.

BUG=b:213151459
TEST=Compiled on linux.

Change-Id: I55b8ee4ac5da953a17e8bdd063e5ed488e3f53f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3684929
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-02 00:05:06 +00:00
Vaibhav Nagarnaik
435e4fd2bd hypervisor: Constrain fnv version
The ebuild update for `fnv` includes versions up to `1.*`. Add
constraints for the dependency to be the same so that a newer `fnv`
version does not break the crosvm build.

ref:
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3630701/comments/af4c79c5_35e4dee4

BUG=b:213151459
TEST=Compiled

Change-Id: I4d67b223eb858c3c46f87cbc9ae275c3859a3e46
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3681278
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-31 21:26:24 +00:00
Vaibhav Nagarnaik
dc95b28adb hypervisor: add haxm hypervisor
The support is behind a feature flag `haxm`. Only tested and works on
Windows. However, it should be easy to make it work on other supported
OSes as well.

This includes the sys bindings for the HAXM interface. Requires that the
haxm driver is already installed on the host.

BUG=b:213151459
BUG=b:213151458
TEST=Compiled

Change-Id: Ifa9ec9236f84156f61443819f97f5d5754e77b93
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3630701
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-05-31 20:05:52 +00:00
Dennis Kempin
ef516189db Refactoring: Move common/base into base
Executes the script in https://crrev.com/c/3530502

BUG=b:223206469
TEST=presubmit

Change-Id: Ibeffdc8de0b2270f070e60bb2de8d9fdc78a2a6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3530503
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-03-17 00:01:27 +00:00
Anton Romanov
bed40ad547 crosvm: migrate to Rust 2021 edition
BUG=none
TEST=cq

Change-Id: I0059c970879b78bfd40b6ce58b10debcf154b50f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508322
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-03-09 01:16:03 +00:00
Daniel Verkamp
0ae13d221e Require memoffset version 0.6
Chrome OS does not currently package memoffset-0.6.5 (only 0.6.4), so
building within cros_sdk will fail to find the expected crate. We don't
need any API requirements past what is provided by 0.6, so just request
that. At the same time, upgrade the cros_asyncv2 memoffset from 0.5 to
0.6 so we don't need two separate versions. (The crosvm ebuild was not
requiring a 0.5 version, so this was technically a bug.)

BUG=None
TEST=cargo build
TEST=emerge-hatch crosvm

Change-Id: I2b6c778cdbf57977e6fffd73867e0c4818c44a61
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3502625
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vineeth Pillai <vineethrp@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-04 05:15:35 +00:00
Andrew Walbran
27f2133dba Use memoffset::offset_of rather than implementing it ourselves.
TEST=tools/dev_container tools/run_tests
TEST=tools/dev_container tools/run_tests --target=vm:aarch64

Change-Id: Iccdf0653001599d76c742db27349e274f7a4bb23
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3497460
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2022-03-02 08:33:02 +00:00
Daniel Verkamp
c13c0c210b enumn: switch to upstream crates.io version
Developers may need to manually clean up the common/enumn directory - it
will be left behind if there are build artifacts (Cargo.lock, target
directory, etc.):

  rm -rf common/enumn

BUG=b:205344148
TEST=cargo build
TEST=tools/presubmit
TEST=emerge-hatch crosvm # with https://crrev.com/c/3265967

Change-Id: I1af3bdd22f40e87895a78a5cbc8033476058c927
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3278774
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-11-15 21:03:25 +00:00
Dennis Kempin
8a1c50d5cd Refactoring: Move various general purpose crates to common/
This change contains the results of running

./tools/contib/cargo_refactor.py

This will break the next uprev, and needs to be synchronizized
with the corresponding ebuild changes in https://crrev.com/c/3248925

BUG=b:195126527
TEST=./tools/run_tests

Change-Id: Ied15a1841887bb8f59fba65b912b81acf69beb73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3248129
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-29 22:31:43 +00:00
Zach Reizner
d49bcdb081 replace all usage of MsgOnSocket derives
Replaced all usage of MsgSocket with Tube.

BUG=b:176847362
TEST=run_tests

Change-Id: Ie647f79926bc0414c125a776eafe7f60c071bab2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2710324
Auto-Submit: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2021-04-02 15:40:41 +00:00
Zach Reizner
304e731cdb make hypervisor traits object safe
This allows code to create references to traits such as `&dyn Vcpu` for
`&dyn IrqChip`. This also allows keeping such traits inside of opaque
`Box` like wrappers.

To achieve this, trait methods referencing `Self` have an additonal
`where` clause that restricts them to sized types. Associated types are
removed and replaced with their trait equivalents (as parameters) or an
opaque Box (as return values).

To work around certain cases where a concrete type is needed, such as
for KVM based `IrqChip` impls, the `downcast_rs` trait is used to allow
`dynamic_cast` style casting.

The binary size impact of this change is small. For comparison, here is
the size change with this commit:

armv7a  -0.49% (-9 kiB)
aarch64 -0.17% (-3 kiB)
x86_64  +1.77% (+40 KiB)

BUG=None
TEST=build_test

Cq-Depend: chromium:2466660
Change-Id: I1a408734832d2971ea2979c1bc64b2ffe051b02d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2439298
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>
2020-10-15 14:31:20 +00:00
Michael Hoyle
6b19695c81 Add "base" crate and transition crosvm usages to it from sys_util
For now, this crate simply re-exports all of sys_util, but it will
be updated to provide new interfaces when needed. This is the
first step to making crosvm not directly depend on sys_util, so
that we can make the interface changes we need without fear of
negatively affecting (i.e. completely breaking) other usages
within chromeos.

BUG=b:162363783
TEST=./build_test

Change-Id: I7d0aa3d8a1f66af1c7fee8fd649723ef17027150
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2325168
Tested-by: Michael Hoyle <mikehoyle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-08-06 18:19:44 +00:00
Dylan Reid
ec058d6c46 vm_memory: A crate to hold vm-specific memory objects
Move GuestAddress and GuestMemory to a new crate for VM memory. This
will make separating sys_util and crosvm independent making it easier
to use sys_util functions outside of crosvm.

Change-Id: I12e14948ea85754dfa6267b3a3fb32b77ef6796e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311251
Auto-Submit: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-24 21:42:34 +00:00
Steven Richman
583651a52a hypervisor: add ioevent, dirty log, TSS, ident map
These functions are mostly unchanged from the kvm crate.

BUG=chromium:1077058
TEST=cargo test -p hypervisor

Change-Id: I819e34b2d7895b10658ca7d8870b64435220ea9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2202847
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Steven Richman <srichman@google.com>
2020-06-30 23:03:08 +00:00
Colin Downs-Razouk
6364823093 devices: irqchip: finish KvmKernelIrqchip impl
Implemented the remaining IrqChip trait functions for the
KvmKernelIrqChip, including register/unregister_irq_event and irq
routing functions.

Added some irqchip tests for setting irq routes and servicing irq lines.
Also added tests for registering irq events.

BUG=chromium:1077058
TEST=cargo test -p devices -p hypervisor

Change-Id: Ia04c927b663ebdcacc88bc61d746077aa5b02514
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2246648
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-06-17 23:49:31 +00:00
Colin Downs-Razouk
c31a7b9fc6 hypervisor: x86 irqchip structs
Hypervisor-agnostic structures for the pic, ioapic, lapic, and pit.
These are derived from existing structures in the pic, ioapic, and pit
implementations, as well as from the kvm_sys bindings.

Includes From implementations converting these structures to their
associated KVM structures. Also includes tests for these conversion
implementations.

BUG=chromium:1077058
TEST=added tests to convert kvm structures to hypervisor-agnostic
structures

Change-Id: Ie2f254bf2dba3aed755008296c00cb6a49f845fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197716
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-05-28 08:00:30 +00:00
Steven Richman
0aacc50fd2 hypervisor: add KvmVm new and try_clone
Vms and Vcpus will be try_cloneable and Send, so we can configure on
vcpu threads and so IrqChips can reference all Vcpus.  To support
cloning, collection fields in Vm have been moved into arc mutexes, and
Vm and Vcpu are now Sized.  Because this breaks object safety, all usage
of the traits will be via static binding.

Add impl AsRawFd for SafeDescriptor, to get the sys_util ioctl functions
working with SafeDescriptor; eventually the functions will change to
take SafeDescriptors.  Copy set_user_memory_region helper from kvm
crate.

BUG=chromium:1077058
TEST=cargo test -p hypervisor

Change-Id: I23de47c4472a77632006d0d45de9754394b400c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197337
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Steven Richman <srichman@google.com>
2020-05-21 15:03:51 +00:00
Udam Saini
3730355406 Implements the Hypervisor trait for Kvm.
This adds the ability for getting both supported/emulated cpuids from
the kvm hypervisor. In addition, checking the available capabilities
for kvm is now implemented.

BUG=chromium:1077058
TEST=Added unit tests for each implemented function.

Change-Id: Ide4c2840b7bfa022deae835eb734ea97c1859169
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2177641
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Udam Saini <udam@google.com>
2020-05-15 16:57:22 +00:00
Udam Saini
6fe08fa363 Adding hypervisor crate to abstract out Kvm implementation
This is a separate hypervisor crate for interacting with Kvm in an
abstract manner. The intention is to not leak the internals of kvm
with its specific calls in various places in the codebase. Currently,
this just creates an initial structure for adding various
implementations over time.

In addition, a SafeDescriptor class is added, that wraps a raw file
descriptor safely, without needing to wrap it in the rust file class.
The intention is to use this for non file raw descriptors.

BUG=chromium:1077058
TEST=added a basic kvm test that creates a Kvm struct

Change-Id: I4229203902e480b52435cde12bf0d25a322c71be
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2174756
Commit-Queue: Udam Saini <udam@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-05-03 22:01:30 +00:00