Commit graph

78 commits

Author SHA1 Message Date
Pierre-Clément Tosi
a6d39c5fa9 rand: Bump dependency to 0.9.2
Use rand::random() or rand::Rng::fill() in place of the now-removed
OsRng.fill_bytes(), note that the generic function now supports arrays
of any length.

Replace the deprecated rand::thread_rng() with its new name rand::rng()
or with new alternatives such as rand::random_range() where appropriate.

In fuzz/, update the impl of rand_core::RndCore which now does not
require implementing try_fill_bytes() (moved to TryRndCore) so remove it
as the function was only used by unit tests (which can also be removed).

As a result, CrosVM now follow the clean split of all client code only
depending on rand::Rnd (no imports of RndCore left) and the one provided
(FuzzRng) uses the rand_core crate, as recommended by the crate docs.

BUG=b:460349550
TEST=tools/presubmit

Change-Id: Icf0121297efcb0388e8aab17394c21457edbb119
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/7253053
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
2026-01-30 03:12:59 -08:00
A. Cody Schuffelen
afaa8be303 Workspace deps grab bag
- anyhow
- argh
- cfg-if
- enumn
- gdbstub
- gdbstub_arch
- rand
- remain
- serde
- serde_json
- thiserror

This level of indirection makes it possible to centrally update the
versions of these dependencies.

Bug: b/418050464
Change-Id: I4223e83d33ea527ed3bab8028ad16160e3fa0364
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551986
Auto-Submit: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-16 11:26:38 -07:00
A. Cody Schuffelen
f34a4abcbb Use workspace dependencies: crosvm workspace crates
Exclusions:
- perfetto
- sandbox
- rutabaga_gfx/ffi
- rutabaga_gfx/kumquat/gpu_client

This adds a level of indirection for internal crate dependencies, making
it less of a hassle to move a crate or add a new feature that is
universally enabled.

Continuation of crrev.com/c/6551983

Partially mechanically generated via
```
$ for TARGET in aarch64 aarch64_sys_reg acpi_tables android_audio anti_tamper arch argh_helpers audio_streams audio_streams_conformance_test audio_util balloon_control base base_tokio bit_field broker_ipc catapult_converter crash_report cros_async cros_fdt cros_tracing crosvm_cli crosvm_control crosvm_plugin crypto data_model devices disk e2e_tests ext2 ffmpeg fuse fuzz gpu_display hypervisor hypervisor_test_macro io_uring kernel_cmdline kernel_loader kvm kvm_sys libcras_stub linux_input_sys metrics metrics_events net_sys net_util power_monitor prebuilts proto_build_tools protos resources rutabaga_gfx serde_keyvalue snapshot swap sync system_api usb_sys usb_util vfio_sys vhost virtio_sys vm_control vm_memory vmm_vhost x86_64; do
  sed -i "s/^$TARGET =.*path[^,]\\+$/$TARGET = { workspace = true }/" $(find . -name Cargo.toml) && git restore Cargo.toml
  sed -i "s/^$TARGET =.*path[^,]\\+,/$TARGET = { workspace = true,/" $(find . -name Cargo.toml) && git restore Cargo.toml;
done
$ git restore perfetto
$ git restore sandbox
$ git restore rutabaga_gfx/ffi
$ git restore rutabaga_gfx/kumquat/gpu_client
```

Bug: b/418050464
Change-Id: I529b1a23128f19459b89e248a7c96ae2e487a441
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6554153
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 19:26:10 -07:00
A. Cody Schuffelen
83cec09245 Use workspace dependencies: libc
This allows all members of the workspace to depend on `libc` using
```
base = { workspace = true }
```
as opposed to the current collection of multiple numbered versions,
which had this distribution:
```
$ rg 'libc =' --no-filename --no-line-number | sort | uniq -c | sort -nr
      33 libc = "0.2"
      3 libc = "0.2.93"
      2 libc = "0.2.65"
      2 libc = "0.2.44"
      1 libc = { version = "0.2", features = ["extra_traits"] }
      1 libc = ">=0.2.39"
      1 libc = "0.2.153"
      1 libc = "0.2.116"
      1 libc = "*"
```

