Commit graph

130 commits

Author SHA1 Message Date
Anton Romanov
9ac4427d7b crosvm: vm_control: make handle_request generic over AsRef<Path>
All the Path::new(string var) are very repeptitive and completely
unnecessary

Change-Id: I05e86bcf9ad35519cd74ed8de78c4ddabd88abe0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3680296
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-06-07 20:19:34 +00:00
Hikaru Nishida
4f5ba4bd28 Revert "crosvm: remove balloon stats request timeout"
This reverts commit 56c0d02760.

Reason for revert: Break ARCVM after suspend/resume

BUG=b:234067421
TEST=Checked that ARCVM kept working after suspend/resume

Original change's description:
> crosvm: remove balloon stats request timeout
>
> It was done to avoid deadlock when stats are requested before guest is
> up. Implement a stub BalloonStats::NotReady replier until host is up so
> that timeout is no longer necessary.
>
> BUG=b:232289535
> TEST=few tast crostini/arc tests
>
> Change-Id: I6731b4ee9eaecdd65aebdd3f530f0932b0660c85
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652887
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Anton Romanov <romanton@google.com>
> Auto-Submit: Anton Romanov <romanton@google.com>

Bug: b:232289535
Change-Id: Iffafaef1e1136ebc050d69d001d384eedd0a2319
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3686789
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Hikaru Nishida <hikalium@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Hikaru Nishida <hikalium@chromium.org>
2022-06-02 11:09:31 +00:00
David Stevens
35ce872a45 devices: virtio: iommu: check for invalid attaches
Check that the same mapper isn't used for multiple domains. This ensures
that there won't be mapping collisions/leaks if the guest tries to use
the same mapper with multiple domains.

BUG=None
TEST=Boot ManaTEE with devices managed by viommu

Change-Id: I45889e6fe020c3a24b355fc05a8f74734bece78a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3641221
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-01 08:46:38 +00:00
Grzegorz Jaszczyk
cadc84b32a crosvm: extend suspend commands about generating sleepbtn event
As a part of full guest suspension/resumption support extend crosvm
suspend command about generating sleepbtn press. This allows to emulate
PM1 and inject the vSCI to the guest. When the guest kernel is built
with ACPI button support enabled, it allows to suspend guest with use of
some guest daemon listening on ACPI events e.g. acpid
(acpid detects the ACPI sleepbtn event and triggers the guest
 suspension).

During suspension process (VmRequest::Suspend), before VmResponse::Ok is
advertise, there is need to wait for actual guest suspension.
This is required, e.g. when crosvm suspend command is triggered
automatically by vm_concierge during host suspension process and
prevents suspending host before the guest is suspended.

Above is achieved by taking advantage of KVM_SYSTEM_EVENT_S2IDLE
request sent by hypervisor on behalf of a non-privileged VM. It is used
to wake up blocked thread, which is awaiting non-privileged guest
suspension to finish.

The enhanced suspend process introduced by this patch is triggered
only when the --s2idle flag is passed.

BUG=b:194391015
TEST=Suspend the guest by issuing "crosvm suspend
/run/vm/vm.<hash>/crosvm.sock" and make sure that the guest actually
triggers suspend process and finalizes it.

Change-Id: I38cf5a786275fc4afa4ba7642ef0be779f8f1548
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3602869
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-27 18:59:16 +00:00
Grzegorz Jaszczyk
2e7ded3fbd crosvm: extend resume commands about generating powerbtn event
As a part of full guest suspension/resumption support extend crosvm
resume about generating powerbtn press during resume. This allows to
emulate PM1 and inject the vSCI to the guest. When the guest kernel
is built with ACPI button support enabled it allows to wakeup guest from
suspend (ACPI powerbtn fixed event is registered for the guest kernel
and since SCI is wakeup armed it allows to wakeup the guest).

Complementary patch for suspend: CL:3602869

The enhanced resume process introduced by this patch is triggered only
when the --s2idle flag is passed.

BUG=b:194391015
TEST=Suspend the guest by "echo mem > /sys/power/state" and wake it up
by issuing "crosvm resume /run/vm/vm.<hash>/crosvm.sock".

