Commit graph

3963 commits

Author SHA1 Message Date
Alexandre Courbot
4a2f1c8cb9 crosvm: linux: device_helpers: pass balloon mode in device creation function
Pass the correct type to the function instead of a boolean that we will
convert.

BUG=None
TEST=cargo build

Change-Id: Ic825e9444847cb38318bd854bcbdf9aefbe83c4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708384
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-18 01:00:26 +00:00
Daniel Verkamp
1dbe52fac4 vm_control: clarify that USB attach only uses dev_path
The bus/address and vendor/product IDs are unused internally; only the
usbdevfs device path matters. Update the internal API parameters and
documentation to match.

The crosvm_control `crosvm_client_usb_attach()` function must keep the
extra parameters to maintain API compatibility, but its documentation is
updated to note that they are unused.

BUG=None
TEST=Attach USB device to Crostini on trogdor

Change-Id: I7086f61a420be1dbf3dd1877fa86a5e82c0c5c77
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708640
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-17 23:18:24 +00:00
Daniel Verkamp
7afb3be9ca hypervisor: whpx: fix Arc::as_ptr usage
Arc::as_ptr() is only available as an associated function.

Fixes compile error:

  error[E0599]: no method named `as_ptr` found for struct
  `Arc<bindings::WHV_RUN_VP_EXIT_CONTEXT>` in the current scope

BUG=b:213151419
TEST=tools/run_tests --target=host --arch=win64 --build-only

Change-Id: Icc6753e4109b54ca507bb91bc89abd80fae098b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707626
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-06-17 22:41:32 +00:00
Daniel Verkamp
bc3204c738 hypervisor: enable x86_64 functions for whpx
These are currently guarded by a feature flag check that was only
enabled for haxm.

BUG=b:213151419
TEST=tools/run_tests --target=host --arch=win64 --build-only

Change-Id: Id40a29ffd63e378ce1583e56ca0f23914705b6fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707625
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-17 22:41:31 +00:00
Daniel Verkamp
77abcb0d0a arch: add VcpuInit data to provide initial values
This will be used to pass the initial register values for each vcpu.
Each architecture can define its own variant of the initial vcpu state.

BUG=b:234155022
TEST=tools/presubmit --all

Change-Id: I696a5ecda202c1ff0681f0b89b89b9eec11e27e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3673615
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-17 20:50:51 +00:00
Daniel Verkamp
299675d957 kernel_loader: replace test_elf.bin
Check in the source to generate the test binary, and make it a minimal
x86-64 ELF binary that can actually work inside crosvm. The new version
uses the COM1 serial port to print a hello message.

This provides a proper test for the ELF loader, including a binary that
is linked with the appropriate physical address fields in its program
headers.

The resulting binary is checked in rather than generated by tbe build
system since we want a consistent file that can be verified against
known good constants in the tests.

BUG=b:234155022
TEST=cargo test -p kernel_loader

Change-Id: I772b4d7e1fcb2b420acd454dc40764943bf975b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3673610
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-17 19:55:58 +00:00
Vaibhav Nagarnaik
0207256ccc irqchip: Add userspace irqchip support
This irqchip is currently used with Haxm which doesn't implement a local
APIC.

BUG=b:213149158
TEST=Compiled.

Change-Id: I3088ea5cad68451230dc3d5f8b649d54e83b938b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3701442
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-17 18:44:21 +00:00
Vaibhav Nagarnaik
b8bfdb496f irqchip: Add IrqEventSource for each event
This allows irq processing thread to log statistics and metrics and
track them using the source of the device. To be upstreamed later.

Introduce `PCI_VENDOR_ID_CROSVM` which identifies devices created by
crosvm. And introduce `CrosvmDeviceId` which adds a unique device ID for
each type of crosvm device.

BUG=b:213149158
BUG=b:213152505
TEST=Compiled.

Change-Id: Ica1374d8a2d8fd627c9397553bb7fb62baeaff7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3687418
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-17 18:44:20 +00:00
Anton Romanov
cde05ba3a1 Fix deprecation warning
Change-Id: I614deae1149a8193a4a0121042d1c8c14abaeaed
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3711611
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Anton Romanov <romanton@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-17 18:02:52 +00:00
Yuanchu Xie
4071d1ef5e examples: use rwdisk instead of rwroot
rwroot automatically adds root=/dev/vd[a-z], but the example image
actually uses /dev/vda5. This leads to confusion when two root= kernel
command line arguments are passed in and only one of them works.