See:
- https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6544746/comments/c2fb58d3_1430749b
- https://doc.rust-lang.org/cargo/reference/workspaces.html#the-dependencies-table
- https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace

Bug: b/418050464
Change-Id: I61438cbfe47b18621ce00791a892af9a56d91fd7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551984
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 17:53:02 -07:00
A. Cody Schuffelen
2eb1a03271 Use workspace dependencies: base
This allows all members of the workspace to depend on `base` using
```
base = { workspace = true }
```
as opposed to the current distribution:
```
$ rg 'base =' -g Cargo.toml --no-filename --no-line-number | sort | uniq -c | sort -nr
     43 base = { path = "../base" }
      4 base = { path = "../../../base" }
      2 base = { path = "../../base" }
      1 base = { path = "base" }
      1 base = { path = "../base/" }
```

See:
- https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6544746/comments/c2fb58d3_1430749b
- https://doc.rust-lang.org/cargo/reference/workspaces.html#the-dependencies-table
- https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace

Bug: b/418050464
Change-Id: I1439fd1a5b99233a36a30a9c542abcf54ce5ac1c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551983
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 17:52:56 -07:00
Daniel Verkamp
c23af313c0 devices: virtio: simplify the common add_used() len case
Most of the time, the caller of Queue::add_used() passes the
DescriptorChain's writer.bytes_written() as len, or 0 if the request is
known to have written 0 bytes, which is equivalent to passing
bytes_written().

Change add_used() to use writer.bytes_written() automatically and
rename the existing function to add_used_with_bytes_written() to make
the common case simpler and the unusual case more explicit.

No functional change intended.

Change-Id: Ie2eb800dd7b7977bdf9199727a6794db90490686
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6495584
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-05-02 11:28:27 -07:00
Daniel Verkamp
4760a63251 x86_64: allow loading 32-bit ELF kernels
The kernel_loader::load_elf() function already allowed reading either
32-bit or 64-bit kernels, but it did not provide any indication to the
caller which one it actually loaded.

Add the ELF class to LoadedKernel and use it to allow x86_64 crosvm to
load either 32-bit or 64-bit ELF kernels and configure the appropriate
CPU mode.

The fuzzer is also updated to call the generic load_elf() function.
This also allows the load_elf32() and load_elf64() functions to be
removed, as they are unused after this change.

BUG=None
TEST=crosvm run kernel_loader/src/test_elf32.bin

Change-Id: I2c8578ff0d1292980d7534d087a76a7f56ceafa4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6439484
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-04-08 11:14:38 -07:00
Daniel Verkamp
85a5d2a264 [clippy] clean up redundant lifetime annotations
Change-Id: I7885de5fcbae19ff26d74cb078a57825059b306b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6195239
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2025-02-11 16:14:19 -08:00
Daniel Verkamp
ca4e28e753 Cargo.toml: upgrade to p9 0.3.1
Pull in the latest release for readdir() fixes related to long
filenames.

BUG=b:375208014

Change-Id: I66977d1717f7678de7bdbf05cbe2c350ebe6e15f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6023698
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-11-25 18:46:17 +00:00
Daniel Verkamp
17b696fd0a fuzz: expect cfg(fuzzing)
Otherwise clippy in Rust 1.80 and newer warns about unexpected_cfgs.

BUG=b:365852007

Change-Id: Id0496dec2491d1e850954f801c2f700b22be5179
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5902376
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-11-05 00:10:58 +00:00
Frederick Mayle
5921c375cc disk: add option to disable file locking
The recent changes to make crosvm lock nested disk files is running
afoul of Android Virtualization Framework's SELinux policies. The file
locking doesn't add much value in that environement because all the
shared files are read-only, so add an opt-out for locking to buy us time
to re-engineer the policies.

BUG=b:330911976