Change-Id: Ifa6626801b495cf96508531783c556804d5a51c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3602868
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-27 18:43:30 +00:00
Anton Romanov
56c0d02760 crosvm: remove balloon stats request timeout
It was done to avoid deadlock when stats are requested before guest is
up. Implement a stub BalloonStats::NotReady replier until host is up so
that timeout is no longer necessary.

BUG=b:232289535
TEST=few tast crostini/arc tests

Change-Id: I6731b4ee9eaecdd65aebdd3f530f0932b0660c85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652887
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
2022-05-19 23:34:28 +00:00
Anton Romanov
0124707336 Revert "crosvm: remove balloon stats request timeout"
This reverts commit 716b698659.

Reason for revert: this is wrong in multithreaded mode

Original change's description:
> crosvm: remove balloon stats request timeout
>
> It was done to avoid deadlock when stats are requested before guest is
> up. Implement a stub BalloonStats::NotReady replier until host is up so
> that timeout is no longer necessary.
>
> BUG=b:232289535
> TEST=few tast crostini/arc tests
>
> Change-Id: Ieb6888487ea5b10664b76d8f94330564e7a3c726
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3647161
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Auto-Submit: Anton Romanov <romanton@google.com>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Anton Romanov <romanton@google.com>

Bug: b:232289535
Change-Id: I11faa967d6030ad4a0c292069b0678260757fda8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3651672
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-05-17 19:23:48 +00:00
Anton Romanov
716b698659 crosvm: remove balloon stats request timeout
It was done to avoid deadlock when stats are requested before guest is
up. Implement a stub BalloonStats::NotReady replier until host is up so
that timeout is no longer necessary.

BUG=b:232289535
TEST=few tast crostini/arc tests

Change-Id: Ieb6888487ea5b10664b76d8f94330564e7a3c726
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3647161
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-05-17 17:45:21 +00:00
Xiong Zhang
7245ebd353 pcie: hotplug in interrupt for mutli devices
When multi pcie endpoint devices are connected to one virtual pcie
root port as pcie multi function device, virtual pcie root port couldn't
inject hotplug in interrupt for each added pcie device. Only one hotplug
in interrupt is needed for all the added pcie devices.

So this commit adds a hp_interupt field into VfioCommandRequest, only
the last added pcie device sets hp_interrupt to true and requests virtual
pcie root port to inject hotplug in interrupt. Ohter added pcie devices
just create and configure vfio-pci device.

BUG=b:185084350
TEST=Check TBT dock's hotplug in function, TBT dock has multi pcie
devices.

Change-Id: I5a68ec38af9a32de9d4233b48e0aa3681e5a3ba3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3604290
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-06 20:33:15 +00:00
Grzegorz Jaszczyk
6b8680bc15 vm_control: minor style improvements for powerbtn command
Minor style improvement - no functional changes.

BUG=None
TEST=Make sure that "crosvm powerbtn /run/<>/crosvm.sock" works as
expected.

Change-Id: Ide843707d69c25c9e0473bc8e55db8c4a6da7553
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3616883
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-01 20:35:34 +00:00
Grzegorz Jaszczyk
ae70c7f3e9 acpi: add support for generating fixed sleep button event from cmd line
Add support for injecting an ACPI sleep button event using the command
line. Upon receiving crosvm sleep command, emulate vPM1 accordingly and
trigger vSCI to the guest if ACPI fixed sleep button event is enabled.

Additionally do not mask the ACPI sleep button event in FADT flags for
the guest anymore. Quoting ACPI specification regarding the sleep button
flag: "If the system does not have a sleep button, this value would be
“1” and no sleep button device would be present".

BUG=b:194391015
TEST=Boot the VM, issue "crosvm sleepbtn /run/vm/vm.<hash>/crosvm.sock",
check guest /sys/firmware/acpi/interrupts/ff_slp_btn counter and if vSCI
was injected. With some additional changes (e.g. acpid on the guest)
suspend guest by issuing sleepbtn command from the host.

Change-Id: Ie50a3a781ba4fbfa04da75186fb5549919a5bd68
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3602867
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
2022-05-01 20:29:35 +00:00
David LeGare
740c824fe8 Update to gdbstub 0.6.1
Update the GDB stub implementation to the 0.6 version of the gdbstub
crate API, attempting to preserve the current behavior as much as
possible. Hardware breakpoints and single stepping still work, but some
existing issues with software breakpoints are still present.

