Commit graph

44 commits

Author SHA1 Message Date
Daniel Verkamp
e74864b7a6 kernel_cmdline: remove capacity from Cmdline
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>
2024-09-12 18:42:20 +00:00
Daniel Verkamp
fd98c741f5 riscv64: fix fdt_position assert
The matches!() expression was missing the fdt_postion parameter that it
was intended to be checking.

BUG=b:358112181

Fixes: 49a6c3cf2d ("aarch64: add cmdline param to control FDT address")
Change-Id: I53d29ea6c31142d79384c1e312e8d2bdf16b324b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5772345
Commit-Queue: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-08-08 18:15:50 +00:00
Daniel Verkamp
190f8bed41 riscv64: add missing FdtPosition import
BUG=b:358112181

Fixes: 49a6c3cf2d ("aarch64: add cmdline param to control FDT address")
Change-Id: Ie6e641af3d4213d37238b76c9bb5380acb5e8a35
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5770471
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-08-07 18:10:13 +00:00
Frederick Mayle
49a6c3cf2d aarch64: add cmdline param to control FDT address
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>
2024-08-06 00:06:52 +00:00
Elie Kheirallah
f7910e5795 riscv: update variable name and type
vm_request_tube was changed to vm_request_tubes as a Vec but was forgotten here,
causing breakages. Update variable.

BUG=b:355735198
TEST=build AOSP

Change-Id: Id99a750da881ec1b76e7482f35aeb667af47d3b1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5740024
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-07-29 17:39:37 +00:00
David Dai
8932366b94 Allow users to specify custom cpu frequencies for vCPUs
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>
2024-07-24 17:19:04 +00:00
Daniel Verkamp
dc310d7cb6 Replace ::max_value() with ::MAX
The max_value() function is considered to be a "legacy numeric constant"
now, and future clippy versions will warn about it:

<https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants>

BUG=None
TEST=tools/clippy # with rust-toolchain = "1.79"

Change-Id: I72a333dc4aa1f48cf71744c848f050097a7e7f55
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5690374
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-07-09 23:26:03 +00:00
Daniel Verkamp
56fcb65a41 arch: remove host OS checks for guest_suspended_cvar
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>
2024-07-02 21:00:31 +00:00
Devin Moore
650b0ec732 riscv64: fix build error from RunnableLinuxVm change
suspend_evt field in RunnableLinuxVm was changed and a riscv user of it
was not yet updated.

TEST=Android build with riscv64
TEST=lunch riscv64-trunk_stable-userdebug && m libriscv
BUG=b:349612065
Change-Id: I0881ca59d408856ea6105b9389a21f2e9c60ce72

Change-Id: I0d9092abfa8c1d33582fa5618b596e0eb1cb6a01
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5661556
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Devin Moore <devinmoore@google.com>
Commit-Queue: Devin Moore <devinmoore@google.com>
2024-06-26 21:37:04 +00:00
Daniel Verkamp
31ff290605 aarch64, riscv64: fix max kernel command line length
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>
2024-06-10 17:43:02 +00:00
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
cf3ef05f67 riscv64: remove unused kvm and kvm_sys dependencies
The riscv64 architecture support uses the `hypervisor` crate API, not
`kvm` directly; this was probably included unintentionally or left over
from old pre-`hypervisor`-crate code.

BUG=None
TEST=grep for `kvm` in `riscv64` directory

Change-Id: I45eb1c9c50a0b0bb4590334d8bf7f374182b9275
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5518122
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-07 20:04:00 +00:00
Daniel Verkamp
a41473f813 hypervisor: remove gdb feature and gdbstub deps
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>
2024-04-30 01:43:02 +00:00
Daniel Verkamp
5b1089f652 riscv64: fix get_serial_cmdline() parameter type
The get_serial_cmdline() function expects the serial devices as a slice,
not a Vec.

The riscv64 version isn't compile-tested in upstream crosvm, so this was
missed as part of the original review.

BUG=b:332595867

Fixes: 2dde104c1e ("arch: return created devices from add_serial_devices()")
Change-Id: I75536649d56e075cfbb87ee775442932fd62b0c3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5416573
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2024-04-02 22:47:21 +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
2c96bed807 Cargo.toml: Remove unused data_model deps
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>
2024-03-13 20:00:26 +00:00
Prashanth Swaminathan
7b86a43a9f Add missing 'use' declaration for arch::CpuSet
Bug: 266664564
Test: Built crosvm riscv64 in Android Open Source.
Change-Id: I91a558d70df7830f9fbb0a3d91ed597a78c685fc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5280800
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-02-09 00:39:04 +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
Pierre-Clément Tosi
b5f4d7dde3 riscv: Fix broken build after crrev.com/c/5029655
Fix the call to arch::sys::linux::generate_platform_bus, as that CL
modified its signature without properly updating the RISC-V caller.

TEST=tools/run_tests -p riscv64

Change-Id: Ie481017d2b09729b1ea6e51f90792fdc2a78d978
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5040632
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-11-20 18:46:07 +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
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
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
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
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
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
Elie Kheirallah
3b4fbfa799 devices: bus: Add BusType to Bus for better debugging.
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>
2023-10-18 23:48:40 +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
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
Daniel Verkamp
88ed5107be riscv64: update generate_pci_root return value
The generate_pci_root() function added an extra field for ACPI GPEs,
which wasn't applied to the riscv architecture-specific code.