Therefore we use rwdisk instead which doesn't add the kernel argument.

BUG=b:236198584
TEST=mdbook builds, examples build and run

Change-Id: I9bfc05445b1e2aef197a43ee647d7c784d50dad7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708365
Commit-Queue: Yuanchu Xie <yuanchu@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-17 17:43:41 +00:00
David Stevens
a4a46df15e x86_64: fix e820 computation
Exclude pci mmio region below 4gb from the e820 table. This is a
followup to CL:3696671.

BUG=None
TEST=arc.Boot.vm

Change-Id: I07c2b9a9e2e4e27682c4b60406625b019eea195f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708390
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-17 09:15:19 +00:00
David Stevens
89479b41db crosvm/linux: fix direct compilation error
Fix a compilation error in the --features=direct build caused by
CL:3696671.

BUG=None
TEST=cargo build --no-default-features --features=direct

Change-Id: Idb90d4712064b007672589db65d93b0168508a8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708388
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-17 06:55:00 +00:00
Keiichi Watanabe
2dcbb98677 x86_64: Fix build errors with direct feature
Make `cargo test --feauture=direct` pass by fixing build dependencies
and skipping a broken test case.

BUG=b:220292205
TEST=cargo build --features=direct in x86_64

Change-Id: I599ad5bc7ebb2fa91f6ff64291fb15ea129f8d05
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708381
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-17 06:21:18 +00:00
Alexandre Courbot
c553d1c283 seccomp: define naming rules for policy files
We are going to use separate policy files per device for the following scenarios:

1) Regular in-VMM virtio device,
2) Virtio device over vhost-user,
3) Virtio device over Vvu.

Each of these scenarios require slightly different policies as a jailed
device process needs to allow not only the system calls necessary for
the device to function, but also those required by the virtio transport
in use.

This CL adds a README.md file to the seccomp directory that details the
naming and policy inclusion rules, and updates the serial, xhci and
coiommu policies to follow the naming scheme.

Vhost-user and VVU policy files will be added along with support for
jailing devices when they are in use.

BUG=b:217480043
TEST=serial device works with `crosvm run`.

Change-Id: I6d454aa6e05d00691fe3346e822ed1fc7b24aed8
Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706490
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-17 04:35:09 +00:00
Alexandre Courbot
172dfd31aa crosvm/linux: stop using Config in device_helpers
The device and jail creation helpers should be reusable in other
contexts than `crosvm run` - e.g. they would be helpful to run a list of
sandboxed vhost-user devices without a VMM. However the `Config`
structure currently represents an entire VM config, which makes these
helpers unusable outside of `crosvm run`, and also expose individual
devices to much more configuration data than they need.

Fix this by only passing the needed configuration data from the `Config`
struct, which for most devices consists of the protection type and jail
configuration.

BUG=b:217480043
TEST=cargo build

Change-Id: If1f6dcb0d6d82a4e73d25a45b367da2364642e6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3546582
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-17 04:35:08 +00:00
Vikram Auradkar
db6ea0adaf devices: cleanup
- a few symbols renamed from fd to descriptor
- comment updates

BUG=b:213149155
TEST=presubmit

Change-Id: I1721c451e3695c50faa5fa416846ca7c317c08e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707620
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-06-16 23:59:31 +00:00
Frederick Mayle
e0b3fe3845 base: Delete unused rand crate
BUG=b:228881485
TEST=cargo build && cargo check --tests

Change-Id: I492d564872873953fa30b1b15ccc8e62f3c5bc23
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3710853
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-16 23:46:15 +00:00
Tinghao Zhang
ff2390c018 devices: pcie: modify PcieHostRootPort to PcieHostPort
Pcie upstream/downstream port will also have their related host port,
and their functionality should be similar with pcie host root port.
So I refactored PcieHostRootPort to PcieHostPort here, so that
pcie upstream/downstream port could use them later.

BUG=b:199986018
TEST=./tools/presubmit