Change-Id: I0b35732978e946a2331507d6061729d53955a8d3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5849284
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-10 22:07:48 +00:00
Frederick Mayle
6cde4e3b9e disk: consolidate disk file opening logic
The disk crate is now responsible for opening the file and handling
options like OVERLAPPED and O_DIRECT.

O_DIRECT is now applied to all nested disk files. For now, OVERLAPPED
contiues to only apply to the root disk file.

BUG=b:330911976
BUG=b:190435784

Change-Id: Ib46a965c0589bf1c1e8e4ae5f0c81747530eff98
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5842394
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:39:03 +00:00
Frederick Mayle
2b9ea3f859 disk: pass more disk options to nested DiskFiles
No behavior difference intended. This is prep work to treat nested
DiskFiles consistently, e.g. using flock for them.

BUG=b:330911976

Change-Id: Id887ca21a9d5d186ba4dc77280c1ce4bfec8b319
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5840918
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:29:41 +00:00
Daniel Verkamp
8cc63c4219 devices: virtio: make Queue track its own Interrupt
When constructing a Queue from a QueueConfig, require the caller to pass
the corresponding Interrupt, and remove the &Interrupt argument from the
Queue::trigger_interrupt() function. This prevents mismatches of Queue
and Interrupt, especially in the case of a re-activation after a reset
where the old and new Interrupt are not the same.

BUG=b:360926085

Change-Id: I31ad9704d4963e46f7ce1b7b7a43aec1a92e342d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5798666
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-08-23 01:23:11 +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
Frederick Mayle
8515568a51 base: don't require &mut for FileReadWriteAtVolatile methods
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: I810b537e971bf007b6b34f0cbc605f2b3943a763
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507754
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-05-02 19:32:17 +00:00
David Stevens
32bf962689 devices: Add power management to virtio devices
Add PCI PM capability to virtio pci devices, and generate PMEs for all
virtio device interrupts. PMEs are GPEs advertised ACPI, so they are x86
only. PCIe PME signalling can be investigated in the future.

This is the VMM side patch to [1], which allows Linux guests to enter
system-wide low power states like s2idle without needing to reset the
virtio devices when PCI PM with No_Soft_Reset is advertised.

[1] https://lore.kernel.org/all/20231208070754.3132339-1-stevensd@chromium.org/

BUG=b:301865273
TEST=Manually enable ARCVM s2idle feature

Change-Id: I6b0a122820c5d6932dc3e181d2fd2852b3640e5e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4666701
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2023-12-14 03:25:11 +00:00
Daniel Verkamp
fcc28f5573 data_model: move IoBuf and VolatileMemory to base
IoBuf is defined in a platform-specific way (it is either iovec on unix
or WSABUF for windows), so it fits into the mission statement of the
base crate, which is meant to be *the* platform abstraction layer in
crosvm.

IoBufMut and VolatileMemory/VolatileSlice are defined in terms of IoBuf,
so they are also moved into base for consistency. Every crate that uses
these types already depended on base, so no extra dependencies are
added, and a few can be removed.

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

Change-Id: I4dddc55d46906dfc55b88e8e6a967d7e1c1922dd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5046605
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-11-27 21:42:49 +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
Joe Hattori
f53421d904 devices: virtio: block: Implement Default for DiskOption
This commit simplifies the initialization of DiskOption.

BUG=b:295282243
TEST=tools/presubmit

Change-Id: I40432ba6d7023f440c19078c47f663171e93de97
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4792842
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Commit-Queue: Joe Hattori <hattorij@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-08-22 21:03:40 +00:00
recipe-roller
dc573349d0 devices: Reduce number of arguments of BlockAsync::new() with
&DiskOption

This simplifies the BlockAsync::new() call utilizing &DiskOption.

BUG=b:295282243
TEST=tools/presubmit