BUG=None
TEST=tools/dev_container tools/presubmit crosvm_unit_tests_riscv64

Fixes: 298be81446 ("acpi: x86: add support for ACPI Notify() forwarding")
Change-Id: I426c7855411abc30bc9d0b0f329ce1f52ae88430
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4736334
Reviewed-by: Grzegorz Jaszczyk <jaszczyk@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-08-01 20:22:56 +00:00
Braden Kell
c4d61d96e8 riscv64: limit only minijail dependency
http://crrev.com/c/4477776 made riscv64 dependencies conditional to fix
Windows builders. This is slightly inconvenient for Android, which needs
to manually fixup dependencies as a result (see http://aosp/2655597).
This change makes only the minijail dependency conditional, which
satisfies Windows builders and simplifies Android.

BUG=b:286142463
TEST=CQ

Change-Id: I88f31f23dcc802dcf81ca554e728e7b9e9aaa46d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4684773
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Braden Kell <bradenkell@google.com>
2023-07-17 16:44:57 +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
Dennis Kempin
4cd4043fd1 Upgrade to 1.68.2: Fix clippy nits
The new rust toolchain comes with improved clippy warnings that
catch more unnecessary casts than before.
Some cases have to be whitelisted since libc types have varying size
based on the architecture we are compiling for.

BUG=None
TEST=presubmit

Change-Id: Ia473b0bfe6e74bdb7b0d4ca15d2c9fb410fc353e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4568144
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-25 18:28:14 +00:00
David Stevens
f420c50593 riscv64: implement missing trait method
Implement a method that was recently added to LinuxArch to fix the
riscv64 build.

BUG=None
TEST=./tools/presubmit crosvm_tests_riscv64

Change-Id: Id7e4100ba977eee980ff34f0a4b5cc8f23c61442
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4518050
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2023-05-12 01:40:53 +00:00
Grzegorz Jaszczyk
769c452925 devices: Introduce virt PMC device support allowing to notify about s2idle
Adding Victual PMC device allows to trap on MMIO access caused by its
Linux driver counterpart upon entering s2idle state. Linux Virtual PMC
driver registers notify() hook, which is triggered before system
actually enters s2idle state and triggers _DSM method which in turn
triggers MMIO access causing mentioned trap.

More info can be found in relevant linux kernel mailing list thread which
implements kernel counterpart:
https://patchwork.kernel.org/project/linux-pm/patch/20230213100921.268770-2-jaz@semihalf.com/

Upon Virtual PMC BusDevice write() handling, trigger functionality
responsible for handling s2idle notification, which is: wakeup blocked
thread awaiting guest suspension to finish.

Old functionality for handling s2idle request based on non-accepted by
Linux community, hypercall based solution - is removed as separate patch
CL:4507305

BUG=b:194391015
TEST=Make sure that S2Idle notification from guest are seen by crosvm
when --s2idle parameter is used. In such case the guest suspension is
detected quite fast and 15s timeout is not reached.

Change-Id: I79e1755cd344c46e7fa0dabc211cf7e354583204
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3780642
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
2023-05-05 22:26:02 +00:00
Daniel Verkamp
7aacb523e4 crosvm: enable gdb feature on all architectures
Remove the architecture-specific requirements from the gdb config
checks. This enables gdb across every supported target_arch without
having to manually add new architectures to each cfg check.

For the specific case of target_arch = "arm", this patch will newly
enable gdb support. The gdbstub protocol will still send aarch64 state,
matching the guest.

This stubs out enough riscv64 gdb functions and types to make
`cargo build --features=gdb` compile, but gdb support will not be
functional on that architecture without additional work.

Change-Id: I63b079b7a3dca4aec2c13c775c0ccb8850625884
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4506285
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dylan Reid <dgreid@rivosinc.com>
2023-05-04 22:59:01 +00:00
Dylan Reid
1940445671 riscv64: Fix clippy lint
In preparation for enabling tools/clippy to check riscv, clean up the
warning in the hypervisor crate.

Change-Id: I8b1c6ff54548ee5a3752fb453a4030b7d4582364
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4505757
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-05-04 15:44:54 +00:00
Daniel Verkamp
db627e80e9 crosvm: make userspace_msr handling x86 only
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>
2023-04-28 17:58:30 +00:00
Dylan Reid
b7193b9b6b riscv: limit dependencies to riscv builds
Instead of unconditionally depending on these dependencies only include
them for riscv64 builds. This will fix a build breakage on the windows
builders.

Thanks to denniskempin and dverkamp for suggesting this fix.

Change-Id: I035dc23cd0b58f63a3bcb3b8f883aba97d56492d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4477776
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-26 17:29:09 +00:00
Dylan Reid
f30889ca70 Add riscv arch crate
Basic support for riscv. This, combined with follow on commits adds
basic support for booting a linux kernel on a riscv machine. This has
been tested with a qemu host as the riscv hypervisor extension is not
yet widely available in hardware.

Change-Id: I44f83f1acf1be2297b62d1f10311e3e47319e5f8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4460936
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-04-25 22:05:38 +00:00