Commit graph

81 commits

Author SHA1 Message Date
Daniel Verkamp
ff3703b575 aarch64: remove support for 32-bit host userspace
Using the 64-bit KVM API from 32-bit Arm userspace was only possible on
ChromeOS due to a kernel hack that enabled the KVM compat ioctl with no
translation (so it passed through structs directly to the 64-bit host
kernel). This never worked on an unmodified upstream Linux kernel.

All supported Arm-based ChromeOS boards have been migrated to 64-bit
userspace, so we can drop the 32-bit Arm host support code.

BUG=b:452696537
TEST=crosvm CQ
TEST=ChromeOS CQ with crrev.com/c/7094556

Change-Id: I254bc4dbe7f760403cd93f37cc5fdcada23cd483
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6542041
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2025-11-13 14:37:26 -08:00
Elie Kheirallah
25fd04b43b hypervisor: kvm: x86: add nested_state to snapshots
BUG=b:430055804
TEST=presubmit, snapshot a nested VM scenario

Change-Id: I19a58e0b85f000aeaa6dc7c5f3e0837dd2e83702
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6794281
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
2025-08-05 13:35:31 -07:00
Mostafa Saleh
5db773b31a vfio : Update pvIOMMU for Android16-6.12
pvIOMMU is moving from experimental UAPI to Android16-6.12

Bug: 357781595
Bug: 348382247
Bug: 236685427
Change-Id: I35899049569286e8f047cba9a996d3797212ae95
Signed-off-by: Mostafa Saleh <smostafa@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6680690
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2025-06-27 10:39:39 -07:00
Nikita Ioffe
315a8aa171 crosvm cli: add --ffa=auto option
Starting with android16-6.12 kernels pkvm adds support for protected
guest VMs to FF-A protocol to communicate with trustzone.

Corresponding kernel UAPI is added in the following commit in ACK repo:
778832cb8b86ef8dbe66498ebb0c60f89629ccb2:
ANDROID: KVM: arm64: Introduce KVM_CAP_ARM_PROTECTED_VM_FLAGS_SET_FFA uapi

BUG=b:391774181
TEST=tools/presubmit

Change-Id: Ib48ce4d8a832e52fb9c0392c360a114a1c273c61
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6381774
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Nikita Ioffe <ioffe@google.com>
Commit-Queue: Nikita Ioffe <ioffe@google.com>
2025-04-28 02:33:47 -07:00
Dennis Kempin
1882d38588 infra: Re-enable riscv64 builds
- Re-enables riscv64 in tools/presubmit
- Re-builds the dev container with riscv64 dependencies
- Fixes a few clippy issues that have come up
- Re-enables the riscv64 builder in postsubmit

BUG=b:304875018
TEST=presubmit linux_riscv64 --no-delta

Change-Id: Icc67f924e2a3475f8f2aa1a5261dfc457afb66a1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6363077
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2025-03-17 14:19:18 -07:00
Daniel Verkamp
8948174ef3 bindgen: use upstream Linux headers
Move the ChromeOS-specific kernel header modifications into the
corresponding bindgen.sh patch sections.

This also downloads the Linux source rather than relying on the ChromeOS
kernel source tree, so it should work without having a chromiumos
checkout.

BUG=b:402466294
TEST=tools/bindgen-all-the-things

Change-Id: I8cb00cdaf847a0a9442722ec9e69e8c6b47cf437
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6345302
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-03-12 12:32:22 -07:00
Daniel Verkamp
f20af151e2 crosvm: upgrade zerocopy to 0.8
BUG=b:372549215
TEST=tools/dev_container tools/presubmit

Change-Id: I3fcc524d1c6c41ae92c51cecb6e4d856c3d60670
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6255229
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-02-24 11:35:51 -08:00
Daniel Verkamp
c5aa46e4ef plugin: replace kvm_ioapic_state with a zerocopy-able version
The plugin code wants to access various kvm_sys structs as raw bytes for
the purpose of serialization/deserialization, but in the case of struct
kvm_ioapic_state, this is a problem, since it contains a union and
bitfields. We previously worked around this by manually implementing
the zerocopy traits for the bindgen-generated bitfield types, but this
breaks when trying to upgrade to zerocopy 0.8.

