Commit graph

2704 commits

Author SHA1 Message Date
Dennis Kempin
10e79005c3 tools: Update clippy and fmt to make use of workspace
We have not been running clippy on many crates before. This CL
does not contain any clippy fixes, but documents how many issues
each disabled clippy check and crate currently has.

Many of them should be easy to fix.

BUG=b:192425184
TEST=./tools/presubmit --quick

Change-Id: I9ea25bc9a24d405700027ca4e72fb2a50e376c9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3276668
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-11-11 23:52:43 +00:00
Daniel Verkamp
f20c1cd1e8 wl: update seccomp policies for SYNC_IOC_FILE_INFO on arm
Fixes https://crrev.com/c/3199298, which only added the new ioctl
argument to the seccomp syscall filters on x86.

BUG=b:169908659
TEST=tast.crostini.SecureCopyPaste.* on scarlet

Change-Id: Ifd44c7b403f862d5528d8cc3655f0cd2c71c6e13
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3276675
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
2021-11-11 19:31:37 +00:00
Dennis Kempin
c8313dc204 crosvm: Use local vmm_vhost when compiling for ebuild
This should fix the current uprev problem.

BUG=b:205997217
TEST=FEATURES=test emerge-amd64-generic crosvm

Change-Id: I0a0bb46fb004a7a057be9b2e4b13878038551e81
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3276714
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-11-11 19:08:32 +00:00
Chirantan Ekbote
f01d4b1f16 seccomp: Add unshare to fs device policy
Needed because of CL:3263932

BUG=none
TEST=vm.Fio

Change-Id: I50502476dd9591c114094cc43dda81f2c6e2c516
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3276112
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-11 13:38:11 +00:00
Jiyong Park
bc144baf0e Handle qcow image backed by a composite disk
This CL fixes a bug that was introduced by [1] where max_nesting_depth
is used to prevent unbounded nesting of qcow images.

When a qcow image is backed by a composite disk, the composite disk is
parsed twice: (1) once before the qcow header is created, and (2) once
again after the composite disk is written to the header and the header
is parsed. The max_nesting_depth was set correctly for (1), but was set
to 1 for (2). Since a composite disk inherently is nested,
max_nesting_depth drops to 0 and it causes an error.

This CL fixes the bug by respecting max_nesting_depth also for the case
(2).

Bug: N/A
Test: launch cuttlefish

[1] https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3146214

Change-Id: Ic2d30df6c76a0c1965e222960e0094fe847b1097
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267734
Auto-Submit: Jiyong Park <jiyong@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-11 11:08:48 +00:00
Chirantan Ekbote
4bfa59ad61 aarch64: Fix warnings
BUG=none
TEST=emerge-kukui crosvm

Change-Id: I6d4eb3655cad7b5f2dbfa6f3315482b50fe033f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3270098
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-11 05:29:02 +00:00
Tina Zhang
7458a3a19b devices: vfio: Fix a msix table and msix pba table overlapping issue
An error occured when passthrough some nvme to a guest based on vfio:

[ERROR:devices/src/pci/vfio_pci.rs:773] add_bar_mmap_msix failed:
		Out-of-space detected in MSIX Allocator

Althrough the issue may only happen to some devices whose msix table
overlaps with its msix pba table, as it was mentioned before[1], this
situation must be covered by some validation test. Otherwise, it will
block crosvm booting.

[1] https://patchwork.kernel.org/project/qemu-devel/patch/099db937-3fa3-465e-9a23-a900df9adb7c@default/

BUG=b:1971693450
TEST=passthrough a nvme with a msix table overlapping the msix pba table,
then boot Linux kernel and verify MSIX-capable passed-through devices
work properly.

Change-Id: I602dda95d4671682dc03478415f6a96d7c40ec6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3152434
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-11-10 23:21:11 +00:00
Christian Blichmann
e32b55670b virtio-fs: Unshare fs attributes to avoid locking
Calling `unshare(CLONE_FS)` from worker threads means we can freely
modify the current working directory and umask without having to guard
theses attributes with locks.

