Commit graph

228 commits

Author SHA1 Message Date
Vikram Auradkar
f054575a8b clippy: Disallow len_without_is_empty and len_zero
BUG=b:283512997
TEST=none

Change-Id: I0477583b3f8c8eefeb1d79f11302b1b28a8bd770
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4549999
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-05-22 21:27:21 +00:00
Vikram Auradkar
0e1c85f293 clippy: Disallow new_without_default
BUG=b:283512997
TEST=none

Change-Id: If10b73f0cd686ff1a1a17e4aa3260f01e1ee8db5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4546662
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-05-22 21:14:06 +00:00
maciek swiech
fac9000051 balloon: use protos for registered events
since the RegisteredEvent model is effectively an external API, switch
to using protobuf as a more formal/stable means of communicating
messages. also introduces exporting the registered_events.proto file as
part of crosvm_control build, alongside the currently existing header
file.

this patch also introduces feature-gating for registered_events and
protos so as not to bring in too many third party dependencies for a
base build.

BUG=b/278117550
TEST=run bzImage locally
TEST=sidecar program available at https://x20.corp.google.com/users/dr/drmasquatch/socket-pinger-proto

Change-Id: I5d91d87f7807effc125352caf5c75eee2593f70d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4521604
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: maciek swiech <drmasquatch@google.com>
2023-05-22 19:28:45 +00:00
Shintaro Kawamura
ca6adae33c crosvm_control: add swap status/trim command support
SwapStatus, SwapState, SwapStateTransition, SwapMetrics are directly
contained into crosvm_control.h

SwapState is translated as C++ enum.

SwapStateTransition::time_ms is now u64 because u128 does not support
repr(C).

Changed usize in the structs to u64 because usize is translated as
uintptr_t.

BUG=b:265386761
TEST=cargo build -p crosvm_control

Change-Id: Ia9df56d40c1884067a712620e0fc797e07af77a2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4486549
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-05-08 01:37:43 +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
Shintaro Kawamura
8590cdcc8a swap: expose Status interface to all variants
Status does not depend on any swap related feature. Exposing Status to
all variants is easy to implement swap status FFI at crosvm_control.

The new "swap/enable" feature switches the actual vmm-swap functionality
to be compiled. The feature is enabled by default on "swap" crate but
disabled on the root package for test dependency.

Vmm-swap feature is enabled by `--features=swap` flag on cargo build as
before.

swap/src/controller.rs is copied from swap/src/lib.rs.

BUG=b:265386761
TEST=tools/dev_container tools/run_tests2

Change-Id: Ifc2539a62d0f594fd5bbb41623c735ea2621f7b6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4486546
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
2023-05-04 12:30:09 +00:00
Noah Gold
31ee64ebee vm_control: refresh Irqchip Event tokens on restore.
When we restore a snapshot, we need to refresh the set of Events that
the IRQ handler thread is listening on, otherwise it won't forward IRQs
from the restored/re-created events.

BUG=b:277651574
TEST=tools/dev-container e2e_tests/run

Change-Id: Icd61112c23f063af0f6f217efe2b3359f884e351
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4416558
Reviewed-by: Steven Moreland <smoreland@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
2023-04-21 18:18:12 +00:00
Maciek Swiech
c10e83c576 balloon: remove wss_op_tube
since run_control is single threaded, we should be able to always
discard stale wss/stats messages in the handlers in vm_control,
obviating the need to keep a separate tube for wss crosvm_commands.

BUG=None
TEST=run bzImage

Change-Id: I7de192a08ae7a42641cbabe183dbad1c6ef627a4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4428055
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
2023-04-18 15:20:13 +00:00
Maciek Swiech
f4c5cd8e42 balloon: return balloon_actual with wss
balloon size is useful for balloon policies using working set size, so
we return the balloon-device cached balloon size. unless there is some
error in adjustement of the balloon, this should reflect that real
balloon size and saves having to query the guest an additional time.

BUG=b/278119213
TEST=run bzImage

