Commit graph

1583 commits

Author SHA1 Message Date
Alexandre Courbot
d8842cf3aa virtio: vhost: user: handler: make sys module follow style guidelines
Export the platform module under the `platform` name as requested on
https://google.github.io/crosvm/contributing/style_guide_platform_specific_code.html#platform-specific-symbols

BUG=None
TEST=cargo build

Change-Id: Ic4fa198a39d9435879e3bccf3e2fc80378c5737e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3729248
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-29 13:23:06 +00:00
Zihan Chen
0423074861 fs: Fix compiler warnings for feature chromeos
Compiler warnings that only occur when compiled with feature chromeos are fixed.

Fixed=b:235772995
TEST=none

Change-Id: Ie1f120798d0812e7e54984292ccccdac2477a030
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3731294
Commit-Queue: Zihan Chen <zihanchen@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-06-29 07:44:09 +00:00
Richard
efde16f4d2 virtio: Enable build and tests for some virtio mods
Still need to enable:
 * balloon (try_clone not implemented)
 * console (Need to enable Serial)
 * snd (Unix code not conditionally compiled out)
 * gpu (Waiting for graphics team to upstream)
 * vhost-user block and handler

The vhost mod is also being built now, but the vhost devices that don't
build on Windows have been disabled.

BUG=b:237011316
TEST=ran "./tools/run_tests --target=host --arch=win64 --verbose"

Change-Id: I3d06a9d49b4bdae14dea47fcfa030834b55925ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723797
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-28 00:46:27 +00:00
Alexandre Courbot
4f902ffc9e ffmpeg: specify supported resolution range for input formats
This is required so the guest can know which resolutions are supported
for encoded formats.

BUG=b:169295147
TEST=ffplay from Linux guest can start streaming.

Change-Id: I6f86108efbc8971f3ee4b9ec494cec16ebce323d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716017
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-28 00:45:55 +00:00
David Stevens
8b9fc10192 vm_control: use Protection in mapping requests
Switch VmMemoryRequest and FsMappingRequest to use base::Protection to
express permissions, in preparation for unifying the APIs.

BUG=b:201745804
TEST=boot ARCVM and crostini

Change-Id: Id001abbd2dde19aa14fcf1643f25abafdd66a2e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716337
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-27 00:51:20 +00:00
Pattara Teerapong
5cf9a8fb87 devices: virtio: snd: Support num_{output,input}_devices
Add support to create multiple PCM devices in virtio-snd
in addition to multiple streams support. Android will
use different PCM devices for different use cases.

Change num_{output,input}_streams to number of streams
per device.

Changes:
- Add num_{output, input}_devices support in ChromeOS's backend
- Update num_{output, input}_streams in ChromeOS's backend
- Update help message

BUG=b:236924546
TEST=unit test for Parameters parsing
TEST=`aplay -l` with different number of output devices/streams
TEST=`arecord -l` with different number of input devices/streams

Change-Id: I29a3ecc6002ce669c5f771ef490f10419848380e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3722007
Commit-Queue: Pattara Teerapong <pteerapong@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-24 16:04:19 +00:00
Alexandre Courbot
8297d745c6 devices: virtio: console: use ReadNotifier trait for polling
AsRawDescriptor is a very generic trait and some of the types we want to
use as input sources already implement it for other purposes.
ReadNotifier makes the purpose of the returned descriptor obvious (wait
for some data), so use it instead.

BUG=b:228912920
TEST=console device works in both regular and vhost-user modes.

Change-Id: I68a4ce05be449e07ea71e7cb472e8cda00e9d84d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671059
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-24 03:19:46 +00:00
Alexandre Courbot
947754f011 devices: virtio: console: add async console device shared with vhost-user
Move the async runner of the vhost-user console device into its own
module and implement a regular VirtioDevice on top of it. This makes
both the virtio and vhost-user console devices use the same
ConsoleDevice struct and runner code, and also removes the input reader
thread from our virtio implementation.

The Windows support cannot use async and thus still needs the older
console device, so keep it around for now even though it is not used on
Linux.

BUG=b:228912920
TEST=virtio console device is working (with input) on Linux.
TEST=vhost-user console device is working (with input) on Linux.
TEST=VVU console device is working (with input) on Linux.

Change-Id: I0a8dfe6c507ef9b765d8d1cdf9870cdcd128a9aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600172
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-24 01:56:17 +00:00
Junichi Uekawa
6af7ff8540 crosvm: Pass down CpuidResult instead.
So that a copy becomes a straightforward copy.

We were copy-pasting eax ebx ecx edx many times here.

BUG=None
TEST=build

Change-Id: Ibdabdd0da3876159bda3d29aa2a3927b9a3f40ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3717927
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-23 22:17:13 +00:00
Vaibhav Nagarnaik
ab004ddc01 irqchip: Upstream tests
Also remove `dead_code` annotation from `apic.rs` since the consumers
have been added.

BUG=b:213149158
TEST=Ran `cargo test -p devices irqchip -- --nocapture`