BUG=None
TEST=Manual

Cq-Depend: chromium:3578400
Change-Id: I522242a1a2055ecdf47b2010a615dc9e0136ebd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578025
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: David LeGare <legare@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-13 12:52:24 +00:00
Daniel Verkamp
fa0ffe7e81 base: accept AsRawDescriptor in PollContext/EpollContext/mmap
This lets us remove the wrap_descriptor() calls.

A few other places around the tree need to be updated to use Descriptor
instead of RawFd to match the new API.

BUG=None
TEST=tools/presubmit

Change-Id: Ie290f082b50bcf6ae8f77ce6a8b7615fad1be480
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3572770
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-04-11 20:27:06 +00:00
Vikram Auradkar
0953c58edb upstream a few file from dev/pci
The files include
- coiommu.rs
- msix.rs
- pci_configuration.rs
- pci_root.rs
- pci_bridge.rs
- pvpanic.rs
- stub.rs

Rest of the changes in the patch are supporting changes to build
and test.

Test: presubmit
Bug: b:213149278

Change-Id: Ic8fbcda4ad95370689b232c1656e782ee33425e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3541336
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-04-04 21:49:33 +00:00
Xiong Zhang
1b6e011dab ACPI: Add register gpe notify event interface
Device want to get notification when a specific gpe happens, this commit
add register_gpe_notify_dev(gpe_num, dev) interface into PmResource trait,
so that others could register (gpe_num, dev) into acpi, then they
could get notification at specific gpe trigger.

BUG=b:185084350
TEST=Verify TBT pcie hotplug function in ManaTEE, virtual pcie root port
must get gpe notification during this process

Change-Id: I56eb90361a6b96be364d35c4b6a5ec598a50757e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3539566
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-24 23:41:05 +00:00
Daniel Verkamp
4440db2370 vm_control: refactor VmMemoryRequest
Many of the subtypes of VmMemoryRequest share similar or exactly
identical code, but it is difficult to tell how they differ and what
each variant does. Reorganize the various memory registration requests
into a single RegisterMemory variant with orthogonal source and
destination structures to unify the shared functionality into a single
implementation.

BUG=None
TEST=tools/presubmit
TEST=Boot Crostini on trogdor
TEST=Boot Crostini on hatch

Change-Id: I059ce40b90812067e5ec882320ea7c8b6a3cc0fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3470539
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-23 22:41:22 +00:00
Xiong Zhang
5631839e90 pcie: Implement added GpeNotify() trait
When specific GPE event happens, some devices want to get notification.
For example, virtual pcie root port wants to get notification when
acpi hotplug GPE occurs. So virtual pcie root port implements this trait.

When virtual pcie root port gets this hotplug GPE notification, it will
inject a PME into CrOS, CrOS PME handler will wakeup virtual pcie root
port and TBT DMA engine, and forbit them to enter into suspend again
during hotplug process.

Once hotplug process is finished, virtual pcie root port and TBT DMA
engine could be allowed to suspend again.

BUG=b:185084350
TEST=Verify TBT pcie hotplug function in ManaTEE

Change-Id: I6c984e4f81713ad34383f1fb4ea2a5776ac2fccf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3539565
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-23 00:48:38 +00:00
Noah Gold
c286772db8 base: upstream Tube cross platform support.
Upstreams support for Tubes on Windows, splitting Tube into platform
specific files. This contains several critical enhancements:

* POSIX Tubes support multi producer multi consumer configurations, but
  Windows has remained strictly SPSC for each direction. Windows cannot
  support MPMC, and that configuration is not really something we want
  either. To address that, this CL introduces directional Tubes. A
  SendTube is clonable, and a RecvTube is not, which gives us MPSC.

* This CL also fixes multiple interface conflicts that have developed
  between Linux & Windows:
    + send wasn't async on the Linux AsyncTube.
    + send data wasn't passed as owned on the Linux AsyncTube.
    + Adds the 'static constraint for AsyncTube::send on POSIX. This is an
      requirement on Windows.
    + Event::read_timeout doesn't need to take &mut self, and it wasn't
      downstream. This CL switches to &self.

* Adds the missing notifier.rs file in base.

