Commit graph

3295 commits

Author SHA1 Message Date
Vikram Auradkar
585337ceae Fix clippy error
Bug: b:223840386
Test: tools/clippy
Change-Id: I450e5c75150c186e4f3c82b84ed471d08a81c938
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3527438
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-03-16 00:06:41 +00:00
Vikram Auradkar
e6bc05ef81 scoped_event: Created macro to reduce duplicate code
ScopedEvent's implementation was the exact same in 3 different places.

Bug: b:215618500
Bug: b:223840386
Test: ran emulator
Change-Id: I835ef9c523936dd651652f344f4857515afb8bdd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3523746
Reviewed-by: Richard Zhang <rizhang@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-03-15 20:36:09 +00:00
Dennis Kempin
fd68b42b6d audio_streams: Add async interface to remove dependency on cros_async
The API allows audio_streams to be used by crosvm and libcras while
their implementations of cros_async may diverge in the future.

BUG=b:223624364
TEST=./tools/presubmit and emerge tests

Cq-Depend: chromium:3519246
Change-Id: I08b6bf12e02c211275c11f1886f23f71217e40b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3518657
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-03-15 17:29:21 +00:00
Vikram Auradkar
835badb57a Upstream win_sys_util
This is as is upstream of win_sys_util except following changes
1. Ignores flaky tests in syslog.rs and priority.rs - a todo is added.
2. Ignore this crate of unix tests/clippy.
3. Fix few doctest issues on windows.

The files are pulled from downstream repo at
  Commit-Id: 53e8dfa6ec26de3f2ea2b637a5bfef96703214f3
  Downstream-Change-Id: I5dd9e70566330b469fe245fc71451fb4dcd7e1ba

The cl should not affect unix binaries.
Bug: b:223840386
Test: Tested on windows by running
      1. cargo test --all-features
      2. cargo clippy
      3. cargo fmt

Change-Id: I454f2e03b6269f374d107b83c8223ce98b9e29bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3514125
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-03-14 20:39:11 +00:00
Vikram Auradkar
89c687919b Upstream win_util
Since this is a windows specific crate, we will skip building and
testing the crate on unix.

The files are pulled from downstream repo at
  Commit-Id: 53e8dfa6ec26de3f2ea2b637a5bfef96703214f3
    Downstream-Change-Id: I5dd9e70566330b469fe245fc71451fb4dcd7e1ba

The cl should not affect unix binaries.

Bug: b:213149154
Test: cargo test on windows

Change-Id: I1be598c119891a6c45b4f397463bcb0a8d89b65c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3515653
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-03-14 20:39:10 +00:00
Daniel Verkamp
052f7df430 x86_64: remove special-case mappings for direct
Now that we can handle file-backed mappings that overlap with guest
memory, we can remove the workarounds for coreboot regions when
compiling with --features=direct.

BUG=b:188011323
TEST=cargo test -p x86_64 --features=direct
TEST=Boot volteer-manatee and brya-manatee

Change-Id: I9ac2a25e1896c5ec61bd302882d4c99d8b36b0dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3498210
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-14 19:57:21 +00:00
Tomasz Nowicki
2968e1b6c5 irqchip: ioapic: Introduce 1:1 GSI mapping for direct IRQ forwarding
In order to emulate IOAPIC pins and still be able to inject IRQs
via KVM eventfd, SplitIrqChip driver allocates input and output eventfd
for each pin:
- the input eventfd listens for incoming events (e.g. physical IRQ
occurrence or userspace emulated IRQ). This gives chance to to emulate
pin states before handing over to KVM
- the output eventfd inject the actual virtual IRQ in KVM standard manner

Once the guest tries to configure a new IOAPIC pin, the output event GSI
number is allocated dynamically. So there is no chance to know GSI number
upfront to expose it via e.g. ACPI. This is the blocker for direct IRQ
forwarding where 1:1 mapping is inherent feature.

Allocate output eventfd vector and fill in with 1:1 GSI mapping upfront
only for direct configuration feature. Any potential guest IOAPIC pin
configuration request will used pre-allocated GSI number so that guest
will see proper IRQ number. No functional changes for the rest of the cases.

BUG=b:184871003
TEST=boot guest using crosvm --split-irqchip flag and check if IOAPIC
related IRQs are working