Change-Id: I47e109a49760280c71a10f84344c5afda9d59e8d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4768225
Commit-Queue: Joe Hattori <hattorij@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-08-22 18:54:03 +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
Dennis Kempin
accbf3b693 Replace internal p9 with crates.io versio
The code is being moved to https://github.com/google/rust-p9 and published via crates.io

BUG=b:293164618
TEST=presubmit

Change-Id: Iee96cdff8bae6f9ae4faa59dfc80d2132ed31822
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4735191
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-08-14 18:34:51 +00:00
Daniel Verkamp
c3622e7f8d devices: virtio: make Queue own its Event
This cleans up the activate() signature and avoids the need to pass two
related (Queue, Event) variables everywhere a queue is needed.

No functional change intended.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: I9e5259428b39ad3a677fbb8a0bf574b3f15a7f35
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4738991
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-08-08 22:57:48 +00:00
Daniel Verkamp
b3c8e72a49 devices: virtio: pass GuestMemory to queue activate
Now that an active Queue is a separate type than the pre-activation
QueueConfig, we can ensure that a Queue has a valid reference to the
GuestMemory at creation time instead of passing it to every queue
operation.

No functional change, but simplifies Queue callers and prepares for
use of AtomicU* types in a later change.

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

Change-Id: I30266a5eadbd4f643da5595fbdd2c8f5df34bab3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4671481
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-08-01 21:45:08 +00:00
yuanyaogoog
9dda510bdf devices: Support packed virtqueue at run-time in block device
To support packed virtqueue in block device, add packed-queue runtime
flag to block device. If flag is set true, block deivice uses packed
virtqueue. If flag is not set or set to false, block device use split
virtqueue as default.

BUG=b:243621596
TEST=crosvm run —block ”…,packed-queue=true”

Change-Id: Iaca015392103858e06c9368553540ba937ec3b3d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4648470
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
2023-07-25 06:12:22 +00:00
Frederick Mayle
e678ede359 Reland "virtio: pass explicit queue indices on device activation"
This reverts commit 0efcbc5a46.

Reason for revert: Adjusted virtio-balloon code to match linux and qemu behavior instead of the virtio spec

Original change's description:
> Revert "virtio: pass explicit queue indices on device activation"
>
> This reverts commit 6199bb371a.
>
> Reason for revert: it broke virtio-balloon on ChromeOS
>
> Original change's description:
> > virtio: pass explicit queue indices on device activation
> >
> > In some cases, I changed the code to actually use the explicit indices
> > defined by the virito spec. In other cases, I was lazy and used
> > `pop_first` to emulate the old behavior.
> >
> > Change-Id: I9f1e4b6681e84b54ddca19e4d41c6508404fce4b
> > Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4697479
> > Reviewed-by: Noah Gold <nkgold@google.com>
> > Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> > Commit-Queue: Frederick Mayle <fmayle@google.com>
>
> Change-Id: I13ac499308f29d8a6a226e98d0eb4748b8e60944
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4705624
> Commit-Queue: Frederick Mayle <fmayle@google.com>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>

Test: use kernel with CONFIG_VIRTIO_BALLOON=y and boot crosvm with --balloon-page-reporting
Change-Id: I59691b1a9c60a44708a0e6c5c05e77e122675934
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4706390
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-07-20 23:06:27 +00:00
Keiichi Watanabe
0efcbc5a46 Revert "virtio: pass explicit queue indices on device activation"
This reverts commit 6199bb371a.

Reason for revert: it broke virtio-balloon on ChromeOS

Original change's description:
> virtio: pass explicit queue indices on device activation
>
> In some cases, I changed the code to actually use the explicit indices
> defined by the virito spec. In other cases, I was lazy and used
> `pop_first` to emulate the old behavior.
>
> Change-Id: I9f1e4b6681e84b54ddca19e4d41c6508404fce4b
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4697479
> Reviewed-by: Noah Gold <nkgold@google.com>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: Frederick Mayle <fmayle@google.com>