Change-Id: I34d46f82c3b3adcfd7b5eb178cda29e902b3eb1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3692430
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-16 22:40:51 +00:00
Tinghao Zhang
c96e46c6a9 devices: pcie: add pcie port structure
Since all pcie ports (root port, upstream port, downstream port)
have similiar pci config space and handling logic, we could have
a common code base for them to use for code simplicity. This
patch adds the code base PciePort structure that could be used
later for both pcie root port and pcie upstream/downstream port.

BUG=b:199986018
TEST=./tools/presubmit

Change-Id: I23cfaf561432ed2cb977d0d2a020fc05370bb4b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3692429
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-16 22:40:50 +00:00
Tinghao Zhang
9b7e350656 devices: pci: introduce pci device hierarchy
To add support for pcie switch, we need to make crosvm support pci
device tree. This patch introduces a new structure PciBus which
stores topology information of a pci bus using a tree-like structure,
so that we can handle bridge window/MMIO allocation properly before
boot up. That is, we have to allocate device MMIO based on their
pre-order in the device tree, otherwise some pci bridge's bridge
window would intersect and guest won't boot. This PciBus structure
is stored in PciRoot later, make it possible for us to modify pci
topology during runtime.

BUG=b:199986018
TEST=run crosvm to see if pci device model has any issues

Change-Id: Ieb677cb7787650804051c43355ba27ce7926819a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3503103
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-16 22:40:48 +00:00
Tinghao Zhang
7b336e8570 devices: pcie: pcie_bridge: refactor configure_bridge_window()
To support pcie switch, we need a correct way to calculate pci
bridge window. This patch is refactoring configure_bridge_window()
for preparation.

This patch does 3 things:
1. The original code does not calculate bridge window correctly.
For the following bar_ranges, the old version would fail:
[[0xd0400000, 0x1000, false], [0xd0000000, 0x100000, false],
[0xd0100000, 0x1000, false]], [0xd0200000, 0x200000, false]]
This patch fixes this bug.

2. We need to round bridge window base down to 1MB aligned, round
window size up to 1MB aligned.

3. Since bridge window are also bar ranges, we need to return
the configured bridge window so that parent bridge can use it.

BUG=b:199986018
TEST=./tools/presubmit

Change-Id: Iff26fdd7e500671688897652ac16aff792882707
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3503102
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-16 22:40:47 +00:00
Vikram Auradkar
13313d403a tracing: Add noop tracing
BUG=b:213154559
TEST=presubmit
Change-Id: Idfe23544c8381e664d913c4a80742f4e25a30006

Change-Id: I2bb0b59098ae183c45e92fcf15e1bcfe834df204
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707622
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-06-16 21:13:55 +00:00
Daniel Verkamp
a059bff152 cmdline: fix naming of --software-tpm argument
This accidentally got renamed to just --tpm in the argh refactor.

BUG=None
TEST=cargo build --features=tpm && crosvm run --software-tpm ...

Change-Id: Ifa31faef9c566d3e3828a726138e635c41beb582
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707379
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-16 20:53:25 +00:00
Daniel Verkamp
fb641f67e4 resources: introduce AddressRange type
The AddressRange type is used for representing contiguous memory or I/O
address ranges, mostly equivalent to RangeInclusive<u64> but with the
added benefit of implementing Copy and not carrying an extra field used
only for iteration, which we don't need.

Using an inclusive range means we can represent the full address space
with no weird corner cases around the upper limit of the range (for
example, an AddressRange covering the full 64-bit space can be
represented as start: 0, end: u64::MAX).

AddressRange also replaces the previous MemRegion type, which was a
start/size pair.

This normalizes the interface of the resources crates to use
AddressRange rather than a start/size pair; more cleanups throughout the
tree may be possible, but this commit attempts to be somewhat smaller to
have a hope of being reviewable.

BUG=b:222769529
TEST=tools/presubmit --all
TEST=cargo test -p resources

Change-Id: I8c90bdc28456221b5107ef7e589233315ea739c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696671
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-16 20:29:26 +00:00
Dmitry Torokhov
321acac101 main: fix a typo in error message for vfio hotplug
Just a simple typo, nothing to see here.

BUG=None
TEST=CI