Change-Id: I7c6b558358b8db099a737430e8431997bb110b2b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4428532
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: T.J. Alumbaugh <talumbau@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Maciek Swiech <drmasquatch@google.com>
2023-04-17 21:32:23 +00:00
David Stevens
df2625c599 Reland "vm_control: reduce user memory region modifications"
This is a reland of commit 22c212d54f

This reland avoids using the new pre-mapped memory regions on arm
devices, since there is insufficient address space. The new path is
still used on aarch64.

Original change's description:
> vm_control: reduce user memory region modifications
>
> Reduce how often KVM_SET_USER_MEMORY_REGION is called when the tdp mmu
> is enabled. With the tdp mmu, there is no memory overhead from creating
> large memory regions (at least until a nested VM is started). Simply
> mmap'ing/munmap'ing fds within a pre-created memory region is more
> efficient. It also addresses audio jank caused by removing a memory
> region.
>
> Adding this support to VmMemoryRequest will allow FsMappingRequest to be
> removed in a later change.
>
> BUG=b:274037632
> TEST=tast run arc.Boot.vm
> TEST=manually launch gedit in crostini
>
> Change-Id: I2ac02454ecb734c9707b6d67546135134b887527
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4402068
> Reviewed-by: Dennis Kempin <denniskempin@google.com>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: David Stevens <stevensd@chromium.org>

Bug: b:274037632
Change-Id: I5deedfd3a030640f9af950cee675fac0d9a411a0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4421352
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-04-17 20:16:39 +00:00
Dennis Kempin
e0c9e789d0 Revert "vm_control: reduce user memory region modifications"
This reverts commit 22c212d54f.

Reason for revert: Suspected to break crostini http://go/bbid/8783938922329906785

Original change's description:
> vm_control: reduce user memory region modifications
>
> Reduce how often KVM_SET_USER_MEMORY_REGION is called when the tdp mmu
> is enabled. With the tdp mmu, there is no memory overhead from creating
> large memory regions (at least until a nested VM is started). Simply
> mmap'ing/munmap'ing fds within a pre-created memory region is more
> efficient. It also addresses audio jank caused by removing a memory
> region.
>
> Adding this support to VmMemoryRequest will allow FsMappingRequest to be
> removed in a later change.
>
> BUG=b:274037632
> TEST=tast run arc.Boot.vm
> TEST=manually launch gedit in crostini
>
> Change-Id: I2ac02454ecb734c9707b6d67546135134b887527
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4402068
> Reviewed-by: Dennis Kempin <denniskempin@google.com>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: David Stevens <stevensd@chromium.org>

Bug: b:274037632
Change-Id: Id5caebd0bd33f4984567ff604f117ae4d95a71ab
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4422453
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-04-13 21:39:27 +00:00
Maciek Swiech
86df65f6d2 balloon: working set size config command
this patch adds the crosvm_control command (and internal implementation)
to send a new WSS config command to a guest balloon driver. included is
a refactor of how wss op notifications are dispatched in the balloon
device.

BUG=b/271891148
TEST=run bzImage
TEST=socket-pinger program available at https://x20.corp.google.com/users/dr/drmasquatch/socket-pinger

Change-Id: Id9696b0e82b3ba54d87cd0928070c55da9a77d1f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4415596
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
2023-04-11 19:36:14 +00:00
David Stevens
22c212d54f vm_control: reduce user memory region modifications
Reduce how often KVM_SET_USER_MEMORY_REGION is called when the tdp mmu
is enabled. With the tdp mmu, there is no memory overhead from creating
large memory regions (at least until a nested VM is started). Simply
mmap'ing/munmap'ing fds within a pre-created memory region is more
efficient. It also addresses audio jank caused by removing a memory
region.

Adding this support to VmMemoryRequest will allow FsMappingRequest to be
removed in a later change.

BUG=b:274037632
TEST=tast run arc.Boot.vm
TEST=manually launch gedit in crostini

