Commit graph

174 commits

Author SHA1 Message Date
Daniel Verkamp
7228ac3d0b Cargo.toml: add missing Windows feature declarations
New clippy warns about cfg(feature) checks for features that are not
present in Cargo.toml. Add the missing features to Cargo.toml to unblock
the Rust toolchain uprev (although if these are truly non-functional in
upstream crosvm, the code that is controlled by these features should
probably be removed instead; most of them don't actually compile right
now, so they are added to the KNOWN_DISABLED_FEATURES exclusion list).

BUG=b:365852007
BUG=b:267788790

Change-Id: I7cf4f11f46b3dcd591701a15724d6f4b8218a5ed
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5961951
Reviewed-by: Idan Raiter <idanr@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-10-25 21:34:53 +00:00
Akilesh Kailash
4775054dbd device: fs: Setup UID-GID mapping between guest and host without user-namespace.
The virtio-fs usually does mapping of UIDs/GIDs between host and guest with user namespace.
In Android, however, user namespace isn't available for non-root users.
This CL allows mapping UIDs and GIDs without user namespace by intercepting FUSE
requests and translating UID/GID in virito-fs's process at runtime.

This leverages pretty much ARCVM usage of FS_IOC_SETPERMISSION ioctl;
however, in this case, host sets up the permission and the UID-GID
mapping.

The format to set the mapping:

"guest-uid,guest-gid,host-uid,host-gid,umask,path;<repeat
for other paths>"

guest-uid: UID to be set for all the files in the path inside guest.
guest-gid: GID to be set for all the files in the path inside guest.
host-uid: UID to be set for all the files in the path in the host.
host-gid: GID to be set for all the files in the path in the host.
umask: umask to be set at runtime for the files in the path.
path: This is the relative path from the root of the shared directory.

Current this is supported only for vhost-user-fs.

Start the device:

$/apex/com.android.virt/bin/crosvm device fs --socket=/tmp/virtiofs --tag=android \
--shared-dir=/data/media/0 \
--cfg=cache_policy=always,uid_gid_map="1000 1000 10286 1023 0007 /DCIM;1000 1000 1023 1023 0007 /Android" \
--disable-sandbox

CrosVM will pass "--vhost-user-fs=/tmp/virtiofs,tag=android" when
ferrochrome app is started.

In the guest (in CrOS) for "chronos" user:

$mount -t virtiofs android Downloads/

Verify DCIM/ and Android/ directories have "chronos" UID and GID.

Create files inside DCIM/ and verify UID and GID's are correctly set on
the host.

Bug=b:340940950
Test: Launch ferrochrome app passing /storage/emulated/0 and mount
virtiofs inside CrOS (guest VM).

Change-Id: I637ad11eaaf8da58df7d1b04bf2fef05856a95a5
Signed-off-by: Akilesh Kailash <akailash@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5852617
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2024-10-11 06:34:30 +00:00
Daniel Verkamp
383ae1a6bf Replace memoffset with std::core::offset_of
offset_of!() is available in the standard library as of Rust 1.77.

Also update intrusive-collections 0.9.4 -> 0.9.6, which drops an
indirect dependency on memoffset 0.5.6:

  cargo update -p intrusive-collections

BUG=b:344974550
TEST=tools/dev_container tools/presubmit

Change-Id: I37a9bf0aee5f5f55bdea1e17d71889e8a3badb36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5667936
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-28 22:07:50 +00:00
Mu-Le Lee
ec39c307da Implement virtio-snd aaudio stream to support audio in android
This change introduces feature audio_aaudio on top of the support of
virtio-snd-multiple-backend. The android_audio uses the Android
AAudio NDK library to play audio. A libaaudio_stub is provided for
building and testing on non-android environment.

Bug=b:325930215
Test=Play Youtube video on panther
Test=./tools/dev_container
Test=cargo build
Test=cargo build -F audio_aaudio,libaaudio_stub
Test=./tools/run_tests
Test=./tools/presubmit

