Commit graph

2510 commits

Author SHA1 Message Date
David Staessens
06d7c9edb9 virtio: video: Recreate encoder on framerate changes.
CL crrev.com/c/3005194 introduced changes to the encoder to allow
dynamic framerate changes even when there are already resources queued
in the input or output queue. As a side effect the encoder is only
recreated if any parameters besides the framerate change.

Unfortunately the above checks assumes that changing the framerate will
never influence any of the other parameters, which isn't always
correct. The requested H.264 level is adjusted to conform to the
minimum requirements for the selected bitrate and framerate. We can't
dynamically adjust the H.264 level during encoding, but as long as we
don't have any resources queued yet we can recreate the encoder to make
sure the H.264 level is properly adjusted if required.

BUG=b:192623395,b:192419592,b:193947502
TEST=android.media.cts.MediaRecorderTest#testProfileAvcBaselineLevel1

Change-Id: Ie02e30a5b6fb82b9b62e88ae3ab75c8ef42f3844
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3037296
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: David Staessens <dstaessens@chromium.org>
Commit-Queue: David Staessens <dstaessens@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2021-07-27 08:33:16 +00:00
Chih-Yang Hsia
b0423fd529 Revert "virtqueue: Try to further reduce unnecessary interrupts"
This reverts commit c6554e9c7e.

Reason for revert:

`time tast run mycros arc.Boot.vm` will always halt at

```
  Waiting for Android boot
  Waiting for initial ARC process
```
till timeout.

Original change's description:
> virtqueue: Try to further reduce unnecessary interrupts
>
> Try to reduce unnecessary interrupts by updating `signalled_used` every
> time we check `used_event` rather than only when we actually write to
> the eventfd.
>
> This technique is lifted out of the vhost_add_used_n and vhost_notify
> methods in drivers/vhost/vhost.c in the kernel and the variable names
> are changed to more easily compare the two implmentations.
>
> This combined with the other notification suppression changes give a
> performance improvement of ~10% across all storage devices in the
> blogbench benchmark.
>
> BUG=none
> TEST=vm.Blogbench.{p9,block,virtiofs}
>
> Change-Id: I618767e4c36ecae607b7641e54a029c25583844d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026691
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>

BUG=b:194452080
TEST=time tast run mycros arc.Boot.vm

Change-Id: Ib7511dec3e0df26be54616f20226ded598fc8a37
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3051292
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-26 07:00:57 +00:00
Chih-Yang Hsia
4dd683a354 ac97: Add timerfd operations to accepted list
Since CL:2999451, libcras is using timerfd features from `cros_async`,
we need to add timerfd operations to the accepted list of
`cras_audio_device`'s seccomp policy files.

BUG=b:179757101
BUG=b:194452080
TEST=tast run ${DUT_IP} arc.Notification.vm

Change-Id: I74b33fa1e304fccc95b7326e04bedc32feff85f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3047951
Auto-Submit: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-07-23 18:43:21 +00:00
Chirantan Ekbote
c6554e9c7e virtqueue: Try to further reduce unnecessary interrupts
Try to reduce unnecessary interrupts by updating `signalled_used` every
time we check `used_event` rather than only when we actually write to
the eventfd.

This technique is lifted out of the vhost_add_used_n and vhost_notify
methods in drivers/vhost/vhost.c in the kernel and the variable names
are changed to more easily compare the two implmentations.

This combined with the other notification suppression changes give a
performance improvement of ~10% across all storage devices in the
blogbench benchmark.

BUG=none
TEST=vm.Blogbench.{p9,block,virtiofs}

Change-Id: I618767e4c36ecae607b7641e54a029c25583844d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026691
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-23 13:00:07 +00:00
Chirantan Ekbote
1ac296b8d9 virtqueue: Re-enable notification suppression
Now that the get and set methods have the proper memory barriers it
should be safe to re-enable this.

BUG=none
TEST=crostini.Basic.buster_stable; reboot arcvm in a loop for 75
     iterations without observing a hang

Change-Id: I03271d838e31ad091536163359836bead7e00178
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026690
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-23 13:00:05 +00:00
Leo Lai
558460fe59 Revert "devices: irqchip: add need_halted function"
This reverts commit e470ef9933.

Reason for revert: possibly breaks critical test, in turn CQ.