BUG=none
TEST=./tools/presubmit --quick

Change-Id: I29144b3d233b84e761c11a5e46efe541117e7f2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3263932
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Christian Blichmann <cblichmann@google.com>
Auto-Submit: Christian Blichmann <cblichmann@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 10:45:39 +00:00
Keiichi Watanabe
ef5b1e711b vmm_vhost: vhost_user: Split socket listener code into separate file
More SocketListener code to socket.rs so that we can easily add a new
file for a new VFIO backend. No behavior will be changed by this CL.

BUG=b:194137301
TEST=cargo test --all-features

Change-Id: I8d987f85a63ba666619882559e5cceddd91814bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3268268
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:18 +00:00
Keiichi Watanabe
63564d55cc vmm_vhost: vhost_user: Introduce Listener trait
Rename Listener struct to SocketListener and introduce Listener trait.
This is a preparation for adding VFIO backend for virtio-vhost-user.

BUG=b:194137301
TEST=cargo test --all-features --all-targets

Change-Id: Iea1e5b4378606b696c4022e3e2e6f4bbf80be55f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3268267
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:17 +00:00
Keiichi Watanabe
10d5bf1cd5 vmm_vhost: vhost_user: Disallow dead_code
BUG=b:204720423
TEST=cargo test --all-features

