Commit graph

230 commits

Author SHA1 Message Date
Shintaro Kawamura
b5a9833d97 swap: send userfaultfd via Tube on device process fork
This implements the equivalent logic on crosvm as
UFFD_FEATURE_EVENT_FORK. When each device process forks, the ProxyDevice
creates userfaultfd and send it to the monitor process by
SwapController::on_process_forked().

Crosvm does not have any child processes which may access the guest
memory except device processes as of now. Crosvm forks
virgl_render_server, but the mmap is not preserved in the process on
execve(2) since it is a different binary. Also no device process forks
grandchild processes according to the seccomp policy.

We actually can't use UFFD_FEATURE_EVENT_FORK because the feature does
not support non-root user namespace (go/uffd-fork-user-ns) and ARCVM
runs in a non-root user namespace.

This also adds syscalls to seccomp policies for devices to allow the
processes to create and setup a userfaultfd.

BUG=b:266641923
TEST=manually tested

Change-Id: Ide3088e1e95ae3c8259e3f4324124b3376e760b7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4194228
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-02-01 00:47:52 +00:00
Frederick Mayle
653f62a4a3 aarch64: static swiotlb allocation
Adds a new hypervisor capability that causes crosvm to statically
allocate the location of the swiotlb buffer.

This will be used by the gunyah hypervisor.

BUG=b:244630071,b:232360323

Change-Id: Ia2f379bb6f2fa89167ddc73d65ec1b8c5494bdf6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4197001
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-02-01 00:05:48 +00:00
Frederick Mayle
078b9e24a1 aarch64: minor refactor of swiotlb FDT code
No behavior change intended.

BUG=b:244630071,b:232360323

Change-Id: I7809fe1d404593868cbd4b9b1875c37e7a68798f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4205150
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-02-01 00:05:48 +00:00
Frederick Mayle
26d841e626 crosvm: create guest memory layout after hypervisor
No behavior change intended.

We'd like to make some aspects of the guest memory layout dependent on
hypervisor capabilities in future commits.

Note for x86_64: `Arch::guest_memory_layout` initializes some global
state so some care is needed when moving it relative to other code. In
this case it is safe because the only code being moved before
`Arch::guest_memory_layout` is `get_default_hypervisor`, which is
currently a constant, and `Kvm::new_with_path`, which just performs an
`open` syscall and wraps it in a `Kvm` struct. Neither depend on the
x86_64 specific global state.

BUG=b:232360323,b:244630071

Change-Id: I8bf70bb18e56dd7e7ac78c615fdb9877a87b66c4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4197000
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
2023-02-01 00:05:48 +00:00
Frederick Mayle
069a266446 aarch64: small doc fixes for create_fdt
Change-Id: Ie07ef973f1aaec3a643ad734e8ad2174b10d27e7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4201154
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-30 22:31:43 +00:00
Elliot Berman
77f6d72395 crosvm: fdt: Add option to dump generated devicetree blob
Add an option to dump the crosvm-generated devicetree blob. This option
can be helpful in understanding what devices are reported to the guest
VM and help diagnose issues related to improper devicetree.

Bug: 249043819
Change-Id: Ic6cfe9c12cc01d7aaa66c193b027e1f66d8a02b3
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4174623
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-20 20:26:55 +00:00
Daniel Verkamp
04e36b573d aarch64: switch rng seed generation to rand crate
Replace the OS-specific /dev/urandom with the cross-platform rand crate.

BUG=b:265031416
TEST=Boot aarch64 Linux kernel on lazor

Change-Id: I6eb3ab4c5b45bc8296ade92b5b5e30da78d039d2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3855345
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-01-13 23:43:44 +00:00
Daniel Verkamp
c116518b50 aarch64: clean up unix-only dependencies
Drop a few unused kvm dependencies and only require minijail on unix
platforms.

The aarch64 platform won't be functional on Windows yet, but it's at
least possible to drop it from the WIN64_DISABLED_CRATES list.