Change-Id: I73a7a60580bf0fdf1c62464dd40a5e54f82775f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708760
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-06-16 17:54:32 +00:00
Vaibhav Nagarnaik
ea7132e158 hypervisor: Add whpx support
Add `whpx` and `whpx_sys` modules that allow using Hyper-V platform as a
hypervisor on Windows. This has been tested running on Windows 19H1 and
above.

BUG=b:213151419
TEST=Compiled and tested on Windows.

Change-Id: If91ea6337876b85c9fdafe6ae4ad39fba40c4979
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3700983
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-16 01:05:36 +00:00
Alistair Delva
7110d673f2 crosvm: split up --no-legacy flag
Replace --no-legacy flag, which implied the removal of both i8042 and
rtc devices, with separate --no-i8042 and --no-rtc flags. The old
flag is still supported and implies the other two.

Because the original landing of this flag didn't protect it as an x86
specific option, this change just leaves that alone. But the new flags
are added as x86-only, because they are very x86 specific.

BUG=b:223443221
TEST=crosvm run --bios u-boot.rom --disk kernel

Change-Id: I4bbea2d0a38fdd3a5d69d12ca79fa360f0460358
Signed-off-by: Alistair Delva <adelva@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3510982
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-15 22:27:40 +00:00
Daniel Verkamp
441b6c71f0 vm_control: use open_file() for /proc/self/fd handling
Replace an open-coded version of base::open_file() to simplify the
vm_control code that opens USB devfs files, and improve the error
message when opening the device fails.

Also clean up unused ModifyUsbError variants while we're here.

BUG=b:213152502
TEST=Share USB device with Crostini on trogdor

Change-Id: I9d220487a77a0b83fbc1602f65455e6f384f4abe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706097
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-15 19:44:51 +00:00
Daniel Verkamp
6c84fa0e2d hypervisor: kvm: use shared host_phys_addr_bits function
The haxm hypervisor introduced a common helper function for this which
is identical to the KVM implementation, so use that everywhere to avoid
duplication.

BUG=None
TEST=cargo build

Change-Id: I346c721cc39b7efdd39f7bb34f78bca203e5a744
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3693051
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-06-15 19:40:51 +00:00
Allen Webb
b1475abeb0 base: Remove unused scoped_path.
scoped path is not exported and isn't used in crosvm, so delete it (and
move it to libchromeos-rs).

BUG=b:229016539
TEST=crosvm presubmit passes

Change-Id: I661c253db909874aec356538a687e99f3aa95e3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706096
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Allen Webb <allenwebb@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-06-15 17:23:57 +00:00
Alexandre Courbot
ca6562849b virtio: vhost: user: box all VhostUserBackend
Using generic code for the whole vhost-user processing loop results in
the same code being instantiated per-device, which turns out to be quite
a bit of code just to avoid a few virtual calls on the VhostUserBackend
interface. Let's make DeviceRequestHandler work with boxed
VhostUserBackend trait objects instead and avoid generating that much
code.

With this patch, the size of the crosvm binary obtained using

    $ cargo build --profile chromeos && strip target/chromeos/crosvm && ls -l target/chromeos/crosvm

Goes from 6577240 to 6249560 bytes, i.e. a reduction of 320KB, of ~5% of
the binary size.

BUG=b:217480043
TEST=vhost-user console device works.

Change-Id: I1cc48404b0eb72a38aeff48bf6731d858cae9349
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3702779
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-15 16:50:12 +00:00
Alexandre Courbot
98bdae6557 virtio: vhost: user: remove associated constants from VhostUserBackend
Replace the associated constants by methods. On top of the fact that the
number of queues and their maximum size might be instance-dependent,
this also prevented us from creating VhostUserBackend trait objects.

BUG=b:217480043
TEST=cargo build

Change-Id: I82a9f6d6e1397af467096458f8797d1089eed1fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3702778
Reviewed-by: Morg <morg@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-15 16:50:10 +00:00
Alexandre Courbot
cf7904a0a0 virtio: vhost: user: remove Sized constraint on VhostUserBackend trait
This constraint seems to be unneeded and prevents us from creating
VhostUserBackend trait objects.

BUG=b:217480043
TEST=cargo build

