Commit graph

330 commits

Author SHA1 Message Date
Daniel Verkamp
52b8e42869 Cargo.toml: avoid "*" versions for external crates
Ensure that every Cargo.toml dependency on a third-party crates.io crate
specifies at least a major version, or a minor version for 0.x crates,
to ensure that if a new major version is published, it cannot cause API
breaks.

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

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

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

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

Change-Id: Ifa18199f812f01d2d10bfb4146b3353c1a76527c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5555656
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-22 01:01:42 +00:00
Daniel Verkamp
cb014484a8 arch: ensure load_image_high() uses a valid guest memory region
There may be holes in the guest memory layout, so simply restricting the
maximum load address (e.g. for initrds) is not sufficient in all cases
to find the highest valid address for loading an image.

Instead, sort the guest memory regions by address and iterate over them
in reverse order until a valid placement for the image is found.

This fixes loading of an initrd on x86_64 when the guest kernel provides
an `initrd_addr_max` value that overlaps with the PCI hole just below
4GB.

Change-Id: I4a4b67f1fd704a4614fc04c956257b4535103b6f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5456842
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-05-13 18:14:54 +00:00
David Stevens
509b8e6c7b devices: Allow GPEs to wake up VCPUs
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>
2024-05-02 01:26:42 +00:00
David Stevens
d05f9e326e linux: Add support for metrics
Initialize the metrics tube and make sure its kept in all forked
children.

BUG=b:332466813
TEST=tast run DUT arc.Boot.vm

Change-Id: Ide7a9e4ba5a3d8a52e69ac65b9aaaefcf21735a6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5400363
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-04-09 01:43:39 +00:00
David Dai
0f49ce02cd aarch64: Add boot_cpu option
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>
2024-04-01 17:45:39 +00:00
Daniel Verkamp
2dde104c1e arch: return created devices from add_serial_devices()
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>
2024-03-27 19:55:52 +00:00
Daniel Verkamp
2abe9b9507 arch: serial: move bus.insert() into add_serial_devices()
The code in sys::add_serial_devices() for adding the device to the bus
is the same in both cases; extract it into the platform-independent
part. This also means the sys code does not need to know about the
serial device index to address mapping (SERIAL_ADDR).

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

Change-Id: Iabf132bd98983c9ce40bd22527e033285668f29f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5399619
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-03-27 19:54:52 +00:00
Dmitrii Merkurev
b305ee33e8 crosvm: support passing pci address for virtio-console serial devices
BUG=b:218364216
BUG=b:322862402
TEST=cuttlefish virtio-console devices assigned on the proper address
TEST=cargo test

Change-Id: Ib537de1d03c8953815a2f2eaca34b9134089dcb0
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5320906
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-02-26 20:08:41 +00:00
Takaya Saeki
f934bc0413 serial: allow multiple console=true devices
Currently crosvm does not allow users to give multiple serial devices
with `console=true`. However, actually Linux kernel can have multiple
`console=` options at the same time. Each serial hardware type can have
one console. Kernel logs will be copied to all consoles, and the inputs
will be taken from the last `console=` device. Even if multiple
`console=` options for the same device type are given, no error occurs
and the last one is effective. Therefore, crosvm doesn't have to
restrict console option.

Thus, this CL removes the restriction on multiple consoles of crosvm.

BUG=b:325362584
TEST=`crosvm run --serial type=file,path=serial,console=true --serial
type=stdout,hardware=virtio-console,console=true,stdin=true ...`. Both
file and stdout have console outputs

Change-Id: I911c9223704eb91f369b74e9cdcd901f115aa7eb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5306814
Commit-Queue: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2024-02-21 07:15:34 +00:00
David Dai
557f1555b4 Change get_host_cpu_clusters to get unique clusters
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>
2024-02-16 19:48:09 +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
Frederick Mayle
18283c9e8e 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>
2024-02-02 03:39:54 +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
David Brazdil
ba2f66ae97 Clone host CPU capacity/clusters for --host-cpu-topology
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>
2024-01-12 10:03:55 +00:00
Ludovic Barman
cd04b6198d Upgrade gdbstub and gdbstub_arch.
gdbstub 0.6.3 -> 0.7.0
gdbstub_arch 0.2.4 -> 0.3.0

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

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

BUG=b:286979636

TEST=tools/presubmit --all

Change-Id: I124d65e673c5943070c2bb5e39e3a7e5506e5528
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5146447
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-01-04 02:06:22 +00:00
A. Cody Schuffelen
98a6921246 Only support cpufreq on arm/aarch64
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>
2023-12-01 00:56:01 +00:00
Tianjie Zhao
201306976e devices: serial: add name to SerialParameters
This patch is to support the port name of VIRTIO_CONSOLE_F_MULTIPORT.

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

