This doesn't seem to correspond to any devices setup by crosvm. We don't
support an AXI bus. Searching for 0x40000000 doesn't turn up anything
relevant.
BUG=b:361390145
Change-Id: Ica4c5bf6ca7b8b417470c37bffd5790776d4086d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5984062
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Add support for virtio-media devices, and command-line options to create
the example and proxy devices.
Due to the use of some Unix-specific constructs, virtio-media is
currently only available on Unix hosts.
Cq-Depend: chromium:5902882
BUG=b:308718439
BUG=b:348316475
BUG=b:347118653
TEST=emerge-brya chromeos-base/crosvm
Change-Id: Ie6ea7b534f9342bd6430e071828dbec8174b55d7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5065329
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
It was unused aside from the Display impl, which is only used for debug
prints.
Change-Id: Ie87a44e53e512b57032d5862ffb180ed57aaa0ba
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6027191
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
Cpu frequencies are specified for each vCPU, not pCPUs.
Bug=b:284367589
Test: tools/presubmit
Change-Id: Ie372c8414d25489e305edc3d799c2ff5f3d45308
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6024313
Reviewed-by: Frederick Mayle <fmayle@google.com>
Returning the current frequency of the physical cpu is going to inflate
sizes of tasks inside the guest when the vCPU's performance is at a
point below pCPU@FMin. Using a simplified example, if the FMin of the
pCPU is 1000Mhz, a task that took 5ms to run @ 400Mhz will instead be
accounted as if it ran at 5ms @ 1000Mhz, resulting in a much larger
and incorrect utilization value according to the guest scheduler.
In the shared freq_domain scenario, linux will select one policy_cpu to
write when selecting performance. This performance state needs to be
shared between the vCPUs in the same domain to report the correct
performance to the other vCPUs that are frequently reading its own
performance state. So to ensure correct utilization tracking of tasks
inside the guest for all vCPUs, return the current domain's requested
performance when perf dips below pCPU@FMin.
Bug=b:284367589
Test: tools/presubmit
Change-Id: Ie4cb65426dd0a1555f8413190daf6027da4a34e5
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6020998
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Add the minimal allow(dead_code) and feature declarations to allow the
clippy checks to pass for Windows with Rust 1.81.
BUG=b:365852007
TEST=tools/presubmit clippy_mingw64
Change-Id: I9ab776b07d8e9e14fe380d9b5ef1fa332788ff63
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6013080
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Rather than placing vcpu_throttle workers based on a fixed offset
from its vCPU's affinity, offset it based on the vcpu_domain's index
instead. This packs the vcpu_throttle workers closer together when
the vCPUs have shared freq domains.
Bug=b:284367589
Test: tools/presubmit
Change-Id: I293597227808eb44d3bbd8ca51bc4bcf2fc6ed30
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6012794
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
The DecoderEvent::PictureReady visible_rect field was checked in a unit
test, but it was otherwise never read, so drop it and remove the checks
from the test.
BUG=b:365852007
Change-Id: Ic428762c89311dcef17572e5b87401dafd437657
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5966506
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
These are mostly places where a field in a struct is only kept around
for lifetime reasons.
Annotating the individual instances means that we don't have to turn off
the warning for new code.
BUG=b:365852007
Change-Id: I9172ea28cc12779331cd48c2c6ad1003d7ca02f8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5966505
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
The performance range of pCPU that the vCPU is running on is limited by
the frequency range that it supports. There are some usecases where even
running the pCPU at its lowest frequency will still be too fast to
accurately emulate a much smaller vCPU.
Add a worker to throttle the vCPU by adding a fixed amount of work to
the vCPU at varying intervals depending on the vCPU's requested
performance.
The relationship to determine the interval is:
THROTTLE_PERIOD = THROTTLE_TIME / (1.0 - VCPU_PERF / PCPU_PERF);
The worker will only throttle vCPU when it requests a performance point
below the performance of pCPU@Fmin, but otherwise falls back to using
frequency ratios to emulate smaller vCPUs.
By emulating correct vCPU sizes and topologies, this enables Cuttlefish
to accurately model real life SoCs and kernel scheduler behaviors inside
the guest. This allows for better power and performance related testing
at scale using ARM64 servers.
Bug=b:284367589
Test: tools/presubmit
Change-Id: Ide6f61a68ea59cee0db163829839ad575db1b208
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5980807
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
The --serial command line option will still accept the old
`hardware=legacy-virtio-console` via a serde alias, but the actual enum
variant can be removed now that it is equivalent to VirtioConsole (since
https://crrev.com/c/5739275).
Change-Id: I0db0302c60707e38dfc93da1effe078046a7b321
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5788964
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Allow for custom vCPU capacity and frequency configurations
by applying a scale to requested and reported frequencies.
This allows users to emulate topologies that are different
from the host to mimic DVFS behaviors in guests that
are similar to real devices.
This is adapted from aosp/3195051.
Bug=b:284367589
Test: tools/presubmit
Change-Id: I48e8f6e7d7eb24eba25bcf98448279688a0c8fa9
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5973949
Reviewed-by: Frederick Mayle <fmayle@google.com>
Allow users to specify frequency domain information along with
frequencies when configuring vCPUs. Many SoCs will scale multiple CPUs
under a single frequency domain. Enabling this feature allows for more
accurate SoC modeling when virtual cpufreq is supported.
Host needs to provide CGroupV2 hiearchies support when
enabling frequency domain emulation.
vCPUs that share a frequency domain will be placed under
the same cgroup and their performance will be adjusted together.
Bug=b:284367589
Test: tools/presubmit
Change-Id: I0a88796a4d9cbccc93caf3a07d8815968c733b49
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5967454
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Replace the unsafe CStr construction with a CString::new() call, and
check the result to ensure the passed string has no embedded NUL bytes.
BUG=None
TEST=tools/dev_container tools/presubmit
Change-Id: I67d4b9d1856c201441c807e5cd23c38f050ed21f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5972799
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Many of the CStr instances were constructed from byte arrays, which can
now be replaced with c"..." literals to avoid the need to call unsafe
CStr::from_bytes_with_nul_unchecked().
BUG=None
TEST=tools/dev_container tools/presubmit
Change-Id: I5fe141dfc10da02b77f80c9b44fdf77018fc4561
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5972798
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
This CL adds two crosvm_control APIs for faking power and resuming
power from fake configuratiion. The APIs are designed for support arcvm
doze mode.
The crosvm_client_fake_power() is used to set battery's fake
configuration. The power status will always be on battery, which means
ac_online=0. Also, the maximum battery capacity that could be read by
guest is set to max_battery_capacity.
The crosvm_client_cancel_fake_power() is used to resume battery from
fake configuration. The battery device will report real host power
status.
BUG=b:353609634
TEST=write C program to call api & test manually
Change-Id: I30513847cfacc211bce885d2ff794fc7ae535c7c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5715936
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
Use unwrap_or() rather than unwrap_or_default() to clarify which values
will be returned in the error case; this still satisfies the clippy
analyzer.
BUG=b:365852007
Change-Id: I7d8b0b856a39f8e211248179a5befd2bd6a11851
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5966503
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
We actually don't need to import the SinkExt trait.
Bug: b/375619688
Test: presubmit
Change-Id: I803fb72aa1fa3f4f5a6c415b13a28102c8f8bfb7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5967223
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
We usually requires the root permission or sandboxing to run
virtiofs to do bind-mount and pivot_root inside
of a mount namespace.
This CL allows non-root user wherein "root_dir" defaults to the
path provided via "--shared-dir". This override is currently
enabled when "fs_runtime_ugid_map" feature is enabled.
Bug=b:340940950
Test: Launch Terminal App with virtiofs enabled.
Verify virtiofs mounts on guest and run basic I/O tests.
Change-Id: Icc0065cb11dd919f473e5d3ee994e7f8d679ecd0
Signed-off-by: Akilesh Kailash <akailash@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5945445
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
It's possible that the running task can also hold a mutable reference to
platform_workers and end up with a panic.
Bug: b/375619688
Test: run the emulator
Change-Id: I3538856c7702976df9a8b661dd5dd95cc27d4ca8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5967475
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
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>
... by serializing/deserializing the map as a series of kv pairs
to avoid `key must be a string` errors with JSON.
Bug: b/369615058
Test: cvd start --enable_virtiofs=false
Test: cvd snapshot_take --snapshot_path=/tmp/snapshot1
Test: cvd create --snapshot_path=/tmp/snapshot1
Change-Id: I037e8e3659b52fa2983712425381431a0bebab87
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5917178
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
A new clippy lint in Rust 1.81 warns about map_err() when the error is
not actually modified, just returned intact. Replace the affected cases
with inspect_err(), which allows the provided function to peek at the
error (if there is one) without modifying/replacing it.
BUG=b:365852007
Change-Id: I556a994011977420e6041ff4c6ea3bec06496014
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5852616
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
... for mapped resources by remapping into the guest on restore.
Bug: b/369615058
Test: b/369615058#comment1
Change-Id: Ic6194c312b019a83b8eee94b082ed2f7e9c249a4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5907646
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
Add the 2nd version of virtual cpufreq device emulation compatible with
the guest <-> host interface used in the V7 patch series of virtual
cpufreq.
See https://lore.kernel.org/all/20240919000837.1004642-1-davidai@google.com/
--virt-cpufreq-v2 is not compatible with v1 and only one version of the
device can be enabled at one time. V1 will be deprecated once the
switch occurs on Android.
Bug=b:284367589
Test: tools/presubmit
Change-Id: Ifb57e6912da0e48663e4308686e930d4c4056ce5
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5956880
Reviewed-by: Frederick Mayle <fmayle@google.com>
Prior to this change, virtio_sleep() would take a snapshot and
then completely destroy the underlying renderer via the
std::mem::drop(worker.state);
and then virtio_wake() would create a new renderer and attempt
to restore the previous state.
Sleep and waking without a snapshot load should be a non
destructive operation. This change attempts to make the
underlying renderer state persistent by updating the GPU worker
to be created once (start_worker_thread() now only called once)
and updating the worker to send/recv deactivation/activation
resources back to the main thread after sleeps/wakes.
Bug: b/369615058
Test: cvd start --enable_virtiofs=false
Test: atest FastbootRebootTest
Test: cvd snapshot_take \
--force \
--auto_suspend \
--snapshot_path=/tmp/snapshot1
Change-Id: I6427c27ee4c21c3e7b1095fbfffb69afcd2a8d24
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5900696
Commit-Queue: Jason Macnak <natsu@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Idan Raiter <idanr@google.com>
This reverts commit 97490c5252.
Reason for revert: Buggy
Original change's description:
> devices: add virtcpufreq_v2
>
> Add the 2nd version of virtual cpufreq device emulation compatible with
> the guest <-> host interface used in the V7 patch series of virtual
> cpufreq.
>
> See https://lore.kernel.org/all/20240919000837.1004642-1-davidai@google.com/
>
> --virt-cpufreq-v2 is not compatible with v1 and only one version of the
> device can be enabled at one time. V1 will be deprecated once the
> switch occurs on Android.
>
> Bug=b:284367589
> Test: tools/presubmit
> Change-Id: I125c8f3de5b4c81003ad301d29e7979aef685e00
> Signed-off-by: David Dai <davidai@google.com>
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5943185
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Bug: b:284367589
Change-Id: I370fe9d5784bf6ebc3e2f4cf1e3a3536c2879eb9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5953595
Reviewed-by: Frederick Mayle <fmayle@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: David Dai <davidai@google.com>
Auto-Submit: David Dai <davidai@google.com>
Add the 2nd version of virtual cpufreq device emulation compatible with
the guest <-> host interface used in the V7 patch series of virtual
cpufreq.
See https://lore.kernel.org/all/20240919000837.1004642-1-davidai@google.com/
--virt-cpufreq-v2 is not compatible with v1 and only one version of the
device can be enabled at one time. V1 will be deprecated once the
switch occurs on Android.
Bug=b:284367589
Test: tools/presubmit
Change-Id: I125c8f3de5b4c81003ad301d29e7979aef685e00
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5943185
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
If the worker exits early with an error, then the device is
disfunctional: we can't detect if the device disconnected and
we can't handle IRQ resample requests (needed for aarch64).
Also tweaked some error messages.
TEST=start VM using vhost-user block device without https://crrev.com/c/5937871 an witness crash instead of just a log
Change-Id: I8f6832481a578c5f7dcec27d6c5df430f2d5b348
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5941521
Auto-Submit: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
On Linux, we don't need to monitor anything special to get close
notifications; the Token::ReqHandlerRead event will be generated when
the fd closes (with is_hungup = true) and the closure will be handled
inline.
Adding the same backend_req_handler.get_read_notifier() to the wait_ctx
again causes an error, since that fd was already added in a previous
call.
BUG=None
TEST=`crosvm device block` + `crosvm run`
Fixes: 8de3640c01 ("devices: vhost-user frontend: rewrite worker as non-async")
Change-Id: I1318c5395670476bdc333a2bae1e8c8aba2c658e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5937871
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
As a follow-up to https://crrev.com/c/5913962 ("hypervisor: pass
IoOperation data as slices"), add a test to verify that Bus::read()
fills the passed data buffer with 0s even if there is no device on the
bus at the requested location.
Change-Id: Ief1359c4c4172865aad5fc1d97b5a3fc96527962
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5936289
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Previously, before powerd monitor is set up and receives first broadcast
signal from powerd, the read() function will return default initial
power property, which does not reflect the real host battery.
This Cl makes goldfish battery device request to get power property
before first time read. It is achieved by sending
GetPowerSupplyProperties dbus request to powerd.
BUG=b:361281568
TEST=deploy to DUT & test
Change-Id: I5044ded5efc744525dfe87fe81370f202f0a43fb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5918906
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Previously, the Vcpu handle_io() and handle_mmio() functions used an
IoOperation containing a fixed-length data array to represent a write
and returning a fixed-length data array to represent a read, along with
a separate size field to indicate how much of the fixed-length array
should be read/written.
This change uses Rust slices to represent the I/O data instead:
- Write contains a &[u8] of data to be written.
- Read contains a &mut [u8] to be filled with the read data.
The new IoOperation matches the Bus read()/write() APIs more closely,
and avoids the need for hypervisors and callers to convert between
fixed-size arrays and slices.
The Bus::read() function now always initializes the data slice before
(potentially) calling a device's read() function. This ensures
consistent results even if a device does not always fill out every data
byte (for example, the default BusDevice read() handler that is a no-op)
or if no device is found. This replaces the previous zeroing that would
happen when initializing the read data array to return from handle_fn.
Without this, the data slice may have had stale data from the previous
MMIO/IO exit, depending on the hypervisor implementation.
No functional change intended.
BUG=b:359382839
TEST=tools/dev_container tools/presubmit
Change-Id: Id88ebfa7ece5cc7466c010db2cbde303aeb97bf8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5913962
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
The chromium:5889431 makes vhost_user front-end device monitor the socket
connection for linux and Android. This CL makes this logic also present
in Windows.
BUG=b:369513363
TEST=tools/dev_container tools/presubmit
Change-Id: Ic7c4fa6c4b85f1d0ee34922a58f47f32f8f20d60
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5906971
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
This CL adds epoll monitoring socket(in backend_client) for
vhost_user_frontend. The monitored event fd is created from
backend_client's close_notifier. If the connection is broken, it means
vhost_user device exits unexpectedly, the crosvm should panic and exits.
BUG=b:369513363
TEST=start vhost_user device & kill the device & verified the crosvm
panic
Change-Id: I1b82aadc8d924978fe03d87a306f199781b428e3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5889431
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Also get rid of the platform-specific worker code in sys, since we can
use ReadNotifier and CloseNotifier to implement the worker in a way that
works on Linux and Windows.
BUG=b:370853464
Change-Id: I14e7f33a584728f9cf54ab807a32b2655b119749
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5901870
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
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>
Reuse the virtio-fs device worker thread implementation to replace the
async vhost-user fs backend. This makes the vhost-user-fs device
independent from the async executor, though it is still needed for the
request handler itself currently.
BUG=b:347782866
TEST=tools/dev_container tools/presubmit
TEST=run `crosvm device fs` and mount the fs in a VM
Change-Id: If4d2bb8c56a88ddac6a3691759cc645cc63b5d24
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5909655
Reviewed-by: Yuan Yao <yuanyaogoog@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
This makes the behavior closer to Linux (which uses flock).
Change-Id: Iff587b58647eec7378972e5442d4da95f3e2b7a8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5841071
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Put device to sleep before restoring.
Add some comments for clarity when creating a new device.
BUG=b:292276136
TEST=presubmit
Change-Id: I166d57437c429cb6bb59179abcc6bd923ca5f55b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5906228
Commit-Queue: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
The worker thread used to be named "vhost_user_virtio_{type}", which is
too long to fix in the 15 characters available for thread names on
Linux. Use the device's debug_label() instead, which follows the pattern
"vu-{type}", so the threads for different devices can be distinguished.
Change-Id: I8cadf54518724c5a764a0b28b0bc4144cd938d1e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5906571
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Similar to the recent `crosvm device fs` change c32a063c84
("vmm_host: support creating VhostUserStream from socket fd"), allow
the --fd option to use an existing connected socket from an already open
file descriptor.
Additionally, add the --socket-path option to replace --socket.
This matches the vhost-user backend program conventions:
<https://qemu-project.gitlab.io/qemu/interop/vhost-user.html#backend-program-conventions>
The old --socket option continues to be supported while callers
transition to the new --socket-path option.
Unfortunately, the argh crate does not support flattening option structs
(https://github.com/google/argh/issues/15), so it is not possible to
share the common device options currently; they are just duplicated in
the Options struct for each device.
`crosvm device net` is not updated yet, since it supports multiple
vhost-user backends in one instance and uses non-standard argument
parsing.
Change-Id: I873de8c81e41dfdf7939878b2fd572cc62a2a099
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5877432
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Ensures the single KVM memslot used with virtio_gpu fixed-blob-mapping
is configured with the correct MemCacheType (i.e. with CacheNonCoherent
on devices that build with --feature=noncoherent-dma).
BUG=b:360295883, b:246334944
TEST=ARCVM Play Store gui opens correctly
Change-Id: I305bd5a5708fa165d2a584dd57f8ce3e20b954ba
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5871722
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Ryan Neph <ryanneph@google.com>