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>
Noticed there's no mention of Rust in the book to build crosvm, so
adding it here.
BUG=N/A
TEST=mdbook build
Change-Id: Id667e1dc4f99e459b0a592fcce69a8f402fd3beb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5939968
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Elie Kheirallah <khei@google.com>
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>
Add option to not use the advertised PMU for the VM.
BUG=b:360388014
TEST=boot VM on Android with --no-pmu
Change-Id: I4e614915371bb55337471023a2cc062f58e6c4ee
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5937867
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Elie Kheirallah <khei@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>
This is only needed when powerd feature is enabled.
When powerd is not enabled, this change allows devices to build without
the new system_api dependency.
BUG=372302460
TEST=android-merge-2-cargo-embargo.sh && verify no new libdbus
dependency
Change-Id: Ie20c6ea5721d6ec1800b91f9d35d7fdea04fbf4a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5936072
Commit-Queue: Devin Moore <devinmoore@google.com>
Auto-Submit: Devin Moore <devinmoore@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@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 all-android features were indented by 8 spaces, unlike the other
feature sets, which use 4 spaces. Additionally, the fs_runtime_ugid_map
feature used a tab instead of spaces, which confuses some editors.
No functional change.
BUG=None
TEST=`git diff -w` is empty
Change-Id: Ic67de3e4daad094b9a97848a1f0cafece2b77c15
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5935132
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
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>
If we defer the gdb tube creation until `run_control`, we don't need to
pass the tube around as much.
TESTED=connect with gdb and step through some instructions
Change-Id: I2821ad6353afaa09167acc08e3324d57c70f59dc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5926547
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
This change defines a new enum that captures most of the types of tubes
connecting the devices and the control threads. During device creation,
all the tubes are gathered into one big list and then, in `run_control`,
they are sorted out into separate lists based on the implementation
details of the control threads.
Change-Id: I11de36543d6a4b07acd88b20f96e9690c843d78b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5923038
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Nixpkgs devs report a regression with crrev.com/c/5747102
"A Tube is always a SOCK_SEQPACKET socket on Linux,
so this changed the base channel socket from SOCK_STREAM
to SOCK_SEQPACKET, which is not correct for a Wayland
socket. This caused connections to the Wayland socket
to fail with EPROTOTYPE."
BUG=372776092
TEST=run a cross-domain vhost-user gpu device
Change-Id: Id7389fb0a2722be4ac97a4a5a4b8140395191c7d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5924626
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@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>
This Cl adds powerd client in powerd module. The power client is a
blocking client that serves to send dbus request to powerd and receive
response. Currently, only GetPowerSupplyProperties dbus request is
supported. The GetPowerSupplyProperties will be used in following CLs.
BUG=b:361281568
TEST=cargo build --features=power-monitor-powerd
Change-Id: I5e9714bdd10ac3d5906995dfa35c34dd360f4567
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5915194
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
Use the GuestMemory get_slice_at_addr() function to ensure the memory
regions corresponding to the descriptor table and used/avail rings are
actually contiguous, rather than just validating the ending address of
each region exists in guest memory.
The log region is currently not validated, which matches previous
behavior.
BUG=None
TEST=tools/dev_container tools/presubmit
Change-Id: I1e80326dfae085380fbbf4dd1c7960dd72485793
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5922041
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Move the init_balloon_size calculation to be closer to the ballon device
creation (so it doesn't need to be passed through multiple layers of
setup functions), and provide a more useful error message when an
invalid --init-mem is requested ("failed to calculate init balloon size"
was pretty meaningless).
Change-Id: I9bb65658a3b9b19ba28c023714271ef4195f052d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5923832
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This CL splits the powerd monitor implementation to individual module to
keeps codes clean. Also, it renamed the mod.rs to powerd.rs.
BUG=b:361281568
TEST=cargo build --features=power-monitor-powerd
Change-Id: I149559ae2b46fc7277818fc14f01dea0ec1c8fee
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5921215
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
This CL adds power_manager D-Bus bindings, which will be used in a
follow-up CL. Also updates other bindings as a result of running
update_bindings.sh.
BUG=b:361281568
TEST=./update_bindings.sh
TEST=emerge-<BOARD> crosvm
Change-Id: I1411d1b07f8a99bab6d6af45fb32649d83cbadf5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5883998
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Yuan Yao <yuanyaogoog@chromium.org>
These are no longer used anywhere in crosvm and can be cleaned up.
BUG=b:301269927
Change-Id: Ia3d2c38fe69e223b1453b72e4e87764c5db18380
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5918013
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
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>
Add vmexit tracepoints to better track how many vmexits we are getting
by type via perfetto.
Test: ran with haxm and gathered perfetto trace
Change-Id: I1bc111cc2f01e252a1d28942aae521ed48f0a94f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5906314
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>