Change-Id: I2ac02454ecb734c9707b6d67546135134b887527
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4402068
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2023-04-11 00:58:43 +00:00
Maciek Swiech
eebc110fbf balloon: implement wss reporting virtio-balloon extensions
this patch implements the virtio-balloon extensions proposed in
go/roziere - namely adding the Working Set Size vqueues and listener on
the wss vqueue. in addition we add a crosvm_control command which allows
a user to request that the balloon device send a request to the driver
to produce a WSS report, similar to asking for balloon stats.

BUG=b:271757427,b:273212204
TEST=sidecar process, available at https://x20.corp.google.com/users/dr/drmasquatch/socket-pinger
TEST=deploy to DUT, restart termina and arcvm

Change-Id: I45753f523aae97d14bfc5dcbad5ddfcb70d10beb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4260158
Reviewed-by: T.J. Alumbaugh <talumbau@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
2023-04-05 22:23:04 +00:00
Daniel Verkamp
10a487a725 tree-wide: replace manual enum Defaults with derive
This is supported since Rust 1.62.

Fixes the new derivable_impls clippy lint, added in Rust 1.67.

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: I3696dd3cf4acbf9b5a2cfa8c2046e7656e13dbbd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4390735
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-04 22:12:39 +00:00
Shintaro Kawamura
f8dcf7528d swap: fix deadlock on the vmm-swap enable operation
The deadlock could happen on this scenario:

1. User enables vmm-swap. The main process sends Command::Enable to the
   monitor process.
2. User request the current status at the same time. The main process
   sends Command::Status to the monitor process and wait for the
   response from the monitor process.
3. The monitor process start enabling vmm-swap. Sends
   VmSwapCommand::Suspend to the main process and wait for
   VmSwapResponse::SuspendCompleted.
4. The main process is blocked by the step 2 and the request from step 3
   is never consumed.

The root issue issue is that Command::Status can be inserted between
Command::Enable and VmSwapCommand::Suspend. This CL simplifies the
communication between the main and monitor processes on enabling
vmm-swap and resolve the deadlock.

VmSwapCommand and corresponding Tube was added by
https://crrev.com/c/4293656, but is now removed by this CL.

BUG=b:275671628
TEST=manual test

Change-Id: Ia838b1feddb4a3f41bd729e9147adc5e2df866aa
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4387662
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-04-03 06:03:18 +00:00
Frederick Mayle
650857d58c vm_control: check CPU count on restore
Change-Id: Id2ee686cdac4af930547686de2c5bacf199d675e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4386084
Reviewed-by: Noah Gold <nkgold@google.com>
Auto-Submit: Frederick Mayle <fmayle@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2023-03-31 04:44:44 +00:00
Frederick Mayle
7603febb15 hypervisor: merge VcpuSnapshot and VcpuInnerSnapshot structs
We can require the ID field to be present in all the arch specific
structs, then we don't need an extra layer.

Change-Id: Icbbf0ec5b99fd6816863a611a538e67def09d87f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4385864
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
2023-03-31 00:22:40 +00:00
Frederick Mayle
a462679011 devices: use File::open/create instead of OpenOptions
No behavior change intended.

Change-Id: I9b4aaf00ef83bc56311389b74bac530e83a680f7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4377983
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-03-29 19:53:13 +00:00
Wang Ningyuan
565890222d Devices: BAR reprogram for virtio-pci devices
This CL adds BAR reprogramming support to a VirtioPciDevice. A tube for
handling ioevent register requests is added. The requests are handled
similarly to existing VmMemoryRequests.

Test: Presubmit tests. Hotplugged virtio device without VM memory
allocation functions after guest OS gives the memory.
Bug: 271204121

Change-Id: Ia0d421d8cd461eeee8f402256d0c7620c507f0e9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4311103
Reviewed-by: Ningyuan Wang <ningyuan@google.com>
Commit-Queue: Ningyuan Wang <ningyuan@google.com>
Reviewed-by: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-29 04:01:30 +00:00
Shintaro Kawamura
018e8caf99 swap: add trim command
"crosvm swap trim <socket_path>" command for trimming 2 types of pages
in the staging memory before swapping out to reduce the disk I/O.

* clean pages
* zero pages

The doc comment of TrimContext explains the page types.

