Commit graph

838 commits

Author SHA1 Message Date
Jorge E. Moreira
3a5178e3b2 Error on stream creation no longer blocks stream ids
BUG=b:184059723
Change-Id: I553b77e5557e6c2058d4bacac96093736dfb8c86

Change-Id: I226e6eeb92b3d9e73fe5fcfbf43e2fa61bc2033c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2854381
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: Dylan Reid <dgreid@chromium.org>
2021-05-20 00:56:46 +00:00
Tomasz Jeznach
f622e504d3 crosvm/kvm: enable runtime detection of IOAPIC pins
Enable support for runtime verification of number
of irqchip kernel emulated inputs, up to 120 pins.

KVM implementation supporting extended input pins shall
report KVM_CHECK_EXTENSION/KVM_CAP_IOAPIC_NUM_PINS value.

BUG=b:179648314
TEST=On systems with 24/120 pin IOAPIC kvm emulation.

Change-Id: I80063216310e427d664e3eaca3aba27e8a972cde
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2893366
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-05-20 00:37:59 +00:00
Keiichi Watanabe
ac63740cf7 devices: virtio: Remove unused method
Remove `VirtioDevice::acked_features()` which is unused.

BUG=none
TEST=build

Change-Id: I35323bb67b23e0d739a100643a81a890919df589
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2902072
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2021-05-18 18:52:33 +00:00
Keiichi Watanabe
03f4c754d7 devices: net: Avoid causing busy loop for interrupt resample
We must have read the resample event before calling
`SignalableInterrupt::do_interrupt_resample`.

BUG=b:179755448
TEST=run crosvm with net device

Change-Id: Ic4bd74d3c89cc8af69401d2c1ebc095a474fba04
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2902057
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2021-05-18 18:52:29 +00:00
Chirantan Ekbote
82cddfef8e net: Switch to thiserror
BUG=none
TEST=cargo build

Change-Id: Iec87dca59eb577e01fb772efb11bb435174d482f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2894325
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2021-05-17 11:23:24 +00:00
Chirantan Ekbote
c4ce3791e9 wl: Fix unused_imports and dead_code warnings
These functions are only used when the gpu feature is enabled.

BUG=none
TEST=`cargo build` and see no warnings

Change-Id: I8c354b0122032a6d6c57d16837d9d9e857ac03c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891122
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-05-17 11:23:22 +00:00
Alexandre Courbot
e1dff2eef8 virtio: video: decoder: add format getters to Capability
Capability is read-only once it has been built, so access its members
using getter methods instead of making them public.

BUG=b:169295147
TEST=cargo build --features="video-decoder"

Change-Id: Ia5d30d94a04fc9b4e87d783c85b3ab5650ca9815
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891135
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-05-14 05:32:22 +00:00
Alexandre Courbot
b77b936d42 virtio: video: encoder: make encoder own its VEA instance
The current design of having the VEA instance outside of the encoder was
mandated by the use of lifetimes on libvda Sessions, which have been
removed from libvda. So it is now possible for the encoder to own its
VEA instance.

This makes sense in itself since there is no reason for the VEA instance
to also be used by someone else, but is also required to add support for
non-libvda encoder backends.

BUG=b:169295147
TEST=arc.VideoEncodeAccel.h264_192p_i420_vm passes on hatch-arc-r

Change-Id: Idb4356dde6124f00d87915da7da0910c7d816863
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2887526
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Staessens <dstaessens@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-05-13 04:41:13 +00:00
Alexandre Courbot
0b96ae0720 virtio: video: encoder: remove lifetimes on VEA instance/sessions
The libvda API has been changed and both instances and sessions do not
use lifetimes anymore. Remove them from our code or it won't compile.

BUG=b:169295147
TEST=arc.VideoEncodeAccel.h264_192p_i420_vm passes on hatch-arc-r

Cq-Depend: chromium:2887389
Change-Id: I9821e7f3b92b89fceb843fb0e60d041a44602f20
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2887525
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Staessens <dstaessens@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-05-13 04:40:59 +00:00
Daniel Verkamp
a8423d73c3 devices: pass MMIO and IO bus to PciRoot::new()
This will be used to dynamically add and remove bus ranges when the PCI
command register is updated to enable/disable memory and IO decode.