Change-Id: Ifda216e23f52ce05b5fee7e80a0751cb3524cf1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3722189
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-23 21:43:11 +00:00
Richard
ff3a722691 devices: Upstream virtio console Windows implementation
This CL also changes the Console::new constructor to only contains
variables in its parameters that it needs.

BUG=b:213149162
TEST=built and presubmits

Change-Id: Iab2a7e7b90cc3f203b8d9ae72320a0c2c50d81f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671594
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Richard Zhang <rizhang@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 20:57:43 +00:00
Tinghao Zhang
b6ef09ecc5 devices: pci: don't reserve bridge window for hot added bridges
We do not need to reserve bridge window for hot added bridges
because guest will do that for us. This chunk of bridge window is
also reserved by pcie root port, so no extra MMIO allocation is
needed. So we config zeros sized window here for hot added bridges.

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

Change-Id: I7e64b7596e1b5c060cf628a488e2399ae9c257fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3709794
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 17:52:57 +00:00
Tinghao Zhang
4d854e80b4 devices: pci: support hotplugged pci bus to be removed from tree
When pcie switch get removed from the system, we need to remove
their pci buses. This patch adds a new bool field in PciBus
structure to mark it as a hotplug bus and add support to remove
a pci bus from a pci bus tree. Also some other helper functions
is added for hotplug out usage.

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

Change-Id: I71064127345424bf050d993f60f9d766a299de8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3709793
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 17:44:21 +00:00
Tinghao Zhang
0e1faf9898 devices: pcie: make pcie root port use PciePort
Since we've had a common code base PciePort for all pcie ports, pcie
root port should also use this code base. This patch refactored pcie
root port to let it use this code base.

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

Change-Id: I9e1d3f3ebe0a0d89a947771306f4a819e106d30c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3692431
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-23 17:31:45 +00:00
Tinghao Zhang
61052012a4 devices: pcie: add pcie upstream and downstream port
To support pcie switch, we need to add both pcie upstream and
downstream port. This patch adds a new file pcie_switch.rs and add
basic implementation for pcie upstream and downstream port.

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

Change-Id: I7cc40d4fd0f017e06c5a0e8b0e3b68a8df9ee185
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508737
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 17:31:43 +00:00
Lepton Wu
1973802bea crosvm: Add a flag to disable INTx for virtio devices.
Sometimes we got buggy interrupt entries in ACPI table which
could confuse linux kernel. Add a new flag to disable it so
virtio devices can skip this part of initialization since they
should all support MSI-X.

BUG=b:236206320
TEST=manual - Run crostini on volteer-manatee

Change-Id: I98764b7cd31a2e68ddcd78d8175442f90ad8b164
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3719139
Commit-Queue: Lepton Wu <lepton@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-23 00:59:52 +00:00
Vikram Auradkar
32cabe0cd4 devices: enable tests
BUG=b:213149155
TEST=presubmit

Change-Id: Iff1a721dddfaed3e2728222a75348745be9ef05a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3710851
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 00:26:06 +00:00
Daniel Verkamp
959a05e7cc devices: virtio-tpm: pass base_features to constructor
Allow the device_helpers code to evaluate base_features() with the value
of protected_vm from the configuration to match the pattern used with
other devices.

BUG=b:227283268
TEST=emerge-hatch crosvm # board with chromeos and tpm features enabled

Change-Id: I15b73bbb32d684c1f29130929ec25c4dc9644967
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3717184
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Yi Chou <yich@google.com>
2022-06-22 15:20:13 +00:00
Noah Gold
f54f7ed040 devices: fix double init of logging on blk for Windows.
BUG=235867298
TEST=tested downstream

Change-Id: I81ff30c9c953b8f2674e1fd8f258a90aad92282a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3712543
Commit-Queue: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-22 01:05:50 +00:00
Daniel Verkamp
19fc097eb8 crosvm: replace lazy_static with once_cell
We depend on both lazy_static and once_cell, which do basically the same
thing.