BUG=None
TEST=tools/dev_container tools/run_tests --platform=mingw64
TEST=tools/dev_container tools/run_tests --platform=aarch64

Change-Id: If48b935afe1295820b6d78cfde3e8634a3e397db
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4167144
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-01-13 23:25:19 +00:00
Pierre-Clément Tosi
f0ee785a5e aarch64: Clarify pvmfw loading error variants
Rename the ProtectVm variant to better describe what it actually covers
i.e. a request to the hypervisor to load the protected fw (note: the VM
is actually protected in KvmVm::new()) and clarify its error message.

To better distinguish between the two cases and as they differ in
underlying error types, make it clear that PvmFwLoadFailure was only
used for "custom" pvmfw images, loaded by crosvm.

TEST=tools/dev_container cargo build --target aarch64-unknown-linux-gnu

Change-Id: I80caa1e52ea7322c5394f246ef020d17bdef4476
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4136213
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-04 18:25:12 +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
Sahitya Tummala
750e821e57 aarch64: load ELF image based on its class detection
Today, it supports only loading ELF64 images. This change
allows to accept both ELF32 and ELF64 images.

BUG=b:261538125
TEST=cargo test -p kernel_loader -p aarch64

Change-Id: Ic9e6eadfc308c317e9bed7ef657e1b5777da897f
Signed-off-by: Sahitya Tummala <quic_stummala@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4089657
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Steven Moreland <smoreland@google.com>
2022-12-09 18:57:28 +00:00
Elie Kheirallah
7b76af0ac1 devices: Add thread to handle device snapshot in unix.
Add snapshot functionality in Bus.
Add thread to handle communication between VM cmdline and devices.
Add DeviceCommandControl in vm_control to handle device-specific
actions.

Bug=b:232437513
Test=cargo build && cargo run ...

Change-Id: If3795c9e1f12ab4cd34ab36cad8eae43d469a50a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3930627
Auto-Submit: Elie Kheirallah <khei@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Steven Moreland <smoreland@google.com>
2022-12-02 19:33:04 +00:00
Alexandre Courbot
135dfad1ac crosvm: introduce CpuSet structure
We are using Vec<usize> as a way to represent sets of CPU cores for
things like CPU clusters, which is not very verbose as to what the
vector is for without context and forces us to separate things like
parsing of CPU clusters into separate, independent functions.

Replace these vectors by a proper CpuSet struct, with its own
implementation of FromStr. We will then extend it with
serialization/deserialization ability to improve argument parsing.

BUG=b:255223604
TEST=cargo test

Change-Id: Ibb954a41bcedc088e2eb07b5157343344f3ad40b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4060286
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-12-01 02:01:37 +00:00
Pierre-Clément Tosi
3be37dfe7e aarch64: fdt: Introduce /config/kernel-* props
When running a VM with a flavor of the --protected-vm flag, crosvm loads
the bios or kernel image but the VM first runs the protected firmware,
which is expected to verify those preloaded images before executing
them.

Previously, a custom ABI was used to allow crosvm to pass the location
and size of the image to the firwmare through CPU registers. Instead,
pass those parameters through the device tree to comply with the Linux
ABI and be more architecture-agnostic.

Use the /config node (ignored by Linux, used by U-Boot in a similar way)
to pass the newly-introduced 'kernel-address' and 'kernel-size'
properties, which follow the naming and size of the existing
'kernel-offset' [1].

[1]: https://u-boot.readthedocs.io/en/latest/develop/config_binding.html

BUG=b:253616035
TEST=Dump DT from guest

Change-Id: If9e3470ed03372adcddb268444daa159ed9fa5a2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4064759
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
2022-11-30 13:42:09 +00:00
Pierre-Clément Tosi
d2205a31cd aarch64: Add accessors to PayloadType
Encapsulate the details of getting the payload entry/size behind helper
methods.