Change-Id: Ib413066612ca9ee6a88d356cb49dd8bbbc0fa017
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3268266
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:17 +00:00
Keiichi Watanabe
92d8d5f8a6 vmm_vhost: vhost_user: Implement DataInit for message structs
Implement DataInit for message structs and use `.as_slice()` when
sending them.
This change makes `trait Req` require `Send + Sync`. This is needed to
implement `DataInit` for `VhostUserMsgHeader<R> where `R: Req`.

BUG=b:204720423
TEST=cargo test --all-features

Change-Id: Icd32861b8d4fef16606a35b387c35271aebe061a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3268265
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:16 +00:00
Keiichi Watanabe
a939c0c77f vmm_vhost: vhost_user: Simplify send_iovec_all algorithm
BUG=b:204720423
TEST=cargo test --all-features

Change-Id: I554526fb39fb5f2aad14189d4825033290d1d6d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3268264
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:15 +00:00
Keiichi Watanabe
a205dc949a vmm_vhost: vhost_user: Remove redundant slice conversion
BUG=b:204720423
TEST=cargo test --all-features

Change-Id: I67c73412a22e52238b0378e5b35dfdb0c72aa68b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267923
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:14 +00:00
Keiichi Watanabe
1704332e1c vmm_vhost: Use thiserror and remain::sorted for Error enums
BUG=b:204720423
TEST=cargo test --all-features

Change-Id: Ic54eb2b625d0eb2f77c58356729cd6a68d5047c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267922
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:14 +00:00
Keiichi Watanabe
d89b31e8d8 vmm_vhost: Enable clippy::{bool_assert_comparison, needless_borrow}
Fix clippy::bool_assert_comparison and clippy::needless_borrow, which
were temporally added at crrev.com/c/3267912.

Most changes are trivial.
`test_should_reconnect` in vhost_user/mod.rs was deleted because the
test doesn't make much sense as a unit test, because it just copies and
pastes the logic of `Error::should_reconnect()`.

BUG=b:205511695, b:204720423
TEST=./tools/clippy
TEST=cargo test --all-features in third_party/vmm_vhost

Change-Id: I664b3aa7df054871d7e127b6dffd0315f9d4c48c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267918
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:13 +00:00
Keiichi Watanabe
d7b5f1da0a vmm_vhost: Remove OWNERS file
Remove vmm-vhost's OWNERS file because it became a part of the crosvm
repository now.

BUG=b:205511695
TEST=kokoro

Change-Id: Iba9f64e647d905a4bdd4580b0115bb79085c9a9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267921
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-10 08:42:12 +00:00
Keiichi Watanabe
3a6ec148d6 third_party/vmm_vhost: Add vmm_vhost code into /third_party/
Move rust-vmm/vhost code from chromiumos's third_party directory to
crosvm's one.

Note that we have crrev.com/c/3269863 for license files in Chrome OS
ebuild.

Changes:
* Copied vmm_vhost files at "7c95b4a2 rust-vmm/vhost: switch to upstream
tempfile", whose latest upstream commit is "488b3adc fix warning:
unaligned_references".
* Remove [patch.crates-io] section from its Cargo.toml.
* Add attributes to skip `clippy::bool_assert_comparison` and
`clippy::needless_borrow`, which will be fixed in following CLs.
* Update crosvm's Cargo.toml and tools/chromeos/setup_cargo

BUG=b:205511695
TEST=tools/chromeos/setup_cargo && cargo build

Change-Id: Icee201b39ff1d352df59469a6c8668fc7cb92ab9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267912
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-10 08:42:11 +00:00
Will Deacon
b975546c3f vm-memory: mlock2(MLOCK_ONFAULT) guest memory for protected VMs
By default, the memory of a protected VM is inaccessible to the host
and crosvm. Consequently, attempts to access guest memory are fatal and
must be avoided in order for the guest to run.

Mlock guest pages as they are faulted in for protected VMs, ensuring
that the host doesn't try to age or swap them out as a result of memory
pressure.

Bug: b:204298056
Test: cargo test on x86 and arm64
Cc: Quentin Perret <qperret@google.com>
Cc: Andrew Walbran <qwandor@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: I618ec1e8b1136a47a8b3ef563e45bc41d75ab517
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3257689
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-09 18:59:20 +00:00
Keiichi Watanabe
3230422d59 cargo: Remove *_stub from workspace member
libcras_stub and system_api_stub are empty replacements for libcras and
system_api respectively. so cargo is happy even if they're missing

BUG=none
TEST=cargo build with CL:3267568

Change-Id: I20ba2ca77a241e354a45816605282d06d26f895f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267907
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-08 18:02:32 +00:00
Junichi Uekawa
7225ebc077 crosvm: Sprinkle notes on API search.
It's not obvious it's possible to search API docs, it's one of the
things I would use the most often if it's reachable.

BUG=None
TEST=read it.

Change-Id: I29df6ae4df3eb667f17e22d0afc00aee80912187
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267906
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-08 07:21:20 +00:00
David Staessens
85fa9ce5f1 Revert "virtio: video: reject resources with more than one entry"
This reverts commit 4ceec18783.

Reason for revert: This breaks all ARCVM HW encoding

BUG=b:205488531
TEST=arc.VideoEncodeAccel.h264_192p_i420_vm

Original change's description:
> virtio: video: reject resources with more than one entry
>
> The crosvm video device cannot currently work with resources that have
> more than one memory/object entry. Enforce this rule at the command
> level.
>
> BUG=b:161774071
> BUG=b:169295147
> TEST=Android Youtube plays properly on Hatch.
>
> Cq-Depend: chromium:3247491
> Cq-Depend: chromium:3247492
> Change-Id: Ibfe2e420b4a77062cca940c5e97e7053aa4b76a7
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026345
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
> Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>

Bug: b:161774071
Bug: b:169295147
Change-Id: Ib24bd8098b37d696b74bc942cdb7c81719d1b8b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267727
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: David Staessens <dstaessens@chromium.org>
2021-11-08 03:57:27 +00:00
Daniel Verkamp
6b29858a34 linux.rs: replace Error enum with anyhow
Use the anyhow crate to provide ad-hoc errors with context. This removes
the large, manually-updated enum, which we never use programmatically
anyway (error messages are printed in human-readable form and otherwise
not matched against).

BUG=b:190433480
TEST=cargo build
TEST=./test_all

Change-Id: Ia7b90b33774d4031054b346d650861d3105044ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105436
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-05 23:06:09 +00:00
Xiong Zhang
2d8e1b09a5 Devices: Return bar reallocation info at bar written
Previous commit "devices: Add/Remove device mmio at config memory enable
/disable", it has an assumption that when driver update bar's location,
driver should disable bar's memory/io at first.

But some driver reallocate bar's address even with memory/io enabled,
this commit monitor bar's config write, if address is modified, it
return this  modification.

BUG=b:174705596
TEST=boot a vm, monitor resource reallocation and check function.

Change-Id: I9aa883192f5e2fec344d3e86c818c7a29287f49a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3184726
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-05 19:35:10 +00:00
Xiong Zhang
479efab2f5 devices: Don't return bar info if memory/io is disabled
get_bar_configuration() returnis bar's info, this ignores memory/io enable
bit. Usually driver disable memory/io first, then wrtie 0xFFFFFFFF to
probe bar's existence and size, finally write real address and enable
memory/io.

if get_bar_configuration is called after mmio/io disabled, current
it may return invalid info. In order to filter these invalid info,
this commit checks memory/io enable bit, only return info at memory/io
enabled.

BUG=b:174705996
TEST=carto test -p devices

Change-Id: Ib8bf1a7f7f959025117f319f8f6c5a9e5efea2e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3252779
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-05 19:35:09 +00:00
Christian Blichmann
7a976d3a8a virtio-fs: Apply syscall!() macro to syscall invocations
TESTED=./tools/presubmit --quick

Change-Id: I5238731b9785f315d0869ed85984cf87ed36ad73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3259940
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Christian Blichmann <cblichmann@google.com>
2021-11-05 09:22:30 +00:00
Christian Blichmann
6addda2203 Add override for container tool in dev_container script
This change allows to override the command line tool that is used to
start the dev container in the `tools/dev_container` script. The
Makefile for creating the dev container uses the `DOCKER` env var to
implement this, so this is used here as well.

Rationale: Googlers are advised to not install Docker
(go/dont-install-docker) and to use Podman instead.

If the `DOCKER` variable is unset, the script will try to use
Docker first and podman.

Change-Id: I33bc8e4af632fa982406e838e762572407ccdc22
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3259939
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Christian Blichmann <cblichmann@google.com>
2021-11-05 08:40:43 +00:00
David Staessens
528fcabc5d virtio: video: Allow config changes if encoding hasn't started yet.
When initializing the device for encoding the underlying encoder
session is immediately brought up, as this is required to determine
parameters such as the desired output buffer size. This causes further
configuration changes to be refused, even when the device isn't
encoding anything yet. This CL makes changes to allow configuration
changes by recreating the encoder sessions as long as no buffers have
been queued.

BUG=b:203608233
TEST=tast run DUT arc.VideoEncodeAccel.h264_192p_i420_vm

Change-Id: I7e9d8b41ea2497b5d86aaca7db7ed13af056f11d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3252185
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Staessens <dstaessens@chromium.org>
2021-11-05 00:32:33 +00:00
Colin Downs-Razouk
11bed5eef7 devices: re-add set_access_id to bus
We need the access id for some future changes that will be posted soon
for a userspace irqchip.

Each vcpu will have a clone of the Bus itself, not the Arc<Bus>, so that
they can each have their own access id.

This also adds a call to set_access_id to run_vcpu.

BUG=b:160610704
TEST=ran local presubmit, and ran test image

Change-Id: I4afb0ef9c234f25150ce2f89d6fb228ad5b88745
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3261627
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2021-11-04 17:55:18 +00:00
Alexandre Courbot
7f02059afc virtio: video: build backends separately from the codec device
The current way for building a codec device is to call the corresponding
constructor method of the backend we want to use. However doing this
forces us to pass the resource bridge to these constructors, introducing
dependencies from the backend to parts of the code that are not used
otherwise.

Switch the construction method to one constructor per backend, which
only takes the arguments relevant to the backend, and one device
constructor that takes the backend to use as parameter.

BUG=b:161774071
BUG=b:169295147
TEST=Android Youtube plays properly on Hatch.

Change-Id: I493f421e982a1d2ba8292a69bae575afeee17e4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026349
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-04 14:01:22 +00:00
Alexandre Courbot
8230abf39a virtio: video: compile out decoder or encoder if corresponding feature not selected
We have two separate features for video decoder and encoder, but
selecting any of them results in all the video code being included. Add
some #[cfg] statements to compile out the unneeded code if only one of
the features is selected.

BUG=b:161774071
TEST=`cargo build` passes without warning
TEST=`cargo build --features "video-decoder"` passes without warning
TEST=`cargo build --features "video-encoder"` passes without warning
TEST=`cargo build --features "video-decoder,video-encoder"` passes without warning

Change-Id: I3e5f2173695ee9dd5e8d26ace14374d426e570a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026347
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-04 14:01:20 +00:00
Alexandre Courbot
66ed8cfb41 virtio: video: make backends accept GuestResources as inputs
Make the backends accept our generic resource types as inputs instead of
expecting virtio objects. This makes the backends able to deal with any
kind of resource, the counterpart being that they must now check what
kind of resource they received. The VDA can only deal with virtio
objects and will reject other kinds of resources.

On top of making backends not limited to virtio objects, this is also
safer than passing FDs because it becomes clear when we are transferring
ownership of a resource, and when we need to clone them. Also since
resources carry information about their layout, the number of arguments
we need to pass to the backends is reduced.

BUG=b:161774071
BUG=b:169295147
TEST=arc.VideoDecodeAccel.h264_vm passes on hatch
TEST=arc.VideoEncodeAccel.h264_360p_i420_vm passes on hatch
TEST=GtsExoPlayerTestCases com.google.android.exoplayer.gts.DashTest
passes on hatch

Change-Id: I09dd81bac13a46fa908a4107a376fa7d59fb9759
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983096
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-04 14:01:17 +00:00
Alexandre Courbot
cf16363c4c virtio: video: introduce basis for proper resource management
Currently the video device only accepts virtio objects (as file
descriptors) for resources, and file descriptors are hard-coded a bit
all over the place to represent buffers and frames. This causes two issues:

1) Multiple buffers cannot currently be used to represent frames, i.e. 1
   frame is exactly one virtio object,
2) Resources that are not virtio objects, like guest memory, cannot
   be used at the moment.

This patch introduces more flexibility in the way resources are handled:
first, all the resource-related code, including their resolution using
the resource bridge, is consolidated into a new resource module. Then,
the command module does not arbitrarily decide that all resources are
virtio objects, and leaves that decision to the queues. Finally,
resources now have their enum type that can unfold into any of the
resource types we will support (currently only virtio objects). This
forces consumers of resources to check their type before using them.

Semantically, very little should change. The only noticeable side-effect
should be that we now call the resource bridge only once per input
buffer instead of once per decoder operation.

BUG=b:161774071
BUG=b:169295147
TEST=arc.VideoDecodeAccel.h264_vm passes on hatch
TEST=arc.VideoEncodeAccel.h264_360p_i420_vm passes on hatch

Change-Id: I93b203117b5c96e91d4f1b8007e95ec5c501ea5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983095
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-04 14:01:16 +00:00
Alexandre Courbot
4ceec18783 virtio: video: reject resources with more than one entry
The crosvm video device cannot currently work with resources that have
more than one memory/object entry. Enforce this rule at the command
level.

BUG=b:161774071
BUG=b:169295147
TEST=Android Youtube plays properly on Hatch.

Cq-Depend: chromium:3247491
Cq-Depend: chromium:3247492
Change-Id: Ibfe2e420b4a77062cca940c5e97e7053aa4b76a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026345
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-04 14:01:16 +00:00
David Stevens
5ebe30d0e5 wl: add support for host fences
Add support for guest fences backed by host sync_files. Rather than
adding a new fence type, fences are implemented as vfds that only
support hup. The host simply waits on the sync_file and sends the guest
a hup when the fence is signaled.

BUG=b:169908659
TEST=Revert ag/15543199, resize ArcCameraFpsTest

Change-Id: I8c79ec9f418b1d71150b5a19f500c5ac7a6c9b02
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3199298
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-04 01:24:37 +00:00
Xiong Zhang
e9020b1c83 devices: Add/Remove deviece mmio at config memory enable/disable
When device memory/io is disabled, its mmio/io range should be
removed from mmio_bus/io_bus.

When device memory/io is enabled, its mmio/io range should be
added into mmio_bus/io_bus.

BUG=b:174705596
TEST=Boot a vm, monitor device mmio/io enable/disable, then check
vm function.

Change-Id: Ic77565b9828599d574329bea76146cff597a94fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3252778
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-03 20:14:02 +00:00
Daniel Verkamp
ff31bcfb48 devices: bus: add BusDevice function to get ranges
When device's bar are reallocated, all the old resource ranges should be
deleted, the new resouce ranges shoud be added, this commit add the
interface to get device mmmio/io old/new ranges.

BUG=b:174705596
TEST=Boot a vm, monitor device bar reallocation and check function

Change-Id: I1000607d9f766ff8b445bf92f17969b094f3b2ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2718280
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-03 20:14:01 +00:00
Xiong Zhang
d982b8d9a3 devices: Introduce remove() for bus
When device's bar is reallocated, the old ranges will be deleted,
this commit add remove() function to delete one old range from
bus->devices.

BUG=b:174705596
TEST=Boot a vm, monitor Bar Reallocation then check function

Change-Id: Id0600ae1d7a3d04c7f05a90abcc8807b7f1020c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3184725
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-03 20:14:00 +00:00
Dennis Kempin
ccb9014afb Deprecate old dev tooling scripts
All of the developer tooling has moved to ./tools to make them
easier to discover.

BUG=None
TEST=None

Change-Id: I4daf6a0ca08c94a0c35ce8bc52f9d86e4cb15de9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3251781
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-11-02 22:23:03 +00:00
Daniel Verkamp
57e4f542a2 Reland "Devices: Allocate non pci bar mmio at top of HighMmio"
Original reason for revert: Causes crosvm to not start on AMD based devices b/204222491
Fixed by clamping the maximum physical address to 64 TiB, which is the
largest physical address supported by x86-64 Linux with only 4-level
page tables enabled.

In addition, the high MMIO region size calculation has been split into a
separate function, get_high_mmio_size(), and an off-by-one error in the
size calculation was fixed.

Original change's description:
> Devices: Allocate non pci bar mmio at top of HighMmio
>
> Some devices like virtio-pmem, intel host bridge need private mmio, these private
> mmio isn't exposed to Vm through pci bar, and crosvm use mmio allocation interface
> to allocate them, so guest OS pci bus driver couldn't detect them, and once guest
> OS reallocate pci mmio, these private mmmio could be assigned to pci device bar.
> then resource conflict happens.
>
> This patch allocates these non pci bar mmio at the top of HighMmio, since HighMmio
> is large enough and OS allocates pci mmio from low to high. So these non pci bar
> mmio won't conflict with pci bar.
>
> BUG=b:199442120
> BUG=b:185084350
> TEST=crosvm run --pmem-device xxxx
>
> Change-Id: I615d7901d595dd46ba6362f88b71d96baa9c4c8f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3184549
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>

This is a reland of https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3184549

BUG=b:199442120
BUG=b:185084350
TEST=Crostini starts on grunt (AMD device)
TEST=crosvm run --pmem-device rootfs -p 'root=/dev/pmem0' kernel

Change-Id: I7c93f7132dbfbc3f38ecbfa0504b59214a1eb6bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3251788
Reviewed-by: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-11-02 22:08:54 +00:00
Gurchetan Singh
3059851cd0 rutabaga_gfx: export rutabaga
This change adds FFI bindings to the Rutabaga Virtual Graphics
Interface (VGI).

BUG=b:173630595
TEST= compile
      cp rutabaga_gfx_ffi.so + rutabaga_gfx.so to sysroot
      ./rutabaga_test

Change-Id: Iba99b0ace9f1ad90b6c42d9075038dd9f05b9367
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3230331
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2021-11-02 15:53:02 +00:00
Junichi Uekawa
b933598310 crosvm: Add python3-pip dependency.
This is required for the following step.

Updated installation steps so that it is possible to follow the steps
and build.

BUG=chromium:1265286
TEST=./install-deps inside docker container running ubuntu.

Change-Id: Icd6b1c9c3c74c790aba2fd41050ebd2f3470e946
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3255185
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2021-11-01 23:58:39 +00:00
Keiichi Watanabe
e538834fe1 ci: kokoro: Run mdbook command
BUG=none
TEST=kokoro

Change-Id: I61f80da1c6d82979201aa1b3c11b60d9da6ba705
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3255195
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-01 19:26:51 +00:00
Keiichi Watanabe
1d0ef4d7a3 mdbook: Fix broken links detected by mdbook-linkcheck
Run mdbook-linkcheck locally and fix detected errors.
Note that we avoid running mdbook-linkcheck in CI, as its installation
takes ~1min.

BUG=none
TEST=run GitHub Action

Change-Id: I2bbd5f30486573454dc9ece86353296eca55be70
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3255194
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-01 19:07:01 +00:00
Keiichi Watanabe
73b68faf7f CONTRIBUTING: Add more instruction on use of mdbook command
BUG=none
TEST=check rendered results

Change-Id: I10532c45317f5189bd867850f36e7ae93b4abcc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3252187
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-01 15:32:26 +00:00
Marc Zyngier
17b1e02fb6 aarch64: Provide the maximum supported IPA size as the machine type
The value 0 passed to KVM_CREATE_VM has a special meaning for KVM/arm64.
It indicates that the VM is configured with a 40bit IPA space.
However, not all HW support such an IPA space, and the KVM_CREATE_VM
call fails on these systems.

In order to maximize compatibility, we can ask KVM for the maximum
supported IPA size, and use that as an input to KVM_CREATE_VM, at
which point the kernel will instantiate a VM with that IPA size.

This enables crosvm on exotic hardware such as the Apple-M1.

TEST=tools/run_tests

Change-Id: I7ea39ac6e5de6a1389c0c30cdfeb7c970c411589
Signed-off-by: Marc Zyngier <mzyngier@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3124677
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-01 14:24:27 +00:00
Andrew Walbran
d80eabc803 Use constants for third_party code locations rather than hard-coding.
The constants already existed but weren't being used consistently. This
will make the Android downstream patches to change the paths a little
simpler.

BUG=b:204072128
TEST=tools/run_tests

Change-Id: If9b81ef9ca0a7c52f0d9fe7cf836841027a2c92d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3253369
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
Auto-Submit: Andrew Walbran <qwandor@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-01 13:26:18 +00:00
Dennis Kempin
8f5978fda2 crosvm: Do not use .cargo/config.toml
Building crates in common/ will try to access the file, but won't
be allowed to read it with CROS_WORKON_SUBTREE set.

BUG=b:195126527
TEST=./tools/run_tests --target=vm:aarch64

Change-Id: Ic455ca6c3102dd363daf70468e5d89003d10bb4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3254042
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
2021-10-30 00:16:33 +00:00
Dennis Kempin
8a1c50d5cd Refactoring: Move various general purpose crates to common/
This change contains the results of running

./tools/contib/cargo_refactor.py

This will break the next uprev, and needs to be synchronizized
with the corresponding ebuild changes in https://crrev.com/c/3248925

BUG=b:195126527
TEST=./tools/run_tests

Change-Id: Ied15a1841887bb8f59fba65b912b81acf69beb73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3248129
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-29 22:31:43 +00:00
Keiichi Watanabe
cb14f61ce7 mdbook: Explain how to build a binary for beginner
Add a section to explain how to build crosvm binary for beginners who
may not have used cargo.
Also, ran mdformat on the file.

BUG=none
TEST=check

Change-Id: I902157cd471652b829d73bb27fc52e04db64d6d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3252186
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-10-29 16:43:56 +00:00