Change-Id: Ie1578a831ff21489e4e7dd9c7ec3f5384b4af16a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3494285
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Steven Richman <srichman@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-11 11:14:01 +00:00
Tomasz Nowicki
64f4355a4b linux: x86_64: Initialize direct-irq before irqchip finalize
In general irqchip finalizes setup and finalize_devices() should be called
once all devices have registered irq events and been added to the io_bus
and mmio_bus.

Split irqchip finilize_device() implementation in particular,
hands over requested irq events to IOAPIC in order to emulate pin state
and do proper forwarding when needed.

Move direct-irq registration before irqchip finalizes so that direct-irq
is taken into account. Note that direct-irq does work with kernel irqchip
implementation because its finalize_devices() is empty.

BUG=b:184871003
TEST=boot guest using crosvm --split-irqchip flag and check if IOAPIC
related IRQs are working

Change-Id: I78dbace08eee4a5bc91695fd8b8d41a84e58cde9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3494284
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Steven Richman <srichman@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-11 11:14:00 +00:00
Victor Hsieh
70f44d9672 fuse: Add FuseConfig builder API
fuse::worker::start_message_loop is not a scalable API, so deprecate it.

This paves the way to support multiple threads.

BUG=b:220386264
TEST=Modify a client in Android to use the API

Change-Id: I41e8d5267384311a7b03beb67f7774332863fbf7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3514617
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2022-03-10 20:17:31 +00:00
Anton Romanov
ee60fe491f crosvm: Change cargo resolver to 1 to fix issues with chromeos and b* builds
BUG=b:223855233,b:223821596
TEST=cq

Change-Id: I9cb84608478a215e6a6768fdc74d383f9334848a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3517908
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Oystein Eftevaag <oysteine@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-03-10 19:43:52 +00:00
Vikram Auradkar
4d88ee98d5 Upstream data_model
Test: cargo test
Bug: b:213147091

Change-Id: I9c73963e18591b8a9548e508f63bbb423f5aafa3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3515113
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-03-10 18:48:52 +00:00
Peter Fang
cd75771ea8 x86_64: acpi: always use virtual reset register
Always advertise support for ACPI reset register, regardless of FADT
forwarding. The current reset register points to the PCI reset register
(CF9), which is always virtualized.

The Linux x86 kernel prioritizes using the ACPI reset register in its
reboot flow.

BUG=b:199383670
TEST=boot Linux kernel and reboot

Change-Id: Ib644e1062eb6e040d16c0c8d7cec2a54a86b3918
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350495
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:23 +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
Peter Fang
8f833c1fca x86_64: acpi: always use vPM1 registers
Previously, when FADT is forwarded to the guest, "direct-pmio" is
usually used to give the guest full access to the physical PM1
registers.

Switch to using vPM1 registers always and overwrite the relevant FADT
fields.

Per spec, the I/O port addresses of PM1A_EVENT_BLK and PM1A_CONTROL_BLK
only need to be 32-bit aligned.

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

Change-Id: Id29df44000d6654615afefd0be6662e4fe96c86e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350490
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:18 +00:00
Peter Fang
80e6d5bf65 acpi: refactor PM1 virtualization
- Refactor read() and write() for ACPIPMResource to protect against PIO
  accesses across PM1 register boundaries, and properly support byte
  accesses.
- If compiled with the feature "direct", all writes to SLP_TYP are
  interpreted as S5 since _Sx is platform-specific.
- Remove Sleep Control and Status Registers since they are only used on
  HW-Reduced ACPI systems.

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

Change-Id: Iaf9fdf5a161eb6f5618235c3a66f8817258ce289
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350489
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:17 +00:00
Anton Romanov
90922be6d6 crosvm: Enable plugin feature in CI builds
BUG=none
TEST=cq

Change-Id: I201f5090c096912f61f2b461fc2f0be9621389a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3515213
Reviewed-by: Anton Romanov <romanton@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-10 01:00:39 +00:00
Anton Romanov
fb1df15477 crosvm: Fix running plugins integration tests
BUG=none
TEST=run plugins tests

Change-Id: I791249c611ff2e5b7a345981a5a7ebe957cef3d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3515212
Reviewed-by: Anton Romanov <romanton@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-10 01:00:38 +00:00
Daniel Verkamp
5586ff508c linux: punch holes in guest memory for file mappings
Rather than manually adding special handling for regions where we want
to put --file-backed-mapping mappings, we can just iterate over those
regions before constructing the GuestMemory object so that there will be
no conflicts/overlaps between RAM and file-backed mappings.