BUG=b:174705596
TEST=cargo test -p devices

Change-Id: I6bb175e0628bf598d049562700e2f55a2a62df59
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2689081
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2021-05-12 00:09:37 +00:00
Keiichi Watanabe
8c817dd349 vhost_user_devices: Add vhost-user net device
Add a vhost-user net device executable which communiates with a VMM having vhost-user net device.

Example command:
vhost-user-net-device \
         --tap 10.0.2.2,255.255.255.0,12:34:56:78:9a:bc \
         --socket /tmp/vhost-net.sock

BUG=b:179755448
TEST=run as a backend of crosvm with vhost-user net device

Cq-Depend: chromium:2861979
Change-Id: Ib723cdd00381b29464855378e568a9fa3de01536
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2807205
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-05-11 18:34:40 +00:00
Keiichi Watanabe
8e7bc96616 Add vhost_user_devices crate
Add `vhost_user_devices` crate which will be used to create a vhost-user
device executables.

BUG=b:185089400
TEST=cargo test in /vhost_user_devices

Change-Id: I7256d68316f7763d3ceaa65abc97663975e7608f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2822169
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-05-11 18:34:39 +00:00
Keiichi Watanabe
8ec40a7fa0 device: vhost: user: Fix offset of GET_CONFIG
BUG=none
TEST=run vhost-user block vmm with dpdk

Cq-Depend: chromium:2861979
Change-Id: I7cf6694338b3eadf910e85af7c0db85805e32451
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2856171
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2021-05-10 13:08:00 +00:00
Daniel Verkamp
7fb40344ff devices: pci: add PciDevice function to get BARs
This will be used to enumerate BARs when the command register is updated
to enable/disable memory or I/O decode.

BUG=b:174705596
TEST=cargo test -p devices

Change-Id: I992a2004dc58955b464467914c4ad735fb2cdd44
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2689085
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2021-05-07 00:37:49 +00:00
Daniel Verkamp
2da1f27fd5 devices: vfio: use PciBarConfiguration struct
Replace the VFIO-specific MmioInfo and IoInfo structs with
PciBarConfiguration.

This will allow a unified interface for retrieving BAR information for
all PciDevice implementations; all other PciDevices use PciConfiguration
to store a list of PciBarConfiguration, so this brings VfioPciDevice in
line with those.

BUG=b:174705596
TEST=cargo test -p devices

Change-Id: Idafd8f9af2ce817877450cfb842805475785ba20
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2689084
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2021-05-07 00:37:49 +00:00
Daniel Verkamp
8954f04e82 devices: pci: add config support for ROM BAR
Extend PciBarConfiguration to support the expansion ROM BAR in addition
to the usual 6 BARs.

This will be used when adapting vfio_pci to use PciBarConfiguration.

BUG=b:174705596
TEST=cargo test -p devices

Change-Id: I712728def41b0f2981029d77c3b9d7ec065e9d9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2689083
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2021-05-07 00:37:48 +00:00
Daniel Verkamp
b2b4d8cabf devices: pci: PciBarConfiguration cleanup
- Consistently use reg_idx to represent an index into all PCI
  configuration space registers and bar_idx to represent an index into
  just the BAR list. (e.g. bar_idx 0 is at reg_idx 0x10).
- Add a PciBarIndex type to make the related APIs clearer versus using
  usize directly.
- Remove Default impl for PciBarConfiguration and fix up the previous
  callers to fully configure the BAR type instead of depending on the
  defaults.
- Omit "get_" from the names of getter functions to follow Rust
  convention.

BUG=b:174705596
TEST=cargo test -p devices

Change-Id: I6921ac627f51e0df9c07585545be031ac3055a7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2689082
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2021-05-07 00:37:46 +00:00
Daniel Verkamp
18750c09df devices: acpi: collapsed nested if inside else
Fixes a new clippy warning ("this `else { if .. }` can be collapsed.").

BUG=None
TEST=bin/clippy

Change-Id: I58aec38b9fac6b7cbdcfe62e81e3b38ca3373a4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2864370
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-06 22:06:57 +00:00
Daniel Verkamp
d8ff7fa7e4 devices: fix redundant ? inside Ok
Fixes a new clippy warning ("Question mark operator is useless here").