Change-Id: I7c275433bf94d4a347720ce0ffa9127ffcb66a1e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5556704
Reviewed-by: Jiyong Park <jiyong@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Mu-Le Lee <mulelee@google.com>
Commit-Queue: Mu-Le Lee <mulelee@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2024-05-31 05:32:38 +00:00
Daniel Verkamp
7599eeddbb base: move fork_process to jail crate
This API directly depends on Minijail, so it does not make sense for it
to be in the base crate that should be cross platform. Move it into the
jail crate, which already wraps other Linux-specific Minijail
functionality.

If we need to add a fork API that works on all unix platforms (including
non-Linux), that could be re-added in base, but for now, this is only
needed for Linux.

This removes the `base` crate's dependency on minijail, as well as the
special case test harness (which is moved to `jail` instead).

Change-Id: Iabefff03ab18222b71b82571bd815d5f028236c8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5556681
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-05-22 21:21:59 +00:00
Daniel Verkamp
52b8e42869 Cargo.toml: avoid "*" versions for external crates
Ensure that every Cargo.toml dependency on a third-party crates.io crate
specifies at least a major version, or a minor version for 0.x crates,
to ensure that if a new major version is published, it cannot cause API
breaks.

The versions are selected to match the ones already in Cargo.lock, so
this should have no functional change, but it will help prevent new "*"
versions from being introduced via copy-and-paste.

For rationale, see the Cargo FAQ:
<https://doc.rust-lang.org/cargo/faq.html#can-libraries-use--as-a-version-for-their-dependencies>

`minijail`, `audio_streams`, and `cras` are left as "*" for now, since
they have unusual situations (imported from a submodule and/or replaced
at build time with ebuild magic).

BUG=None
TEST=tools/dev_container tools/presubmit
TEST=verify Cargo.lock is unchanged

Change-Id: Ifa18199f812f01d2d10bfb4146b3353c1a76527c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5555656
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-22 01:01:42 +00:00
David Stevens
d05f9e326e linux: Add support for metrics
Initialize the metrics tube and make sure its kept in all forked
children.

BUG=b:332466813
TEST=tast run DUT arc.Boot.vm

Change-Id: Ide7a9e4ba5a3d8a52e69ac65b9aaaefcf21735a6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5400363
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-04-09 01:43:39 +00:00
Jason Macnak
8eab91e544 gpu_display: add Android display backend
This change introduces two features:
* android_display and
* android_display_stub

The android_display feature adds a new GPU display backend for Android
which emits the display output to an Android surface. The surface is not
created by the backend itself, but by an external entity (ex: Android
app) by creating a SurfaceView. This allows us to display a VM anywhere
the app is shown.

The owner of the surface (the app) is expected to share the surface with
the new backend by calling an AIDL method that the backend will
implement. The AIDL service implementing the method will be registered
to the service manager using the name set via the cmdline option
--android-display-service NAME.

This CL however doesn't include the implementation of the AIDL service
because upstream crosvm doesn't support building an AIDL service and
Android-specific libraries like libnativewindow. Instead, the
android_display_stub feature provides a no-op stub for the AIDL service,
so that we can at least build the rest of the new display backend.

TEST=cargo build
TEST=cargo build -F android_display,android_display_stub
TEST=./tools/run_tests
TEST=./tools/run_tests -F android_display,android_display_stub
TEST=./tools/presubmit
Bug: 325929966

Change-Id: I24f672beaa4a28253f150306a64df34f4962361e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5390926
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jiyong Park <jiyong@google.com>
2024-03-26 00:08:54 +00:00
Hikaru Nishida
80f14ee450 virtio/pvclock: Support Linux hosts
BUG=b:295256641
TEST=cargo build -F pvclock
TEST=cargo test -p devices -F pvclock -- pvclock
TEST=cargo test -p e2e_tests -- suspend
TEST=tools/dev_container tools/presubmit all
TEST=crrev/c/5151637