Signed-off-by: Tianjie Zhao <tianjie.zhao@samsung.com>
Change-Id: I028bccd1fb52797dd402e312d96cec2a42a6289a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4776928
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-11-21 05:05:59 +00:00
Pierre-Clément Tosi
869e16cdeb vfio_platform: Map device MMIO before booting pVMs
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>
2023-11-17 12:04:03 +00:00
Pierre-Clément Tosi
a342b8fba3 Extend pKVM-VFIO support to virtual SIDs
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>
2023-11-15 10:50:46 +00:00
Pierre-Clément Tosi
1abdd9af88 fdt: Add support for pKVM-VFIO pvIOMMUs
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>
2023-11-15 10:50:46 +00:00
Mike Gerow
dea38e7552 smbios: add support for setting UUID in SysInfo
TEST=booted test kernel, ensured uuid is correctly returned at
/sys/class/dmi/id/product_uuid.
BUG=b:249382713

Change-Id: I444adebcea4b374b8c2744afba32cad5ff794ce0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5010881
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Mike Gerow <gerow@google.com>
2023-11-13 23:42:14 +00:00
Jakob Vukalovic
138ecc7e67 crosvm: Filter VFIO devices in DT overlays
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>
2023-11-13 20:29:48 +00:00
Jakob Vukalovic
d31b856040 crosvm: Apply device tree overlays
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>
2023-11-11 18:54:42 +00:00
Daniel Verkamp
be33277580 base: remove read_from/write_to_memory
These duplicate existing VolatileSlice and FileReadWriteAtVolatile
functionality. Removing them means that they don't need to be
reimplemented separately for each platform's MemoryMapping.

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

Change-Id: Ia4332159461efc001b4e980fdb2a9984e852c931
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5019440
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-11-10 18:41:10 +00:00
Jakob Vukalovic
9ab89c2832 cmdline: Add DT overlay command line options
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>
2023-11-10 09:38:27 +00:00
Daniel Verkamp
3e1c271449 Fix clippy useless_conversion into_iter() warnings
Change-Id: Ie526b343dea32598565e56156afe33455a70a744
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5005513
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-11-06 19:43:56 +00:00
David Stevens
7eb7a4ede2 devices: Add read-only memslots for pci config space
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>
2023-11-01 03:37:49 +00:00
Jakob Vukalovic
a7dc630170 cros_fdt: Load FDTs from binary blobs
A prerequisite for applying external FDT overlays is being able to load
them from byte vectors. This change implements deserialization of Fdt
structure from a byte slice using `Fdt::from_blob` function.

Bug: b/296796644
Test: cd cros_fdt && cargo test
Change-Id: Ic2d5398b8b49bbe44f248aea70ef13f3e890a532
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4855963
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jakob Vukalović <jakobvukalovic@google.com>
2023-10-31 09:38:33 +00:00
Jakob Vukalovic
3f8e5003d6 cros_fdt: Write FDT to io::Write instance
To avoid allocating and merging many vectors, pass an io::Write instance
to `write_blob` functions and write directly to an output buffer.

Bug: b/296796644
Test: cd cros_fdt && cargo test
Change-Id: I5a96d5b08eb224d81ffca7b85d6e3415bfedf257
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4960116
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jakob Vukalović <jakobvukalovic@google.com>
2023-10-31 09:29:23 +00:00
Jakob Vukalovic
f16d67a2ff cros_fdt: Restructure Fdt
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>
2023-10-25 17:56:10 +00:00
Jakob Vukalovic
73534c684f cros_fdt: Introduce ToFdtPropval trait
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>
2023-10-18 10:24:15 +00:00
Jakob Vukalovic
6a7b20d48b cros_fdt: Rename FdtWriter to Fdt
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>
2023-10-16 11:04:06 +00:00
A. Cody Schuffelen
4748c54b95 Rename "unix" to "linux" in code and docs
$ for DIR in $(find . -name "unix"); do mv $DIR $(echo $DIR | sed "s/unix/linux/"); done
$ for FILE in $(find . -name "unix.rs"); do mv $FILE $(echo $FILE | sed "s/unix/linux/"); done
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/mod unix/mod linux/g" {}
$ find . -type f -not -path '*/\.git/*' -not -path '*/third_party/perfetto/*' | xargs -I {} sed -E -i "s/([^o][^s])::unix/\1::linux/g" {}
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/use unix::/use linux::/g" {}
$ find . -type f -not -path '*/\.git/*' -not -path '*/third_party/perfetto/*' | xargs -I {} sed -E -i "s/sys::unix/sys::linux/g" {}
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/use unix as platform/use linux as platform/g" {}

Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I2c8acb14d77a5588dab4eae124f4a9afbb9025f5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909060
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-10-11 01:15:07 +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
David Stevens
3878d34388 x86_64: Add option to force linux to use ECAM
Linux prioritizes accessing the PCI configuration space via PIO over
accessing it via MMIO (i.e. ECAM), due to compatibility issues when ECAM
was introduced 15+ years ago. Unfortunately, there is no straightforward
path to changing this behavior, due to nebulous compatibility concerns.