https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark

BUG=None
TEST=bin/clippy

Change-Id: I2888f070030d2838b8fb63e5d98a929f57cdfde7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2864369
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-06 22:06:57 +00:00
Daniel Verkamp
8f325301ec devices: vfio_pci: rewrite nested ifs as match
Simplify a lookup against two boolean variables that was implemented as
a nested set of ifs as a single match.

This also fixes a clippy warning about nested if inside else.

BUG=None
TEST=bin/clippy

Change-Id: Ia8e57a87dc5555ba505bcca67912eef978db0420
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2864366
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-06 22:06:54 +00:00
Daniel Verkamp
c7215b5dc4 devices: vfio: use vec![] in keep_rds
Replace an instance of Vec::new() followed by push to fix a new clippy
warning and simplify the code.

BUG=None
TEST=bin/clippy

Change-Id: Ie216df8ce5dcc12f5a2cceda8e322303804b451d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2864365
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-06 22:06:54 +00:00
Daniel Verkamp
19a12403cf devices: vfio: take a slice instead of Vec for irq_enable
Generalize the irq_enable() interface to accept a slice instead of a
Vec.  This also fixes a few instances of the new clippy warning about
calling Vec::new() immediately followed by inserting items.

BUG=None
TEST=bin/clippy

Change-Id: If4c66999a245f340f54c96ccafc904c99bedf1ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2864364
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-06 22:06:53 +00:00
Daniel Verkamp
548754cd2f Specify file paths via Path instead of PathBuf
Many functions took a reference to PathBuf, but then just passed the
parameter to File::open(), so they can be changed to a reference to
Path instead to avoid a potential allocation.

https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

BUG=None
TEST=bin/clippy

Change-Id: Ife5a52df2ba16da1ce1307efb2fe921cd8b4f956
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2862581
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-06 22:06:51 +00:00
Zach Reizner
dc74848b7c arch: Simplify build_vm by removing closure parameters
These parameters multiplied the number of type arguments to build_vm
unnecessarily and complicated the thread of execution in the programmers
head. Closures also complicate the borrow rules, making things much
harder to change.

This change uses the results of the closures (e.g. PCI devices, IRQ
chips) as parameters instead. The rest of this change follows naturally
from pulling on that thread until tests pass.

As a result of the removal of several type arguments, the code size was
reduced by ~100KiB on a 5MiB build.

BUG=b:185170486
TEST=./test_all

Change-Id: I6bcc5eb1b1f3031d4328bb4a81ddef618d04767b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2829136
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-05-06 16:31:49 +00:00
Allen Webb
e6c584a6aa devices: Deduplicate mapped file descriptors.
A bugfix to minijail made the logic more strict so deduplicate the
mapping requests before giving them to libminijail.

BUG=b:2591867,chromium:1198756
TEST=CQ passes

Change-Id: Ide397e9aa82b493418d8ac4e51a73af649295424
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2851078
Tested-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Allen Webb <allenwebb@google.com>
2021-05-03 23:09:47 +00:00
Gurchetan Singh
538128dc98 data_model: add flexible_array_impl! macro
- Removes duplicated code
- Assumes "u32" as the type of the flexible array
  length field, which should be fine.

BUG=b:173630595
TEST=compile and run

Change-Id: Ia2d9f74b823e06d2f2f0b60cebb8a3b999a9cba0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2848283
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2021-04-30 20:49:53 +00:00
Daniel Verkamp
6ded64f192 unblocked_terms.txt: clean up trivial cases
Avoid some easily-replaced non-inclusive words and remove them from the
unblocked_terms.txt list.

Remove a clippy lint with a name matching the list since all affected
warnings have already been removed.

Remove all terms that are already not present in the crosvm
repository from unblocked_terms.txt (including the commented lines).

BUG=b:178821708
TEST=../dev/contrib/search_blocked_words.sh unblocked_terms.txt
TEST=cargo test -p devices
TEST=cargo test -p disk
TEST=bin/clippy