Note that this CL does not attempt to remove balloon's usage of
Tube::try_clone. That's a somewhat involved issue that should be tackled in
its own CL.

Test: tested downstream on Windows & Linux bots, upstream on Linux bots.

Bug: b:221484449

Change-Id: I288dbc1d1e42f8ce08258cdaaf85100ca93721ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3536897
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-03-22 19:00:54 +00:00
Dennis Kempin
ef516189db Refactoring: Move common/base into base
Executes the script in https://crrev.com/c/3530502

BUG=b:223206469
TEST=presubmit

Change-Id: Ibeffdc8de0b2270f070e60bb2de8d9fdc78a2a6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3530503
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-03-17 00:01:27 +00:00
Peter Fang
3fbf6c21fd acpi: support GPE injection in command line
Support injecting GPE using "gpe x" in the command line.

BUG=b:199383670
TEST=boot Linux kernel and inject GPE via command line

Change-Id: I512a1f3973c5da2ef06b17d5ac7c7981261f2514
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350494
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:22 +00:00
Peter Fang
eb16dd5118 acpi: support vGPE
- Add vGPE registers to ACPIPMResource and inject vSCI when a GPE is
  enabled and its event is received.
- Add a new interface, gpe_evt(), to trait PmResource.
- Always use vGPE, regardless of FADT forwarding.
- Always advertise support for 256 GPEs [1] to reduce code complexity.

[1] "Up to 256 GPEx_STS bits and matching GPEx_EN bits can be
    implemented." 5.6.1, ACPI Spec Version 6.4

BUG=b:199383670
TEST=boot Linux kernel and inspect /sys/firmware/acpi/interrupts/

Change-Id: I97687326e9313c26b84dfacade5c8741719e7841
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350493
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:21 +00:00
Peter Fang
6ca0323c87 acpi: support fixed power button event in command line
Support injecting an ACPI fixed power button event using "powerbtn" in
the command line.

BUG=b:199383670
TEST=boot Linux kernel and trigger a power button event

Change-Id: I5ed57f533fa3d91043491fd1f0695223a139fc7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350492
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:20 +00:00
Peter Fang
072c103be6 acpi: support fixed power button in vPM1
- Add a new trait, PmResource, for PM-related public interfaces.
- Use SCI_INT in FADT as vSCI if FADT is forwarded.
- Inject vSCI if ACPI fixed power button is enabled and a power button
  event is received.
- Disable MPTable generation if FADT is forwarded [1].

[1] MPTable generation in mptable.rs makes certain assumptions about
    SCI which is incompatible with FADT forwarding. MADT takes
    precedence over MPTable in the Linux kernel so hopefully things
    should work correctly.

BUG=b:199383670
TEST=boot Linux kernel and shut down

Change-Id: Icc93c3e7492e44b3a5badc5e75373c472c9b9791
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350491
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:19 +00:00
Daniel Verkamp
578e7cce45 base: remove wildcard and export specific sys_util symbols
As a step toward creating a well-defined base API distinct from
sys_util, remove the wildcard `pub use sys_util::*` and individuall
export just the types, functions, and macros that are intended to be a
part of the public base API.

The only functional change is that the net namespace is flattened into
the top-level base namespace, since it inconsistent with the rest of the
API. (sys_util is not affected and still exports mod net, but base does
not.)

BUG=None
TEST=tools/presubmit
TEST=emerge-hatch crosvm
TEST=emerge-trogdor crosvm

Change-Id: I4028d3489cb3816ec9b8d609b3957db8825eb63d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3500062
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-09 20:50:40 +00:00
Anton Romanov
bed40ad547 crosvm: migrate to Rust 2021 edition
BUG=none
TEST=cq

Change-Id: I0059c970879b78bfd40b6ce58b10debcf154b50f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508322
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-03-09 01:16:03 +00:00
Haiwei Li
e2dffbfd1c devices: virtio: iommu: implement the vfio-device hotplug and unplug
When a vfio pci device is hot-plugged in, its vfio container should be
passed to the virtio-iommu worker for later dynamic mapping/unmapping
requests.

BUG=b:185084350
TEST=Boot a guest, hotplug in and out a vfio-pci
device repeatedly

