Commit graph

2645 commits

Author SHA1 Message Date
Keiichi Watanabe
5a01341edb Disable pre-upload hook
Stop running pre-upload hook because we have kokoro which runs clippy.

BUG=none
TEST=none

Change-Id: Iaa29a1785fdedca929c7c42f41c165066585c5ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3033234
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2021-07-20 18:31:30 +00:00
Chirantan Ekbote
1eb7712652 vhost-user-devices: Drop optional dependencies
Compiling different binaries with different sets of features means that
we also end up recompiling a bunch of dependencies every time.  Instead
just make the dependencies a superset of all crates/features needed by
all devices.

BUG=b:179755651
TEST=cargo test

Cq-Depend: chromium:3009693
Change-Id: Ic8faf2cbabd7b55b87d501639aee56ba5063de06
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987592
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-07-20 04:54:50 +00:00
Chirantan Ekbote
c950eb92c5 cros_async: Make file offsets optional
p{read,write} cannot be used on sockets even if the file offset is 0.
Make the file offset optional and fall back to regular read/write when
it is not set.

BUG=none
TEST=cargo test

Change-Id: Iff938aabe613b6164782714cfac94743d64f551a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3033233
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Woody Chow <woodychow@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-07-20 02:38:48 +00:00
Chirantan Ekbote
52c97d41bd tpm: Process all descriptors when notified
In order to enable the VIRTIO_RING_F_EVENT_IDX feature, devices need to
keep processing the queue until it is empty as the guest may not send
any more notifications until the device has processed all pending
messages.

Change the process_queue method to process all messages in the queue.

BUG=none
TEST=????

Change-Id: I7df56111ad99bc7511c685ecafc051aef077b34e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026688
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-20 02:28:41 +00:00
Chirantan Ekbote
378e338f12 virtqueue: Remove update_int_required
When the VIRTIO_RING_F_EVENT_IDX feature is enabled we will
automatically update avail_event when a descriptor from the queue is
popped.  Having update_int_required set this to a different value means
that it would keep going back and forth.

BUG=none
TEST=crostini.Basic.buster_stable

Change-Id: I9098259c306cf19c034656169ee0e70ad69d1c64
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026687
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-20 02:28:40 +00:00
Chirantan Ekbote
c013a658e2 devices: Trigger interrupts via the Queue
Have all devices trigger interrupts via the Queue rather than directly.
This way we can skip sending the interrupt entirely when notification
suppression features have been negotiated with the guest kernel.

BUG=none
TEST=crostini.Basic.buster_stable

Change-Id: Ica6f978127aa648fd983f641518940d7a857916f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026686
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-20 02:28:39 +00:00
Junichi Uekawa
f8fff1c5bf qcow_img: Fix warning message.
warning: panic message is not a string literal
  --> qcow_utils/src/qcow_img.rs:52:26
   |
52 |         Err(f) => panic!(f.to_string()),
   |                          ^^^^^^^^^^^^^
   |
   = note: `#[warn(non_fmt_panic)]` on by default
   = note: this is no longer accepted in Rust 2021
help: add a "{}" format string to Display the message
   |
52 |         Err(f) => panic!("{}", f.to_string()),
   |                          ^^^^^
help: or use std::panic::panic_any instead
   |
52 |         Err(f) => std::panic::panic_any(f.to_string()),
   |                   ^^^^^^^^^^^^^^^^^^^^^^

warning: 1 warning emitted

BUG=None
TEST=build

Change-Id: I06a18610b455e57c9c9813513963385749fad17c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026651
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-20 01:33:20 +00:00
Jorge E. Moreira
227beb25c9 virtio-snd: Add support for channel maps
BUG=b:174713663

Change-Id: If04128763823ed82a6267a8a50c25c9f3d8df6f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983390
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-19 23:00:23 +00:00
Jorge E. Moreira
d4562d0ab5 Partial implementation of the virtio-snd device
Supports everything related to pcm streams, but not jacks or channel
maps.

BUG=b:174713663