Change-Id: I13ac499308f29d8a6a226e98d0eb4748b8e60944
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4705624
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-07-20 17:49:54 +00:00
Frederick Mayle
6199bb371a virtio: pass explicit queue indices on device activation
In some cases, I changed the code to actually use the explicit indices
defined by the virito spec. In other cases, I was lazy and used
`pop_first` to emulate the old behavior.

Change-Id: I9f1e4b6681e84b54ddca19e4d41c6508404fce4b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4697479
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-07-19 21:31:56 +00:00
Daniel Verkamp
0c29eac704 devices: virtio: factor Queue into QueueConfig+Queue
This change creates a new type (QueueConfig) that represents a queue
configuration before it has been activated. The QueueConfig::activate
function serves the same purpose as the previous Queue::activate, but
now it also returns the Queue type, which now always represents an
actively running queue.

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

Change-Id: I502ac6b29bf9f0cfc33ef15f6fb7fe482214eafd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4111872
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Yuan Yao <yuanyaogoog@chromium.org>
Reviewed-by: Takaya Saeki <takayas@chromium.org>
2023-07-12 20:21:02 +00:00
yuanyaogoog
72e6f31102 devices: Change virtqueue to use enum interface
Previously, devices used the split virtqueue implemented in
/src/virtio/queue.rs by default. In order to support packed virtqueue in
the future, we implemented the enum type for virtqueue to abstract over
different virtqueue types. We migrated existing split virtqueue to a new
mod in /src/virtio/queue/ directory.

To support different types of virtqueue for each device, we enhanced
virtio_device trait by defining queue_type method to decide which
virtqueue type the device should use. We also modified base_feature function to accept queue type as a parameter.

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

Change-Id: If6cb3e3dd93a7ee3621e54a95742f6f9a524c79b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4648252
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
2023-07-06 03:08:52 +00:00
Daniel Verkamp
5da3111c57 fuzz: improve virtqueue fuzzer coverage
Exercise more of the virtqueue descriptor chain API by consuming the
reader and writer. This also makes the fuzzer match the real-world usage
of the DescriptorChain APIs.

BUG=None
TEST=cargo +nightly fuzz run virtqueue_fuzzer

Change-Id: Ic56362cda87dd482a7c8fa6b3dd89cebfee8bc30
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4553720
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-05-23 00:24:32 +00:00
Dennis Kempin
981f304f84 fuzz: Move fuzzers to standard cargo fuzz location
This simplifies `cargo fuzz` usage. Fuzzers can be built with
`cargo fuzz build` without any other arguments.

BUG=b:279217867
TEST=`cargo fuzz build`

Change-Id: I11b8a8ba4c2b3e2d1a42973699e4d9c3920635b6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4540001
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-16 20:43:37 +00:00
Dennis Kempin
8a1c50d5cd Refactoring: Move various general purpose crates to common/
This change contains the results of running

./tools/contib/cargo_refactor.py

This will break the next uprev, and needs to be synchronizized
with the corresponding ebuild changes in https://crrev.com/c/3248925

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

Change-Id: Ied15a1841887bb8f59fba65b912b81acf69beb73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3248129
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-29 22:31:43 +00:00
Daniel Verkamp
7fd815ed22 crosvm: switch to upstream tempfile crate
Use the crates.io implementation of tempfile instead of our own version.

Our reimplementation is kept in the tree for now in case of dependencies
outside of the crosvm tree; it can be removed later once those are fully
switched over to the crates.io implementation.

BUG=b:199204746
TEST=emerge-hatch crosvm

Change-Id: I07d3404239302ab9a17f4ddc82a9479b256e4eb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3209839
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-10-11 18:35:55 +00:00
Daniel Verkamp
eb1640e301 disk: limit maximum nesting depth
Impose a limit on the maximum nesting of file formats that can open more
files. For example, a qcow2 file can have a backing file, which could be
another qcow2 file with a backing file (or even the same file as the
original), potentially causing unbounded recursion.

BUG=b:198326611
TEST=cros_fuzz