Change-Id: I57fe8ece5a205decb36ef7863d8e5c4f4f4c6bde
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4576848
Commit-Queue: Hikaru Nishida <hikalium@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2024-03-13 09:05:17 +00:00
Hikaru Nishida
64010dd1f7 Use PvClockState struct for storing serializable part at runtime
Create and use PvClockState struct. Before this CL, PvClockSnapshot
had been created by hand because of Arc is used for total_suspend_ns.
However, it can be serialized when rc feature is enabled for serde crate
so enable it and share the common struct to make the code clean.

c.f. https://docs.rs/serde/latest/serde/trait.Serialize.html#impl-Serialize-for-Arc%3CT%3E

BUG=None
TEST=cargo build -F pvclock
TEST=cargo test -p devices -F pvclock -- pvclock
TEST=cargo test -p e2e_tests -- pvclock

Change-Id: I28ef9a3a4b2bf757397ce0be5a0c36bc72bc1489
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5312036
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Hikaru Nishida <hikalium@chromium.org>
2024-03-12 03:50:47 +00:00
Andrew Walbran
33c385a24d Update chrono.
BUG=b:326256145

Change-Id: Ia16b88151efa8ad0103324bde6c555c8650ebbab
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5314562
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Andrew Walbran <qwandor@google.com>
2024-03-11 11:16:18 +00:00
Daniel Verkamp
fa159ee24a devices: virtio-fs: enable dbus crate stdfd feature
"stdfd" replaces the dbus::arg::OwnedFd type with the OwnedFd from the
standard library (std::os::fd::OwnedFd), which allows safe conversion.

Also use SafeDescriptor::try_from() to clone the descriptor rather than
base::clone_descriptor(), which returns an unmanaged RawDescriptor.

BUG=b:327639547

Change-Id: Ifa1e6b783217e946c027e4db9a6202b39c92936e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5354030
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-03-08 22:14:51 +00:00
Andrew Walbran
3009bf2722 Only use required features of chrono.
BUG=b:326256145

Change-Id: I3c1b5b7bc39ebd190ca9ff74e41efbdc312bde67
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5313721
Commit-Queue: Andrew Walbran <qwandor@google.com>
Auto-Submit: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-02-23 09:51:09 +00:00
Stanislaw Kardach
3363fb9fe7 Cargo.toml: add noncoherent-dma feature flag
Add a top level noncoherent-dma feature flag as well as its
counterparts in devices and hypervisor modules.
This flag enables the MemCacheType::CacheNonCoherent handling,
ensuring that behavior introduced in the previous commit can be
selectively enabled.

BUG=b:316337317
TEST=emerge-rex chromeos-base/crosvm
TEST=USE=crosvm-noncoherent-dma emerge-rex chromeos-base/crosvm

Change-Id: I13f50547b21ce804c5fa4b8f6328931f558b717e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5237126
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Zhenyu Z Wang <zhenyuw@linux.intel.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stanisław Kardach <skardach@google.com>
2024-01-26 23:27:58 +00:00
Dmitry Osipenko
dbda320eb8 rutabaga_gfx: Remove virgl_renderer_next feature flag
Crosvm enables unstable virglrenderer features based on the pkgconfig
flags. The virgl_renderer_next build flag isn't used anymore, remove it.

BUG=none
TEST=none
Suggested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Change-Id: I96ba36a9a8c1af9a252e8dcbe664cbf1597543a6
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5077248
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Ryan Neph <ryanneph@google.com>
2023-12-15 00:59:44 +00:00
Daniel Verkamp
fca49a3980 vmm_vhost: remove vmm and device features
crosvm always enables both of these features, and the crate doesn't
build properly without them enabled anymore due to our local changes, so
just drop the features and all cfg checks for them.

TEST=(cd third_party/vmm_vhost/; cargo test)