Change-Id: I16f44d66fc7580a94eda91383d46cb52f9513eee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983389
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-19 17:38:51 +00:00
Peter Fang
e42a43d880 acpi: add _SB.PCI0 to DSDT
Supply the OS with basic PCI hostbridge information (PIO region, MMIO
region, etc) using Device (_SB.PCI0) in DSDT. Without this info the
Linux kernel behaves erroneously in iova_reserve_pci_windows().

Output from the Linux kernel, w/o _SB.PCI0:

    pci_bus 0000:00: root bus resource [mem 0x00000000-0x7fffffffff]

Since DSDT contains PCI hostbridge information, ACPI is always required.

Use "acpi=noirq" in cmdline when DSDT/MADT is not provided by the user.
The Linux kernel refers to PCI configuration space for interrupt
routing.

BUG=b:181736020
TEST=boot Linux kernel and check dmesg

Change-Id: Id328a958fb770e087788e71fe480839eab4f40c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2846422
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-19 06:29:46 +00:00
Zide Chen
4638906314 devices: allow vfio_dma_map() to map read only guest memory
This is needed because virtio IOMMU may not allow writes to mapped
memory if VIRTIO_IOMMU_MAP_F_WRITE flag is not set in driver MAP
request.

BUG=b:181736020
TEST=--vfio=/sys/bus/pci/devices/0000:00:14.0,iommu=on

Change-Id: I2c101410594782f1b66b3f6ae527d4a7621b7496
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2757279
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-19 06:29:46 +00:00
Zide Chen
71435c1aea devices: virtio: iommu: implement VIRTIO_IOMMU_F_INPUT_RANGE feature
In VT-d, the IOMMU hardware can translate guest physical address that
is no more than MGAW (Maximum Guest Address Width) which is reported
from the VT-d Capability register.

We pass this information to the guest IOMMU front driver so that it
can allocate appropriate IOVA.

VT-d indicates that "implementations must support MGAW at least equal
to the physical addressability (host address width) of the platform".
Thus we take the Physical Address Bits that is reported by
CPUID.80000008H as the minimum MGAW.

BUG=b:181736020
TEST=--vfio=/sys/bus/pci/devices/0000:00:14.0,iommu=on

Change-Id: I26a421ea2e7dd893d413d63ab313721cfdf0b5c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2757278
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2021-07-19 06:29:44 +00:00
Federico 'Morg' Pareschi
762d609366 vhost_user_devices: Add in/out files for console
This change allows us to redirect in/out streams for a vhost user
console device to any file. This means we can assign individual PTYs for
input/output redirection to the host VM.

Example command:

vhost-user-console-device --socket $SOCKET --output-file $OUT_FILE \
                          --input-file /dev/pts/$NUM

You can `echo <message> > /dev/pts/$NUM` to send input signals to the
VM, and `tail -f $OUT_FILE` to monitor the output in real time as it is
written to a file.

BUG=b:192517623
TEST=run vhost-user-console-device with --output-file and --input-file

Change-Id: Iee0929d63d39848f2626c17e440d6d9368ae2d0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026359
Auto-Submit: Morg <morg@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Morg <morg@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-16 10:20:52 +00:00
Louis-Francis Ratté-Boulianne
775aa4f594 virtio: gpu: add support for non-blocking fence synchronization
A completed fence callback is set in Rutabaga. When the callback
is executed, the descriptor associated with the fence is immediately
marked as used and the control queue is signalled.

As of now, the callback is still called in the main worker thread
when poll_fence() is executed, but once we enable the async callback
feature in virglrenderer, the callback might be called from another
thread. This is the reason everything is protected with mutexes.

The completed_fences hash map keeps track of the latest completed
fence for each context to avoid any race condition.

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Change-Id: I6f3f55d21b7f4722721bdc2b16da1b39bae4ff7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2845984
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2021-07-16 02:22:53 +00:00
Chirantan Ekbote
2f879fb2be cros_async: Add spawn_blocking()
Add a spawn_blocking() method to the Executor so that users don't need
to manually create a BlockingPool every time they need to do some
blocking work.

BUG=b:179755651
TEST=cargo test

