Rather than checking and re-checking the capacity on every insert, just
check the final length of the string when the command line is finished.
BUG=b:362168475
Change-Id: I0cae6a76f64aaeffbfd0b71dd18c2e0dc96f0a11
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5838025
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Gives the method a better name as not only was it not clear but it was
confusing, potentially being interpreted as the hypervisor (implementing
the protection type) loading the firmware, similarly to how it performs
what .isolates_memory() refers to.
Note: No functional change intended.
TEST=-
Change-Id: Ie7d7fb9dc3732658837ce035298c374e6e52bf30
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5800574
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmytro Maluka <dmaluka@chromium.org>
On aarch64, we load BIOS payloads at offset 0x200000 because
cuttlefish's u-boot BIOS requires the FDT at offset zero. However, in a
separate use case, we are loading BIOS payloads that are OK with dynamic
FDT addresses, but might use the Gunyah hypervisor, which currently
requires the payload to be loaded at offset zero. One algorithm can't
satisfy both.
Both the u-boot setup and Gunyah ought to be made more flexible, but it
seems useful to make crosvm's behavior configurable. It lets us adjust
those use cases eventually without causing an immediate backwards
incompatability scramble.
A new "after-payload" mode is included that matches crosvm's RISCV FDT
address behavior and potentially helps with the TODO for >4GB VMs.
BUG=b:353758405
Change-Id: I886f47cf8e0a6b02218794615215a0e972a4ace2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5740018
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
There were lots of unwraps in the code. Change the functions to return
results and return errors when possible. Otherwise, expect instead.
BUG=N/A
TEST=presubmit
Change-Id: I218aabefc30e40185eb6855117e85f1ff8bac09a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5704476
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Vmwdt is getting the pid/tid of vCPUs whenever a write happens. Instead,
get the Vcpu PID/TID on VM startup.
BUG=b:274145255
TEST=presubmit
Change-Id: I4f41dd20b807b320b6202d36061b18d4c9aa77df
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5703919
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Add an option to allow users to specify custom cpu frequencies
rather than obtaining frequencies from the host. This is
useful for emulating cores that have different performance
points from the host.
Bug=b:284367589
Test: tools/presubmit
Change-Id: I9508a7b20d6d2db16babb9e43d912fd891f41b2e
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5709094
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This reverts commit 18283c9e8e.
Reason for revert: Clean this up, since it's not being used.
Original change's description:
> devices: virtcpufreq: Add proxy syscall support through UDS
>
> Add skeleton for allowing virtcpufreq to communicate
> via sockets to make syscalls using privileged proxy
> services. This acts a fallback mechanism for systems
> that do not grant CAP_SYS_NICE for crosvm.
>
> Bug: 322197421
> Test: ./tools/presubmit
> Change-Id: I2ca4e01c477d3867a052bcf709bdeddf32e5ded1
> Signed-off-by: David Dai <davidai@google.com>
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5258454
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Bug: 284367589
Change-Id: If07a2f0fe88bc724d814e3f239087608dc7a5ae7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5623438
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Dai <davidai@google.com>
We don't load anything after the BIOS image, so let it be as big as it
wants to. If it doesn't fit in physical memory, `arch::load_image` will
return an error.
BUG=b:349646856
Change-Id: I4b12adcde47bd8a635d18b1bdc421b9cf4a7a5f9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5709102
Reviewed-by: Ram Muthiah <rammuthiah@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Previously, if `--mem` was set to 100MB and `--swiotlb` to 1MB, then
we'd essentially allocate 101MB of RAM for the guest and tell it about a
single 101MB memory region in the FDT (adjacent regions are merged in
the FDT). In contrast, for hypervisors that don't require static
swiotlb, we'd only allocate 100MB of RAM (and then the guest would need
to choose 1MB of its own memory to dedicate to this purpose).
Now both cases will get the same RAM size.
Removed the swiotlb reference from memory_layout.md since it is part of
the RAM region from the perspective of the guest. The need for the
static swiotlb to be created as a separate memslot is more of a
hypervisor implementation detail I think.
BUG=b:346770542
Change-Id: I60b10521635c16fa77b4320de0e11f03ebeca0c5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5637774
Reviewed-by: Elliot Berman <quic_eberman@quicinc.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
The VirtualPmc setup code does not require any OS-specific
functionality, only a portable Condvar, so we can clean up some
unnecessary conditional compilation in the arch crates.
The force_s2idle feature is not actually wired up on Windows yet, but
that should also be possible to enable in an OS-agnostic way if desired.
BUG=b:194391015
TEST=tools/dev_container tools/presubmit
Change-Id: Iceee1068c20d64539063387b1073ff71c5d05fec
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5671243
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
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>
This adds support for interrupt injection when a guest vcpu is being
detected as stalled. A vCPU is stalled when it hasn't been
scheduled to run for a predefined interval chosen bt the VMM.
The interrupt property is appended to the device tree when using a Linux
configuration build under aarch64.
BUG=b:272284118
TEST=manual testing with CrosVM being built as part of the
Virtualization service apk. The Virtualization service is patched with
an updated prebuilt of the guest kernel with the patch that contains the
frontend kernel driver changes for the vcpu stall detector from here:
https://android-kvm.googlesource.com/linux/+/refs/heads/sebastianene/vcpu_stall_detector_ppi
Change-Id: Ia59910ea99c20cf37afc8c6ca9b3dfb001458a14
Signed-off-by: Sebastian Ene <sebastianene@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5053958
Reviewed-by: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
The maximum command line length accepted by the guest kernel is a fixed
per-architecture constant; it is unrelated to the (host) page size,
which was used as the limit on aarch64 and riscv64 before this change.
Making crosvm limit the command line to the correct maximum length
allows for a more useful error message to be printed if the user tries
to use an overly-long command line; without this change, it would not be
apparent that the guest kernel was truncating the command line, leading
to unexpected behavior at runtime.
BUG=b:345478075
TEST=Boot Crostini and ARCVM on arm64
Change-Id: I207bda318b60d207ccb1ef5df1e59f30be238126
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5606562
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
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>
The high MMIO region should be marked as prefetchable. This fixes a
kernel warning that resulted from the high MMIO region extending beyond
the range of a 32-bit memory region, which seems to be a limitation of
the Linux kernel PCI host support:
pci-host-generic 10000.pci: host bridge /pci ranges:
pci-host-generic 10000.pci: MEM 0x0002000000..0x0003ffffff -> 0x0002000000
pci-host-generic 10000.pci: MEM 0x0226a00000..0xffffffffff -> 0x0226a00000]
pci-host-generic 10000.pci: Memory resource size exceeds max for 32 bits
This is also just a more accurate representation of the available MMIO
regions. In particular, the GPU's 64-bit prefetchable BAR is allocated
from this region, so this makes the Devicetree description match the PCI
BAR properties.
BUG=None
TEST=Start Crostini and ARCVM on trogdor
Change-Id: I08fd74d5ba2c30525be9064fc996871501941c24
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5523021
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Allow GPEs to wake up VCPUs, so that the guest can properly wake up from
S3.
BUG=b:301862490
TEST=Manual test with ArcS2Idle feature flag
Change-Id: I2eb6738c3806fc27e15085fc4d71bf7f2c83fe7d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5491345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
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>
This moves the system register encoding infrastructure to the generic
aarch64 level (out of KVM), which will allow it to be used for snapshot
and restore code for all hypervisors.
Additionally, the two system registers that KVM API encodes incorrectly
are handled in the AArch64SystemReg to KvmVcpuRegister mapping function
(CNTV_CVAL_EL0 and CNTVCT_EL0).
Now that the hypervisor API exposes enough functionality to get and set
the basic architectural state for aarch64, we don't need to implement
the gdbstub-specific API inside each hypervisor; it can be moved into
the aarch64 architecture support module instead.
BUG=b:323354478
TEST=tools/dev_container tools/presubmit
Change-Id: I257d24060dec177f89e233cbdbf80e5df9641742
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5441434
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Pierre-Clément Tosi <ptosi@google.com>
This reverts commit b7e72de084.
Reason for revert: It turns out some devices intentionally flattens out their cpu-map topology to improve scheduling behavior. Revert back to using package id to determine clustering info.
Original change's description:
> aarch64: Use cpu_capacity to determine clustering instead
>
> Some systems do not populate cpu-map information and
> use other ways of grouping CPUs in a frequency/topology
> domain instead. Use normalized cpu_capacity information
> to determine clustering instead.
>
> BUG=b:326170473
> Test=./tools/presubmit
> Change-Id: If4ba7d224338798fcf2c0ffbaa91547dc2f2e16d
> Signed-off-by: David Dai <davidai@google.com>
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5319790
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Bug: b:335130218
Change-Id: I1a601e65a79aacb68c1244127420b2e395f12d5d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5467699
Commit-Queue: David Dai <davidai@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
The "arm,arm-v8" compatible string is not documented in the Linux kernel
DT bindings [1] and the intended string probably was "arm,armv8" so
update the DT generation code and test files to use that instead.
[1]: https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/cpus.yaml
BUG=b:335470851
Change-Id: I537b7599a89988244714e2c7af766d6b01e398bc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5464099
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Allow users to start a VM using a specified vCPU thread, this
dramatically improves boot times for system using some form of vCPU to
pCPU pinning.
This is especially useful if a bootloader spends a large amount of time
running single threaded on an asymmetrical system before enabling other
cores.
Bug=b:329911550
Test: tools/presubmit
Change-Id: I81e2ae10769b230b201e98c18cca85daee47148f
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5384625
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
On AArch64, Linux expects the <reg> property to match the MPIDR:
> On ARM v8 64-bit systems <reg> is required and matches the MPIDR_EL1
> register affinity bits. If cpus node's #address-cells property is set
> to 1 the reg cell bits [23:0] must be set to bits [23:0] of MPIDR_EL1.
> All other bits in the reg cells must be set to 0.
so introduce the plumbing to let hypervisor backends describe the MPIDR
topology while generating the FDT. For now, use a default implementation
that matches the previous behavior for all realistic topologies (i.e.
when the VM has 16777215 or fewer vCPUs).
Keep generating the DT with #address-cells=1, even if it limits us to
bits MPIDR_EL1[23:0], as that is more than enough with the default
topology.
Bug: b/331362077
Test: tools/run_tests -p aarch64
Change-Id: I4850e582f197b53bdfce7fe6c40c2c9726c65c6b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5401898
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Iterate over the list of serial devices returned by
arch::create_serial_devices() rather than hard coding the list.
BUG=b:331472317
TEST=tools/dev_container tools/presubmit
Change-Id: I2e3383f634baab1730e8fc72a9a2be3e1e2b23f0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5399621
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
This will allow the architecture-specific code to iterate over devices
without needing to have hard-coded knowledge of the address space layout
or IRQ assignment.
BUG=b:331472317
TEST=tools/dev_container tools/presubmit
Change-Id: I59c29c4695cf12332de58fa32f9bf14b19852be9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5399620
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Several crates still declared a dependency on data_model despite not
using any imports from it.
BUG=b:312312646
TEST=tools/dev_container tools/presubmit
Change-Id: I63a67696c205f684b1e4ac8bdad4de5f294b63dc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5370964
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Some systems do not populate cpu-map information and
use other ways of grouping CPUs in a frequency/topology
domain instead. Use normalized cpu_capacity information
to determine clustering instead.
BUG=b:326170473
Test=./tools/presubmit
Change-Id: If4ba7d224338798fcf2c0ffbaa91547dc2f2e16d
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5319790
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Ensure cluster lists are unique, while the current cluster
configurations are handled by Linux, they bloat the devicetree and are
difficult to parse by some secure firmwares.
Bug=b:284369518
Test: ./tools/presubmit
Change-Id: If26fe8d82b0056f656ac29bca130969fdd303ce7
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5303156
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Move opp-table nodes inside cpu nodes, this makes it
easier for some systems to strip out or patch opp table
nodes.
Bug=b:284369518
Test: ./tools/presubmit
Change-Id: I8ecec279f9ca1f4eb321bf33ba3e87f080e434fe
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5270362
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Add skeleton for allowing virtcpufreq to communicate
via sockets to make syscalls using privileged proxy
services. This acts a fallback mechanism for systems
that do not grant CAP_SYS_NICE for crosvm.
Bug: 322197421
Test: ./tools/presubmit
Change-Id: I2ca4e01c477d3867a052bcf709bdeddf32e5ded1
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5258454
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
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>
Kernel images are often stored compressed because they can take up a
significant amount of disk space. One of the popular formats for this is
LZ4. Even though it does not offer the best compression ratio, it excels
at decompression speeds.
On arm64, kernels do not come with their own decompressor like they do
on x86. Instead, it is the job of the bootloader to decompress the
kernel before it is executed.
To this end, add crosvm support for LZ4 decompression of kernel images,
via the Rust-safe lz4_flex library. LZ4 file format is detected
automatically via one of its magic numbers. Otherwise crosvm will fall
back to loading the kernel as a raw image.
Some rough numbers using Android's Generic Kernel Image on Pixel 8:
* compresion rate: 49% (33MB -> 16MB)
* decompression time: 20-30ms
Given that the total VM boot takes about 1.5s, the overhead is more than
acceptable.
BUG=b:315141974
TEST=tools/dev_container tools/run_tests --platform=aarch64
Change-Id: I1030abe6fdf7087603cea9ac5273bf9136bad693
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5110323
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: David Brazdil <dbrazdil@google.com>
Use "qemu,virtual-cpufreq" for compatible string when instantiating
virtual cpufreq devices.
Bug: None
Test: ./tools/presubmit
Change-Id: I46651ee1bfe1df1003920b199f25225b12be8b59
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4923275
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
When --host-cpu-topology flag is specified, crosvm will create 1:1
affinity masks between host CPUs and VM's vCPUs. Extend this mechanims
to also pass the cluster IDs and CPU capacity information to the guest.
Same as with --cpu-affinity, the client now cannot specify
--cpu-capacity and --cpu clusters together with --host-cpu-topology.
This only has an effect on DeviceTree-based platforms, same as the two
cmdline flags mentioned above.
Bug: 266664564
Test: ./tools/presubmit
Change-Id: I8f6d5cea7d8861e27f02ec55b50c0d12e1c2866b
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4208668
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Brazdil <dbrazdil@google.com>
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>
This doesn't have mac os or windows equivalents, so delete the stubbed
implementations.
Test: tools/dev_container tools/presubmit
Change-Id: Id1898889d57d362078631980373f71644ae2c492
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5074589
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
When memory is protected, the guest address space mapped to physical
memory shouldn't be modified dynamically after the guest has started
running so force CrosVM to map the device MMIO regions before that.
Otherwise, the protected VM firmware will fail to validate the assigned
regions (as they haven't actually been assigned yet), aborting the boot
of the pVM.
Note that we can't simply call device.regions_mmap() at this point
because the crosvm internal IPC (in particular vm_memory_handler_thread)
isn't set-up yet so this commit had to duplicate the mmap() logic to be
available in the main thread.
This change was verified using strace, going from
ioctl(7, KVM_CREATE_VM, 0x80000028) = 9
[...]
ioctl(36, VFIO_SET_IOMMU, 0xb) = 0
ioctl(9, KVM_CREATE_DEVICE, {type=KVM_DEV_TYPE_VFIO, flags=0}) = 0
ioctl(43, KVM_SET_DEVICE_ATTR, {flags=0, group=1, attr=1, addr=0x7fdd3a4a60}) = 0
ioctl(42, VFIO_GROUP_GET_DEVICE_FD, 0xb400007cc3d0eb90) = 60
ioctl(60, VFIO_DEVICE_GET_INFO, 0x7fdd3a3cd0) = 0
ioctl(60, VFIO_DEVICE_GET_REGION_INFO, 0x7fdd3a3570) = 0
[...]
[pid 4279] ioctl(5, KVM_RUN <unfinished ...>
[...]
[pid 4279] ioctl(5, KVM_RUN, 0) = 0
[pid 4281] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 369, 0) = 0x7d5b3fb000
[pid 4281] ioctl(239, KVM_SET_USER_MEMORY_REGION, {slot=2, flags=0, guest_phys_addr=0x90000000, memory_size=4096, userspace_addr=0x7d5b3fb000}) = 0
to
ioctl(7, KVM_CREATE_VM, 0x80000028) = 9
[...]
ioctl(36, VFIO_SET_IOMMU, 0xb) = 0
ioctl(9, KVM_CREATE_DEVICE, {type=KVM_DEV_TYPE_VFIO, flags=0}) = 0
ioctl(43, KVM_SET_DEVICE_ATTR, {flags=0, group=1, attr=1, addr=0x7fd1c1e030}) = 0
ioctl(42, VFIO_GROUP_GET_DEVICE_FD, 0xb4000077a0628b70) = 60
ioctl(60, VFIO_DEVICE_GET_INFO, 0x7fd1c1d2a0) = 0
ioctl(60, VFIO_DEVICE_GET_REGION_INFO, 0x7fd1c1cb40) = 0
[...]
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 189, 0) = 0x7917dbc000
ioctl(9, KVM_SET_USER_MEMORY_REGION, {slot=2, flags=0, guest_phys_addr=0x90000000, memory_size=4096, userspace_addr=0x7917dbc000}) = 0
[...]
[pid 4233] ioctl(5, KVM_RUN <unfinished ...>
BUG=b:308642771
TEST=Manual run with a pKVM-VFIO device assigned
Change-Id: Iad3494c4e9c309f99fc5cab37ed913d484fc5150
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5029655
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
Add support for assigning VFIO devices with more than one Stream ID to
pKVM guests. The guest DT now uses <#iommu-cells> == 1.
Implement a virtual topology where the n-th SID is mapped to the virtual
SID with value n.
TEST=tools/run_tests
BUG=b:306110430
Change-Id: I053f4697b13b40c8c7f6eb9ef27afe5c7aeb36ca
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5009548
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Expose pvIOMMUs to guests through the device tree. Due to the topology
of 1-to-1 mapping between VFIO devices and pvIOMMUs set `#iommu-cells`
to 0 as DMA masters (VFIO devices) can be uniquely identified from their
assigned pvIOMMU.
TEST=tools/run_tests
BUG=b:306110430
Change-Id: Iddac86500901b51e61de3c9b060c3bc541c64866
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5009547
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This change uses the overlay filtering mechanism to only apply nodes
pertaining to the VFIO devices given to crosvm.
For each VFIO device, define its device tree symbol by passing a
`dt-symbol` option in addition to the sysfs path. The DT symbol must
match the label of the device node in the FDT. In addition, specify
which device tree files will be filtered using these symbols by passing
a `filter` option in addition to the device tree overlay path.
As the device nodes are applied to the base FDT, update the `reg` and
`interrupts` properties with correct values for each VFIO device.
Since these values are allocated by crosvm, they are not known ahead of
time and even if written to the overlay file, are unlikely to be
correct. This change will set the correct values for each VFIO device.
Bug: b/296796644
Test: tools/run_tests
Change-Id: I1ca38b5ef223e551b91a831093b9ae790962aa5b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4855969
Commit-Queue: Jakob Vukalović <jakobvukalovic@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This change propagates the overlay files to the `fdt::create_fdt`
function, load the file contents, and applies a series of device tree
overlays to the base device tree after it has been constructed.
Test: tools/run_tests
Bug: b/296796644
Change-Id: I01f4db604fba5b8ecd756f93d092432145357977
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4855968
Commit-Queue: Jakob Vukalović <jakobvukalovic@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This change adds a '--device-tree-overlay' command line option to pass
device tree overlay files which will be applied to the VM device tree.
The overlay files are opened and propagated to `Arch::build_vm`
function.
Bug: b/296796644
Test: cargo test
Change-Id: I6a1571b2b14cb36cdb9f02e099ef56ee263d6efc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4855959
Commit-Queue: Jakob Vukalović <jakobvukalovic@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Take advantage of the fact that the PCI spec does not define any
configuration register attributes where reads have side-effects to back
the PCI configuration space with read-only memslots. Support in crosvm
needs to be done at the PciDevice implementation level, to support
situations where device-internal events lead to modifications of the PCI
configuration space memory.
After applying other optimizations, this reduces the average time needed
to exit s2idle from 120ms->40ms/200ms->100ms on delbin/dood, and helps
to reduce variance as well.
BUG=b:301865576
TEST=boot ARCVM with --break-linux-pci-config-io on x86 and ARM
TEST=manually verify virtio-net hotplug w/--break-linux-pci-config-io
Change-Id: Idcbddbed0235bfbd44cca70a46c1d526928621e8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4891756
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
To make updating nodes and node properties easier, this change
restructures the internals of the Fdt struct. The single binary blob
that made up the contents of the FDT binary is replaced with with a tree
structure of `FdtNodes`.
This change allows adding new nodes and properties nested inside an
existing node structure. With prevous implementation which kept FDT data
stored in its binary form, inserting nodes and properties would require
a lot of byte shifts and lookups. These changes will make applying FDT
overlays much easier.
The API is also simplified, writing properties after adding subnodes is
no longer an error, and the concept of "opening" and "closing" FDT nodes
is no longer used.
Bug: b/296796644
Test: cd cros_fdt && cargo test
Change-Id: I1ad90771c0a4a0bb29f0322773d55c82d4cd5575
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4916796
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jakob Vukalović <jakobvukalovic@google.com>
With snapshot/restore, we are snapshotting and restoring all Bus devices
on crosvm (MMIO and IO). However there's no message differentiating
which bus was snapshotting/restoring, and the message only displays that
the action succeeded.
Add the type to Bus device and to the logs.
BUG=N/A
TEST=presubmit
Change-Id: Iec4f97f6f7502bfadc96026cc90710c97d351a83
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4936779
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Modifying FDTs and applying overlays will require additional APIs to
read property values. Ideally, we want to avoid implementing a new
getter method for each supported property value type, and instead have
a single `get_prop` method, and the same for alreaddy existing setters.
Therefore, before implementing property value getters, this change
replaces the seven setter methods for each supported property value
type with a single `set_prop` method taking a type which implements
`ToFdtPropval` trait. Also, implement the trait for each supported type.
Bug: b/296796644
Test: cd cros_fdt && cargo test
Change-Id: Iac05b4b2064d98657e19058fa25ffc689789c8b3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4916795
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jakob Vukalović <jakobvukalovic@google.com>
Currently crosvm has no support for generating device tree nodes for
platform devices assigned via VFIO. That limits usage of platfor VFIO
devices in VMs.
Additional DT nodes can be added to the DT via the overlay mechanism.
This and the following patches add support for amending the VM device
tree by adding support for device tree overlays.
As the first step, rename the FdtWriter struct to Fdt. It makes sense
to use a more general name as the crate gains additional features.
Bug: b/296796644
Test: cd cros_fdt && cargo test
Change-Id: Id6b943f23f7d89151dc66565f694eb0f988265d2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4855960
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jakob Vukalović <jakobvukalovic@google.com>
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>