Original change's description:
> devices: irqchip: add need_halted function
>
> This allows irqchip implementations to specify whether they need to be
> notified via the halted() function when the vCPU encounters a HLT
> instruction.
>
> All of the current in-tree irqchip implementations do nothing on
> halted(), so this will always return false for now, but a fully
> userspace irqchip would need these notifications.
>
> Querying this function will allow the hypervisor code to determine
> whether disabling VM exits on HLT instructions is allowed.
>
> BUG=b:181106085
> TEST=test_all
>
> Change-Id: I433fe208d125dcd14e7100ce5aff37474b423a83
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2937304
> Reviewed-by: Colin Downs-Razouk <colindr@google.com>
> Reviewed-by: Zach Reizner <zachr@chromium.org>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>

Bug: b:181106085
BUG=b:194452080

Change-Id: I755fc732e79a56f0306819e23ba9bd6c840dc927
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3045583
Commit-Queue: Leo Lai <cylai@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Leo Lai <cylai@google.com>
Auto-Submit: Leo Lai <cylai@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2021-07-23 06:41:40 +00:00
Jordan R Abrahams
e3c53096d7 seccomp: Update seccomp filters for glibc
At present, libraries which use glibc to dynamically load
shared libraries do not have fstafs in their seccomp policies.
A change in glibc will force all systems which load shared
libraries to call the fstatfs or fstatfs64 syscall.

Without the call, crosvm will not start when running
crostini/android tests.

BUG=chromium:1182687
TEST=CQ of https://crrev.com/c/2910526

Change-Id: I10abb8866474c2fe0398a17a80069cf2b0629493
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3011355
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jordan R Abrahams <ajordanr@google.com>
2021-07-22 17:08:20 +00:00
Daniel Verkamp
da4e8a9fcd arch: move resume_notify_devices out of Bus
The devices to be notified on resume are unrelated to the functionality
of Bus, which is looking up devices in an address space. Additionally,
each Bus instance had its own list of devices to notify, although in
practice, only the one in the I/O bus was used.

Move the resume_notify_devices list into RunnableLinuxVm instead.

BUG=None
TEST=Boot Crostini on x86 and arm

Change-Id: I72c629c6d6589c4a9350831c8a076c5c0c9f9aeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3043489
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2021-07-22 02:59:34 +00:00
Daniel Verkamp
ba4cf4d985 rand_ish: remove unused crate
BUG=None
TEST=./test_all

Change-Id: Iee374cac5da7e6f4e91b4d0b704c6f4c209bc2f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3017609
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-07-21 23:28:28 +00:00
Daniel Verkamp
5cf2691610 tests/plugins: replace rand_ish use with a counter
Rather than generating a random temporary file name for each plugin
generated by the test, just use a counter to ensure uniqueness.

This was the only remaining rand_ish user, so this change will allow the
removal of rand_ish.

BUG=None
TEST=cargo test --features=plugin

Change-Id: I8d42da97870db54a850f686826ca107255b8c3ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3017608
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-07-21 23:28:27 +00:00
Jorge E. Moreira
771a03b12f Add jack support in virtio-snd
BUG=b:174713663

Change-Id: I8b80edd33279ff5443895fa6ad4572d454d3fcec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983392
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-21 23:04:06 +00:00
Daniel Verkamp
e470ef9933 devices: irqchip: add need_halted function
This allows irqchip implementations to specify whether they need to be
notified via the halted() function when the vCPU encounters a HLT
instruction.

All of the current in-tree irqchip implementations do nothing on
halted(), so this will always return false for now, but a fully
userspace irqchip would need these notifications.

Querying this function will allow the hypervisor code to determine
whether disabling VM exits on HLT instructions is allowed.

BUG=b:181106085
TEST=test_all

Change-Id: I433fe208d125dcd14e7100ce5aff37474b423a83
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2937304
Reviewed-by: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-07-21 21:47:30 +00:00
Chirantan Ekbote
e63a531356 Enable VIRTIO_RING_F_EVENT_IDX in base_features
This should reduce the number of interrupts generated by the device as
well as the number of vm exits triggered by the guest for notifying the
device.

BUG=none
TEST=crostini.*; reboot arcvm in a loop for 30 iterations without
     observing a hang

Change-Id: Iea4a59092ba6306de9eecbb7722d0ae356183272
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026689
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-21 07:59:39 +00:00
Jorge E. Moreira
e75114e978 Add support for events in virtio-snd
BUG=b:174713663

Change-Id: I6b3044d95c4e6b74565c5adf3a00066b6c437be7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983391
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-07-21 01:25:14 +00:00
Junichi Uekawa
2a33360586 crosvm: Add a note on cros_workon_make.
It took me a while to realize the side effects making cargo fail.

BUG=None
TEST=read it.

Change-Id: I55db0e267452f865985d36d75c91a2314d117b06
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026652
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-07-21 00:26:07 +00:00
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