Change-Id: I02f9caca387846dd24d9486284b064897f275205
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5063679
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-11-28 01:21:42 +00:00
Daniel Verkamp
b0406736ed net_util, devices: refactor platform-specific net code
The validate_and_configure_tap() and virtio_features_to_tap_offload()
functions already effectively did nothing on Windows, since the
implementations of these for Slirp were not provided. These functions
are moved to sys so the Linux-specific TAP interfaces are no longer
needed in TapTCommon.

The get_ifreq() function is only called internally inside the
implementation of the Linux Tap struct; it does not need to be part of
the TapT trait at all.

The MacAddress <-> sockaddr interop is only needed on Linux, and the
conversion can be moved into the get_mac_address and set_mac_address
implementations for Linux.

With these changes, net_sys is used only on Linux, so it can be
conditionally compiled and not included in non-Linux builds at all.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: I3419a3bdb1470c4d72588fe19e43fabcdfe4e451
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5046598
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-11-27 19:23:56 +00:00
David Stevens
9c5b815e9d devices: pci: Refactor capability handling
Add support for complex capabilities to PciConfiguration, instead of
relying on every PciDevice implementation to implement their own
support.

BUG=b:301865576
TEST=./tools/dev_container ./tools/presubmit all
TEST=tast run DUT arc.Boot.vm
TEST=manual testing of virtio-net hotplug

Change-Id: If3db625dcb21ebd8ce8e671f7e636f67cf6473b2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4911554
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2023-10-31 01:47:14 +00:00
A. Cody Schuffelen
97dff044f8 Replace #[cfg(unix)] with #[cfg(any(target_os = "android", target_os = "linux"))]
Updates are made to source and documentation.

This more accurately represents the currently supported platforms of
Android/Linux and Windows, without unexpectedly including other
unix-like operating systems.

Command to reproduce:
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -i 's/cfg(unix)/cfg(any(target_os = "android", target_os = "linux"))/g' {}
$ cargo fmt

md files manually updated to fix line lengths.

Renaming `unix` modules to `linux` will be done in a later CL.

Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I42c1bf0abf80b9a0df25551613910293217c7295
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909059
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-10-11 00:43:29 +00:00
Zihan Chen
cbba480ebe crosvm: Uprev zerocopy to 0.7.x
zerocopy 0.7.x has finally released as a stable version, uprev it
to allow some remaining structs to be derivable.

TEST=CQ

BUG=b:300969352
FIXED=b:300969352

Change-Id: I90f0dfb09494f875fef1cd11bfcbd48030846092
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4878761
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-10-10 17:34:32 +00:00
Daniel Verkamp
157ce87067 Cargo.toml: remove chromeos from base and devices
This feature does nothing in the base and devices crates, so remove it.

The remaining features enabled by chromeos are still needed until they
are enabled explicitly in the crosvm ebuild, so they aren't removed yet.

BUG=b:244618505
TEST=emerge-brya crosvm

Change-Id: I4fec40fb7ceb4eeff75266a66f19c0f142b9195a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4873792
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-10-09 20:14:59 +00:00
Daniel Verkamp
e10df59fd3 devices: remove --software-tpm support
The software TPM backed by the libtpm2 simulator was only used for
testing; now that we have the vTPM proxy device, the software TPM is no
longer needed.

This also allows removal of the tpm2 submodule (tpm2-sys/libtpm2).

BUG=b:300673042
TEST=tools/dev_container tools/presubmit

Change-Id: I3feb5f715f9f12f832450df712c0f63ed7b4fb13
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4875221
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-10-02 23:28:45 +00:00
Daniel Verkamp
03dd1feab7 Cargo.toml: depend on zerocopy 0.6 explicitly
Previously all of the zerocopy imports just used "*", but there are
API changes in zerocopy 0.7, so ensure we get a compatible version by
depending on 0.6 everywhere.

This is a no-op since Cargo.lock already specifies a 0.6.x version, but
it will prevent accidentally upgrading to 0.7.x without updating to the
new API.