BUG=b:188011323
TEST=Boot volteer-manatee and brya-manatee

Change-Id: I986f33460fa45cd1f85d849810e1f6934cc73c0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3489809
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-09 20:53:38 +00:00
Daniel Verkamp
de4d729c39 linux: allow file-backed mappings outside of MMIO regions
Now that the address allocator returns different error types for overlap
(Error::ExistingAlloc) and allocation attempts outside the managed
region (Error::OutOfSpace), we can disallow file mappings that overlap
MMIO regions while still allowing mappings elsewhere (e.g. in the normal
guest RAM regions). The next commit will modify the GuestMemory setup so
that file mappings that overlap guest RAM will be handled correctly.

BUG=b:188011323
TEST=tools/presubmit

Change-Id: I0e9ad8d97d0cb2f0a2a8d74516582eefd230fe8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3498209
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-09 20:53:37 +00:00
Daniel Verkamp
808bb0f5ad resources: return overlapping Alloc in allocate_at
If AddressAllocator::allocate_at() fails, check if there is an existing
overlapping allocation and return it with Error::ExistingAlloc if so;
otherwise, return Error::OutOfSpace as before. This allows the caller to
distinguish between failure due to overlap and failure due to a range
that is not managed by the allocator at all.

BUG=b:188011323
TEST=cargo test -p resources

Change-Id: I1f6cde63a995dc461db221c509f4d0a1f0c7f186
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3498208
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-09 20:53:36 +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
Paramjit Oberoi
449dd6b709 Don't add ramoops parameters except addr and size
BUG=b:218891911
TEST=manual testing

Cq-Depend: chromium:3491214
Change-Id: If2b7e4856ac497f2c3b277ed02bd96c9e629aa2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3491603
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Paramjit Oberoi <psoberoi@google.com>
2022-03-09 18:34:50 +00:00
Abhishek Bhardwaj
4a3341ce48 crosvm: vvu: proxy: Handle sibling disconnect
This change fixes the Worker run function infinitely looping when the
sibling disconnects.

BUG=b:194136484
TEST=Test with sibling VM with Vhost master connecting to a device VM.

Change-Id: I7bce45dd50919d5aead6749932d33036c263f322
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3463214
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Auto-Submit: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-03-09 10:26:19 +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
Anton Romanov
6fd8926373 crosvm: pci: prefer to/from le_bytes instead of manual byte manipulation
Change-Id: I6f7d18662d546e6d76af349de0633f2c99f3e44d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508319
Reviewed-by: Anton Romanov <romanton@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-09 01:05:33 +00:00
Daniel Verkamp
d6a42bdf6c Remove duplicated add_vfio_device address parsing
The second block of OsStr and PciAddress parsing into host_addr was an
exact duplicate of code earlier in the function. Reuse the existing
host_addr variable instead of parsing it again.

BUG=None
TEST=tools/presubmit

Change-Id: I1cd65701a07636daa6e537d97abff808397d3181
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3488160
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-07 23:24:28 +00:00
Daniel Verkamp
906a38fac3 devices: pci: return Result from PciAddress::from_string
Add error checking so invalid user input does not get silently ignored
and converted into bogus addresses.

Also add a PciAddress::new() function that accepts numeric values and
checks their ranges as a helper for the string parsing function as well
as for general use in other cases.

BUG=None
TEST=cargo test -p devices pci_address

Change-Id: I1131716bfd99e1819e7630021048482c2397b137
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3475440
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-03-07 23:24:27 +00:00
Daniel Verkamp
ee12440953 disk: qcow: restore Read/Write/Seek impls
The standard I/O traits are used by a downstream tool [1], so we can't
remove them for now. However, this is not a perfect revert because of
the other qcow cleanup patches, so some minor changes were needed (the
Write impl's write_cb needs to seek itself now that the offset is passed
in as a parameter).

Also add some basic Read/Write/Seek unit tests to ensure these keep
working.

This partially reverts commit 7f400e70fb.

[1]: https://cs.android.com/android/platform/superproject/+/master:packages/modules/Virtualization/virtualizationservice/src/aidl.rs;l=460;drc=dcf1741a18a0e552a85038a0e14671a506e8729a