Change-Id: I79c1015d3a45902bc18cd22e52de78b2639354aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3702777
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-15 16:50:09 +00:00
Alexandre Courbot
2ac78210ef virtio: vhost: user: remove Error type parameter for VhostUserBackend
This type is never set to anything else than `anyhow::Error` and makes
it harder to work with VhostUserBackends as trait objects.

BUG=b:217480043
TEST=cargo build

Change-Id: Iae0be59f9b2bcec1e3fe9b22cbec2f9b99a59020
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3702776
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Morg <morg@chromium.org>
2022-06-15 16:50:08 +00:00
David Stevens
c12ea3dc0b crosvm: fix some direct only argument parsing
Fix a couple of compilation errors around direct-only argument parsing.
This is a followup to CL:3684144.

BUG=None
TEST=emerge-brya-manatee crosvm, boot brya-manatee w/new crosvm-direct

Change-Id: Iff45f5dd2240f183f303056e7855078fa891e058
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706477
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-15 16:49:02 +00:00
Alexandre Courbot
9b8ef9d65b crosvm: config: re-enable ffmpeg feature
The ffmpeg feature flag handling code has been inadvertedly removed by
http://crrev.com/c/3684144. Restore it.

BUG=b:169295147
BUG=b:179756087
TEST=`cargo build --features "video-decoder,ffmpeg"` and decode a video
     from a guest.

Change-Id: Id0d0f8c380353648e53602c6fa56ae9a0115cb8c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706480
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-15 16:46:57 +00:00
Masami Hiramatsu
eb83ee79b6 aarch64: Add Goldfish battery to aarch64 crosvm
Add Goldfish battery to aarch64 crosvm. The guest kernel will
see the goldfish battery node on the FDT.
This copies the seccomp policy for the battery from x86-64.

BUG=b:214124318
TEST=create VM with parameter "--battery" or "--battery=type=goldfish"
TEST=android-sh -c 'dumpsys battery'
TEST=tast run ${DUT} arc.PerfBoot.vm

Change-Id: I8212e760db5ffbc5d01442cfa7930baa5962ef6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3686713
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Masami Hiramatsu <mhiramat@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Masami Hiramatsu <mhiramat@google.com>
2022-06-15 02:46:45 +00:00
Federico 'Morg' Pareschi
44b5dccc2c devices: virtio: Use mmap for vvu QueueNotifier
Just like with the doorbell notification system, this patch makes use of
mmap for the queue notification mechanism. It also refactors some of the
code to make the QueueNotifier struct more standalone and changes the
signature of the notify() method.

BUG=b:231938067
TEST=built and run, verified vvu communication happens as expected

Change-Id: I2d51432a38ac0048a2bd3aae7c5c31d7ab45d65f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3686712
Auto-Submit: Morg <morg@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Morg <morg@chromium.org>
2022-06-15 00:56:50 +00:00
Peter Fang
cc4d016445 devices: vfio: fix mmap offset in VFIO_REGION_INFO_CAP_MSIX_MAPPABLE
vfio_region_info.offset refers to the region offset from start of device
fd while add_bar_mmap() expects the mmap offset from its BAR address.

When VFIO_REGION_INFO_CAP_MSIX_MAPPABLE is included, the entire BAR
region is considered mmap-able at first until add_bar_mmap_msix() carves
out the MSIX portions, so the offset should always be 0.

BUG=b:184904868
TEST=boot Linux kernel and verify MSIX-capable passthru devices work
properly

Fixes: 01527e39b3 ("add support for VFIO_REGION_INFO_CAP_MSIX_MAPPABLE")
Change-Id: Ib16c13b14199221ac247733feb05b3aa6fd4c73c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696656
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Xiong Y Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-15 00:01:33 +00:00
Daniel Verkamp
29ba40cec9 crosvm: fix copyright headers
Remove the accidental trailing comma to silence repo pre-upload checks.

BUG=None
TEST=repo upload

Change-Id: I819c7584640065aceafa53ef8bca38879b4a39f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3703394
Reviewed-by: Anton Romanov <romanton@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-14 23:56:51 +00:00
Devin Moore
617c6ba837 crosvm: Add gpu parameter for the PCI BAR size
Some devices may need to use smaller sizes. The default of 8GB (1 <<33)
won't work with 32-bit.