Change-Id: I8261921380decc839f01adb9ad1d4d14d5a85114
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2847462
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-04-26 20:32:38 +00:00
Alexandre Courbot
62a57e9656 virtio: video: decoder: remove LibvdaSession struct
This structure only embeds libvda::decode::Session, so we can directly
implement our traits on it. Doing so is actually more consistent with
the way the rest of the module is implemented.

BUG=None
TEST=cargo build

Change-Id: Ib03481ae91affca03cff21829e09d6d94731f78d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2845634
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-04-25 07:13:23 +00:00
Alexandre Courbot
e604c331e6 virtio: video: decoder: make decoder own its VDA instance
The current design of having the VDA instance outside of the Decoder was
mandated by the use of lifetimes on libvda Sessions, which have been
removed from libvda. So it is now possible for the Decoder to own its
VDA instance.

This makes sense in itself since there is no reason for the VDA instance
to also be used by someone else, but is also required to add support for
non-libvda decoder backends.

BUG=b:169295147
TEST=Video plays correctly on hatch-arc-r.

Change-Id: I7cbafbb48373a25195de07e954846e1bd9f1cc0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2839464
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-04-25 07:13:22 +00:00
Alexandre Courbot
10722b260e virtio: video: decoder: remove lifetimes on VDA instance/sessions
The libvda API has been changes and both instances and sessions do not
use lifetimes anymore. Remove them from our code or it won't compile.

BUG=b:169295147
TEST=cargo build --features="video-decoder"

Cq-Depend: chromium:2838714
Change-Id: I7ba771abcdddfc4bc366dc38e37c0568ce5a9cb3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2845633
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-04-25 07:13:16 +00:00
Gurchetan Singh
33079335ad gpu_display: rustify error handling
As new features are about to be added, it only makes sense to
improve error handling first.

Also improve/update naming of errors in other GPU-focused areas.

BUG=b:173630595
TEST=compile and run

Change-Id: If0d4f8b7d548c46f0a15b64699502e0fefeaae3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2844350
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2021-04-23 22:51:59 +00:00
Daniel Verkamp
ff1ed69c6b devices: usb: filter unclaimed interfaces
Replace the interface descriptors for unclaimed interfaces with
vendor-specific class codes so that the guest driver does not attempt to
bind to them.

BUG=b:180238956
BUG=chromium:1030778
TEST=Attach YubiKey, Circuit Playground Express to Crostini

Change-Id: Ia2826479c470e6f8a6dff21fe12e6c4bb5fd2efa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2811862
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-04-22 17:25:25 +00:00
Daniel Verkamp
425e4aad1e devices: usb: clean up intercepted_control_transfer
Rearrange the control request type match to check the request and
recipient together in a tuple (along with direction, which will be
different for a Get Descriptor request, to be added in the next commit).

No functional change.

BUG=b:180238956
BUG=chromium:1030778
TEST=Share USB device with Crostini

Change-Id: I51badd8f8b067a5e19216a92257c2b75c2041663
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2811860
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2021-04-22 17:25:23 +00:00
Daniel Verkamp
7b17f50df9 devices: usb: claim interfaces on device creation
This initializes the claimed_interfaces list at startup (before the
first Set Configuration request).  It also makes it possible to catch
initialization errors earlier in the process of adding a device, before
it is added to the emulated USB hub.

BUG=b:180238956
BUG=chromium:1030778
TEST=Share USB device with Crostini

Change-Id: I6f27ec9b7ff6cda2ff23cadd77611f8ce1cfc89e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2811859
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-04-22 17:25:22 +00:00
Daniel Verkamp
d3935a5702 usb_util: assume active config for single-config devices
When there is only one configuration listed in a device's descriptors,
assume that configuration is the active one without needing to send a
blocking control request to get the active configuration from the
device.

This moves the logic used in the USB host device code into usb_util, so
it will be used for all callers of get_active_configuration().

BUG=b:180238956
BUG=chromium:1030778
TEST=Share USB device with Crostini

Change-Id: I71a7d12a7edcd1fd0d063af58f63708b3dbda348
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2811858
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-04-22 17:25:21 +00:00
Jorge E. Moreira
6021705055 Improve code around creation of VioS recv thread
The mutex around the thread is locked-unlocked twice, the first time
just to check that something actually needs to be done, the second time
to check again and do it. The temporary release of the lock is to avoid
holding multiple locks while duplicating the fds and avoid the risk of
deadlock.