This patch adds a commandline argument that breaks Linux's PIO probing,
to force it to use ECAM. Using MMIO reduces the number of VM-exits
needed for each register access by half, and it makes it possible to
completely avoid VM-exits for reads with KVM read-only slots.

BUG=b:301865576
TEST=Modify arcvm_dev.conf; tast run DUT arc.Boot.vm

Change-Id: I8dfefe2afa2c77e42c124076946a1a4105749de7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4891754
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2023-10-06 01:06:16 +00:00
Daniel Verkamp
10387bdee9 x86_64: remove --userspace-msr option
This was only used by crosvm-direct.

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

Change-Id: I5c7b7827da92d9becda339df3e61852675d83009
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4811783
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-08-25 19:55:54 +00:00
Daniel Verkamp
3524c35d67 arch: remove unused has_bios flag
The BIOS-specific startup information is contained in VcpuInit now.

Change-Id: I698975a33e254165c78a06b97a24c7a36d9f8d1d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4811781
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-08-25 19:13:01 +00:00
Sebastian Hereu
7a3bf2d6f0 devices: fw_cfg: add --enable-fw-cfg argument
certain files such as "bootindex" and "etc/acpi/rsdp" are automatically
generated by crosvm and are expected by the OVMF guest. We would like an
agrument that acts as a switch to enable fw_cfg so that we can add the
automatically generated files without having to add a file to device.
Towards this end, this CL introduces the --enable-fw-cfg argument.
Additionally, we automatically enable fw_cfg if the user specifies the
bootindex argument from the command line. The bootindex argument is
useless if the "bootorder" file is not made available to the guest b/c
fw_cfg is not present.

BUG=b:283990685

Change-Id: Ie60e27a20a94d7d52bd5af8d301f77f9f83cdcde
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4797982
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Denise Costin <dcostin@google.com>
Commit-Queue: Sebastian Hereu <sebastianhereu@google.com>
2023-08-24 16:45:37 +00:00
Sebastian Hereu
ce5f9f8b8d devices: fw_cfg: add jailing
Before this change, fw_cfg could not be sandboxed. This change sticks
fw_cfg into its own sandbox unless --disable-sandbox is specified on the
command line.

Change-Id: Icb3898d10d76dd689820876b2e1f42f140200c5b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4793215
Commit-Queue: Sebastian Hereu <sebastianhereu@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-08-22 18:21:22 +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
Sebastian Hereu
c1c27448a3 devices: x86_64: add bootindex
Currently, crosvm running with --bios <OVMF executable> will only boot
from available block devices if started with a clean BIOS pflash. If
crosvm is not run with a clean pflash, OVMF will get confused and refuse
to boot. The reason for this behavior is that OVMF expects a "bootorder"
file to be present in the fw_cfg device to calibrate its boot order.
This CL allows fw_cfg to specify bootorder, solving the inconsistent
booting behavior. Boot order is specified from the command line with the
bootindex=NUM argument.The bootindex argument is available for block
devices specified with the --block flag. Note that the --fw-cfg flag
must be specified w/ at least on file (can be an empty file with a
random name) on the command line for fw_cfg to actually be made
available to the guest. Also, further investigation is needed if we wish
to boot from pmem devices in the future. See crosvm run -h for more
information about the bootindex argument.

BUG=b:243051819

Change-Id: Ieae1e2cacc14c018832b228db898884281c38a96
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4755415
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Sebastian Hereu <sebastianhereu@google.com>
2023-08-18 22:11:48 +00:00
Daniel Verkamp
54f80c60f1 x86_64: add SMBIOS serial number option
Allows adding an optional serial number to the SMBIOS table.

BUG=b:249382713
TEST=crosvm run --smbios serial-number=abcdef ...

Change-Id: I00a00defb6904dbfa8ae38910b887e0a464787e3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4761847
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zihan Chen <zihanchen@google.com>
Reviewed-by: Mike Gerow <gerow@google.com>
2023-08-09 21:00:20 +00:00
Daniel Verkamp
2422c65f3d x86_64: move SMBIOS config to a new --smbios option
Move oem_strings into a struct to allow for clearly-named parameters.
This allows overriding the default SMBIOS strings for BIOS and product
information.

BUG=b:282921262
BUG=b:249382713
TEST=cargo test -p x86_64