Avoid this by manually defining an equivalently sized and aligned
structure without the problematic features. This will get cleaned up
once we drop the separate `kvm` crate and only have the `hypervisor`
crate left.

BUG=b:372549215
TEST=cargo build --features=plugin

Change-Id: I5fb800793663149f4272514416de6620cfbca7e6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6255228
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zihan Chen <zihanchen@google.com>
2025-02-14 13:07:18 -08:00
Daniel Verkamp
e8d03c74ac bindgen-common: use ChromeOS kernel 6.12 headers
Update the kernel version used to generate the bindings from Linux 6.6
to Linux 6.12, and remove the manual kvm_userspace_memory_region2
additions from kvm_sys/bindgen.sh.

The KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA capability index was changed
between ChromeOS v6.6 and v6.12, so a workaround to use the v6.6 value
is added; this maintains the existing behavior of querying cap index 236
on all kernels, which may return unexpected results on non-ChromeOS
kernels or ChromeOS v6.12 kernels.

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

Change-Id: Icccc022005de37e12d552951eaadcf6c20ac914a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6150076
Reviewed-by: Ryan Neph <ryanneph@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-01-09 14:41:33 -08:00
Ryan Neph
d843f25959 kvm_sys: update bindings for KVM_SET_USER_MEMORY_REGION2
Remove NONCOHERENT_DMA constants, which are now patched into
chromeos-6.6 kernel for bindgen to automatically generate.

Add SET_USER_MEMORY_REGION2 constants + ioctl, which are present in
upstream 6.12 kernel but not chromeos-6.6 kernel branch. These are
needed for crosvm running on `-kernelnext` board variants, which track
6.10-6.12 kernels containing the new ioctl.

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

Change-Id: I1f6d9c1dc66081627d239ea2e0faae3f480401b0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6094777
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Ryan Neph <ryanneph@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-12-17 15:06:43 -08:00
Dmytro Maluka
f0c46addbb x86_64: support running protected VMs with pvmfw
Add support for running protected VMs on x86 in the proper way, i.e.
similarly to arm64, ask the pKVM hypervisor to load the pVM firmware
(pvmfw) into the VM memory at a dedicated address and to set the VM
entry point to the pvmfw address.

The KVM uAPI used for that (for setting pvmfw address in guest memory
and for querying pvmfw size) is almost exactly the same as on arm64.
But as explained in [1], this is a temporary uAPI anyway, so for now
don't try to generalize the crosvm code using this uAPI between both
architectures.

[1] https://android-review.git.corp.google.com/c/kernel/common/+/3372231
[2] https://android-review.git.corp.google.com/c/kernel/common/+/3372235

BUG=b:350694931
TEST=a VM run with "crosvm run --protected-vm" runs successfully,
assuming that the bootloader provides pvmfw image to the host kernel, or
using a pKVM hack described in "Test:" in [2] instead.

Change-Id: I64242bcd0a4c053b8c27c2f83d5c876a885d0442
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6043709
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dmytro Maluka <dmaluka@chromium.org>
Reviewed-by: Pierre-Clément Tosi <ptosi@google.com>
2024-11-25 18:00:07 +00:00
Dmytro Maluka
b12e8c2cac x86_64: add initial support for protected VMs
Add support for running protected VMs with pKVM on Intel x86 [1].

The --protected-vm option is not workable yet, since loading pvmfw into
guest memory via pKVM is not implemented yet, but the developer options
--protected-vm-without-firmware and --protected-vm-with-firmware are
working.

Following the approach used for pKVM on arm64, the KVM uAPI used for
running protected VMs on x86 is a "stable temporary" uAPI: the
KVM_X86_PKVM_PROTECTED_VM value shall be updated when upstreaming pKVM
to the mainline kernel (see also [2]).