Change-Id: I2f8573a7c71c6d8b310f2c2a75a240f2f8f0c9b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3146214
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-09-17 02:55:04 +00:00
Dylan Reid
60efe11939 OWNERS: Remove dgreid
denniskempin will inherit fuzzing or find someone to.

Change-Id: Icb4dc76949726c0d958dab41228ba848ec292c94
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2988148
Auto-Submit: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
2021-06-25 19:42:12 +00:00
Chirantan Ekbote
fa4bf10955 Add fuzz to crosvm's workspace
I don't really remember why the fuzz crate needed to be a separate
workspace and doing it that way seems to break our fuzzer builds so just
move it into crosvm's workspace.

BUG=none
TEST=USE="asan fuzzer" emerge-amd64-generic crosvm

Cq-Depend: chromium:2777911
Change-Id: Ibb0e2de14189683ee5af501392594230996accc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2772678
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2021-03-24 06:23:34 +00:00
Andrew Walbran
413f854564 Enable KVM_CAP_ARM_PROTECTED_VM when --protected-vm is passed.
- Add an address space region for the protected KVM firmware.
- Query firmware size, mmap something that size and create a memslot.

BUG=b:163789172
TEST=cargo test

Change-Id: I054cf5d763c980d073c17bce70e85a781816b64d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2623942
Auto-Submit: Andrew Walbran <qwandor@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Andrew Walbran <qwandor@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-03-02 19:04:43 +00:00
Daniel Verkamp
4e1f99a68d devices: virtio: block: add VIRTIO_BLK_T_GET_ID
Allow the user to specify a serial number for each virtio block device
using the new id= parameter:

  crosvm run --disk disk.img,id=SERIALNO ...

These serial numbers show up in sysfs for each block device, which
allows them to be uniquely identified regardless of the number or order
of block devices added on the crosvm command line.  This can be used to
find a specific device by serial number for mounting at boot time.

BUG=b:157687637
BUG=chromium:775781
TEST=crosvm run -r vm_rootfs.img,id=root -p init=/bin/bash vm_kernel
TEST=cat /sys/block/vda/serial # see serial is set to "root"
TEST=cargo test -p devices

Change-Id: I108cdc47c367fb038d6acd55da60f9e1aae59e68
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2225559
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-12-02 05:21:16 +00:00
Daniel Verkamp
6c987cf924 fuzz: block_fuzzer: remove use of AsRawFd
The Event API has changed so that it exposes only RawDescriptor, not
RawFd, so the block fuzzer's use of as_raw_fd() no longer worked.

The actual intent of the code using as_raw_fd() was to clone the Event,
so just use the existing Event::try_clone function which achieves the
same result without using platform-specific code.

BUG=chromium:1144535
TEST=`FEATURES=test USE='asan fuzzer' emerge-amd64-generic crosvm`

Change-Id: I64689dde1b1351997aa2f11ed440416e3d226815
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2514901
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-03 03:32:24 +00:00
Daniel Verkamp
0b0dd364ff fuzz: block_fuzzer: add new base_features arg
virtio::base_features() now takes an argument to indicate whether the
protected VM feature is enabled; update the block fuzzer to match.

BUG=chromium:1142959
TEST=`FEATURES=test USE='asan fuzzer' emerge-amd64-generic crosvm`

Change-Id: I79de47d2bfff8705a4d35c6d978c1d08b36d0db7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2508468
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-10-30 20:15:47 +00:00
Victor Hsieh
bae88f4f65 fuse: extract FUSE as a crate from virtio/fs
The current crate still require some work to be really reusable as a
regular FUSE, i.e. with a new reader/writer against /dev/fuse. This
change intends to focus on creating the crate, without trying to find
the optimal interface, and still keep virtio/fs working.

BUG=b:168305155
TEST=./build_test
TEST=USE='asan fuzzer' emerge-hatch crosvm

Change-Id: I8b623c9262221113b720c10125a6770763f14dc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2466484
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2020-10-27 16:18:51 +00:00
Daniel Verkamp
298f1724a1 fuzz: adapt block_fuzzer for Block::new features param
The Block::new() function now requires the base virtio features to be
passed as the first parameter; add it to the block fuzzer to fix the
fuzzer build.