BUG=b:301283548
TEST=cargo build

Change-Id: Ifd702d982a09b5083dddd666dc6f3052cba22214
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4878502
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-09-20 21:28:58 +00:00
Daniel Verkamp
6513b888b0 Cargo.toml: introduce net feature
This commit just adds the feature but intentionally does not use it yet.
For downstream projects (e.g. the ChromeOS crosvm ebuild) that use
--no-default-features and enable individual features manually, those
projects will need to add the net feature to their build scripts in
order to keep network functionality. Once that is done, then we can make
the net feature actually control whether the net device is built.

Change-Id: I47e405ac295eef933f5d83ec3a4a490028da231b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4823132
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-09-12 21:02:33 +00:00
Daniel Verkamp
40114fd26e Remove virtio-vhost-user (VVU) support
This code is unused and untested, while simultaneously making the rest
of the virtio device code more complex. Remove it.

BUG=b:276993009
TEST=tools/dev_container tools/presubmit

Change-Id: I9d44f92419c6912d1735043404d4f64efc95bba4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4676076
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2023-09-05 17:59:33 +00:00
Daniel Verkamp
045a3074ef Cargo.toml: add version to chrono dependencies
The newest chrono version is currently on the 0.4.x branch, but there
are preparations to release a 0.5.x version. Explicitly specify a 0.4.x
version in our dependencies since there will be backwards-incompatible
API breakages in 0.5.x.
<https://github.com/chronotope/chrono/issues/970>

The exact version chosen (chrono 0.4.19) matches the version we have
pinned in Cargo.lock currently and will match any newer 0.4.x releases,
so there should be no functional change.

BUG=None
TEST=cargo build

Change-Id: Ifa24a547e435ab4987be9358343e6b25c1385c66
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4774870
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-08-11 21:02:25 +00:00
Alexandre Courbot
f484411e29 video: decoder: vaapi: use cros-codecs 0.0.4
The cros-codecs API has changed a lot, and it supports zero-copy
decoding as well as HEVC now.

BUG=b:262824148
TEST=presubmit

Change-Id: Icc2a258642cef012b5640f1c71ccff481b5808f2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4744560
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
2023-08-04 18:17:26 +00:00
Daniel Verkamp
4bd4358aa4 Remove all remaining --features=direct code
BUG=b:279663365
TEST=tools/dev_container tools/presubmit

Change-Id: Iaa0b8176a54982044137b112039bf04f1e183c4e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4713506
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Grzegorz Jaszczyk <jaszczyk@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmytro Maluka <dmy@semihalf.com>
2023-07-25 17:55:10 +00:00
Wang Ningyuan
c1e471e52a devices: pci: Hotplug compatible PCI trait
CL introduces HotPluggable, additional requirements for a PciDevice to
be configured in a hotplug context. VirtioPciDevice is currently the
only supported type.

TEST=tools/presubmit
BUG=b:243767476

Change-Id: I0e8a6c6fbd430216874b54d7b577f04cd4bae5fd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4615383
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Ryuichiro Chiba <chibar@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-07-24 06:24:52 +00:00
maciek swiech
fac9000051 balloon: use protos for registered events
since the RegisteredEvent model is effectively an external API, switch
to using protobuf as a more formal/stable means of communicating
messages. also introduces exporting the registered_events.proto file as
part of crosvm_control build, alongside the currently existing header
file.

this patch also introduces feature-gating for registered_events and
protos so as not to bring in too many third party dependencies for a
base build.

BUG=b/278117550
TEST=run bzImage locally
TEST=sidecar program available at https://x20.corp.google.com/users/dr/drmasquatch/socket-pinger-proto