The once_cell crate has a few advantages:
- once_cell is on track to be included into libstd.
  (https://github.com/rust-lang/rust/issues/74465)
- once_cell doesn't require macro magic.

Replace the uses of lazy_static with their once_cell equivalents so we
don't need to pull in both crates.

BUG=b:236191006
TEST=tools/presubmit --all
TEST=tools/run_tests --target=host --arch=win64 --build-only
TEST=cargo test --features=plugin

Change-Id: I7cabcd837ef4878e8e8ae635bb4f235a58e4cae3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707624
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-21 23:40:55 +00:00
Vaibhav Nagarnaik
24b9db5095 irqchip: Add WhpxSplitIrqChip implementation
Implement `WhpxSplitIrqChip` for `whpx` (Hyper-V) which has a split IRQ
chip architecture. Add dependencies for the root `whpx` feature on the
`devices/whpx` feature set.

BUG=b:213149158
TEST=Compiled on windows.

Change-Id: I3b0aec441b5abdff3f0266a9467380b0cdc4fdee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3717187
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-21 21:31:21 +00:00
Daniel Verkamp
927488df91 devices: tsc: pass cpuid as a function pointer
Rather than having a global CPUIDS variable that is used by all tests
for the TSC CPUID code, we can pass a function pointer to the
tsc_frequency_cpuid() function to retrieve a specified CPUID value. For
normal use, we provide a host_cpuid_count function that uses the normal
__cpuid_count intrinsic as before. For the tests, we provide a fake
CPUID function that returns the desired test values.

This removes the potential for problems when running multiple tests in
parallel (which was hypothetical, since we only had one test so far, but
worth fixing).

BUG=b:234508273
TEST=cargo test -p devices tsc

Change-Id: Ic963b21f09f8e8d7665386ad134ae5e242b3051d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707623
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-21 21:25:28 +00:00
Daniel Verkamp
d42d2004a1 devices: tsc: move logs to debug level
Don't log the TSC calibration results for every core at the default info
log level, since that can be quite noisy on machines with many CPUs.

The logs can be re-enabled using the `--log-level` option:

  crosvm --log-level=devices::tsc=debug run ...

BUG=b:234508273
TEST=crosvm run doesn't print tsc logs by default

Change-Id: I5051e22740b6b2136d35936c60dee776abd1d00d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707388
Reviewed-by: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-21 21:24:57 +00:00
Daniel Almeida
8062587362 devices: video: decoder: Derive Clone for Capability
In preparation for the upcoming VAAPI backend, derive Clone for Capability.
This is so a Decoder can own a Capability and merely clone it in the
DecoderBackend::get_capabilities call, reducing the number of calls into
the libva driver.

BUG=b:214478588
TEST=None

Change-Id: Ide3d410e0e0a89e774400ea466cac5875ebc8dc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3422777
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-21 16:10:18 +00:00
Junichi Uekawa
ff246f4317 crosvm: Add a better error message.
When resources are overlapping we probably want to know what is
overlapping.

BUG=b:236574949
TEST=boot

Change-Id: I4f99f742bda91945f7fe6e94d60bc8adbfe4326f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3715074
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-21 05:33:52 +00:00
Vaibhav Nagarnaik
0aa44acd7d direct: Fix irq registration for "direct" feature
Create an `IrqEventSource` for each instance of IRQ registration with
the `direct` feature.

This fixes a compilation issue with the `direct` feature.

TEST=Compiled with `cargo build --features=direct`

Change-Id: I691b156f84bc6795c887d5203aad7d15aaad22e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3715270
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-06-20 21:21:45 +00:00
Yi Chou
3f532cd2f6 Remove the useless Mutex in virtio-tpm
BUG=b:227283268
TEST=Build OK.

Change-Id: Ic0f82c3bd09614db569e7bed529e8f41b64e1717
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708380
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Leo Lai <cylai@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Yi Chou <yich@google.com>
2022-06-20 03:41:36 +00:00
Yi Chou
f8dd84e080 Add base_features into virtio tpm device
We need base features to prevent the "virtio: device uses modern
interface but does not have VIRTIO_F_VERSION_1" error in the kernel
driver.

BUG=b:227283268
TEST=Build OK.
TEST=vmc start --software-tpm termina
TEST=ls /dev/tpm0

Change-Id: Icf3c288f2acc39ec1e8e23250a9d0cd6b8f84eb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696295
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Leo Lai <cylai@google.com>
Commit-Queue: Yi Chou <yich@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2022-06-20 03:41:35 +00:00
Yi Chou
12ce514c0f Add VtpmProxy as a new TpmBackend
This CL will introduce a new TpmBackend called VTpmProxy.
This proxy will bridge the VM tpm device and the vtpm daemon on
ChromeOS.

BUG=b:227283268
TEST=Build OK.

Change-Id: Ibfbfdddbaca2af1d066920bb62918d88b0943d59
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696292
Commit-Queue: Yi Chou <yich@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Leo Lai <cylai@google.com>
2022-06-20 03:41:31 +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
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
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
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
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
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
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
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
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
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
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
Keiichi Watanabe
77ca3e34e6 devices: vvu-proxy: Support reconnecting when a sibling exits
This change will allow the guest to start a new VVU device backend
after an old VVU device backend process exited due to sibling
disconnection.

More specifically, this CL will allow the vvu-proxy to support scenarios
like follows:
1. A device backend starts in the guest and a sibling VM connects to
the socket.
2. The sibling VM shuts down. Then, the device backend process exists in
the guest. And, the vvu-proxy's state is changed from `Running` to
`Activated`.
3. Return to 1.

Note that we don't support more complicated reconnection scenario such
as:
* reconnection after sibling's unexpected crash
* restart after device backend's unexpected crash

To support the reconnection feature, the vvu-proxy device needs to clean
its status when a sibling disconnected. Specifically, it needs to
* reset virtqueues' state,
* unregister memory regions that it registered via VmMemoryRequest, and
* update the device state from the worker thread.

BUG=b:216407443
TEST=run on workstation; sibling could reconnect after the first
instance exits.

Change-Id: I4c01e6069484ff74a0d643edd6a3b3231fb5c2d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3602361
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-13 09:19:37 +00:00