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>
In preparation for enabling tools/clippy to check riscv, clean up the
warning in the hypervisor crate.
Change-Id: Iab2d1f703e0ab5e40ed165873376cdfabdc3de60
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4505756
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
The KVM docs say
If setting an MSR fails, ..., it stops processing the MSR list and
returns the number of MSRs that have been set successfully.
So, a return value of zero really means the operation completely failed.
Change-Id: Ic98cdb02513ff86e22fb6b048e7ceb2d6b7e554a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4500732
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
MSRs are specific to x86/x86-64; add the appropriate cfg checks and
remove the MsrHandlers stubs from aarch64 and riscv64.
Change-Id: I94f0b5b4b9f75fecdc8e03c569f89a70b7f9f647
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4482135
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
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>
Add basic support for linux kvm running on a riscv64 cpu. Mostly mirrors
the arm support as the interfaces are luckily similar.
Change-Id: I77c091d9b30758788b7c97bc0b3804879e27055d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4460938
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
When snapshotting, the interrupt state (pending or otherwise) needs to
be saved from the VCPU. Every hypervisor has its own implementation
of how this is exposed to VMMs (KVM uses vcpu_events). This CL adds
an implementation for WHPX's VCPU.
BUG=b:270734340
TEST=builds (we can't test the full WHPX snapshot flow yet; need to
reach critical mass on implementation first).
Change-Id: Ic97ad15391f277967bd7b19a7ff6b55c57f3a00b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4428057
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
EIO is more appropriate than unsupported for this error.
BUG=b:270734340
TEST=builds
Change-Id: Idaf8c291c7301f1ee929aafc12bf032f19d71e35
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4425875
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Originally VcpuEvents was modeled on KVM's vcpu_events struct. Other
hypervisors like WHPX represent the sort of data that's in KVM's struct
very differently. This CL moves us to use a json blob that each
hypervisor can define for itself, which unblocks implementing for WHPX.
BUG=b:270734340
TEST=tools/dev-container e2e_tests/run
Change-Id: I1600f4303ee5bf2aebeaeb92a215edaea2f69a87
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4421490
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
MSR index 0x3f1 (MSR_IA32_PEBS_ENABLE) is now allowed to be fetched by
KVM_GET_MSRS in newer kernels.
Pick an even more invalid MSR index so the MSR will actually fail to be
fetched.
BUG=b:275605159
TEST=cargo test -p kvm -p hypervisor # on Linux 6.1
Change-Id: Ia4f34ca43893535883620e82f35a955e630a9743
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4419606
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
I suggested a workaround to make Xsave data 4-byte aligned for KVM while
representing it equivalent to a Vec<u8>, but the suggestion was
incorrect - the workaround made each XsaveByte one byte of data and
three bytes of padding, which was not intended.
Partially revert the representation of Xsave to a Vec<u32>, but keep the
Xsave::new() function so the caller does not need to know about the
internal representation.
BUG=b:270734340
TEST=tools/dev_container tools/presubmit
Change-Id: I5d51f02d4fee061840d591a9ef16a78f44274064
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4412666
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
get/set_xsave lets us get/set the xsave data on a VCPU. Originally this
was set to be represented as Vec<u32> since that's what KVM uses on its
ioctl; however, other hypervisors like WHPX prefer an opaque byte array.
This CL switches us to a byte array. From KVM's perspective, this is
identical because we still require a 4 byte alignment.
BUG=b:270734340
TEST=builds
Change-Id: Ia7931f0f07e5e95beab39f65ad1a5942ad9841f6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4410240
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Steven Moreland <smoreland@google.com>
Implement base gunyah abstractions.
Bindings are based off aosp/2475305/9.
Cherry-pick notes: Fixed license headers and uppercased bindgen constant
to workaround "constant in pattern ... should have an upper case name"
warning that can't be disabled (will need to adjust the bindgen script
later to match).
BUG=b:232360323
Change-Id: I4815128ce827112b25add87ac11e28868b4cdb46
Co-developed-by: Sreenad Menon <quic_sreemeno@quicinc.com>
Signed-off-by: Sreenad Menon <quic_sreemeno@quicinc.com>
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4404217
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
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>
Gunyah initializes at VM level, not the vCPU level as KVM. Add
VM-generic initialization which happens after build_vm, but before the
VM starts to run.
BUG=b:232360323
Change-Id: Iea38cf63eca9b525e613450fd7bca2d422923063
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4400669
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This is supported since Rust 1.62.
Fixes the new derivable_impls clippy lint, added in Rust 1.67.
BUG=b:276487055
TEST=tools/clippy # with rust 1.68
Change-Id: I3696dd3cf4acbf9b5a2cfa8c2046e7656e13dbbd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4390735
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
The ioapic can now be serialized, and re-create its MSIs on restore.
BUG=b:266513575
TEST=presubmit
Change-Id: I1d164526a0e61de1e38371fc3943cd1136ca15d0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4368984
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Steven Moreland <smoreland@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
We can require the ID field to be present in all the arch specific
structs, then we don't need an extra layer.
Change-Id: Icbbf0ec5b99fd6816863a611a538e67def09d87f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4385864
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
Some hypervisors (presently: Gunyah) will configure boot-time registers
for vCPUs and not allow userspace VMM to set the boot configuration.
If this capability is declared, then crosvm will not try to initialize
vcpu registers upon VM bootup.
BUG=b:232360323
Change-Id: If2f05c832170f75eabfd7f0c63975465ba75aadf
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4379525
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Introduce a struct argument, MemoryRegionInformation, for use with
with_regions.
No functional change intended.
BUG=b:232360323
Change-Id: Icd40630c32878b3bd185aeeedcf9e1e9de20e20b
Suggested-by: Frederick Mayle <fmayle@google.com>
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4379522
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
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>
Add restore to Vcpu to restore VCPU state from snapshot.
Add kick_vcpu to kick a specific vcpu.
BUG=b:266515147
BUG=b:232437513
Test=crosvm run && crosvm snapshot take img_name socket
Change-Id: Ie09419fd50dcecd0226b2b716236d2c8196b58ec
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4260157
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Elie Kheirallah <khei@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
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>
This is recommended by the kernel KVM documentation, and it also helps
to provide a more meaningful error if the user provides an incorrect KVM
device path for a file that exists but is not actually a KVM device node
("Inappropriate ioctl for device").
BUG=None
TEST=crosvm run --kvm-device=/dev/null ...
Change-Id: If8e505e2945a76bdd6ba2bf559eeeb3a12f77b15
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4363327
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zihan Chen <zihanchen@google.com>
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>
Move generic implementation of BlockedSignal to base sys.
Change-Id: I459ca424a633dc3fc2a5dec625dde8e5878132c0
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
(cherry picked from commit 5f51fa4ae3b979972d273dff4c224c1999b6e641)
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4346950
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Remove KVM-specific code from the generic aarch64 module by providing a
generic enum for hypervisor-specific vCpus to use instead:
VCpuRegAArch64.
(cherry picked from commit cfd5acd14f924fe17f09c007fb20bf2abc632a79)
Change-Id: I486ea24993493c314ed6dacd5cedeeb135225135
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4346944
Reviewed-by: Dennis Kempin <denniskempin@google.com>
This seems to be purely reserved for alignment reasons; the kernel
never touches it, so we don't need to serialize/deserialize it.
BUG=b:266515147
TEST=tools/presubmit
Change-Id: I3074d24f50a8e0e86340c398885c2fbef1410a88
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4342173
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Add get/set VCPU_EVENTS as required to snapshot the full state of the
VCPUs for suspend/resume.
BUG=b:266515147
TEST=build and run VM
Change-Id: Iabca21b67a0eb9906d2e639a616e3f0826dfa659
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4327459
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
This CL adds trait implementation for PciDevice to handle BAR
reprogramming. When BAR reprogramming is detected, the PciDevice checks
all ioevents needed, and requests ioevent registeration for events that
are in the changed domain. The requests are handled by instances of
PciDevice via the trait function ioevent_register_request.
Before the CL, ioevent re-registering is unhandled, and PciDevice is
broken without notification. After CL, an error message will appear, but
device still would not function as the added trait is not implemented.
Test: Presubmit Tests. Hotplugged virtio device triggers error
IoEventNotSupported as expected.
Bug: 271204121
Change-Id: Ibf4bc00cfdce24e508cd50b5009f148c5a49db30
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4310071
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Ningyuan Wang <ningyuan@google.com>
use of `unaligned_references` will be blocked soon and spits out a
warning during compiling. fix it in haxm.
Test: Compiled and ran with haxm enabled.
Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Change-Id: Ia887cff1ce01e6c14a9cf4978bf49835e996dd5a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4324279
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
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>
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>
We will enable clippy checks on those platforms in CI soon.
BUG=b:268356784
TEST=tools/clippy --platform=aarch64/armhf
Change-Id: Icfefdbce7498731d78448b00c7c21a0f86639dff
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4233580
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
- Rust toolchain is updated to 1.65.0
- Catapult dashboard upload tool is added to dev_container
- Bindgen is updated to latest version to support custom derive
- Derive Eq when PartialEq is derived as required by new Clippy
TEST=CQ, bindgen-all-the-things
FIXED=b:260784028
BUG=b:257303497
Change-Id: I2034cd09e0aed84d4e9b30f2e85d84d94a442ea4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4228427
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
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>
Move generic implementation of BlockedSignal to base sys.
Change-Id: Ib6b0aae7cf9e1405c83f8b91131e04c765482d9a
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4174622
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Frederick Mayle <fmayle@google.com>
Add a new configure option in CpuConfigX86_64, and use this option to
set hybrid flags in CPUID for vCPU.
The flags include:
1. CPUID.07H.0H:EDX.Hybrid[bit 15];
2. The Atom/Core type flags in CPUID.1AH.EAX.
Co-Developed-by: Zhuocheng Ding <zhuocheng.ding@intel.com>
BUG=b:255908920
TEST=presubmit
Change-Id: I33663b56fd201221c5fa3557f80d1f5ec5a31c03
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4020038
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
The extra vm_evt_wrtube parameter was added in b375cbf575 ("crosvm:
reduce kiwi feature flag usage"), but the WhpxVm::new() function was not
changed and does not take a SendTube parameter.
The cl introduces dormant vm_evt_wrtube too keep the diff minimum.
BUG=None
TEST=cargo build --target=x86_64-pc-windows-gnu --features=whpx
Change-Id: Ic0c77f67b5dfca1cf666caf94c53add0fe2bdf36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4133835
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>