TEST=cargo build --target aarch64-unknown-linux-gnu

Change-Id: Id17f14626fc121dcabbea917fac8518b56e4dc88
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4061465
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-11-30 13:42:09 +00:00
Daniel Verkamp
f50029e071 kernel_loader: accept physical address offset
This interprets the p_paddr field of ELF program headers as an offset
into physical RAM on aarch64 systems, which is a change in behavior. We
pass an offset of 0 on x86-64, so it makes no difference there.

BUG=b:254601048
BUG=b:255697205
TEST=cargo test -p kernel_loader

Change-Id: I9ebaa285c4cde1f70cb7752e91ff4520e06dc82f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4035738
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-28 19:41:53 +00:00
Daniel Verkamp
e7473e600e aarch64: load arm64 kernels at physical address 0
There is no reason to leave an 8 MB gap at the beginning of guest
memory; shift the kernel load address down to the very beginning of
RAM. This accomodates alternate ELF kernels that want to be loaded at
address 0 as well.

BUG=b:254601048
TEST=boot crostini on arm

Change-Id: Iaa58efc5b20046732ef0f75b3c779134a3ee454b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4015002
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-15 22:12:04 +00:00
Daniel Verkamp
b6c3227d2d kernel_loader: add arm64 kernel loader
The new load_arm64_kernel() function loads and validates the Linux arm64
image format. This allows detecting whether the magic number and other
fields are valid, similar to the existing ELF loader.

BUG=b:254601048
TEST=Boot Crostini on arm

Change-Id: I62dc4670c2a216aa9a062f6d57ff945162e26037
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3976062
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-11-15 22:12:01 +00:00
Daniel Verkamp
0fcd5c7c04 kernel_loader: rename some errors to be more generic
This will allow them to be used in a non-ELF kernel loader without being
misleading.

BUG=b:254601048
TEST=cargo test -p kernel_loader

Change-Id: I47e632e16b242813ffebcab88285b284cafcb6c2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3995582
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-11-15 21:01:36 +00:00
Keiichi Watanabe
621e719751 cargo: Deny compiler warnings
Fix exiting compiler warnings and enable "-Dwarnings" to reject code
emitting new warnings

BUG=b:181763000
TEST=CQ

Change-Id: I2ab69e861f0bf9dee8378ac1b33354c87a6a0c42
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4011747
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-11-08 16:53:48 +00:00
Daniel Verkamp
e8fe4b2400 aarch64: provide initial vcpu regs via vcpu_init
The code from configure_vcpu_early() is split into two parts:
1. vcpu_features() returns the `VcpuFeature`s required for vcpu.init()
2. vcpu_init() returns the general register state

This makes use of the new generic vcpu_init code path and moves the
general purpose register initialization into configure_vcpu() rather
than the ARM-specific confgiure_vcpu_early() to be consistent with other
architectures. Only the vcpu.init() call needs to happen before irqchip
is finalized on ARM, not other register setup.

BUG=b:237095693
TEST=tools/presubmit --all
TEST=Boot Crostini on trogdor

Change-Id: Ib3eab946ba9f1e407f339c2119d36d280655066f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3786979
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-02 18:08:46 +00:00
Masami Hiramatsu
c80de3af0e aarch64: Fix Goldfish battery to send IRQ correctly
Since the virtio allocates all available IRQ lines for VGIC,
system_allocator::allocate_irq() returns 32 for Goldfish battery,
but that is not handled by the VGIC. In the result, the interrupts
from Goldfish Battery device are dropped in the host kernel. Thus
even if the crosvm detects the AC unplug, it is not notified to
the guest.