Change-Id: I5bf40f3c3ee1b675fdcaf427c15e5b0c74549379
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4761846
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Mike Gerow <gerow@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zihan Chen <zihanchen@google.com>
2023-08-09 20:59:35 +00:00
Grzegorz Jaszczyk
298be81446 acpi: x86: add support for ACPI Notify() forwarding
In order to replicate the ACPI notification from the host to the guest
pass-through devices:
1) allocate GPE and eventfd per pci-vfio device
2) generate proper aml code for ACPI GPE handler. The example of generated aml:

    Scope (_GPE)
    {
        Method (_E00, 0, NotSerialized)  // _Exx: Edge-Triggered GPE, xx=0x00-0xFF
        {
            Local0 = \_SB.PC00.PE08.NOTY
            Notify (\_SB.PC00.PE08, Local0)
        }
    }

The eventfd is registered by host kernel via VFIO_DEVICE_SET_IRQS
ioctl. Crosvm upon receiving early provided, per pci-vfio eventfd,
stores the notification value and triggers GPE associated to pci-vfio
device.

Guest kernel upon handling GPE (thanks to generated aml [ad 2)],
triggers Notify on required pass-through device and therefore replicates
the ACPI Notification on the guest side [Accessing \_SB.PC00.PE08.NOTY
pointed by VCFG opregion result with trap to crosvm, which returns
previously stored notify value].

Kernel counterpart: CL:4538472

BUG=b:244205651
TEST=Observe replication of ACPI notification in the guest kernel

Change-Id: Iaf66097acd84f3066f6ff70d382f83ecaeea9a00
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4538483
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-07-27 11:30:18 +00:00
Daniel Verkamp
4bd4358aa4 Remove all remaining --features=direct code
BUG=b:279663365
TEST=tools/dev_container tools/presubmit

Change-Id: Iaa0b8176a54982044137b112039bf04f1e183c4e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4713506
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Grzegorz Jaszczyk <jaszczyk@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmytro Maluka <dmy@semihalf.com>
2023-07-25 17:55:10 +00:00
Sebastian Hereu
e87cdc40b3 devices: fw_cfg: add fw_cfg device
Basic implementation of fw_cfg device. The device is recognized by
OVMF, and OVMF can read a hard-coded number 0x66 from the device with fw_cfg's read(). Arbitary files can be written to the device via FwcfgDevice::add_file(). The device is activated with the command line param --fw-cfg. Specifying --fw-cfg alone will activate the device
and additional arguments may be specified so that a user-specified data blob may be added from the command line. Currently, however, attempting to add a data blob from the command line is a noop.Still need to implement read() and write().

BUG=b:283990685

Change-Id: Iec899b7568b7f9195084c5cbcde1fc8a8fafd9fa
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4659945
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Sebastian Hereu <sebastianhereu@google.com>
2023-07-18 21:09:37 +00:00
Elie Kheirallah
e8705e87f0 crosvm: Add flag to use legacy console
Some downstreams currently still use the legacy console. Some e2e_tests
(snapshot/restore) also will require using the legacy console, as the
AsyncConsole does not currently have an implementation for these
functions.

BUG=N/A
TEST=presubmit
TEST=run VM with legacy console flag

Change-Id: I97f94d79c6b0c2c23115283e1539f7cda580f5b8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4618965
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
2023-06-22 15:37:42 +00:00
Daniel Verkamp
659252d103 devices: pci: propagate PciRoot add_device errors
Rather than just printing an error and continuing, this makes the errors
fatal when adding a PCI device with invalid configuration (e.g. an
address on the wrong bus) at startup time. Hotplug errors are still
considered non-fatal and execution continues in that case.

BUG=None
TEST=crosvm run --stub-pci-device 2:00.0,...

Change-Id: Ia831cc1fc1ca1f04ad7e45dba5978671157a51b4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4583465
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Ningyuan Wang <ningyuan@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-06-13 18:31:36 +00:00
Shintaro Kawamura
4a70373f29 swap: garbage collect uffds for detached hot plug devices
When a hot plug device is detached, its uffd becomes dead. This commit
adds a garbage collector to remove dead uffds and prevent the uffd list
and obsolete opened file descriptors from growing indefinitely.

BUG=b:267124393
BUG=b:281791015
BUG=b:266898615
TEST=https://crrev.com/c/4562369

Change-Id: I11d3298b8e4838bbb843e4dc10f29f32a02b0646
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4525480
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-05-26 01:39:50 +00:00
Elie Kheirallah
6fad425736 devices: irqchip: add snapshot/restore
Add snapshot/restore to irqchip for kvm and whpx to save the state of the irqchip.
Add saving apic_base as part of the irqchip.

BUG=b:266515147
BUG=b:232437513
Test=crosvm build - testing requires more changes related to VmRunnableLinux

Change-Id: Iffbd38634390d276d70d6467549df9ffaf176059
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4518572
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
2023-05-18 17:27:36 +00:00