Change-Id: Ia2a9c9ef4a3ee6399d90aa17c6656acb52647663
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3476650
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-05 00:24:15 +00:00
Haiwei Li
dbba029d13 devices: virtio: iommu: add socket between main process and virtio-iommu
A tube channel is needed for the communication between main process and
virtio-iommu worker thread, e.g. passing a vfio container file
descriptor of a hot-pluggable device to the virtio-iommu backend which
is in charge of the mapping/unmapping for the endpoint.

BUG=b:185084350
TEST=Boot a guest with no error

Change-Id: Ib5061e795227040ca400bc9a92df84a27cd26438
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3301703
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-05 00:24:13 +00:00
David Stevens
b5aea72eb7 balloon: add failable balloon adjustment
Add a flag to the adjust command that allows the command to fail. When
this flag is set, a reply is sent with the balloon size at the end of
adjustment.

The flag also changes the semantics of inflation somewhat.  By default,
the balloon driver will indefinitely retry if it fails to allocate pages
during inflation. When the flag is set, the device reacts to puff
failure notifications on the event queue by setting the target num_pages
to the current balloon size, to abort and fail the inflation attempt.

BUG=b:213962590
TEST=manual testing with crrev.com/c/3394436
TEST=check ARCVM balloon still works

Change-Id: Idd606b90550c544ce5bea085f62ac35979679d71
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3394442
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-03-02 01:07:00 +00:00
Vikram Auradkar
ae5118f5c7 Enable windows tests for a few crates
Run tests for sys_util_core, poll_token_derive and balloon_control on
windows.

Using dotfiles to disable/serialize test runs of a subset of crates does
not work well with third party crates as it forces us to commit the dot
file to the crate.

The patch modifies and uses the script that runs linux tests.
This patch also allows us to
- build/test child crate even if parent crate has disabled build/test.
- avoid building crosvm if it is not explicitly specified.

RIP short lived .windows_build_test_skip. You allowed us to run noop
kokoro tests.

Test: py .\tools\impl\test_runner.py --arch x86_64
Bug: b:215610772
Change-Id: Icc6d04ffd7c0c33d4f60aeac16fc7d23881c387d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3459809
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-02-18 03:18:58 +00:00
Anton Romanov
cb3cabe3ba Upgrade rust toolchain version to 1.58.1
Pre 1.58.1 have CVE-2022-21658
Cros toolchain got upgraded to 1.58.1

BUG=None
TEST=cq

Change-Id: I2ce5a08b40bcc4895c4f2ecef83efd4162d67494
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3435385
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-02-04 02:20:36 +00:00
David Stevens
0f924dd693 balloon_control: expose rust API for balloon
Add a crate containing an API for controlling the balloon. This is done
by reusing the API between the control socket and the balloon device.

BUG=b:213962590
TEST=compiles

Change-Id: I5d89d5ebee55162d28ba45ca2c49b7083561b916
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3394440
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-01-28 03:52:35 +00:00
Vikram Auradkar
0108238474 Upstream windows build/test script
The patch also adds files to skip building and testing crates on
windows. When we run
```
tools/windows/build_test.py --skip_file_name .windows_build_test_skip
```

the build/test succeeds without actually doing anything as build/test
for all crates is skipped by creating '.windows_build_test_skip'.

Bug: 213170957
Test: Ran script on downstream repo
Change-Id: Iebd2cea463ee722be4feaed88229e1fb5e9fd6c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3417918
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-01-28 00:55:08 +00:00
Andrew Walbran
3cd9360fac Disable virtio balloon device for protected VMs.
It is not compatible with pKVM and leads to RCU stalls on the host due
to the virtio_balloon thread getting stuck.

BUG=b:215517095

Change-Id: Ibd1c9db53bfa001e07ba6399ff50e9073476017d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3412776
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2022-01-27 11:23:47 +00:00
Xiong Zhang
c78e72b7cf main: Add hotplug vfio device commmand through control socket
Through control socket, user could request crosvm to hotplug a
vfio pci device.
Hotplug in vfio pci device:
    crosvm vfio add host_pci_device_sysfs_path control_socket_path
Hotplug out vfio pci device:
    crosvm vfio remove host_pci_device_sysfs_path control_socket_path

BUG=b:185084350
TEST=Boot a guest and hotplug vfio pci device repeatedly