To fix this issue, assign a static IRQ number (#3) to Goldfish
battery device as same as other devices, so that it can deriver the
interrupts correctly to the guest side via VGIC.

BUG=b:252582345
TEST=Boot the ARCVM and run 'dumpsys battery' and unplug/re-plug
  AC connector several times, and confirm the AC status is updated.

Change-Id: Icdf3713cdf615d0039dd4e7719b80cad32333094
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3971137
Reviewed-by: Masami Hiramatsu <mhiramat@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Masami Hiramatsu <mhiramat@google.com>
2022-10-25 01:02:33 +00:00
Daniel Verkamp
474d2eea17 arch: split fdt code into its own crate
This will let the hypervisor crate use types and functions from the new
cros_fdt crate (it could not depend on arch, since that would cause a
circular dependency).

No functional change, just code movement.

BUG=b:253416076
TEST=cargo build
TEST=cargo build --target=aarch64-unknown-linux-gnu

Change-Id: I62d906941867c45f1b77ff1db6923d915ce2123e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3965088
Reviewed-by: Steven Moreland <smoreland@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-10-19 17:43:19 +00:00
Pierre-Clément Tosi
b779c5cdef hypervisor: ProtectionType: Add helper methods
Introduce a set of helper methods that expose individual characteristics
that particular subsets of the ProtectionType variants share. These will
simplify various match statements into conditionals by encapsulating the
deduction of those characteristics, making the calling code more concise
and robust.

BUG=b:243646855
TEST=build

Change-Id: I65ff3e61c448d90704551b79c21c64d1b4c11dc4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3944852
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-10-14 14:12:46 +00:00
Andrew Walbran
13cbc69abc aarch64: Don't include pVM firmware region in memory size calculation.
The pVM firmware memory region is allocated before
AARCH64_PHYS_MEM_START, but several parts of the code were assuming that
all memory was contiguous and after that.

BUG=b:244553205
TEST=Patched into AOSP and ran some VMs.

Change-Id: I8caefc9cae79c98ea62ee02a506b1b485d3f09a6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3921604
Reviewed-by: Pierre-Clément Tosi <ptosi@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Jiyong Park <jiyong@google.com>
2022-10-12 17:42:33 +00:00
Pierre-Clément Tosi
7245e26c57 aarch64: Add support for GDB SingleRegisterAccess
Add the infrastructre for GDB 'p'/'P' packets, used by the client to get
or set individual registers.

Implement a back-end using KVM_{G,S}ET_ONE_REG on AArch64, enabling the
client to access the architecture's numerous system registers.

Add stubs for x86 to please the compiler; leave them unimplemented as,
although the ioctl is available, the architecture doesn't seem to make
use of it.

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

Change-Id: I01968275e88e9d0098de40b3f78e2cd3a61b75da
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3785468
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-09-28 11:26:00 +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
Dennis Kempin
1dab58a2cf Update all copyright headers to match new style
This search/replace updates all copyright notices to drop the
"All rights reserved", Use "ChromiumOS" instead of "Chromium OS"
and drops the trailing dots.

This fulfills the request from legal and unifies our notices.

./tools/health-check has been updated to only accept this style.

BUG=b:246579983
TEST=./tools/health-check

Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-09-13 18:41:29 +00:00
Peter Collingbourne
87ddd08405 hypervisor: change the last KvmVm::new argument to a struct
We are going to need to start passing a new arch-dependent configuration
parameter to KvmVm::new in addition to protection_type. Since we can't
[cfg] a function argument, and to avoid churning the tests the next time
we need another argument, let's create a hypervisor::Config struct and
start passing protection_type that way.

Bug: b:234779841
Change-Id: I42ce9438b064658ebb9732e78ee5c82dac2636b6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892140
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Peter Collingbourne <pcc@chromium.org>
2022-09-13 17:14:44 +00:00
Xiong Zhang
6a3fa62327 pci: Add a function to construct ssdt method for vfio-pci
For vfio-pci device, guest couldn't call this device's acpi method like
_DSM/_DSD/_PS0..., in order to let guest run it, crosvm will provide
virtual method to guest, this virtual method pass guest method call into
host and pass host return value into guest.

This commit adds a function into pci device trait, which returns the
aml code to construct virtual acpi method. Two pages mmio are used to
pass acpi parameters and return value, when guest access the first page,
vm exit happens and it is trapped into crosvm, when guest access the
second page, no vm exit happens.

Co-authored-by: Victor Ding <victording@google.com>

BUG=b:194390621
TEST=tools/presubmit

Change-Id: I71797394de61437d4d105e65488d36511c71cbd7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3813137
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Victor Ding <victording@chromium.org>
Commit-Queue: Victor Ding <victording@chromium.org>
2022-09-07 04:42:44 +00:00
Pierre-Clément Tosi
3174c86a36 tree-wide: Rename protected_vm as protection_type
Rename all local variables across the codebase to be consistent with the
recently renamed cfg.protection_type (from cfg.protected_vm). This
commit is intended to make the renaming less cumbersome to review.

Note: no functional change intended.

BUG=b:243646855
TEST=build

Change-Id: I495b0854ce60cb1dc041ef43480fe11b379883c2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3867616
Tested-by: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
2022-09-01 22:20:40 +00:00
Pierre-Clément Tosi
436d19645c config: Rename cfg.protected_vm as protection_type
Improve clarity and consistency between the variable and its type, given
that it represents the protected/unprotected state AND whether some
firmware needs to be used. In particular, it isn't the protected VM
itself.

Similarly, rename components.protected_vm for the same reason.

OTOH, keep cmd.protected_vm for --protected-vm as it is dedicated to
making the VM protected and follows the name of the CLI flag.

Note: no functional change intended.

BUG=b:243646855
TEST=build

Change-Id: Id91d1c83e9efa79562022dacf37f4c89e451f2b5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3867615
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Pierre-Clément Tosi <ptosi@google.com>
2022-09-01 22:20:40 +00:00
Pierre-Clément Tosi
a673d2e639 aarch64: configure_vcpu_early: Refactor ABI setup
Flatten the logic for initializing the PC and group the pvmfw ABI code.

Note: no functional change intended

BUG=b:243646855
TEST=build

Change-Id: I973dfb324d9facdc3f79cbdb41b69b8a7fd1444e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3867614
Tested-by: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
2022-09-01 22:20:40 +00:00
Dmytro Maluka
d98e20b908 crosvm: Preserve platform devices in RunnableLinuxVm
If a vfio-platform device has no mmio regions, it is unexpectedly
destroyed at startup (in particular, its vfio device fd is unexpectedly
closed, so its interrupt forwarding stops working, etc) since in
generate_platform_bus() arced_dev is not added to mmio_bus so there are
no more references to the device. To fix this issue, preserve references
to platform devices also in platform_devices field of RunnableLinuxVm.

BUG=b:197169350
TEST=Use vfio-platform for passthrough of a device with interrupts but
without mmio regions, e.g. touchpad on Brya, and check if it works in
the VM (i.e. its interrupts are successfully delivered).

Change-Id: I4042c5508ef6b69649c7d20962edf61b735abc03
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3820043
Commit-Queue: Dmytro Maluka <dmaluka@google.com>
Tested-by: Dmytro Maluka <dmy@semihalf.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-26 08:41:37 +00:00
Pierre-Clément Tosi
669af0d4d7 VcpuRegAArch64: Parametrize X0-X30 as X(u8)
Use a single variant to represent a core GPR instead of having one
variant per register. This simplifies manipulating VcpuRegAArch64 at the
expense of needing the instantiating code to ensure that the <u8> is
properly set (i.e. is < 31). This is currently not an issue as the
variant is only instantiated with constant values.

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

Change-Id: I0043c101e88794a1661fadbc22b79fc68356270d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3822688
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Tested-by: Pierre-Clément Tosi <ptosi@google.com>
2022-08-18 12:57:45 +00:00
Andrew Walbran
379dd2dfec Allocate pVM firmware memory consistently.
Allocate the same way as the rest of RAM, whether in
unprotected-with-firmware mode or actually protected mode.

TEST=tools/dev_container tools/run_tests --target=vm:aarch64

Change-Id: Ic0ebc0d90e91bd450af55f3252039ddab8d26443
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3827215
Commit-Queue: Andrew Walbran <qwandor@google.com>
Tested-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-17 10:08:53 +00:00
Andrew Walbran
3fcf6e68eb Allocate more RAM for pVM firmware.
We would like 2 MiB for runtime data as well as the 2 MiB image.

TEST=tools/dev_container tools/run_tests --target=vm:aarch64

Change-Id: I0c0cba35bfc6cf6d8c54afd7df8bd929726e2053
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3827214
Commit-Queue: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Andrew Walbran <qwandor@google.com>
2022-08-17 09:54:33 +00:00
Pierre-Clément Tosi
7b5f6b198f VcpuRegAArch64: Follow AArch64 for variant names
Rename the confusing GPR variants from the Wn naming convention (defined
by the architecture as the lower 32 bits of the 64-bit register) to Xn,
which the enum variants actually represent.

Note: no functional change intended.

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

Change-Id: I510b93f8aea901dc3707016368c9871392701f51
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3780660
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
Tested-by: Pierre-Clément Tosi <ptosi@google.com>
2022-08-16 18:51:13 +00:00
Tinghao Zhang
e3401082c9 devices: support hotplug for pcie switch
This patch adds support for hotplug pcie switch. The user send
HotplugCommand of the new added device with the same order they
appear in device tree, and in handle_hotplug_command we add device
accordingly. During hotplug out, firstly vfio endpoint device will
send hot unplug command, we remove these endpoint device immediate-
ly, and then remove any bridge that is hotplugged into the system
but with zero child device connected to it. When all child bridges
got cleared up and pcie root port have no child devices, we send
plug out interrupt to guest kernel and probe hotplug out handling
in guest.

BUG=b:199986018
TEST=hotplug in and out pcie switch repeatedly

Change-Id: Ic3ab86d14efba4d05e204936e08bc6a582723484
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3769817
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-10 18:50:26 +00:00
Daniel Verkamp
cd251b3067 Reformat imports with tools/fmt --nightly
A few new grouped imports have made it in since the tree-wide
reformatting.

BUG=None
TEST=tools/presubmit

Change-Id: I93af3c741f57c1da73d4c9e8a28be424c1ea45fe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3818244
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-08-08 20:29:50 +00:00
Tinghao Zhang
e931dee2a6 devices: pci: impl pci root worker
Hotplug command is facing dead lock issue when it tries to acquire
the lock for pci root in the vm control thread. Dead lock could
happen when the vm control thread(Thread A namely) is handling the
hotplug command and it tries to get the lock for pci root. However,
the lock is already hold by another device in thread B, which is
actively sending an vm control to be handled by thread A and
waiting for response. However, thread A is blocked on acquiring the
lock, so dead lock happens. In order to resolve this issue, we add
a new pci root worker thread and push all work that locks pci root
to this thread.

BUG=b:199986018
TEST=tools/presubmit

Change-Id: I11552a1c9c626035d0ca01ce2835fd8b6c067a67
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3765366
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-08 18:22:50 +00:00
Zide Chen
69775f0346 x86_64: add new option enable-hwp to expose HWP feature to guests
Expose HWP (HW P-State) feature to the guest if enable-hwp is present
and implement these dependencies:

- enable-hwp depends on host-cpu-topology option
- itmt depends on enable-hwp option

Group the CPU configuration entries to a new struct CpuConfigArch,
to simplify APIs in the vCPU configuration path.

BUG=b:199380745
TEST=boot Redrix manatee and verified that intel_pstate driver works

Change-Id: Icdd19190f6a7518492ff5fc54708af40288a1422
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3771065
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2022-08-05 20:33:12 +00:00
Alexandre Courbot
4c4ee4543c main: convert battery options to use serde_keyvalue
This requires the introduction of a BatteryConfig structure to parse,
which is probably a good idea anyway as it reserves some space to add
more battery-related options.

BUG=b:218223240
TEST=cargo test parse_battery

Change-Id: I82db7fe7ce2daeca004e734aaafa542583998561
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784661
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-08-02 07:06:10 +00:00
Sebastian Ene
46be6c3b59 vmwdt: Update the fdt node
Update the compatible name of the device to qemu,vcpu-stall-detector
and fix the clock-frequency property name to reflect the one defined in
LK upstream:

https://lore.kernel.org/all/20220711081720.2870509-2-sebastianene@google.com/

BUG: b:240271204
Change-Id: Ib0c6442343d95261f36f485f31426feec0f7dde3
Signed-off-by: Sebastian Ene <sebastianene@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3785482
Reviewed-by: Will Deacon <willdeacon@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-07-28 08:59:30 +00:00
Dennis Kempin
4fea399df9 Reformat imports
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.

Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.

BUG=b:239937122
TEST=CQ

Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-28 00:15:50 +00:00
Frederick Mayle
92e4fc9e75 aarch64: Don't add goldfish battery to fdt when not present
TEST=tools/presubmit
BUG=b:239577091,b:240298654

Change-Id: Idb171a4e326fcb2fba5ce788c40b97dcea3058f6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3787271
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-07-26 21:30:27 +00:00
Steven Richman
e3259f6319 kernel_loader: load elf32 images
Loading 32-bit images is needed for kvm-unit-tests.

BUG=b:233317135
TEST=boots, new unit tests

Change-Id: I6ba63255e0e2993f3735ef81489f64dbd0bb6374
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3764465
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Steven Richman <srichman@google.com>
Tested-by: Steven Richman <srichman@google.com>
Commit-Queue: Steven Richman <srichman@google.com>
2022-07-26 16:10:07 +00:00
Sebastian Ene
acb1f6683c vmwdt: Add memory mapped watchdog backend driver
This adds a new dt node identified by "qemu,vm-watchdog". The watchdog
is instantiated per-cpu and each instance has the following layout
described in this document:
https://docs.google.com/document/d/1DYmk2roxlwHZsOfcJi8xDMdWOHAmomvs2SDh7KPud3Y/edit?resourcekey=0-oSNabc-t040a1q0K4cyI8Q#heading=h.4hbqud2zl941

The watchdog uses an internal clock which is driven by the
timerfd at regular intervals. When the internal clock expires, a counter
value is decremented. When the counter register reaches value "0",
the watchdog expires. To prevent 'watchdog expiration', regular pet
events should be sent from the guest kernel driver.

BUG=b:213422094
Signed-off-by: Sebastian Ene <sebastianene@google.com>
Change-Id: Ic8c0488ffdfed1a43b6deb34b72d37f46e5e18a2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3768290
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-07-21 14:07:11 +00:00
Noah Gold
637b1ee1d1 arch: split platform lib code into sys mod.
Highlights:
* goldfish battery never worked on Windows, but it sort of compiled
  anyways downstream. This CL makes it unix only because it never worked
  on Windows as a device anyway.

BUG=b:237597358
TEST=builds

Change-Id: Ia5fc3b5e5fcd243d8454646b00a6857085d018ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3741432
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2022-07-14 00:08:33 +00:00
Daniel Verkamp
1b7d5b8fba arch: provide one vcpu_init per vcpu
Rather than having a single vcpu_init instance that is used for all
VCPUs, make vcpu_init into a Vec so it can store different initial state
for each VCPU. This allows us to set up e.g. bootstrap processor state
differently than other processors, and it also means that the VcpuInit
struct doesn't need to be Copy.

BUG=b:237095693
TEST=Boot Linux with >1 CPU

Change-Id: I0ebfdc2dbd84d0817e3f75c2c852e4320b9e77c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723798
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-29 18:14:49 +00:00