Change-Id: I70d111d98a4c51af4bc8ed8181a4b102bf3c2ffa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987586
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-07-15 23:18:23 +00:00
Chirantan Ekbote
f95a1df7d2 virtqueue: Add missing fences
These values are either written by the device and read by the guest or
vice versa.  Either way, since these could happen simultaneously on
separate cores we need fences to prevent the CPU from re-ordering loads
and stores.

"get" methods use acquire-load semantics while "set" methods use
release-store semantics.  This also matches what we were already doing
for "get_avail_index" and "set_used_index".

With this it should be possible to re-enable the check for
VIRTIO_AVAIL_F_NO_INTERRUPT but we'll do that in a separate change since
we need these changes no matter what.

BUG=none
TEST=crostini.Basic.buster_stable

Change-Id: I2d52c92fbd7ab0fe6d64693d60f46d0dec4b4cb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026685
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-07-15 19:27:13 +00:00
Andrew Walbran
bc55e30b89 Handle /proc/self/fd/N specially for composite disk components and QCOW2.
Follow-up to https://crrev.com/c/3000986.

BUG=b:192256642
TEST=cargo test

Change-Id: I08c87f9295e3c8d977c6028e5d8d7e8beeafbaec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3024191
Auto-Submit: Andrew Walbran <qwandor@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-15 08:33:52 +00:00
David Staessens
563008fc99 virtio: video: Support dynamic framerate changes in encoder.
Currently changing the framerate during video encoding will always fail
once resources are queued on the input or output queue. This CL makes
adaptations to the crosvm encoder to fix dynamic framerate changes.

To support dynamic parameter changes the crosvm encoder will now
properly check whether values actually changed, and only report an
error if we're trying to change static parameters during encoding (such
as the output format). As a side effect this greatly reduces the amount
of times the Chrome encoder is recreated; parameters are configured
one-by-one through virtio and each parameter change requires us to
initialize an encoder, as we only know the coded size after the
initialized encoder calls the RequireBitstreamBuffers() callback.

BUG=b:192623395,b:192419592
TEST=android.media.gts.RtcVideoCodecTest#testDynamicFramerateChangeVp8

Change-Id: I20e60013dbdf9f4b139c795f503c6a08a7d3e6e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3005194
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Staessens <dstaessens@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2021-07-15 04:37:39 +00:00
Allen Webb
c6fa73d76f Fix clippy warnings and Cargo.lock
This fixes:
* version mismatches in Cargo.lock
* style issues
* implementations of Into that should be From
* deprecated protobuf APIs

It also adds RUST_BACKTRACE=1 to the kokoro tests.

BUG=None
TEST=./bin/preupload-clippy

Change-Id: I8e9157c903f2080a5fdcc4d3e4ed72fbad41c64f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3024427
Auto-Submit: Allen Webb <allenwebb@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Allen Webb <allenwebb@google.com>
2021-07-15 03:33:17 +00:00
JaeMan Park
eb9cc53dee Add vhost-user of mac80211_hwsim at crosvm
Add vhost-user device of mac80211_hwsim that connects to
the unix socket of vhost server for mac80211_hwsim for
emulating Wifi device at crosvm.

Add cmdline flag --vhost-user-mac80211-hwsim for
specifying unix socket path to connect.

BUG=b:182577273
TEST=At Android's source tree,
     lunch aosp_cf_x86_64_phone-userdebug &&
     m PRODUCT_ENFORCE_MAC80211_HWSIM=true &&
     launch_cvd \
     --vhost-user-mac80211-hwsim=${VHOST_SOCKET_PATH}
     Check AndroidWifi appears at wifi connection settings.

Change-Id: I33e5d8fed59c84d3848bfe24d935ce973d758e12
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3020848
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: JaeMan Park <jaeman@google.com>
2021-07-14 23:14:05 +00:00
Chirantan Ekbote
6074d45aeb cros_async: Don't use io_uring on kernels < 5.10
Kernels before 5.10 had known bugs in the io_uring implementation.
Don't use io_uring when we detect this.  Also skip all the io_uring
tests in this case.

BUG=none
TEST=cargo test