Change-Id: Id66e05ae3da8eb85da49407d69fe1efe7e39fe85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955582
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-01-21 20:48:25 +00:00
Chuanxiao Dong
c41ee08e99 crosvm: Extend VmMemoryRequest to support read_only map
Extend with read_only support so that the user can create a
read-only map for some read-only memory region, like read-only
memory backed MMIO bar.

BUG=None
TEST=Boot a VM

Change-Id: Ia6c1fd365808991f02298f7bbfaac0be8c801f8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3292929
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-01-21 07:11:43 +00:00
Xiong Zhang
4fbc554e60 Vfio-pci: Release irq_num at pci device remove
Device gets irq_num from system_allocator when device is added, this
irq_num should return to system_allocator when device is hotplug removed.

this commit adds a ReleseOneIrq interface into VmIrqRequest, it release
one gsi into system_allocator. So vfio-pci device could call it at device
close function.

For msi and msix interrupt vectors, they have irq tube already and could
call ReleaseOneIrq easily.
For legacy INTx, the gsi for vfio-pci's INTx is gotten from host, and this
gsi maybe share with other device, so the commit doesn't release this gsi
at vfio-pci device's remove, otherwise the gsi shared device will be broken.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio pci device repeatedly

Change-Id: Ibcca226b4b5b2092b5bc94bef8219eea82979086
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955580
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-01-06 23:32:54 +00:00
Xiong Zhang
3897cd0a2c devices:vfio-pci: Handle vfio pci device bar reallocation
Vfio pci device's bar are mapped into ept and iommu page table for
hardware acceleration, when vfio pci device is hotplug in the guest,
guest kernel will reallocate the bar, so the old bar address should
be deleted from ept and iommu, and the new bar address should be
added.

BUG=b:185084350
TEST=Boot a vm and hotplug add a device

Change-Id: Icc489917f4c241180bbef412a17917b34fafe7e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955571
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-19 22:10:09 +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
c42ef90be1 vm_control: convert to ThisError and sort
BUG=b:197143586
TEST=cargo check

Change-Id: Ibf99cd24cc0c246fa1e70f3c91b45bc1716adf41
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105430
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-10-06 21:38:32 +00:00
Udam Saini
38fedb73e5 Revert "vm_memory: Add from_desciptor() in MemoryMappingBuilder"
If we need descriptor for things that aren't file or other shared_memory objects, we can create a separate descriptor change, but it shouldn't be the default.

This reverts commit 533c5c8258.

Reason for revert: this causes conflicts with other platforms.

Original change's description:
> vm_memory: Add from_desciptor() in MemoryMappingBuilder
>
> MemoryMappingBuilder had `from_file()` and `from_shared_memory`, which
> are almost the same. So, this commit adds `from_descriptor()` to replace
> both of the two.
>
> BUG=b:194137301
> TEST=build
>
> Change-Id: Ia13f5e8e0f95a5c32e47dc9b3be13b7a7fa510bf
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3159881
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>

Bug: b:194137301
Change-Id: Ie203ee3eb3dcddd41c5e55b6980dc6292eb24f85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3183183
Auto-Submit: Udam Saini <udam@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Udam Saini <udam@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-09-27 16:36:24 +00:00
Keiichi Watanabe
533c5c8258 vm_memory: Add from_desciptor() in MemoryMappingBuilder
MemoryMappingBuilder had `from_file()` and `from_shared_memory`, which
are almost the same. So, this commit adds `from_descriptor()` to replace
both of the two.

BUG=b:194137301
TEST=build

Change-Id: Ia13f5e8e0f95a5c32e47dc9b3be13b7a7fa510bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3159881
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-09-22 04:37:44 +00:00
Charles William Dick
4745f03ce0 virtio_balloon shared and unevictable stats
This CL adds support for parsing stats introduced by:
https://crrev.com/c/3115084

BUG=b:198468047
TEST=candy crush runs

Change-Id: I8e258ebf7f2b7dd7a3019f40397c59514e7b18bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3168561
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Charles William Dick <cwd@google.com>
2021-09-22 01:06:43 +00:00
Daniel Verkamp
166d1ddfbe crosvm: fix needless_borrow clippy warning
Tree-wide cleanup of new clippy warning in Rust 1.54 that warns about
needless borrows:

  error: this expression borrows a reference (`&...`) that is
  immediately dereferenced by the compiler