[1] https://android-review.git.corp.google.com/c/kernel/common/+/3351287
[2] https://android-review.git.corp.google.com/c/kernel/common/+/3351286

BUG=b:349990461
TEST=On an Intel device with kernel compiled with pKVM-IA patches [1]
and kvm-intel.pkvm=1 added to kernel command line, run a VM with
--protected-vm-without-firmware or with --protected-vm-with-firmware
with the same test pvmfw image as in TEST= in CL:5797353.

Change-Id: I625f5eb9a38eaef9312ba62308739efb66f163b0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6022852
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dmytro Maluka <dmaluka@chromium.org>
2024-11-18 15:03:41 +00:00
Elie Kheirallah
97dbce5226 hypervisor: aarch64: add SVE support
Refactor `init` and add function `get_features` to get the Vcpu features.
Previously some features were only retrieved as part of `init`.
Add function `finalize` which is required for SVE support. SVE requires
`KVM_ARM_VCPU_INIT` to be called first, which gives access to the SVE
config, specifically `KVM_REG_ARM64_SVE_VLS`, which is a
pseudo-register that allows discovering and configuring the vector
lengths by userspace. After `finalize` is called,
`KVM_REG_ARM64_SVE_VLS` is no longer accessible, and the config is
final. In this patch, we are not modifying the vector lengths, reason
behind this is `KVM_ARM_VCPU_INIT` initializes `KVM_REG_ARM64_SVE_VLS`
to the best set of vector lengths that the host supports.

BUG=b:375372656
TEST=presubmit

Change-Id: Ibd0902ad68f28b9d4e9a595070fe972e620e5572
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5973935
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
2024-11-01 17:08:42 +00:00
Pierre-Clément Tosi
20eee9bace kvm_sys: Move KVM_PVIOMMU_SET_CONFIG to lib.rs
Replace the ioctl definition using a magic number with the appropriate
macro call. Note that this commit also limits the availability of the
constant to AArch64 Android, the only builds using it as per the cfg
attributes of KvmVfioPviommu::ioctl_kvm_pviommu_set_config().

TEST=m crosvm # in AOSP, then validated the constant using decompilation

Change-Id: I6099a69419c5c562b0c5ce5b27ac3f24b73c9244
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5750141
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-07-30 18:17:34 +00:00
Pierre-Clément Tosi
b03a2f699d bindgen: Update KVM_PVIOMMU_SET_CONFIG ioctl num
Update the ioctl number to a well-formed value, following the similar
fix to the experimental Android kernel. Obviously, this is a breaking
change rendering new (resp. old) versions of that kernel incompatible
with version of crosvm missing (resp. including) this commit.