Change-Id: I5d91d87f7807effc125352caf5c75eee2593f70d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4521604
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: maciek swiech <drmasquatch@google.com>
2023-05-22 19:28:45 +00:00
Alexandre Courbot
9ae485d979 video: decoder: vaapi: switch to external cros-codecs
Use the version of cros-codecs publishes on crates.io and adapt the code
to be able to use it. This results in a few simplifications as e.g.
frame ordering is guaranteed by cros-codecs and we don't need to handle
it anymore.

BUG=b:262824148
TEST=ffmpeg -codec:v vp9_v4l2m2m -i Big_Buck_Bunny_720_10s_1MB.webm Big_Buck_Bunny-%03d.png
TEST=cargo test --features "video-decoder,vaapi,ffmpeg" -p devices -- --include-ignored test_decode_h264

Change-Id: Ib694afe8206a4d85b307efaaf3f6669dfe4e18bb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4518093
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-05-17 00:52:34 +00:00
Shintaro Kawamura
8590cdcc8a swap: expose Status interface to all variants
Status does not depend on any swap related feature. Exposing Status to
all variants is easy to implement swap status FFI at crosvm_control.

The new "swap/enable" feature switches the actual vmm-swap functionality
to be compiled. The feature is enabled by default on "swap" crate but
disabled on the root package for test dependency.

Vmm-swap feature is enabled by `--features=swap` flag on cargo build as
before.

swap/src/controller.rs is copied from swap/src/lib.rs.

BUG=b:265386761
TEST=tools/dev_container tools/run_tests2

Change-Id: Ifc2539a62d0f594fd5bbb41623c735ea2621f7b6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4486546
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
2023-05-04 12:30:09 +00:00
Daniel Verkamp
a360baa819 Cargo.toml: upgrade protobuf 2.x -> 3.x
system_api bindings have been regenerated with protobuf 3.2; this should
be okay to land before the full ChromeOS system_api migration, since
crosvm always uses its own copy of the bindings rather than the ones
provided by the dev-rust/system_api package.

The protoc-rust crate is replaced with protobuf_codegen in 3.x.

BUG=b:277243607
BUG=b:279834784
TEST=tools/dev_container tools/presubmit

Change-Id: I6aad45ded2639d7506a7238800584bebab196455
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4405309
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-04-28 19:32:01 +00:00
Daniel Verkamp
894e7ed13c vhost: only compile on unix platforms
The vhost kernel API is specific to Linux; it doesn't make sense to
build it on Windows.

Change-Id: I3b8f726f74389f2a3ff78eff43b0c4f312382004
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4437030
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-17 23:43:52 +00:00
Keiichi Watanabe
bc9e331085 devices: Explicitly specify "serde" feature for chrono
Since we're serializing `DateTime<Utc>` with `derive(Serialize)` in
cmos.rs, "serde" feature needs to be specified.
Even without this commit, `serde` feature was specified probably because
of indirect dependency. But, it'd be better to specify the feature
explicitly.

BUG=none
TEST=CQ

Change-Id: I637a804d93dab825cb4452d22e4b3882ac27cf98
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4414505
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-04-12 16:57:57 +00:00
Keiichi Watanabe
e0c35da0b0 devices: virtio: Serialize PassthroughFs unit tests with NamedLock
Use NamedLock to prevent PassthroughFs tests from running in
multi-threads when one runs `cargo test`.
Previously, we ran these tests as a part of integration tests with
`libtest_mimic` to ensure it's not parallelized. But, using nextest's
feature is more straightforward. Also, running them as unit tests allow
us to call mocked functions with `#[cfg(test)]` in the future.

Note that NamedLock is not necessary for `cargo nextest` because it runs
each test single-threaded, but in multi-processes.

BUG=b:275016855
BUG=b:277302336
TEST=run_tests

Change-Id: I3751b712eaf1b2180bf4153ab501a32b402c0a29
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4406098
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2023-04-12 04:05:41 +00:00
Elliot Berman
ea5fab36a4 devices: irqchip: Implement GunyahIrqChip
Implement GunyahIrqChip.

Cherry-pick notes: Added license header + delete unused imports.