https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

BUG=b:197251702
TEST=bin/clippy # with rust-toolchain = 1.54.0

Change-Id: Ib702ec524d4623d264a00ec11dbc2150c411a67b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108321
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-25 23:02:23 +00:00
Joel Galenson
06392aabd4 Migrate to gdbstub 0.5.0.
BUG=b:191784608
TEST=Build and run atest in Android tree

Cq-Depend: chromium:3073700
Change-Id: I5fcfa166caf8c5a5f759a8f62ef78a293db95f1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3071900
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-08-13 18:30:47 +00:00
Suleiman Souhlal
2ac78b9ea0 Add "make_rt" command.
This is used to finally make a "delay-rt" VM's RT VCPUs RT.

BUG=b:142777321
TEST="grep policy /proc/<pid of rt vcpu>/sched" to make sure RT vcpu
    isn't RT until "make_rt".

Change-Id: I73177f8adadf3d1099c2b09871ee9d5feab82587
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2703225
Auto-Submit: Suleiman Souhlal <suleiman@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Suleiman Souhlal <suleiman@chromium.org>
2021-08-11 11:39:31 +00:00
Charles William Dick
5404501966 crosvm fix stale balloon stats
Stale balloon stats results can be returned from a stats request for the
following reasons:
* The initial stats buffer from the guest is posted to the
  balloon_host_tube without a request.
* Balloon stats requests can fail because the balloon device isn't
  completely set up yet; writing a stats request to the tube without
  reading the response.
* Balloon stats requests can time out, returning an error. When the
  balloon stats are eventually computed, they will be queued to the tube
  without a read to consume them.

Possibly other reasons too.

This CL fixes this by adding an id to the balloon stats request. The id
is then returned with the computed stats. When consuming stats results
from the balloon_host_tube, we check that the ID is the one we expect,
if not, we keep reading from the tube until we do.

BUG=b:189282316
TEST=tast run dut multivm.Lifecycle.arc_host

Change-Id: I08e50196a45383b30c9e510b3bacbe32888aef80
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3056310
Auto-Submit: Charles William Dick <cwd@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Charles William Dick <cwd@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Hikaru Nishida <hikalium@chromium.org>
2021-08-06 15:39:15 +00:00
Hikaru Nishida
a0e381b0d8 Change balloon_stats output format to JSON
This CL changes the output format of `crosvm balloon_stats` command to
JSON to ease parsing the result.

BUG=b:181267848
TEST=built and checked the output of crosvm balloon_stats

Change-Id: I4af40237109efdd02b5b70375ef8aa706cf5de55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2914247
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Hikaru Nishida <hikalium@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Charles William Dick <cwd@google.com>
2021-06-15 17:29:30 +00:00
Daniel Verkamp
f1439d444b devices: add "usb" feature for emulated xHCI
Add a default-enabled "usb" feature to allow compiling out the emulated
USB controller and host device provider when not needed (e.g. for
crosvm-direct).

This reduces the crosvm-direct binary size by about 400 KiB.

BUG=b:173824333
TEST=cargo build --no-default-features
TEST=cargo build # ensure xhci controller is added

Change-Id: I1fc0eeb09c647854e5df57cd2fe7e92140256853
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2913136
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-24 21:37:22 +00:00
Daniel Verkamp
2940980d2e linux: generalize kick_all_vcpus to send any VcpuControl message
Previously, kick_all_vcpus() would only accept VmControl::RunState
messages; extend it to accept any VmControl message type instead.
This required adding the Clone trait to a few types.

BUG=b:174705596
TEST=./test_all

Change-Id: I3c8c42ee8a96ff151fa8f01ab067931bdff2b7b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2718281
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-05-14 05:24:47 +00:00
Daniel Verkamp
7b17f50df9 devices: usb: claim interfaces on device creation
This initializes the claimed_interfaces list at startup (before the
first Set Configuration request).  It also makes it possible to catch
initialization errors earlier in the process of adding a device, before
it is added to the emulated USB hub.

BUG=b:180238956
BUG=chromium:1030778
TEST=Share USB device with Crostini

Change-Id: I6f27ec9b7ff6cda2ff23cadd77611f8ce1cfc89e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2811859
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-04-22 17:25:22 +00:00