BUG=b:228880581
TEST= build and boot 32-bit Cuttlefish with smaller size

Change-Id: Ic170fa655b963188c34ecaf32b51cc0ddafb84ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3703159
Reviewed-by: Jason Macnak <natsu@google.com>
Commit-Queue: Devin Moore <devinmoore@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Devin Moore <devinmoore@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-14 20:22:39 +00:00
Takaya Saeki
69c8d8093d devices: vvu: fix incorrect VVU PCI feature bits initialization
At present the VVU PCI driver writes the feature bits it wants to
enable to the device feature bits first, and then reads the device
feature bits in the initialization sequence. However, the correct
sequence is reading the device feature bits first, and writing the
feature bits to enable to the driver feature bits next. This incorrect
initialization sequence causes warning messages when you run the VVU
driver.

Fix the driver so that it follows the correct feature bits
initialization sequence.

BUG=b:216752120
TEST=VVU block device works with no warning message.
TEST=presubmit --quick

Change-Id: I7f7536143ee2a037fd71aa216513ad732b407cc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3705077
Commit-Queue: Takaya Saeki <takayas@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-14 17:22:35 +00:00
soichiro
f51e3a3ce2 docs: book: add balloon device docs
BUG=b:235067563
TEST=mdbook build

Change-Id: Ibf65e96adef4cebdd4356b7de55820018622ca01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3697995
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-14 05:13:14 +00:00
Anton Romanov
7910b89eb3 crosvm: move run command to argh
Due to the way we allow arguments to be specified I was not able to
reuse Config structure for cmdline arguments. (eg we allow multiple ways
to specify same config)

There is still some usage of arguments mod that we need to cleanup
later.

Change-Id: Ia0c12d508d0a10d17f58944de71276e5984d69ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3684144
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-06-13 23:55:20 +00:00
Allen Webb
efdcf90a42 base: Minor Cargo.toml changes for ChromeOS support.
Add 'provided by ebuild' in necessary places to install crosvm's base
crate on ChromeOS as crosvm_base. Also fix dependency ordering and add a
missing version attribute.

BUG=b:229016539
TEST=FEATURES=test emerge-${BOARD} crosvm_base

Change-Id: Ie09e16819e7e27664b5897afd8c6a40e19cc87ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3703158
Auto-Submit: Allen Webb <allenwebb@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
2022-06-13 23:16:13 +00:00
Vikram Auradkar
3a2f600275 devices: Conditionally depend on unix only crates
BUG=b:213149155
TEST=presubmit

Change-Id: I89a1aaf3e171cbd6c1591ae510dd46424d6f8752
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3703221
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-06-13 23:08:52 +00:00
Vaibhav Nagarnaik
e88a40eb9e haxm: Switch from haxm/mod.rs to haxm.rs
Use the upstream style for adding module specific file in the crate
instead of adding a `mod.rs`.

TEST=compiled.

Change-Id: I2225f6615b68738cd3e1cdce68b4d011dfaab790
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3700982
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-13 22:35:36 +00:00
Vaibhav Nagarnaik
ed632b56a8 cpuid.rs: Fix Formatting
From the change https://crrev.com/c/3690369, some unexpected indentation
happened which rustfmt didn't/couldn't catch.

Fix the whitespacing.

Test: NA
Change-Id: Ic8bd80a9c72b8d57b9131ba7e37165dba934bc8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3703224
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-13 20:53:54 +00:00
Vaibhav Nagarnaik
f007f335a4 tsc: Refactor test imports
Use `cfg_if` to refactor test imports to provide test only definition
for `__cpuid_count`. Otherwise use the definition from
`std::arch::x86_64`.

BUG=b:234508273
TEST=Compiled.

Change-Id: I0d93f6a86522451c540af9d520bfdeffd4f8dbf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3701441
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-13 20:53:52 +00:00
Daniel Verkamp
cdbe5cb842 docs: book: add pmem device docs
BUG=b:235067568
TEST=mdbook build

Change-Id: I38d58a4ce3910ad382c1cf3e7bdc5a43f5b0b4ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3692420
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-13 20:06:44 +00:00