Change-Id: I5fd6203ad25a6fb85ff28f1a6ddb0181f836ad89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3006309
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Woody Chow <woodychow@google.com>
2021-07-14 09:42:39 +00:00
Jorge E. Moreira
313f5133dc Add more functionality the virtqueue Writer interface
This adds get_remaining() and consume_bytes(), which behave like its
counterparts in Reader.

BUG=b:174713663

Change-Id: Ie9c73e7993fbdb609150c5a01bc3ed9100552109
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2993560
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-14 00:59:43 +00:00
Chirantan Ekbote
f3ff0a88d9 arch: Keep GuestMemory descriptors in child processes
Make sure that file descriptors associated with GuestMemory are
inherited by each child process.  Not inheriting them means that
GuestMemory thinks it owns a bunch of fds when it actually doesn't and
closing them in the child process would either lead to EBADF errors or
closing some unrelated fd.

BUG=none
TEST=CQ

Change-Id: I5475f3f9cc24cc62522066b8535693f95327cd92
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3023805
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-13 18:46:07 +00:00
Pierre-Clément Tosi
86d5b199bc aarch64: Only enable pVM once umem allocs are done
Move the call to enable_protected_vm past the PVTIME memory region
allocation introduced by 895c90c5f2 ("aarch64: Implement
ARM_VCPU_PVTIME for "stolen time" accounting"). As such allocation is
prohibited once protected VM mode has been enabled (Kernel returns
EPERM), which currently results in crosvm failing when started with
--protected-vm.

BUG=b:193231584
TEST=crosvm --protected-vm on a kernel with KVM_CAP_ARM_PROTECTED_VM

Change-Id: I2a97d3ff64ed59dd6679e51951c79e27bf290d5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3021126
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
2021-07-13 17:57:05 +00:00
Chirantan Ekbote
93e27733d8 cros_async: Add BlockingPool
BlockingPool provides a dedicated thread pool for running blocking
operations.  This is useful when an async task wants to do some
CPU-intensive computation, run some IO operation that cannot be
performed asynchronously, or to call a blocking API in a dependency that
doesn't have an asynchronous variant.

BUG=b:179755651
TEST=cargo test

Change-Id: I389fc504f380d66325739d2d6b7afe58e024194d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987585
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-07-13 17:02:37 +00:00
Federico 'Morg' Pareschi
53d7d1587a vhost_user_devices: Make console use SerialDevice
This change is a refactoring of the initial Console backend
implementation to make use of already-existing serial console
initialization code. It allows us to leverage from already-existing code
for alternative input/output files.

BUG=b:192517623
TEST=run crosvm with vhost-user-console and no changes are detected

Change-Id: I433cad1fac8f415173aee06b8ad1c96eb8f6690b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3023804
Commit-Queue: Morg <morg@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Morg <morg@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-13 16:46:16 +00:00
Jorge E. Moreira
82a8a76409 Prepare the VioSClient implementation to support a virtio-snd device
- Adds the ability to start/stop background thread on demand
- Changes the way audio data is injected to not assume how the data is
kept by users of the api
- Adds new functions for jacks and chmaps
- Rename constants to match the name used in the virtio-snd spec

BUG=b:174713663

Change-Id: Ie0fe20747a26122258cb63bac09ec0347f13ecc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983388
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2021-07-13 01:05:25 +00:00
Keiichi Watanabe
ef55773dd4 vhost_user_devices: Update VhostUserSlaveReqHandler interface
BUG=b:185089400
TEST=cargo test in /vhost_user_devices
TEST=run net device

Cq-Depend: chromium:2884020
Change-Id: I0fd2c9e1c6d97635356dc3e43ecfaf721a1fa5b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2884021
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-07-13 01:04:46 +00:00
Leonid Lobachev
0eed9a4ce3 usb: fix descriptors parsing for interfaces with multiple alternative settings.
Previous code assumed there's a single InterfaceDescriptor per
ConfigDescriptor's bNumInterfaces. Which means they can only have a
single alternative setting. However that isn't always the case.
For example Logitech C930E webcam has the following configuration:
Device Descriptor:
  bNumConfigurations      1
  Configuration Descriptor:
    bNumInterfaces          4
    Interface Descriptor:
      bInterfaceNumber        0
      bAlternateSetting       0
    Interface Descriptor:
      bInterfaceNumber        1
      bAlternateSetting       0
    Interface Descriptor:
      bInterfaceNumber        1
      bAlternateSetting       1
<skipped>
    Interface Descriptor:
      bInterfaceNumber        1
      bAlternateSetting      11
    Interface Descriptor:
      bInterfaceNumber        2
      bAlternateSetting       0
    Interface Descriptor:
      bInterfaceNumber        3
      bAlternateSetting       0
    Interface Descriptor:
      bInterfaceNumber        3
      bAlternateSetting       1
<skipped>

Trying to attach a device where this isn't true led to errors like this:
[transfer_ring_controller.rs:50] failed to send transfer to backend

Tested by attaching Logitech C930E webcam to VM and
./ci/builder 'cargo test -p usb_util'

Change-Id: Iab671bff26558838becbbafe0a43ed6dc220306c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983386
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Leonid Lobachev <leonidl@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-09 23:44:58 +00:00
Zide Chen
2f19cf0d95 devices: get all possible host IOMMU device supported page sizes
page_size_mask in IOMMU device configuration contains the bitmask of all
page sizes that can be mapped. It's good to get this information from host
VFIO/IOMMU driver, so that the guest is able to issue DMA mapping requests
with page size as large as possible to reduce the number of DMA map requests.

BUG=b:181736020
TEST=--vfio=/sys/bus/pci/devices/0000:00:14.0,iommu=on

Change-Id: I4c003473a48688cbdde0ff162dd0b414926d5c88
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2757277
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2021-07-09 05:49:27 +00:00
Zide Chen
dfc4b88040 devices: virtio: iommu: enable virtio IOMMU driver
By default virtio-IOMMU is disabled. It can be enabled per pass-through
device. Sample command lines:

default: virtio IOMMU disabled on pass-through device:
--vfio=/sys/bus/pci/devices/0000:00:02.0

Explicitly disable virtio IOMMU:
--vfio=/sys/bus/pci/devices/0000:00:02.0,iommu=off

Enable virtio IOMMU on the desired pass-through device:
--vfio=/sys/bus/pci/devices/0000:00:02.0,iommu=on

BUG=b:181736020
TEST=passthru one device with iommu=on
TEST=passthru two devices with iommu=on from different VFIO group
TEST=passthru two devices with iommu=on from same VFIO group
TEST=passthru one device with iommu=on and another device with iommu=off

Change-Id: Id74d2210f774a90ba5e83671e76e061cb8fec758
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2757276
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2021-07-09 05:49:26 +00:00
Zide Chen
337dc1cf1d devices: virtio: iommu: add virtio-iommu support
This is to backport virtio IOMMU backend driver from Cloud-hypervisor,
which emulates an IOMMU device to manage DMA from one or more endpoints
in the guest.

Some differences from the Cloud-hypervisor implementation:
- Simplified the mapping between IOMMU driver and Vfio container
- This port supports multiple endpoints attach to same IOMMU domain.

BUG=b:181736020
TEST=bin/clippy, functional tests specified in the patch
     "iommu: enable virtio IOMMU driver"

Change-Id: I3db3b46a72e82908459e91a4e6852a335c606db1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2846421
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2021-07-09 05:49:26 +00:00
Zide Chen
afdb938bc8 devices: vfio: prepare for vIOMMU support: multiple VFIO containers
In preparation for virtio IOMMU support, implement global variables
IOMMU_CONTAINERS and NO_IOMMU_CONTAINER to hold the VFIO containers
for VFIO devices with or without IOMMu enabled respectively.

Also implement vfio_get_container()help create VFIO container based
on the more complicated policies.

- all VFIO devices without attaching to virtio IOMMU devices share
  one VFIO container.

- for IOMMU enabled devices, one VFIO container manages all devices
  under one VFIO group.

- we don't support multiple IOMMU groups set to one VFIO container.
  Currently don't see an user case for this.

BUG=b:181736020
TEST=unit tests.

Change-Id: I44d792cbc8ca9696c1da54c571aad1b94c7f665d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2976054
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2021-07-09 05:49:25 +00:00
Zide Chen
5deee48856 devices: vfio: create KVM_DEV_TYPE_VFIO device from linux.rs
One KVM_DEV_TYPE_VFIO instance may be created per VM.  Currently this
device is created from VfioContainer::init(), which makes it not able
to create multiple vfio container.

This patch creates the KVM_DEV_TYPE_VFIO virtual device before creating
any VfioContainer or VfioDevice instances, and passes it into the
VfioDevice constructor where it's actually used.  In this way, it's
possible to create multiple VFIO containers

BUG=b:181736020
TEST=passthru multiple devices and create more than one VFIO containers

Change-Id: I4b4e4941363efa91f2217af385f4f00eadd041c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2976053
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2021-07-09 05:49:24 +00:00
Vikram Auradkar
f7979867d6 Cargo.toml: Sort features alphabetically
BUG=b:191669804
TEST=cargo test

Change-Id: Ibfddb00c8720b938fdc476dd268f7208492921fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3003923
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-07-08 21:41:46 +00:00
Vikram Auradkar
ede68c76ba base: Remove is_packet_ready
BUG=b:184398671
TEST=cargo test

Change-Id: I91770504ef95121246e75e29e9fd64fc32022fc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3002387
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-08 16:55:55 +00:00
Dennis Kempin
fa32ced1e0 Crosvm Externalization: Move libvda rust code into crosvm
Long-term libvda will be replaced with an implementation that can
function outside of ChromeOS.

In the meantime thes allows crosvm to be built externally and pass
clippy with all features enabled.

BUG=b:191507399
TEST=Tests in crosvm and cros_sdk both pass:
  $ ./test_all
  $ cros_run_unit_tests --package=crosvm

Cq-Depend: chromium:2989315, chromium:2986403
Change-Id: Ic37bda4426d69d16cb4bc0d7ba6f81052f6f2f59
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983505
Tested-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2021-07-08 05:32:04 +00:00
Nicholas Verne
fde29976b1 crosvm: deprecate wayland-dmabuf flag.
The flag sets a config option wayland_dmabuf which is
no longer used. Deprecating the flag first, then
a separate CL will remove it once callers no longer
set it.

BUG=b:192823933
TEST=cros_workon_make --board=nami crosvm --test

Change-Id: Iea0bc6d89ed8991351eecff357b43c8eb74c553b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3008479
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Reviewed-by: Fergus Dall <sidereal@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-08 02:12:33 +00:00
Dennis Kempin
75eef5f065 Docker: Do not curl | bash
Instead, download the rustup-init binary directly and verify it's sha
before executing.
Also update debian image used in the bundled VM. The previous image
file was no longer available.

TEST=Rebuilt docker images
BUG=b:192355221

Change-Id: I8a2d8091b9cecdf40ecbdd4bb6cef7ca161421d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3011343
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-07-07 23:55:27 +00:00
Chirantan Ekbote
5401edf519 Make vhost-user-devices a workspace member
We don't actually need vhost-user-devices when building crosvm so make
it a workspace member instead.

BUG=b:179755651
TEST=cargo test

Change-Id: Id39e37b3d2e59fd040e1c70a58d1b9b7f8380e36
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987591
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-07-07 19:00:44 +00:00
Andrew Walbran
fb7c108f15 Add methods to create composite disk image.
This can be used like:
crosvm create_composite composite.img partiton1:partition1.img partition2:partition2.img

BUG=b:190503456
TEST=cargo test

Cq-Depend: chromium:2982777, chromium:3008399
Change-Id: I31a9afe1e5f1e2a850ce1f892122150bcf3441b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2972869
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Andrew Walbran <qwandor@google.com>
2021-07-07 15:59:02 +00:00
Federico 'Morg' Pareschi
da1f83c0b3 vhost_user_devices: Add vhost-user console
Add a new vhost-user device binary implementation.

Example command to launch the device:
vhost-user-console-device --socket test

BUG=b:179755825
TEST=run crosvm with vhost-user-console and the console comes up

Change-Id: I4bb06e058523b73cb01fbe993e0fe7f9e4ee6423
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2951187
Auto-Submit: Morg <morg@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Morg <morg@chromium.org>
2021-07-07 03:55:04 +00:00
Chirantan Ekbote
eff60328c1 Add a From impl for async errors to io::Error
Sometimes users of cros_async need to return an io::Error.  Provide a
conversion function to convert the various async errors into an
io::Error.  This allows callers to access the underlying error without
forcing us to expose these internal implementation details.

BUG=none
TEST=unit tests

Change-Id: Ie0ab00cb80ea58f628a38c173e28babf30b8d5b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3006308
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-07-06 11:35:26 +00:00
Nicholas Verne
b57c124e86 crosvm: Delay RutabagaGralloc creation
RutabagaGralloc::new can cause a thread to be spawned
inside the crosvm process (via libgdm). This is not
allowed before crosvm has forked off its device
process children.

BUG=b:192823933
TEST=Build and deploy on nami, no problems detected with
Crostini graphics.

Change-Id: I9d86e299923c7c4ca3cdd6c54ad03c13e3011564
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3005196
Auto-Submit: Nicholas Verne <nverne@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Nicholas Verne <nverne@chromium.org>
2021-07-05 23:07:39 +00:00
Andrew Walbran
4cad30a560 Handle /proc/self/fd/N specially for kernel, bios and initrd.
This was already done for block device images, so reuse the same logic.

BUG=b:192256642
TEST=cargo test

Change-Id: Ifa69c0170ac39fc13eab61024d31e6ee5b2dd97c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3000986
Auto-Submit: Andrew Walbran <qwandor@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Andrew Walbran <qwandor@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-07-05 11:58:50 +00:00
Federico 'Morg' Pareschi
70fc7deb09 devices: virtio: Add vhost-user-console to the vmm
This adds a vhost-user console to the vmm, which will be enabled by
`--vhost-user-console <socket path>` option.

BUG=b:179755825
TEST=launch crosvm with --vhost-user-console and connection happens

Change-Id: I6339c6cde3a221fd3e6a1652474e17344c73d6d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2814058
Auto-Submit: Morg <morg@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Morg <morg@chromium.org>
2021-07-05 02:26:54 +00:00
Jason Macnak
64f1e3ac99 gpu_display: Fix up display destruction
Ensures that GpuDisplayImport and GpuDisplaySurfaces
are dropped before DisplayT (changed in crrev.com/c/2852523).

Also, call destroy on the new wayland surface metadata object
on drop.

BUG=b:189933900
TEST=launch Cuttlefish and `adb reboot`

Change-Id: I6718b03dc01e29c9b6e68189cf540a5a5cf93617
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3002149
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2021-07-02 19:28:45 +00:00
Alexandre Courbot
ab6c4822a6 virtio: video: decoder: pass output format along with number of buffers
The output buffers must all have the same pixel format, therefore it
doesn't make sense to pass it with each buffer we import. Instead, pass
it alongside the number of output buffers (before any buffer is
imported) and let the backend remember it.

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: I1890ad24f9874ed3c674a7bdf7d4be303ba24e92
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983094
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-07-02 14:43:36 +00:00
Alexandre Courbot
93d7a12cf9 virtio: video: decoder: use mutable references for state-changing methods
Methods that mutate the backend should take a mutable reference to self.
This problem was not apparent with the VDA backend since libvda's
methods themselves are not mutable, but this will cause issues with
backends that include more of their own data.

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: I61cc64b6cbb9f4d1633c6a0acc188bbfc8dd0c54
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983093
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-07-02 14:43:35 +00:00
Alexandre Courbot
ce6515a1c4 virtio: video: make Rect struct comparable
This is useful for e.g. unit tests.

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

Change-Id: Ica409926c9da6c788a60134fa3f609db97f4aaa4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983092
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: David Staessens <dstaessens@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-07-02 14:43:34 +00:00