Commit graph

858 commits

Author SHA1 Message Date
Daniel Verkamp
34d2b36a42 devices: irqchip: rewrite if-let-else None with ?
Replace an else block that just returns None with the equivalent use of
the question mark operator, and rewrite the comment that used to be in
the else block to match.

Fixes the clippy warning "this if-let-else may be rewritten with the `?`
operator".

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

BUG=None
TEST=bin/clippy
TEST=cargo test -p devices

Change-Id: Ifda6d55c16e12fc7939343757d7f2843b4df9b27
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2885784
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2021-05-22 00:43:29 +00:00
Daniel Verkamp
3638ae21f8 Remove needless returns
Fixes clippy warning "unneeded `return` statement".

BUG=None
TEST=bin/clippy

Change-Id: Ib31ce9c31d4edccd9c3a518dfa3a07186124d259
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2885783
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-05-22 00:43:28 +00:00
Daniel Verkamp
15fadba6ea devices: replace .into_iter() on ref with .iter()
Fixes clippy warning:

  this `.into_iter()` call is equivalent to `.iter()` and will not
  consume the `slice`

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

BUG=None
TEST=bin/clippy

Change-Id: Id31c3f6252b86a7f453ab4e6e7dac0ed6654bc52
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2885782
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2021-05-22 00:43:27 +00:00
Daniel Verkamp
358101242a devices: drop redundant clone calls
Fixes clippy warnings like:

  using `clone` on type `...` which implements the `Copy` trait

and

  redundant clone
  note: this value is dropped without further use

BUG=None
TEST=bin/clippy
TEST=cargo test -p devices

Change-Id: I8c13b79b54265e5527cadcb8a2e9f54419044bcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2885781
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-22 00:43:27 +00:00
Chirantan Ekbote
584fc8944d wl: Switch to thiserror
BUG=b:179755841
TEST=cargo build

Change-Id: Iaafae1cb235b7611f36f1b88d3e9e20d6a36d2ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2910214
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-05-21 10:55:51 +00:00
Alexandre Courbot
582d68acf9 virtio: video: encoder: add VDA encoder constructor
Add a constructor for building a VDA-backed encoder instead of requiring
the user to build one.

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

Change-Id: I712499904845b3cccb52a3e9e07c87cc1a3c92c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891144
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-05-21 09:36:40 +00:00
Alexandre Courbot
71b2ddb962 virtio: video: make Worker work on Device trait objects
The current generic Worker code is being instanciated once per kind of
video decoder and encoder. This results in quite a bit of duplication to
avoid one virtual call per device event, and also prevents us from
selecting the codec backend dynamically.

Convert that code to use a Device trait object instead for both
simplicity and flexibility.

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

Change-Id: I9aacd0286022d9eaa44bd57656d1959de78322a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891143
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-05-21 09:36:39 +00:00
Alexandre Courbot
2ddc36d222 virtio: video: encoder: use the same backend code layout as the decoder
Move the backend code into a module of the same name, to mirror the
structure used by the decoder.

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

Change-Id: I9175b054811d294c338f8b58961e4b45b10c99ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891142
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-05-21 09:36:38 +00:00
Alexandre Courbot
de3a48a651 virtio: video: move VDA common code into its own module
Move VDA code that is used by both the decoder and encoder into its own
module, so it can be easily included (or not) during compilation.

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

Change-Id: Ic42f94a1118fad5d60da0d5358a28a9b27c3dbc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891141
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-05-21 09:36:37 +00:00
Alexandre Courbot
c9f43bf6be virtio: video: decoder: move capability and decoder building into VDA backend
These operations are backend-specific and reference libvda, so move them
out of the generic code into the backend so they can easily be compiled
out.

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

Change-Id: Id5b32684df8aabef0c9ee2a00977339e0191d41b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891140
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-05-21 09:36:36 +00:00
Alexandre Courbot
96e3fb363f virtio: video: use the thiserror crate with VideoError
The thiserror crate is available to crosvm, so use it to make our
error handling code a bit more readable.

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

Change-Id: I2aacc63ffa8311d7e0bb4d1192fd0b11b4ca5d03
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891139
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-05-20 19:29:28 +00:00
Alexandre Courbot
f148e1b0df virtio: video: encoder: remove EncoderError
Make all the encoder backend methods return a VideoError, similarly to
what the decoder does. This allows us to merge the EncoderError's enums
into VideoError and return a BackendFailure when a backend-related
problem has occured, removing references to the encoder-specific code in
the generic video code.

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

Change-Id: I948927ae43cbbac70c4b829fbbb314122a0b6628
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891138
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-05-20 19:29:27 +00:00
Alexandre Courbot
0d714e1572 virtio: video: decoder: replace decoder VDA errors with generic backend error.
This follows the more flexible model that is used with the encoder and
removes references to libvda in the generic code.

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

Change-Id: Idff2894c9ea84c7bc26c5d02374c167756767a15
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891137
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
2021-05-20 19:29:26 +00:00
Alexandre Courbot
3727976368 virtio: video: decoder: replace ContextMap's new() method by Default implementation
This is more idiomatic for constructors that take no arguments, and
spares us one compiler warning if decoding support is enabled without
any backend (in which case nobody creates ContextMaps).

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

Change-Id: I01b909eac6d443e43617f6e8cb91c6254dea5cc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2891136
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
2021-05-20 19:29:25 +00:00
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