BUG=b:265592787
TEST=cargo test -p swap

Change-Id: I5c33149f7d0bfd712f07fd11eb9aa07c1a8b0e7a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4357224
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
2023-03-29 01:22:02 +00:00
Frederick Mayle
e2c5236661 crosvm: restore vCPUs during "cold restore"
We only restored the devices before.

BUG=b:269174485

Change-Id: I524c055fcdbed6c8cac4b1e3bfe280ba368c3b37
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4375647
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-03-28 20:54:02 +00:00
Daniel Verkamp
083dcf75f4 tree-wide: apply nightly rustfmt
BUG=None
TEST=tools/fmt --nightly

Change-Id: Ifb08dd55ccf2a74ef739d7517a64970d24a82405
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4375640
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-03-27 21:30:45 +00:00
Gurchetan Singh
61ee6744f2 rutabaga_gfx: nuke base dependency
The base crate has some nifty abstractions but also
pulls in things like minijail, audio_streams and
various random items.

This prevents true cross-platform interoperatibility,
which requires the ability to upload to crates.io
with relative ease.

This change removes the base crate.  The replacement
strategy is two fold:

- For things like SafeDescriptor which don't have
  adequate solutions on crates.io, just copy it
  internally.  I think SafeDescriptor in particular --
  since it works on bot Windows/Linux should probably
  be made into a separate crate long-term since it is
  generically valuable.  Similarly for the Event and
  WaitContext APIs.  For now, live with the duplication.

- Otherwise, the nix crate does most of the Linux
  specific items.

The cross-domain context type has a lot of dependencies
on Linux sockets / epoll.  This is refactored to look more
like the Fuchsia solution, which uses std::sync::mspc
channels to connect to an utility Wayland FIDL library.

The rest of Rutabaga mostly relies just on SafeDescriptor
and the ability to clone it.  rutabaga_gralloc allows
provides shared memory used via virtwl.

Another thing to call out is zerocopy is now strongly
versioned to the latest stable release on crates.io

I also got rid of #[cfg(feature = "virgl_renderer_next")]
on the renderer server fd, since it was complicating the
refactoring.  SafeDescriptor works everywhere and adding
the #ifdef should be reserved for the lowest-levels of
platform specific code when possible.

Overall, this makes compiling on Fuchsia hosts much
simpler.

BUG=b:273555494
TEST= - run cross_domain context type, see Wayland apps
      - note there is a previous bug in cross domain
        when resizing windows, it occurs before this CL.
        The reason seems to be raciness and can likely be fixed
        gfxstream-like seqno.
      - run gfxstream + virgl on Linux, verify everything works.

Change-Id: I7519f2b8ed0cd57c47980d4e76403057498cf064
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4353700
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2023-03-27 18:46:22 +00:00
David Stevens
00af43e1b5 Reland "devices: cmos: implement rtc alarm"
This is a reland of commit 42a437de5e

This change fixes a crash that occurs when no-rtc is set by properly
checking the Option that can contain the cmos's control tube, instead of
just calling unwrap. It also replaces an unwrap during cmos
initialization with proper error propagation.

Original change's description:
> devices: cmos: implement rtc alarm
>
> Implement CMOS alarm functionality. This allows guests to set rtc
> alarms, which is useful when putting a Linux guest into s2idle.
>
> This change allocates a dedicated interrupt for the goldfish battery,
> instead of reusing the sci irq. Sharing an irq line between a wakeup
> interrupt and a non-wakeup interrupt doesn't work well because the
> non-wakeup interrupt won't be delivered to its driver while the driver
> is suspended, which results in the irq being permanently asserted.
> Simply using a dedicated interrupt for the goldfish battery is much
> easier than adding suspend/resume support to the Linux driver.
>
> BUG=None
> TEST=cargo test -p devices cmos, manual tests w/rtcwake
>
> Change-Id: I757acc64b61e414d5d9df5a1fb4770943ef985bf
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4314184
> Reviewed-by: Elie Kheirallah <khei@google.com>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: David Stevens <stevensd@chromium.org>