BUG=chromium:1139427
TEST=`FEATURES=test USE='asan fuzz' emerge-amd64-generic crosvm`

Change-Id: Ia8afd1e38b7bb2bf55dfc18805684e3c462e66a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477250
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-10-18 03:27:28 +00:00
Zach Reizner
ab04758814 build_test: misc options, improvements, amd bug fixes
New option, --size-only, speeds up using build_test for getting release
binary size by skipping everything else. The lto flag is also added for
release builds to get a more realistic comparison.

The list of crates to test is built up automatically instead of
hard coded. To modify what gets included, empty .build_test_* files are
checked for existance. This is better than hard coding the list of
packages because it was frequently out of date.

For certain crate tests, a dynamic library that only exists in a sysroot
is required. This change includes a fix that adds the sysroot's lib
directory to the LD_LIBRARY_PATH env variable, similar to how
PKG_CONFIG_LIBDIR is modified.

TEST=build_test
BUG=None

Change-Id: I626cbcccf40035a0d29001cef7989a091848e4c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2444273
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-10-15 13:40:32 +00:00
Daniel Verkamp
1eedd1bfb4 fuzz: replace SharedMemory with tempfile
The block, qcow, and zimage fuzzers all created a SharedMemory and then
converted it into a file; with the new base API changes, this is no
longer supported.  Replace the SharedMemory uses with tempfile to fix
the build (this also simplifies the code).

BUG=chromium:1136895
TEST=`FEATURES=test USE='asan fuzz' emerge-amd64-generic crosvm`

Change-Id: I50d4e8c57ed41419c79a3fac440654224696f80c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2463895
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-12 09:45:46 +00:00
Michael Hoyle
685316f0bd base: EventFd -> Event renaming
Note the CL size is large entirely due to the rename,
the changes are mostly negligible.

Also making a few small additional changes in sys_util
areas that don't need much attention in base. This includes
typedefing and adding specific imports for areas that don't
require significant interface changes.

BUG=b:162363783
TEST=./build_test

Change-Id: I4a2c9c4cdce7565806ed338e241c6b8c82c855c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2415180
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-06 13:50:09 +00:00
George Burgess IV
61126c786c fuzz: fix build
A recent API change made `{Reader,Writer}::new` take `GuestMemory` by
value instead of reference. Since `GuestMemory` is just a pair o'
`Arc`s, this appears to be an easy fix.

BUG=chromium:1125394
TEST=`emerge-amd64-generic crosvm` with a `--profile=fuzzer`'ed board

Change-Id: I964f284134241f958456f87912334a387dfcf61e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2394756
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: George Burgess <gbiv@chromium.org>
2020-09-07 13:15:32 +00:00
Michael Hoyle
6b19695c81 Add "base" crate and transition crosvm usages to it from sys_util
For now, this crate simply re-exports all of sys_util, but it will
be updated to provide new interfaces when needed. This is the
first step to making crosvm not directly depend on sys_util, so
that we can make the interface changes we need without fear of
negatively affecting (i.e. completely breaking) other usages
within chromeos.

BUG=b:162363783
TEST=./build_test

Change-Id: I7d0aa3d8a1f66af1c7fee8fd649723ef17027150
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2325168
Tested-by: Michael Hoyle <mikehoyle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-08-06 18:19:44 +00:00
Tiancong Wang
61724a4ce0 fuzzer: Add vm_memory to fuzzer Cargo
After vm_memory was added, the dependency wasn't added. So it
caused crosvm-fuzz fail to build. This patch adds the dependency.

BUG=chromium:1110970
TEST=USE="asan fuzzer" emerge-amd64-generic crosvm

Change-Id: Ic71243365ed8603928ba30bce7b7361ca368bf1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2327870
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Tiancong Wang <tcwang@google.com>
2020-07-30 20:11:52 +00:00