BUG=b:219595052
TEST=cargo test -p disk

Change-Id: I0bdd4aed4938acde10516f31dd517bb070b51d0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3503935
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-07 22:53:09 +00:00
Dennis Kempin
7f03a70790 Parallelize tools/fmt
cargo fmt will only format those files that are referenced by
crosvm. To really catch all files in our source tree, we need to
run rustfmt directly.

This will check files multiple times, since rustfmt will follow
included modules. But is still faster that cargo fmt.

To run these in parallel, this change adds some tools to common.py
for parallel execution of commands.

This reduces the fmt check time from ~9s to 1.5s.

I verified that we are actually catching all files now by adding a
newline to all .rs files in our sources tree. The formatter reverted
them all.

BUG=b:218559722
TEST=./tools/fmt

Change-Id: If721d837ebc9eee3ce28fa7f439ab0bcc0b993cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3474926
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-03-07 22:50:12 +00:00
Daniel Verkamp
f2df14802c kernel_loader: regenerate ELF bindings
BUG=b:218388029
TEST=tools/presubmit --quick

Change-Id: I6625b52691fc570e56005d4f59aeeea8d53e5eea
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3339808
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-07 21:52:26 +00:00
Daniel Verkamp
fde6c3bb39 devices: virtio: gpu: regenerate udmabuf bindings
BUG=b:218388029
TEST=tools/presubmit --quick

Change-Id: If52944dc97bd61e62a0ee2e18df3bc976b95813d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3339806
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-07 21:52:25 +00:00
Daniel Verkamp
90c1700c66 io_uring: regenerate bindgen bindings
The original io_uring bindings were hand edited to eliminate some of the
anonymous unions, so there are some changes in the helper functions.

BUG=b:218388029
TEST=tools/presubmit --quick

Change-Id: I8e049296020dd38ba7c97b096ca6cc346b0a20d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3339805
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-07 21:52:24 +00:00
Dennis Kempin
bd3044301e Fix clippy in devices/src/pci
Some changes made it through without clippy testing. Fixing these
now.

BUG=None
TEST=./tools/clippy

Change-Id: If369354042691181d5a251e5707b85672757330b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508311
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-07 21:09:23 +00:00
Victor Ding
7151e10103 Introduce PCI virtual configuration space
PCI virtual configuration space is a set of virtual registers similar to
PCI configuration space, but for the guest to configure the hypervisor.

One use case is to facilitate ACPI forwarding at API level.

BUG=b:194390621
TEST=builds

Change-Id: I7902d8f589d19426c8b81629722abbf5c68a905a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3344575
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Victor Ding <victording@chromium.org>
Auto-Submit: Victor Ding <victording@chromium.org>
2022-03-07 03:49:47 +00:00
Abhishek Bhardwaj
b619623968 crosvm: vvu: proxy: Move listener accept to Worker
This change fixes a bug in the VVU proxy device where the main thread
would block until a sibling connected to it. This may disrupt the device
from writing and reading bars from it as those operations happen on the
main thread. Instead, the socket accept logic is now moved to the
beginning of the worker thread and the main thread is unblocked.

BUG=b:194136484
TEST=Run device VM without --disable-sandbox.

Change-Id: I4e3344df20a80316316f2b586c52c8c1a88cc36d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3457900
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Auto-Submit: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-03-05 00:42:34 +00:00
Haiwei Li
87bc2fcb46 devices: virtio: iommu: add an option to create a virtio-iommu device
Add an option to allow creating a virtio-iommu device backend without
attached vfio device. This is for hot-pluggable devices whose DMAs are
restricted by the virtio-iommu backend.

BUG=b:185084350
TEST=Boot a guest with crosvm option "--virtio-iommu", a virtio-iommu
device can be seen in guest

Change-Id: I7799cb6ae3051f8ce2b6069a856480a9c9485fef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3301702
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:17 +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
09b7b8e92b devices: virtio: iommu: add hot-plugable bus pci ranges to virtio-iommu
Virtio-iommu device can generate viot using pci ranges. After adding a
vfio device, guest can attach this device to virtio-iommu.

BUG=b:185084350
TEST=Boot a guest with vfio device and 'iommu=viommu', another PCI range
node is generated in guest viot.