Change-Id: I455415dc32a31ae54025454f2709583e54a216b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2844354
Tested-by: Jorge Moreira Broche <jemoreira@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2021-04-22 00:21:40 +00:00
Allen Webb
82561b445b sys_util: Fix 1.51.0 acronym case clippy warnings.
This also fixes a self convention warning for sys_util::sock_ctl_msg and
removes a stray semicolon from ac97_bus_master.

BUG=None
TEST=cargo clippy && cargo test

Change-Id: I7fcf7577e09888836f7664d7127f94c9c24d3cfa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2840050
Tested-by: Allen Webb <allenwebb@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Allen Webb <allenwebb@google.com>
2021-04-21 00:14:11 +00:00
Jorge E. Moreira
8a5127b325 Delay the start of VioS recv thread until after sandbox
The recv thread was started immediately after the client object was created,
which caused minijail to abort refusing to fork a multithreaded process.

BUG=b/185811304

Change-Id: I5608e3b89eb4dfd944542d163e60b78937d37ba1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2837306
Tested-by: Jorge Moreira Broche <jemoreira@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2021-04-20 22:50:19 +00:00
Micah Morton
c5e7a4879e crosvm: vfio: allow forwarding of multiple non-MSI IRQs
For vfio-platform we will have many platform IRQs per vfio-platform
device, so we need to pass the irq index to these functions in this
commit, rather than inferring the IRQ index from the IRQ type (intx
vs msi vs msix).

In other words, this commit eliminates some assumptions in the common
vfio code that we are working with vfio-pci devices when doing vfio
passthrough.

BUG=b:185504618
TEST=cros_workon_make

Change-Id: Iaa02c387fb8a679217d4cc9dabecf7fc61f9c9fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2829293
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Micah Morton <mortonm@chromium.org>
2021-04-20 18:24:56 +00:00
Chih-Yu Huang
b5bc8082ec video: pass buffer modifier to decoder backend
In this CL, the decoder gets the buffer modifier via resource_bridge,
and then passes the value to the backend.

BUG=b:79682290
TEST=run media CTS and check the modifier is passed to GAVDA

Cq-Depend: chromium:2820734
Change-Id: I27b845251bf4a12efb74193945a6cb952c8f14af
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2821108
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: David Staessens <dstaessens@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2021-04-20 05:26:47 +00:00
Jorge E. Moreira
1e3cb9faa1 Conditionally apply linux-only operations
Rust's libc considers android to be different than linux and provides
certain functions exclusively for target_os = "linux".

BUG=b:185155959

Change-Id: I664821fd678f0c911deb9312fe5fcfc9faf00053
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2822209
Tested-by: Jorge Moreira Broche <jemoreira@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2021-04-19 19:58:32 +00:00
Chia-I Wu
6d473b3615 device: respect --gpu vulkan=true in GpuMode::ModeVirglRenderer
BUG=b:178104043
TEST=vkcube

Change-Id: I289612f567ddd8221b498de739c18454cb3d9e7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2823013
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Chia-I Wu <olv@google.com>
Commit-Queue: Chia-I Wu <olv@google.com>
2021-04-17 03:03:02 +00:00
Chia-I Wu
91df656291 devices: disable vulkan by default
Because the default value for mode is GpuMode::ModeVirglRenderer, make
the default value for use_vulkan false as well.

Set use_vulkan to true when mode is set to GpuMode::ModeGfxstream for
backward compatibility.

BUG=b:178104043
TEST=cargo build

Change-Id: Idf1417f04d23999cf5a03b0bf640973b69de93e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2823012
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Chia-I Wu <olv@google.com>
Commit-Queue: Chia-I Wu <olv@google.com>
2021-04-17 03:03:01 +00:00
Chia-I Wu
e25859becb devices: rename GpuMode::Mode3D to GpuMode::ModeVirglRenderer
BUG=b:178104043
TEST=cargo build