BUG=b:232360323

Change-Id: I11d32599f221b57974f9d942d1aa9f128fc14516
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4404218
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-04-05 18:32:18 +00:00
Junichi Uekawa
d03c99fc0c crosvm: Uprev uuid > 1
Uprev to version available in Debian.

This seem to end up doing uprev to 1.3 now.

BUG=b:265082456
BUG=b:229895468
TEST=build

Change-Id: I550778acb675c9034b9cfcea77f4ae847e2d2ea1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4364559
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-04-04 23:56:13 +00:00
Keiichi Watanabe
a58648f339 devices: Force to run Passthroughfs integration tests in single thread
We can't run PassthroughFS unit in multithreaded environment because each test creates its own PassthroughFS and the difference instances can execute conflicting process-wide operations (e.g. fchdir).
So, we need to have an integration test binary with a custom test
harness.

BUG=b:275016855
TEST=run_tests --dut=host
TEST=run_tests -p mingw64

Change-Id: I33855ab37bbe9486723038ed196f50a1a85ca748
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4369818
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-03-31 01:43:15 +00:00
Yi-De Wu
65d98b04f6 aarch64: MTK GenieZone hypervisor enablement as Crosvm backend
To support GenieZone (gz) hypervisor as a crosvm hypervisor backend:
- Implement GenieZone hypervisor
- Implement GenieZone’s irqchip
- Create config and feature for GenieZone
- Probe proper hypervisor backend with naive logic
- Inject virtual interrupts
- Bootup guest VM with linux kernel to shell

We still have other todos:

- Integrate with protected VM and pvmfw
- Support multi-core VM

Fixed bugs:
- Replace gz with geniezone in most cases for clarity
- Replace KVM’s ioctl number with GZVM’s ioctl in bindings

Bug: 264630327
TEST:
$ taskset 10 ./crosvm run --disable-sandbox -m 512 -s s1 \
  --rwroot alpine-rootfs.img -p 'init=/bin/sh rodata=off' \
  --display-window-keyboard Image_515_41_no_numa_20230130 \
  --serial type=stdout,hardware=serial,earlycon \
  --serial type=stdout,hardware=virtio-console,console,stdin

Change-Id: Ia5d92ba5cbb4198ab7f9f2a778da03b2199892cd
Signed-off-by: Ze-yu Wang <ze-yu.wang@mediatek.com>
Signed-off-by: Yi-de Wu <yi-de.wu@mediatek.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4170415
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-03-22 18:04:47 +00:00
Norman Bintang
32ca7e250a devices: virtio: snd: Implement file backend for VirtioSnd
File backend will write audio playback to files. Every PCM playback
stream will have its own file.
Changes:
* Add playback_path and playback_size to virtio::snd::Parameters
* Add new file_backend file in virtio::snd
* Add virtio-snd arg help.

BUG=b:233542268
TEST=run crosvm with --virtio-snd backend=file and call aplay

Change-Id: Iaec01f52292f1181b0137fa3c8d8c2b2b9e7cc49
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4306260
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-03-21 07:46:05 +00:00
Zihan Chen
e670159c2e crosvm: Add seccomp_trace feature
Add a minijail's mode of operation where an always-allow seccomp
filter is attached to forked device processes. This facilitates
capturing seccomp filters used by each device process separately.

TESTED=./tools/build_release -- --features seccomp_trace && strace -ff crosvm --log-level debug run <args>

BUG=b:258316090

Change-Id: Ic4d3f5178e6a2dcbd748d101db43574f3224ff78
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4289510
Commit-Queue: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-03-01 19:18:12 +00:00
Zihan Chen
8a7550c40a crosvm: Partially convert DataInit to zerocopy (1/n)
Thie effort is splitted into multiple CLs, to reduce change size
and also make bisecing breakages easier.

TESTED=CQ only

BUG=b:204409584