BUG=None
TEST=cargo test -p devices cmos, manual tests w/rtcwake and no-rtc

Change-Id: Iec73c0aa08b4f2081c3b7a824254723ea9da5365
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4364558
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
Auto-Submit: David Stevens <stevensd@chromium.org>
2023-03-27 04:46:32 +00:00
Elie Kheirallah
425764d60f hypervisor: Add restore to x86/x86-64 Vcpu
Add restore to Vcpu to restore VCPU state from snapshot.
Add kick_vcpu to kick a specific vcpu.

BUG=b:266515147
BUG=b:232437513
Test=crosvm run && crosvm snapshot take img_name socket

Change-Id: Ie09419fd50dcecd0226b2b716236d2c8196b58ec
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4260157
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Elie Kheirallah <khei@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
2023-03-23 20:55:00 +00:00
Elie Kheirallah
9d214c1843 hypervisor: Add snapshot to vCPU x86_64
Add snapshot to vCPU for x86 and x86_64 arch.

BUG=b:266515147
BUG=b:232437513
Test=crosvm run && crosvm snapshot take img_name socket

Change-Id: I65d059a7537c713e9ef6c1456a7aeae2b6bc4728
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237759
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
2023-03-23 17:15:47 +00:00
Noah Gold
7036a3a70e devices: snapshot serializion for MsixConfig.
MsixConfig is now serializable. After deserialization, there is a new function
`restore_msix_all`, which will re-create the MSI-X vectors based on the
data that was deserialized. We could try to weave this into the actual
serde deserialization process, but that will likely be more hassle than
it is worth (it will also stop us from fixing up the msi control Tube on
restore, which we'll have to do in a future CL).

BUG=b:272137957
TEST=presubmit

Change-Id: I36fbc35a13fe11ae2f7c899431d2ef239ac00f90
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4337964
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2023-03-21 00:16:40 +00:00
Wang Ningyuan
3d67441192 Devices: Renaming for BAR reprogram
This CL renames some functions and variables introduced for PCI BAR
reprogramming to avoid confusion.

Test: presubmit tests.
Bug: b:271204121
Change-Id: I77aaca123a677b56da0b45ce78a54e84bec64a59
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4332623
Commit-Queue: Ningyuan Wang <ningyuan@google.com>
Reviewed-by: Hugo Benichi <hugobenichi@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-14 01:14:39 +00:00
Frederick Mayle
ff42de0098 vm_control: simplify VcpuControl::GetStates plumbing
Instead of wiring up a channel ahead of time, set one up on demand. This
significantly reduces the amount of plumbing required. We'll need more
VcpuControl cases in the near future that require responses like this
(e.g. vcpu snapshotting and restoring) and the extra plumbing for each
in unpalatable.

It isn't obvious what the performance difference is and we don't have a
relevant benchmark. None of the use cases are particularly performance
sensitive yet.

BUG=b:232437513

Change-Id: I96e720065275894ac0eb2965d5f707ec57b19c64
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4326945
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
2023-03-10 23:14:41 +00:00
Vikram Auradkar
948735a289 base: upstream overlapped send recv message functions
Upstreams blocking overlapped read/write commmands to base.
These funtions will be used by the broker to forward messages exchanged
between main and service.

Bug: 269191436
Test: none
Change-Id: I029e8c440bb6b8234fe2d1ca3b1dd5ddb408d814
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4329913
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-03-10 23:01:40 +00:00
Maciek Swiech
d7bfa2dc54 crosvm: reland socket control mechanism
crrev.com/v/4237140 was reverted in crrev.com/c/4310064 due to the
generated header file not defining the RegisteredEvent type. along with
re-reverting the original cl (and corresponding bugfix cl) this patch
introduces a RegisteredEventFfi type which mirrors the original
RegisteredEvent type but should be exposed in the generated header file.

BUG=b:269609274
TEST=sidecar process (patch: crrev.com/c/4276642)
TEST=cargo build, header file inspection

Change-Id: I4a17163e36eb466a540a72d2bb4356419739c974
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4311831
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
2023-03-10 18:49:13 +00:00
Dennis Kempin
6d5d075448 Revert "devices: cmos: implement rtc alarm"
This reverts commit 42a437de5e.

Reason for revert: This is crashing if no_rtc is set (http://go/bbid/8787052669966742145/test-results)

Original change's description:
> devices: cmos: implement rtc alarm
>
> Implement CMOS alarm functionality. This allows guests to set rtc
> alarms, which is useful when putting a Linux guest into s2idle.
>
> This change allocates a dedicated interrupt for the goldfish battery,
> instead of reusing the sci irq. Sharing an irq line between a wakeup
> interrupt and a non-wakeup interrupt doesn't work well because the
> non-wakeup interrupt won't be delivered to its driver while the driver
> is suspended, which results in the irq being permanently asserted.
> Simply using a dedicated interrupt for the goldfish battery is much
> easier than adding suspend/resume support to the Linux driver.
>
> BUG=None
> TEST=cargo test -p devices cmos, manual tests w/rtcwake
>
> Change-Id: I757acc64b61e414d5d9df5a1fb4770943ef985bf
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4314184
> Reviewed-by: Elie Kheirallah <khei@google.com>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: David Stevens <stevensd@chromium.org>

Bug: None
Change-Id: I25737095f84ca0b56d94924a9d8ccb5fd42ff51c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4329909
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-03-10 15:16:27 +00:00
Wang Ningyuan
dda04eda47 Devices: trait implementation for BAR reprogram
This CL adds trait implementation for PciDevice to handle BAR
reprogramming. When BAR reprogramming is detected, the PciDevice checks
all ioevents needed, and requests ioevent registeration for events that
are in the changed domain. The requests are handled by instances of
PciDevice via the trait function ioevent_register_request.
Before the CL, ioevent re-registering is unhandled, and PciDevice is
broken without notification. After CL, an error message will appear, but
device still would not function as the added trait is not implemented.

Test: Presubmit Tests. Hotplugged virtio device triggers error
IoEventNotSupported as expected.
Bug: 271204121

Change-Id: Ibf4bc00cfdce24e508cd50b5009f148c5a49db30
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4310071
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Ningyuan Wang <ningyuan@google.com>
2023-03-10 04:17:52 +00:00
David Stevens
42a437de5e devices: cmos: implement rtc alarm
Implement CMOS alarm functionality. This allows guests to set rtc
alarms, which is useful when putting a Linux guest into s2idle.

This change allocates a dedicated interrupt for the goldfish battery,
instead of reusing the sci irq. Sharing an irq line between a wakeup
interrupt and a non-wakeup interrupt doesn't work well because the
non-wakeup interrupt won't be delivered to its driver while the driver
is suspended, which results in the irq being permanently asserted.
Simply using a dedicated interrupt for the goldfish battery is much
easier than adding suspend/resume support to the Linux driver.

BUG=None
TEST=cargo test -p devices cmos, manual tests w/rtcwake

Change-Id: I757acc64b61e414d5d9df5a1fb4770943ef985bf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4314184
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2023-03-09 01:27:16 +00:00
Shin Kawamura
0ce2557fc5 Revert "balloon: add event registration mechanism for sidecar processes."
This reverts commit 2404c5ed44.

Reason for revert: This fails to build crosvm C interface and blocking ChromeOS CQ.

Original change's description:
> balloon: add event registration mechanism for sidecar processes.
>
> this patch introduces a mechanism for so-called 'sidecar processes' to
> register as event listeners, consuming events that are generated in
> various parts of crosvm. in this patch we focus on events that enable
> roziere cooperative ballooning, but lay the groundwork for a more
> general framework.
>
> the general idea is that a sidecar process would open a listening socket
> and register the path with crosvm for a specific event. crosvm will pass
> along a handle to a registered event tube to the appropriate device (or
> other internal component) which would then be responsible for passing
> along events. once events arrive back in the crosvm control loop, an
> attempt is made to dispatch the events to any registered sockets.
>
> BUG=b:269609274
> TEST=sidecar program that performs registration and receives events
>
> Change-Id: Iaff41aad8f862ed99a104c75623caaabc53e9e88
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237140
> Commit-Queue: Maciek Swiech <drmasquatch@google.com>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>

Bug: b:269609274
Change-Id: I135e0d55bb296cf591548b7bd4feffc7ff9f3447
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4310064
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2023-03-06 06:51:35 +00:00
Noah Gold
9625125386 devices: split snapshot command into phases.
To safely flush IRQs, we need devices to be asleep. This CL splits our
existing snapshot device control command into three: sleep, snapshot,
and wake. This way we can ensure the devices are sleeping while we flush
IRQs & snapshot the VCPUs (in the future).

BUG=b:269652620
TEST=./tools/dev_container e2e_tests/run --tests suspend_resume

Change-Id: I82a3f280c24378ea5d2a28a5cd4e3db49c9b78f2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4304243
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-03-03 22:04:21 +00:00
Frederick Mayle
963e1fd7f3 vm_control: fix and simplify snapshot/restore IPC types
https://crrev.com/c/4304741 broke these because the expected responses
are not `VmResponse::Ok`. There isn't good reason for them to have
custom types though, so I've moved them to `VmResponse::Ok` and added a
generic `VmResponse::ErrString` case to support stringy errors. Maybe
more stuff could be moved to `VmResponse::ErrString`, but I'm holding
off for now.

Change-Id: Ib5760217037ceb8718e36a77aeb300a4b0eb2a9f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4304683
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-03-03 05:50:54 +00:00
Frederick Mayle
951bfc7523 vm_control: snapshot: fix tube response deserialization
The tube response should be deserialized as a `SnapshotControlResult`
instead of `()`.

Also, we want to flush IRQs before snapshotting the IRQ chip state, so
it should be done before sending the snapshot command. However, this
part is still not right because the devices aren't asleep.

Change-Id: I94245b23a5166ec231dd36020e55930a80e007cd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4304682
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-03-03 05:50:26 +00:00
Frederick Mayle
3e400e9293 vm_control: check for errors in VmResponse
A command like `crosvm stop` could fail, but report an exit code of 0
with no error message.

Change-Id: I6491f8fcb755717999816d34d4a4eaf3964e1270
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4304741
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-02 23:25:24 +00:00
Frederick Mayle
3db841f74c vm_control: fix misc error messages
Change-Id: Ie261824a7653724469522fd60098a729df3a7726
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4304740
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-03-02 23:04:16 +00:00
Maciek Swiech
2404c5ed44 balloon: add event registration mechanism for sidecar processes.
this patch introduces a mechanism for so-called 'sidecar processes' to
register as event listeners, consuming events that are generated in
various parts of crosvm. in this patch we focus on events that enable
roziere cooperative ballooning, but lay the groundwork for a more
general framework.

the general idea is that a sidecar process would open a listening socket
and register the path with crosvm for a specific event. crosvm will pass
along a handle to a registered event tube to the appropriate device (or
other internal component) which would then be responsible for passing
along events. once events arrive back in the crosvm control loop, an
attempt is made to dispatch the events to any registered sockets.

BUG=b:269609274
TEST=sidecar program that performs registration and receives events

Change-Id: Iaff41aad8f862ed99a104c75623caaabc53e9e88
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237140
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-02 20:50:18 +00:00
Shintaro Kawamura
d4b59d8878 swap: send SIGSTOP from the main process on swap enable
The design sending SIGSTOP to the main process and the device processes
from the monitor process does not work with sandboxing the monitor
process because user namespace without pid namespace is not supported by
minijail.

This changes the design so that monitor process sends a message to the
main process, which is then responsible for guaranteeing that nothing
except the monitor process will access guest memory when vmm-swap is
being enabled. The main process does this by sending SIGSTOP to device
processes and suspending the vCPU threads. Although there are other
threads in the main process, none of them currently access guest memory.

The vmm-swap feature now does not support `--disable-sandbox`. It would
be possible to support it by sending `SIGSTOP` from the monitor process
to the main process. However there is no clear use case for vmm-swap
with `--disable-sandbox`, so the extra complexity is not worth it.

BUG=b:270248453
TEST=manual test

Change-Id: Ie24d5a5b5f8e6999d133beb9b4c3562e26427838
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4293656
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-03-02 00:33:00 +00:00
Noah Gold
7ac2622480 vm_control: fix up IRQ flush constant.
The constant was for a max, not an expected loop value.

BUG=none
TEST=tools/clippy

Change-Id: I71a69612951b0f12f32e7d800d7a892e7f472371
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4299921
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2023-03-02 00:31:00 +00:00
Noah Gold
dcee988cdc vm_control: flush IRQs to LAPIC for snapshot.
Just prior to taking a snapshot, we want to ensure that all pending IRQs
are flushed to LAPICs so that they can be safely saved & restored with a
snapshot. This CL wires the snapshot handler to the IRQ handler so that
the IRQs can be confirmed to be flushed.

BUG=b:269652620
TEST=./tools/dev_container e2e_tests/run --tests suspend_resume exercises this
code path, but does not directly test the changed behavior.
TEST=this fixes a race condition. Writing a test to reproduce that race
condition would just introduce a flakey test. When we have a cold boot
test (which we can't write yet because it depends future features), it
will flake on restoring LAPIC state *if* this CL has not fixed the race
condition properly. Thus, the testing strategy for this CL is to make
sure our cold boot test is run with *many* iterations to detect such
flakes (see b/270778349).

Change-Id: I2f326a7fdee9f21edda8402920661ef984943761
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4292623
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2023-03-01 22:51:35 +00:00
Takaya Saeki
b34fd215e2 devices: virtio: block: test resize and reset
Add unit test cases to test disk resize and device reset.

BUG=b:270280130
TEST=`cargo test -p devices`

Change-Id: Idac5e5e18ff520b6ae7d85ca9a6d5d103b114e78
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4272806
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Takaya Saeki <takayas@chromium.org>
2023-02-28 01:35:27 +00:00
Shintaro Kawamura
d733be714d vm_control: refactor do_while_vcpus_suspended
do_while_vcpus_suspended() deeply depends on device snapshot feature.
It should be more generic.

The vmm-swap feature will need to execute enabling logic while vCPUs are
suspended.

BUG=b:270248453
TEST=cargo build

Change-Id: I4f1acb2cf9ad61ee0887c6c7bfa7f68ba1dfb3ed
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4279545
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-02-22 23:41:55 +00:00
Shintaro Kawamura
7654908fec swap: switch page fault logger with compiler feature flag
page fault logger is only for debugging purpose. It has a security
concern about exposing the trigger to enable the logger. The logger will
make the page fault handling slower and consumes disk resources.

Instead, the page fault logger is only enabled by compiler feature flag
like:

```
cargo build --features=swap,swap/log_page_fault
```

Opening a file on the monitor process is blocking the upcoming minijail
migration. Open the log file on the main process and pass the file
descriptor to the monitor process.

BUG=b:269372016
TEST=manual test

Change-Id: I5df2a32da7fb149680fa24617ffd905b2483108b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4253287
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-02-15 07:06:22 +00:00
Victor Ding
0e18fe3032 vm_control: trivial code cleanup
Cleanup VmRequest:Gpe handler to better fit Rust coding style.

BUG=None
TEST=Builds "crosvm"

Change-Id: I39b987a530d110734923f34b545474db84144e81
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4173353
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Victor Ding <victording@chromium.org>
2023-01-18 18:37:59 +00:00
Victor Ding
9aa4eb1bf8 vfio_pci: forward wakeup event to guest as a PME
Allow devices to notice wakeup events supported by
VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY_WITH_WAKEUP.

BUG=b:241526471
TEST=Trigger a wakeup event and verify the output from `lspci`

Change-Id: Ie93780606fbfaa7efff853b6ff12314b3f54f276
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4048547
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Victor Ding <victording@chromium.org>
Commit-Queue: Victor Ding <victording@chromium.org>
2023-01-18 05:38:44 +00:00