Change-Id: I0e549dbaf7e804e4a40104426ce58637b478fac2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2827237
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Chia-I Wu <olv@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chia-I Wu <olv@google.com>
2021-04-17 03:03:00 +00:00
Chia-I Wu
0beb246d8e devices: rename gfxstream_support_vulkan to use_vulkan
BUG=b:178104043
TEST=cargo build

Change-Id: Iefb316c41b8e485af3243e54b66ac7cd46ee7733
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2823011
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Chia-I Wu <olv@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Commit-Queue: Chia-I Wu <olv@google.com>
2021-04-17 03:02:59 +00:00
Dylan Reid
4786cee521 devices: Add a trait for Interrupt
Having a trait for interrupts used by queue and the devices allows for a
slightly different implementation to handle interrupting the guest when
using vhost-user.

Change devices to handle the resample event being optional as it is
handled on the VMM side with vhost_user.

Change-Id: I511d3db66a7986e7a2a8bce5f48285171dee3388
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2795284
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2021-04-15 19:38:31 +00:00
Gurchetan Singh
f860f50b8a rutabaga_gfx: cross-process Vulkan mappings
In multi-process mode, we currently rely on dma-buf mmap() to
map GPU buffers into the guest.  We usually have to fix the
Mesa driver, and maybe even the kernel to get to work.  That's
"kind of" fine for ChromeOS, which owns the entire stack.

For their Virtual Graphics Interface (VGI) initiative, Android
upstream has requested multi-process mode to work in a
cross-platform, generic way.  Using Vulkan is the only option
that meets the rigorous, uncompromising, strict, meticulous and
bone-crushing requirements of Android upstream.

This has possible two benefits:
  1) We can enable multi-process mode on Nvidia or other
     closed-source drivers, which is nice for Cuttlefish.

  2) On open-source drivers, dma-buf memory is pinned to the
     GTT (amdgpu), even when ideally it can be moved into faster
     vram regions.  This atleast gives the implementation the
     chance to do the smarter and faster option.

We shouldn't run into any SELinux issues since the main crosvm
process is not sandboxed.

Incidentals:
   * Changes vulkano_gralloc to consider integrated GPUs and dGPUs.
     Metadata query is preferred done on the integrated GPU.
   * Update vulkano_gralloc to match top of tree vulkano.

BUG=b:173630595
TEST=used Vulkano allocator and mapped memory into the guest

Change-Id: I78b069c7478d11b3201397894dcccd13bdc61f2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2792042
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2021-04-15 17:58:25 +00:00
Chirantan Ekbote
a00991cd84 Replace dup with fcntl(F_DUPFD_CLOEXEC)
Fds created via dup don't share file descriptor flags with the original
fd, which means that they don't have the FD_CLOEXEC flag set.  Use
fcntl(F_DUPFD_CLOEXEC) so that this flag gets set for the duplicated fds
as well.

BUG=none
TEST=unit tests

Change-Id: Ib471cf40acac1eacf72969ba45247f50b349ed58
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2809687
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2021-04-15 10:34:04 +00:00
Noah Gold
9af97d72fa [base] update/clean mmap interfaces.
This CL addresses some minor issues with the existing interface:
1. from_descriptor is too generic for some platforms that require
   special handling for file/File backed mappings.
2. Nearly all call sites pass either File or SharedMemory. Now
   we just have from_ methods for those types to preserve type
   information.
3. Other platforms require additional fields in MemoryMapping, so a
   tuple struct no longer makes sense.
4. The mmap syscall error message was misleading as we use it for more
   than just the mmap syscall.

BUG=None
TEST=builds

Change-Id: I74c41bad52bb81880a11231cd18f47e233548a24
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2815614
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2021-04-15 02:10:35 +00:00
Chirantan Ekbote
ac4d09d43d Use small vector optimization
WaitContext and Reader/Writer are in the critical path for every device.
Use small vector optimization to avoid making unnecessary small heap
allocations.

The smallvec crate is maintained by the servo authors and only has an
optional dependency on serde.

BUG=none
TEST=pre-cq

Cq-Depend: chromium:2687076
Change-Id: Ic0c57ac949e263b70b76495e3c9121dd8c2e1177
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2684062
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-04-14 06:37:47 +00:00