Change-Id: Ie90f171bd5f74b732df3129e94733f3b34621092
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4210751
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-02-02 19:28:57 +00:00
Shintaro Kawamura
b5a9833d97 swap: send userfaultfd via Tube on device process fork
This implements the equivalent logic on crosvm as
UFFD_FEATURE_EVENT_FORK. When each device process forks, the ProxyDevice
creates userfaultfd and send it to the monitor process by
SwapController::on_process_forked().

Crosvm does not have any child processes which may access the guest
memory except device processes as of now. Crosvm forks
virgl_render_server, but the mmap is not preserved in the process on
execve(2) since it is a different binary. Also no device process forks
grandchild processes according to the seccomp policy.

We actually can't use UFFD_FEATURE_EVENT_FORK because the feature does
not support non-root user namespace (go/uffd-fork-user-ns) and ARCVM
runs in a non-root user namespace.

This also adds syscalls to seccomp policies for devices to allow the
processes to create and setup a userfaultfd.

BUG=b:266641923
TEST=manually tested

Change-Id: Ide3088e1e95ae3c8259e3f4324124b3376e760b7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4194228
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-02-01 00:47:52 +00:00
Daniel Verkamp
9e2494f7e0 devices: serial: implement out_timestamp for all platforms
This feature has nothing specific to Windows in its implementation, so
pull it up to the portable part of the Serial device.

The unit test is slightly modified to avoid the need for the regex
crate. This was the only use of regex in devices, so it can be dropped
from Cargo.toml.

BUG=None
TEST=cargo test -p devices serial
TEST=tools/run_tests --platform=mingw64

Change-Id: I3073e90d71bda3c9f6da1df3a3b657e62e087302
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126251
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-01-04 06:21:02 +00:00
Daniel Verkamp
c68c51a84b devices: battery: move monitor code out of sys
The PowerMonitor trait and the code monitoring it for events is not
platform specific, so it can be moved out of sys/unix into the main
battery code.

BUG=b:213149155
TEST=tools/presubmit --all
TEST=emerge-brya crosvm

Change-Id: I5c34c0e98009d866d5345fd940ecc7f742da1d2c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4122803
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-01-03 22:44:29 +00:00
Daniel Verkamp
ac0fc378a3 Fix remaining Chrome/Chromium OS instances
These should be written as ChromeOS and ChromiumOS (without the space)
to match the updated branding. The copyright headers were already
migrated to the new style (https://crrev.com/c/3894243), but there were
some more instances left over.

BUG=None
TEST=tools/cargo-doc

Change-Id: I8c76aea2eb33b2e370ab71ee9b5cc0a4cfd00585
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4129934
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-01-03 22:14:30 +00:00
Frederick Mayle
f51a6f9ef1 devices: remove unconditional dependency on slirp
If we always enable "slirp", then there are new, unwanted dependencies
on "libslirp-sys" and "pcap-file" in android.

The following line from the [features] section is sufficient to enable
it when needed:

    slirp = ["net_util/slirp"]

BUG=b:260604615
TEST=cd devices; cargo test --target=x86_64-pc-windows-gnu --features=slirp

Change-Id: I87ff19a0101b9d09f42b11517bee2fef8b83ec3f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4082148
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2022-12-08 18:53:48 +00:00
Richard Zhang
ac6c68a9fc virtio-snd: Upstream Window's virtio-snd Playback impl
TEST=presubmits and this code works downstream
BUG=b:258298873

Change-Id: I7369fb08af474d107d056da8538de86bbc03eeb8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4015562
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-12-07 21:33:49 +00:00
Keiichi Watanabe
20863a3c36 devices: Enable net_util/slirp if slirp is enabled
This is needed to build the `devices` crate only for the windows target.

BUG=none
TEST=cargo test --target=x86_64-pc-windows-gnu --features=slirp in devices

Change-Id: I781def962a716e4ee2ea80f3c6d1a426fc92e2e8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4028759
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-11-19 07:13:20 +00:00