However, this is fine because both the kernel and this support for
pKVM-VFIO are experimental, as stated in fdb527c202 ("vfio: Add
support for pKVM-VFIO pvIOMMUs").

TEST=Commit-Queue
Bug=b:278039964
BUG=b:306110430

Change-Id: Iefdebfb3df41aa647fac43eab50e379ca7821817
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5739077
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-07-29 12:11:23 +00:00
Tatsuyuki Ishi
c2bad2ed99 Implement virtio-pvclock for arm64
BUG=b:333815324
TEST=tast run arc.Suspend.* (with https://crrev.com/c/5529202)

Co-authored-by: Suleiman Souhlal <suleiman@google.com>
Change-Id: I991192b42419d5aef488ffc625eb28ef4931124c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5487336
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2024-05-14 04:04:52 +00:00
Daniel Verkamp
de988e9eb7 kvm_sys: clean up arch-specific ioctls
A few x86-specific definitions are moved inside `mod x86`.

The cfg checks for `KVM_GET_REGS` are removed, since this ioctl is in
fact available on aarch64 (arm64); possibly the original confusion was
due to the fact that this ioctl is not available on 32-bit arm, but we
don't support the 32-bit arm ioctl interface.

The arch-specific re-exports are moved to immediately follow the
relevant module for consistency (and to ensure `cargo fmt` doesn't
rearrange them in a confusing way).

Outdated bindgen commands in comments are removed; the bindings are now
generated by an automated script.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: I9b0072e7dc90e7b328652dc39d5d82b30ba8d462
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5518125
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
2024-05-06 22:44:24 +00:00
Kaiyi Li
c28067d1d9 Reformat comments
Test: presubmit
Change-Id: I39c261d9985989873b698213c5d8b653fc13757b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5299850
Auto-Submit: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-02-15 23:30:13 +00:00
Zhenyu Wang
53c8fb14bf devices: apply new noncoherent attribute for GPU mem's cache info
On Intel, new noncoherent DMA mem flag can be set to allow KVM to
recognize guest cache setting for EPT, which allows WC attribute to be
applied to ensure guest memory access is synchronized in noncoherent DMA.

Unlike previous POC for new device attribute, this uses new added flag
for mem slot.

BUG=b:316337317
TEST=cargo build and run GPU workload

Change-Id: If16d61031bdb2cf0252a57e99d4b6725a89dd38a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5171312
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stanisław Kardach <skardach@google.com>
2024-01-26 23:27:58 +00:00
Daniel Verkamp
650fbaf7fc kvm_sys: add riscv support to bindgen.sh
This generates riscv64/bindings.rs from the kernel headers to bring it
in line with the other auto-generated bindings, which is possible now
that we are generating the bindings from new enough kernel headers
(Linux 6.6).

BUG=b:287496832
TEST=tools/dev_container tools/presubmit crosvm_unit_tests_riscv64

Change-Id: I86c17d75a467368dcc99e616a2dfd31ee8cb1071
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4676074
Reviewed-by: Dylan Reid <dgreid@rivosinc.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-01-09 00:37:43 +00:00
Daniel Verkamp
c970dd44f4 bindgen: update to Linux 6.6 headers
The obsolete KVM_SET_MEMORY_ALIAS ioctl was removed from the kernel; it
was already unused in crosvm, so remove the corresponding ioctl macro.

Change-Id: I1ecfce4b8df886680154c567f82ab7f006fbfd1f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5178535
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-01-09 00:37:43 +00:00
Daniel Verkamp
ae33ac2934 bindgen: regenerate all bindings with bindgen 0.68.1
This removes some auto-generated safety comments, but should otherwise
be a no-op.

Change-Id: Ibfcf75c6e296367fe1a6114ce2047fb79e34041b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5178534
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-01-09 00:37:43 +00:00
Daniel Verkamp
345cefa5cd kvm_sys: regenerate x86 bindings with bindgen.sh
This was missing the most recent additions from kvm_sys/bindgen.sh.

The changes are not relevant for x86, but it is useful to keep the
generated file up to date to avoid confusion when the bindings are
modified in the future.

TEST=kvm_sys/bindgen.sh

Fixes: fdb527c202 ("vfio: Add support for pKVM-VFIO pvIOMMUs")
Change-Id: I9305150506785c2b4b4d0e25e88b2c2b365bf80c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5178532
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-01-09 00:37:43 +00:00
Vikram Auradkar
2768f223ee clippy: enforce safety block comments
BUG=b:316174930
TEST=none

Change-Id: I5c7811b2c548155aa003e4b71a54bbc16e2f2588
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5120567
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-12-14 18:21:54 +00:00
Pierre-Clément Tosi
fdb527c202 vfio: Add support for pKVM-VFIO pvIOMMUs
Teach crosvm to spawn para-virtualized IOMMUs emulated by pKVM, which
are used by protected VMs to control the DMA translation regime of their
assigned (physical) devices without relying on the (untrusted) host or
VMM.

Implement a virtual topology with a 1-to-1 mapping between VFIO devices
and pvIOMMUs (i.e. no support for multiple devices per pvIOMMU nor for
multiple pvIOMMUs per device).

To allow guests to refer to individual pvIOMMUs in calls to the
hypervisor (for example, to map/unmap DMA), they are given an ID, which
the uAPI defines as the FD returned from one of its ioctls.

Like the rest of pKVM, this feature is specific to Android on AArch64.

Note: This makes use of a uAPI that is currently only available on some
      experimental (non-production) Android kernels and is likely to
      change!

TEST=tools/run_tests
BUG=b:306110430

Change-Id: I00c065754cffa39307272ad00698647e56404894
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5009546
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-11-15 10:50:46 +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
Daniel Verkamp
931fcafe0b bindgen: regenerate bindings with bindgen 0.68.1
In particular, this fixes the Clone impl for __BindgenUnionField, which
triggers clippy's incorrect_clone_impl_on_copy_type in Rust 1.73.

Additionally, --size_t-is-usize became the default and the option was
removed in bindgen 0.65.0, so the flag is dropped from our bindgen
command line.

BUG=None
TEST=tools/bindgen-all-the-things

Change-Id: I40a26cd4a9e2897af8a354f454f4909429d2feda
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4927831
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-10-10 22:54:22 +00:00
Zihan Chen
a5e63d4474 crosvm: Remove DataInit
DataInit type is finally completely eliminated from crosvm. No
traces, not even in comments, were left.

BUG=b:300969352
BUG=b:204409584

Change-Id: I79742f8e06b90afd53fab338d9052b25ae0af84e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4878508
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-10-10 19:40:48 +00:00
Zihan Chen
26dbfe3cb4 kvm_sys: Update bindings
Update bindings for new kernel to seprate from change to bindings
due to modified bindgen script.

TEST=CQ

BUG=b:300969352

Change-Id: I8a1ff5c1e7cc25b0af3b25b6509c693b3c0e1f95
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4928008
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Zihan Chen <zihanchen@google.com>
2023-10-10 19:40:48 +00:00
Daniel Verkamp
4be56406b6 Remove target_arch = "x86" checks
crosvm has never actually supported running on a 32-bit x86 host, only
x86-64. Remove the cfg(target_arch = "x86") checks throughout the tree
to make this clear (and to simplify the code).

This doesn't affect the code running inside the guest, which can still
be a 32-bit x86 operating system if launched via --bios, for example.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: Ifd888db54c58ec8a5fcf840871ef564771d9066b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4794387
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-08-18 23:36:47 +00:00
Daniel Verkamp
8943b0c616 kvm: remove KVM_CAP_IOAPIC_NUM_PINS
This is not in upstream Linux, only used by crosvm-direct, which is
being removed. Partially reverts commit f622e504d3 ("crosvm/kvm:
enable runtime detection of IOAPIC pins").

BUG=b:276993009
BUG=b:279663365
TEST=tools/dev_container tools/presubmit

Change-Id: I2d6501a268c635145d8cd25944b5c82fc82b4ec4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4615556
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-07-05 23:10:55 +00:00
Daniel Verkamp
a758a209ba kvm_sys: finish KVM_SYSTEM_EVENT_S2IDLE removal
This was left over from commit a8985f0ba8 ("x86: remove deprecated
KVM based s2idle notification related code"). Additionally, the comment
about the bindgen script was removed even though it is still in the
script, so the generated output did not match what was checked in.

BUG=None
TEST=kvm_sys/bindgen.sh

Change-Id: I241220dd5d0121ce2dca1ce0597ebf1f258f1c20
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4518567
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-05-09 18:17:17 +00:00
Grzegorz Jaszczyk
a8985f0ba8 x86: remove deprecated KVM based s2idle notification related code
This commit reverts 344e2432d1 "x86:
handle KVM_SYSTEM_EVENT_S2IDLE request" but also some other parts which
grow around this concept. The s2idle notification linux counterpart
based on KVM hypercall was rejected in the linux kernel mailing list and
new approach was suggested which is based on virtual PMC.  Additionally
the privileged guest term was introduced only for ManaTEE, which is not
evaluated anymore.

The new Virtual PMC related approach is used instead for getting guest
s2idle notifications, see CL:3780642.

BUG=None
TEST=Build + tools/presubmit crosvm_tests_x86_64

Change-Id: I3cf4b77ab192198fe9e8b990b994a41105c2e72f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4507305
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-05 22:24:58 +00:00
Dylan Reid
94f82931a4 kvm_sys: initial riscv64 bindings
Add initial KVM bindings generated from a 6.2 tree with the AIA patches
applied.
See the riscv_kvm_aia_v1 branch here: https://github.com/avpatel/linux
The AIA changes should land soon upstream, but pulling them in early
won't hurt other arches and will allow riscv to get started.

Change-Id: I9e20c968e6c044100bc6ec1b2fb5f441f0276f77
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4460933
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-25 00:13:57 +00:00
Dylan Reid
79b959f6cf kvm_sys: Remove KVM_SET_MEMORY_REGION
This ioctl has been long deprecated and is removed from 6.2+ kernels.
It's not used by crosvm so this change should have no affect.

Change-Id: Ieb1b7c1772643d221356ca1ecb8f6a32095febba
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4460931
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-24 23:20:41 +00:00
Elie Kheirallah
041764bcd3 hypervisor: Add get_xsave and set_xsave support to x86.
This change adds the function get_xsave to the x86/86_64 platform.
get_xsave allows us to get state of the x87 FPU, MMX, XMM and YMM registers.
This change is needed for serializing vCPUs.
Adds also function to check if XSAVE2 Capability is enabled.
get_xsave is not implemented yet for Windows.

BUG=b:266515147
Test=Build and run VM

Change-Id: I5a9d3b2b86bc11a66db331b4b25d0c348459ab69
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4292298
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Elie Kheirallah <khei@google.com>
2023-03-03 00:30:04 +00:00
Daniel Verkamp
2712fc59b1 bindgen: update kernel bindings to Linux 6.1
Switch to the ChromeOS v6.1 branch and regenerate all affected bindings
in the crosvm tree.

Some minor fixes were required in users of the bindings:
- KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 is available in the kernel now
  and was removed from the manually-added section of kvm_sys.
- The KVM system_event now contains an anonymous union, requiring a few
  renames.
- IORING_OP_* were moved into an enum, which required the enum name to
  be prefixed to the uses of those values.

BUG=None
TEST=tools/presubmit --all

Change-Id: I84568fb76658832130e2e9a631495ba82fd4c3ed
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4285742
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-02-23 21:31:44 +00:00
Dennis Kempin
acc162000f Add conditional compilation for unix-only crates
Instead of configuring which crates to --exclude in
test_config.py, we can use conditional compilation to
exclude code that is not supported on windows.

This allows more fine-grained control and also allows
us to use plain cargo for building without complicated
configuration and exclusions.

BUG=b:265829867
TEST=cargo test --lib --bins --workspace
	--target=x86_64-pc-windows-gnu
	--features=all-mingw64

Change-Id: I8422c3f08053bc27d9896b220876a56bd25543d6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4165868
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-19 21:21:59 +00:00
Daniel Verkamp
11a94b98a8 crosvm bindgen: regenerate with missing_safety_doc
Regenerate all of the automated bindgen bindings by running
tools/bindgen-all-the-things after commit 54311a8da9 ("crosvm bindgen:
Allow missing_safety_doc").

BUG=b:157245930
BUG=chromium:908640
TEST=tools/presubmit --all

Change-Id: I334f2ddc071acbf634f0d771d88650ee348cd5a0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4025271
Reviewed-by: Zihan Chen <zihanchen@google.com>
Reviewed-by: Clarissa Garvey <clarissagarvey@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-15 20:43:50 +00:00
Daniel Verkamp
74f1ca4e78 bindgen: update bindings to Linux 5.15
This requires a few tweaks to non-generated code:
- VIRTIO_ID_VIDEO_ENC/DEC -> ENCODER/DECODER
- io_uring unnamed union layout change

Change-Id: I58e118efa5c6bf28ff56d211fec5603651cb60bc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3893753
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-09-14 22:09:30 +00:00
Peter Collingbourne
96b95accf3 aarch64: Expose MTE to guests
A proposed set of kernel patches makes it possible to map anonymous
MAP_SHARED mappings into the IPA space of a virtual machine with MTE
enabled. With these patches we can use most features of crosvm with the
exception of pmem which relies on being able to make file mappings in the
IPA space. Therefore, we make MTE an opt-in feature via the --mte command
line argument and forbid specifying --mte together with --pmem-device
or --rw-pmem-device.

Bug: b:234779841
Change-Id: I70bf2d0a8c1aff7c5956d6009ca5169a623bc6b2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892141
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Peter Collingbourne <pcc@chromium.org>
Commit-Queue: Peter Collingbourne <pcc@chromium.org>
2022-09-13 21:05:15 +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
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
Daniel Verkamp
62636c5b2f data_model: use fully qualified name in flexible_array_impl! macro
The flexible_array_impl! macro should not rely on the caller to import
FlexibleArray; use $crate::FlexibleArray to refer to it instead.

BUG=None
TEST=tools/presubmit

Change-Id: I9743a4cbc01deb6cdfadd98e63f4803a5572421c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3687064
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-06 18:17:03 +00:00
Peter Collingbourne
4f7d84e5b9 Fix some clippy warnings on aarch64.
Change-Id: Iac9a9540c585a08374c966a1014c6746fbba0554
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3687061
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Peter Collingbourne <pcc@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-06 16:58:32 +00:00
Dapeng Mi
a5d52312d5 crosvm: implement KVM_X86_SET_MSR_FILTER ioctl
turbostat shows cpu freq/c-state/thermal statistics data by reading
some related MSRs. Unfortunately some MSRs such as MSR_IA32_POWER_CTL
are already emulated by KVM. The emulated value are not what we want
to expose to Chrome OS guest. KVM_X86_SET_MSR_FILTER ioctl provides
a way to skip KVM's emulation and let user space handle the MSR.

We added two MSR actions "MsrPassthroughFilter" and "MsrEmulateFilter"
to indicate the corresponding MSR needs to be filtered.

BUG=b:229770963
TEST=Run "turbostat" in Chrome OS guest and show correct value.

Change-Id: I5920ddba091589170dc326e10187aec66f75df79
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3641465
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-30 06:35:12 +00:00
Daniel Verkamp
45b0920767 doc: add a top-level comment to all crates
This provides at least a minimal one-line description to show what each
crate is about.

BUG=None
TEST=tools/cargo-doc

Change-Id: I26732e8c29062e622d5be09bdc120a49d564b9fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3630422
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-06 20:46:57 +00:00
Daniel Verkamp
4da1409c03 kvm_sys: regenerate x86 and aarch64 bindings
BUG=b:218388029
TEST=tools/presubmit --quick

Change-Id: Iac652e043575f5c16acf4da5101dd89a15220f33
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3339809
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-17 22:26:55 +00:00
Zide Chen
344e2432d1 x86: handle KVM_SYSTEM_EVENT_S2IDLE request
When Crosvm receives a KVM_SYSTEM_EVENT_S2IDLE event, it means the
guest VM is entering s2idle suspend state, and it's requesting the
host to put the whole system in the same state.

If hypervisor sends the request on behalf of a privileged VM, Crosvm
can initiate s2idle suspend on the host since it's been granted with
system power management privileges.

BUG=b:199383670
TEST=trigger s2idle from ChromeOS guest

Change-Id: I589a7e1d93abb5ab971fd58de94ee75df48c3c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3414635
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmytro Maluka <dmaluka@google.com>
Commit-Queue: Allen Webb <allenwebb@google.com>
2022-03-03 22:30:45 +00:00
Andrew Walbran
40b470c6b5 Log reset_type and cookie for PSCI SYSTEM_RESET2.
These may be used by the pVM firmware or bootloader for protected VMs on
Android to indicate the reason why a VM failed to boot, such as a
verification failure, and so we want to have them in the logs for
debugging.

BUG=b:220084045

Change-Id: I449873fb85d590d9e7978a93648e90586ecfff10
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3473452
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2022-03-01 16:03:06 +00:00