Change-Id: I9204d8bd341b6e544a62923164d5c8ce46fdd8bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3476649
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:14 +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
Daniel Verkamp
0ae13d221e Require memoffset version 0.6
Chrome OS does not currently package memoffset-0.6.5 (only 0.6.4), so
building within cros_sdk will fail to find the expected crate. We don't
need any API requirements past what is provided by 0.6, so just request
that. At the same time, upgrade the cros_asyncv2 memoffset from 0.5 to
0.6 so we don't need two separate versions. (The crosvm ebuild was not
requiring a 0.5 version, so this was technically a bug.)

BUG=None
TEST=cargo build
TEST=emerge-hatch crosvm

Change-Id: I2b6c778cdbf57977e6fffd73867e0c4818c44a61
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3502625
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vineeth Pillai <vineethrp@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-04 05:15:35 +00:00
Alexandre Courbot
8e0e121bb0 virtio: video: fix clippy warning
BUG=None
TEST=cargo build

Change-Id: I7a350f67efca113b3aba00972f63eac581704563
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3501057
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
2022-03-04 04:08:48 +00:00
Daniel Verkamp
8894542adf io_uring: simplify with helper functions
Add some wrappers to help tame the unruly bindgen anonymous union member
names.

BUG=b:218388029
TEST=cargo build

Change-Id: I4ca5bd9c4d0ae7f60a905a516e8cb5eab761213e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3445532
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-03 23:47:11 +00:00
Daniel Verkamp
a6f8814c7b tools/bindgen-all-the-things: add script to regenerate bindings
Add a framework for bindgen scripts.

This will be filled in when each binding is added in upcoming separate
commits.

BUG=b:218388029
TEST=None

Change-Id: I62363b49d92ceb5b54700589c2329daace7181b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3339804
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-03 23:47:03 +00:00
Zide Chen
344e2432d1 x86: handle KVM_SYSTEM_EVENT_S2IDLE request
When Crosvm receives a KVM_SYSTEM_EVENT_S2IDLE event, it means the
guest VM is entering s2idle suspend state, and it's requesting the
host to put the whole system in the same state.

If hypervisor sends the request on behalf of a privileged VM, Crosvm
can initiate s2idle suspend on the host since it's been granted with
system power management privileges.

BUG=b:199383670
TEST=trigger s2idle from ChromeOS guest

Change-Id: I589a7e1d93abb5ab971fd58de94ee75df48c3c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3414635
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmytro Maluka <dmaluka@google.com>
Commit-Queue: Allen Webb <allenwebb@google.com>
2022-03-03 22:30:45 +00:00
Keiichi Watanabe
3e297bb36b devices: vvu: Fix calculation of total net devices numbers
BUG=b:213531892
TEST=crosvm device net --vvu-tap-fd ADDR,FD

Change-Id: I47cdbfc816b01f520f7b957208de795ec8dbe2e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3490266
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-03-03 06:33:18 +00:00
Xiong Zhang
9a24be33e9 vfio-pci: Descend bars by size for nonroot device.
For nonroot vfio-pci device, its prefetchable bars will be allocated
in continuous region, its nonprefetchable bars will be allocated in
another continuous region. Without descending the bar's size, this
allocation waste some mmio.

For example, a vfio-pci device has two non prefetchable bars:
bar0's size is 1M, bar2's size is 8M.
without descending [bar0, bar2], it will allocate 16M mmio, 0~8M
for Bar0, 8~16M for Bar2, although bar0 need 1M only, it occupy 8M
to satisfy bar2's 8M alignment requirement.
With descending [bar2, bar0], it will allocate 9M mmio, 0~8M for
bar2, 8M ~ 9M for bar0.

BUG=b:185084350
TEST=check pcie rp's bridge window in brya-manatee.

Change-Id: I7d93e601f6a46cabe8896aaec065a9dba18c60fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3500060
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-02 23:47:45 +00:00
Xiong Zhang
edc7ad4091 pcie: Fix bridge window's mmio alignment
Bridge window's mmio alignment went wrong during our refactor, fix
it in this commit.

BUG=b:185084350
TEST=Check bridge window and pci device mmio setting in CrOS

Change-Id: Ia1a01d1740f943ec7aa36812defe3aabffcfcbde
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3498219
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-02 23:47:44 +00:00