Commit graph

216 commits

Author SHA1 Message Date
David Tolnay
1c5e2557e2 edition: Eliminate blocks superseded by NLL
Before the new borrow checker in the 2018 edition, we sometimes used to
have to manually insert curly braced blocks to limit the scope of
borrows. These are no longer needed.

Details in:

https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html

TEST=cargo check --all-features
TEST=local kokoro

Change-Id: I59f9f98dcc03c8790c53e080a527ad9b68c8d6f3
Reviewed-on: https://chromium-review.googlesource.com/1568075
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:57 -07:00
David Tolnay
35ee9d9184 clippy: Resolve useless_format
TEST=bin/clippy

Change-Id: I13fcde5655f9f9c207c9a704fa32b99510946a1e
Reviewed-on: https://chromium-review.googlesource.com/1566893
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:56 -07:00
David Tolnay
d611f27cb1 clippy: Resolve unused_unit
TEST=bin/clippy

Change-Id: I96fe9711d99a999cda706a8b78f79ff5ef8f60de
Reviewed-on: https://chromium-review.googlesource.com/1566892
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:56 -07:00
David Tolnay
2b82fbbeda clippy: Resolve unneeded_field_pattern
TEST=bin/clippy

Change-Id: Ia0e0163441fafd4ce44fef7ebaa18d1cc947e20e
Reviewed-on: https://chromium-review.googlesource.com/1566891
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:55 -07:00
David Tolnay
4b74f59c2a clippy: Resolve string_lit_as_bytes
TEST=bin/clippy

Change-Id: Icf56040c26cd67560358d360353d276146a63eca
Reviewed-on: https://chromium-review.googlesource.com/1566749
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:54 -07:00
David Tolnay
9f2929479b clippy: Resolve single_match
TEST=bin/clippy

Change-Id: Iea0d3539b3ab587a2d97f676e1d9c7a239504308
Reviewed-on: https://chromium-review.googlesource.com/1566748
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:54 -07:00
David Tolnay
5e73d9090a clippy: Resolve redundant_pattern_matching
TEST=bin/clippy

Change-Id: I7b8fc90ae5250e7a506b75345a66305653a095ac
Reviewed-on: https://chromium-review.googlesource.com/1566746
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:53 -07:00
David Tolnay
5fb3f51517 clippy: Resolve redundant_closure
TEST=bin/clippy

Change-Id: Id4f38956d788e4402df164df03e80c4b487b1ad6
Reviewed-on: https://chromium-review.googlesource.com/1566745
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:53 -07:00
David Tolnay
56c2d3631c clippy: Resolve option_map_unit_fn
TEST=bin/clippy

Change-Id: I814cfce68c147f63d96fce6d0c465488ad3e336a
Reviewed-on: https://chromium-review.googlesource.com/1566744
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:53 -07:00
David Tolnay
55bc919e69 clippy: Resolve let_and_return
TEST=bin/clippy

Change-Id: I83e7fa6fd9075370854b7c651311642748916dc6
Reviewed-on: https://chromium-review.googlesource.com/1566741
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:51 -07:00
David Tolnay
a5aa8239a5 clippy: Resolve const_static_lifetime
TEST=bin/clippy

Change-Id: I51453ae1a6b6c6bf9c105a41352fd95500f76b05
Reviewed-on: https://chromium-review.googlesource.com/1566662
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:50 -07:00
David Tolnay
d0d46495a8 clippy: Resolve collapsible_if
TEST=bin/clippy

Change-Id: I1884c90e2efce3b972802e68a0a9d9395faa0f4c
Reviewed-on: https://chromium-review.googlesource.com/1566660
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:50 -07:00
David Tolnay
3fbeda1d08 clippy: Resolve clone_on_copy
TEST=bin/clippy

Change-Id: Ia9f58fd7ba0b7af6eee455f52b3b9004547aa25e
Reviewed-on: https://chromium-review.googlesource.com/1566659
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:49 -07:00
David Tolnay
2da9b8181f clippy: Resolve block_in_if_condition_stmt
TEST=bin/clippy

Change-Id: I36153632fbe21e8e23a36f0522b7afa1a72b5192
Reviewed-on: https://chromium-review.googlesource.com/1566658
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:49 -07:00
David Tolnay
526d0dad92 clippy: Resolve assign_op_pattern
TEST=bin/clippy

Change-Id: I1cb259f399f9aff2b9b745413f9a28e130688a2b
Reviewed-on: https://chromium-review.googlesource.com/1566657
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:48 -07:00
David Tolnay
8b274875fb clippy: Resolve ptr_arg
TEST=bin/clippy

Change-Id: I2880852da218bcb96c56c49977ba9d86e3156f70
Reviewed-on: https://chromium-review.googlesource.com/1566738
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:48 -07:00
David Tolnay
afb1401500 clippy: Resolve if_same_then_else
Suppressing the lint locally because by the author's and reviewers'
judgement this was the clearest way to write this code. The lint is
still valuable for catching mistakes in copied and pasted code
elsewhere.

TEST=bin/clippy

Change-Id: I77477fce51571220fd6259072519b31764a15aeb
Reviewed-on: https://chromium-review.googlesource.com/1566737
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:48 -07:00
David Tolnay
e246836798 clippy: Resolve while_let_loop
TEST=bin/clippy

Change-Id: Iae447ec2c1b095286ab02cd153bd2daafe95fae1
Reviewed-on: https://chromium-review.googlesource.com/1566894
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:47 -07:00
David Tolnay
79a2a2d7b4 clippy: Resolve absurd_extreme_comparisons
TEST=bin/clippy

Change-Id: I838792f228bb7b6d64ac1a3511a0dcbc551aad40
Reviewed-on: https://chromium-review.googlesource.com/1566735
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-15 02:06:09 -07:00
David Tolnay
aecf9a4dee edition: Remove extern crate lines
In Rust 2018 edition, `extern crate` is no longer required for importing
from other crates. Instead of writing:

    extern crate dep;
    use dep::Thing;

we write:

    use dep::Thing;

In this approach, macros are imported individually from the declaring
crate rather than through #[macro_use]. Before:

    #[macro_use]
    extern crate sys_util;

After:

    use sys_util::{debug, error};

The only place that `extern crate` continues to be required is in
importing the compiler's proc_macro API into a procedural macro crate.
This will hopefully be fixed in a future Rust release.

    extern crate proc_macro;

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu
TEST=local kokoro

Change-Id: I0b43768c0d81f2a250b1959fb97ba35cbac56293
Reviewed-on: https://chromium-review.googlesource.com/1565302
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-15 02:06:08 -07:00
David Tolnay
633426a8fc edition: Fill in macro imports
Macros were previously imported through `#[macro_use] extern crate`,
which is basically a glob import of all macros from the crate. As of
2018 edition of Rust, `extern crate` is no longer required and macros
are imported individually like any other item from a dependency. This CL
fills in all the appropriate macro imports that will allow us to remove
our use of `extern crate` in a subsequent CL.

TEST=cargo check --all-features --tests
TEST=kokoro

Change-Id: If2ec08b06b743abf5f62677c6a9927c3d5d90a54
Reviewed-on: https://chromium-review.googlesource.com/1565546
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-15 02:06:07 -07:00
David Tolnay
dc63ca9bfe devices: Replace imports involving super::super
I find that imports get disorienting when they refer to super::super or
beyond and are better written as relative to the crate root.

TEST=cargo check --all-features --tests

Change-Id: I96dfd09a2784046669ae57a05f83582203a9c29d
Reviewed-on: https://chromium-review.googlesource.com/1565727
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-15 02:06:06 -07:00
David Tolnay
4c706a2c4e gpu: Simplify imports from gpu_*
The gpu_buffer, gpu_display, and gpu_renderer refer to crates outside of
the devices crate. Typically importing from other crates is written as:

    use name_of_crate::path::to::ThingToImport;

TEST=cargo check --features gpu

Change-Id: Ic7b1a3fa6b4a06fca7f3e9ed09cbd2a9982279cc
Reviewed-on: https://chromium-review.googlesource.com/1565726
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-15 02:06:05 -07:00
David Tolnay
e50ba38a7d usb: Simplify imports from usb_util
The devices crate imports things from usb_util which is a separate
crate. Importing from a crate normally looks like:

    use name_of_crate::path::to::ThingToImport;

In the case it would be e.g.:

    use usb_util::hotplug::UsbHotplugHandler;

Importing these things through crate::usb::usb_util is unnecessary.

TEST=cargo check

Change-Id: I70554639a71b2423c1e13a30361d5f9d92e9d9a9
Reviewed-on: https://chromium-review.googlesource.com/1565725
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2019-04-15 02:06:05 -07:00
David Tolnay
1b7f3ed235 edition: Update devices crate to 2018 edition
Separated out of CL:1513058 to make it possible to land parts
individually while the affected crate has no other significant CLs
pending. This avoids repeatedly introducing non-textual conflicts with
new code that adds `use` statements.

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu

Change-Id: I964a198b54dfa7b98fa2f49a404fda3d09c0f44f
Reviewed-on: https://chromium-review.googlesource.com/1519693
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-15 02:06:04 -07:00
David Tolnay
3df3552e4d lints: Enforce sorted order for enum variants
To avoid wasting time re-sorting these things (CL:1492612).

https://docs.rs/remain

Disclaimer: I wrote the macro.

This CL adds #[sorted] attributes to those Error enums that seemed to
have made some effort to be in sorted order.

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu
TEST=emerge-nami crosvm
TEST=local kokoro
CQ-DEPEND=CL:1524247

Change-Id: I89685ced05e2f149fa189ca509bc14c70aebb531
Reviewed-on: https://chromium-review.googlesource.com/1515998
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-13 18:37:55 -07:00
Miriam Zimmerman
c211a6ccc6 devices: Start to implement IOAPIC.
This change implements service_irq, end_of_interrupt, and just enough to
add some basic tests for those.

Still TODO: Interrupt routing (and tests for that) and tests that
require additional functionality.

BUG=chromium:908689
TEST=Unit tests in file. Integration testing is blocked on rest of split-irqchip being implemented.

Change-Id: Ia8418f9a8bec92b53d99cdafb92f05f82eafa2b1
Reviewed-on: https://chromium-review.googlesource.com/1558935
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Miriam Zimmerman <mutexlox@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-12 14:50:01 -07:00
David Tolnay
65928af6c9 protos: Merge plugin_proto crate under protos::plugin
This de-duplicates the two separate build.rs files dealing with proto
compilation. The trunks interface.proto will be exposed under
protos::trunks and the plugin proto will be exposed under protos::plugin.

BUG=none
TEST=cargo check
TEST=cargo check --features tpm
TEST=cargo check --features plugin
TEST=cargo check --features tpm,plugin
TEST=FEATURES=test emerge-nami crosvm
TEST=FEATURES=test USE=crosvm-tpm emerge-nami crosvm
TEST=FEATURES=test USE=crosvm-plugin emerge-nami crosvm
TEST=FEATURES=test USE='crosvm-tpm crosvm-plugin' emerge-nami crosvm
TEST=local kokoro
CQ-DEPEND=CL:1553971

Change-Id: I203b654a38e9d671a508156ae06dfb6f70047c4f
Reviewed-on: https://chromium-review.googlesource.com/1556417
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-12 14:49:57 -07:00
David Tolnay
1aca8b7269 protos: Compile protos for trunks daemon
The TPM device will need these protos to communicate TPM commands to the
Trunks daemon and receive TPM responses.

BUG=chromium:911799
TEST=cargo check
TEST=cargo check --features tpm
TEST=FEATURES=test emerge-nami crosvm
TEST=FEATURES=test USE=crosvm-tpm emerge-nami crosvm
TEST=local kokoro
CQ-DEPEND=CL:1553610
CQ-DEPEND=CL:1553971

Change-Id: I1a67a7b4a3714236b20a790068ca19129446f71c
Reviewed-on: https://chromium-review.googlesource.com/1554982
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-12 14:49:56 -07:00
Daniel Verkamp
0268e26e1a devices: usb: remove unused imports in tests
Clean up warnings when building tests.

BUG=None
TEST=cargo test -p devices; FEATURES=test emerge-nami crosvm

Change-Id: I0efe723fee37c822a6bdd4a88766b37d559833d8
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1560092
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-10 18:06:51 -07:00
Jakub Staron
e7c590507c Wrap the UnixSeqpacket with a more descriptive type.
Host/device sockets are now created as a pairs of MsgSockets instead of UnixSeqpacket sockets.

BUG=chromium:950663
TEST=cargo check
TEST=cargo test

Change-Id: I8f61a711fe3c2547bf5d18fcfa23bfd0dc0ef5fd
Reviewed-on: https://chromium-review.googlesource.com/1559041
Commit-Ready: Jakub Staroń <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Jakub Staroń <jstaron@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-10 02:20:58 -07:00
David Tolnay
902e7c8450 edition: Use 2018-style paths in devices crate
These are import paths in new code added since CL:1513054 that need to
be made compatible with 2018 edition's treatment of paths.

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu

Change-Id: Icb3ecf2fb2015332e0c03cdc22bff2ecab2c40df
Reviewed-on: https://chromium-review.googlesource.com/1559264
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-09 22:08:37 -07:00
David Tolnay
48ff4165d2 cargo: Sort all dependency lists in Cargo.toml
This may help reduce cases of conflicts between independent CLs each
appending a dependency at the bottom of the list, of which I hit two
today rebasing some of my open CLs.

TEST=cargo check --all-features

Change-Id: Ief10bb004cc7b44b107dc3841ce36c6b23632aed
Reviewed-on: https://chromium-review.googlesource.com/1557172
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-09 01:55:14 -07:00
David Tolnay
fdac5ede46 edition: Use dyn syntax for trait objects
Found by running: `cargo rustc -- -D bare_trait_objects`

Bare trait objects like `&Trait` and `Box<Trait>` are soft-deprecated in
2018 edition and will start warning at some point.

As part of this, I replaced `Box<Trait + 'static>` with `Box<dyn Trait>`
because the 'static bound is implied for boxed trait objects.

TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu
TEST=local kokoro

Change-Id: I41c4f13530bece8a34a8ed1c1afd7035b8f86f19
Reviewed-on: https://chromium-review.googlesource.com/1513059
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-08 02:51:37 -07:00
Miriam Zimmerman
e8243e326a Add PIC device.
The PIC device that this commit provides isn't quite complete: It needs to
interact with a userspace APIC in order to properly route interrupts,
but crosvm does not yet have a userspace APIC. In the interest of not
making this CL too much larger, the userspace APIC implementation will
come in a future CL.

BUG=chromium:908689
TEST=Unit tests in file. Integration testing is blocked on rest of split-irqchip being implemented.

Change-Id: Id1f23da12fa7b83511a2a4df895b0cfacdbc559e
Reviewed-on: https://chromium-review.googlesource.com/1475057
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Miriam Zimmerman <mutexlox@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-03 18:14:09 -07:00
David Riley
ef495df7c1 devices: gpu: Silently accept empty command buffers.
Prior to this change empty command buffers would generate errors and syslogs.

BUG=None
TEST=glbench nop_virtgpu_execbuffer test

Change-Id: I456fb342c945beebe121e22543bd93fe41cc5cbe
Reviewed-on: https://chromium-review.googlesource.com/1532796
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-03 18:14:05 -07:00
Jingkui Wang
6bfc6a0304 fix endpoint id in set tr dequeue pointer
We were lucky that adb does not trigger this code path, but Arduino do.

BUG=None
TEST=local build, deploy and run

Change-Id: I0cf02c5de0a73af4e5cb6f5b668cef6606ed166b
Reviewed-on: https://chromium-review.googlesource.com/1542032
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-03-30 02:53:02 -07:00
Daniel Verkamp
e6c6cc908e devices: block: report block size in config
Set up the infrastructure for reporting block size in the virtio-blk
device model.  For now, we'll keep reporting SECTOR_SIZE (512), which is
the default block size that is assumed if we don't report it.  This
prepares us to easily switch the reported block size in the future.

BUG=chromium:942700
TEST=Boot Crostini on nami with an existing VM and container

Change-Id: I983817743c40e8278fe6cb9a10498011a8887ec9
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1526334
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-03-28 19:04:10 -07:00
Jorge E. Moreira
96e26c2681 Validate and configure tap interfaces from --tap_fd
Checks for the IFF_NO_PI and IFF_VNET_HDR flags, failing if those are
not set.
Sets the offload and vnet header sizes to the required values, instead
of trusting the values on the interface.

Bug=b/128686192

Change-Id: Ibbbfbf3cdedd6e64cdcfb446bcdfb26b4fd38395
Reviewed-on: https://chromium-review.googlesource.com/1526771
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2019-03-28 11:17:26 -07:00
Daniel Prilik
b3d382c942 pci: match pci cap structs with linux/virtio_pci.h
VirtioPciCap omits the `cap_vndr` and `cap_next` fields from it's
definition, deferring the instantiation of these bytes to the
add_capability method in PCI configuration. There is even a
comment on add_capability that mentions this omission.

Unfortunately, comments tend not to be read, and mismatches between
the linux headers and crosvm structures can result in some subtle
and tricky to debug bugs, especially when implementing other types
of virtio capabilties that subsume VirtioPciCap.

Case in point, when implementing the VirtioPciShmCap (used by
virtio-fs), this subtle mismatch resulted in a bug where an
additional 2 bytes of padding were inserted between the `cap` member
and the `offset_hi` member (see CL:1493014 for the exact struct).
Since the cap_len field was instantiated using mem::sizeof Self, the
additional padding just-so-happened to be the perfect ammount to sneak
past the sanity checks in add_capabilities. The bug manifested itself by
shifting over the length_hi field by 16 bits, resulting in much larger
than expected cache sizes.

This CL brings the VirtioPciCap structures in-line with their
linux/virtio_pci.h counterparts, marking the structures as repr(C) (as
opposed to repr(packed)) and leaving the cap_vndr and cap_next members
in the struct, noting that they will be automatically populated in
add_capability.

BUG=chromium:936567
TEST=cargo test -p devices, boot vm

Change-Id: Ia360e532b58070372a52346e85dd4e30e81ace7a
Reviewed-on: https://chromium-review.googlesource.com/1540397
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-03-28 11:17:09 -07:00
Daniel Prilik
45b3ed437d devices: improve get_device_bars/caps interface
Removes an unnecessary Option from the return type.

Also added a note about moving PCI methods out of the VirtioDevice
trait, as the trait shouldn't be tied to any particular transport layer.

BUG=chromium:936567
TEST=cargo build --features=gpu

Change-Id: I2c75c830bbe2d2b4a15461e8497535c526775bbe
Reviewed-on: https://chromium-review.googlesource.com/1536206
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-03-28 11:17:08 -07:00
Gurchetan Singh
5aaa63f508 devices: gpu: use render optimized buffers
Using non-linear buffer seems to be safe based on the apps I've
tested. This is similiar to the ARC++ use case, which also doesn't
explicitly send modifiers to Chrome.

BUG=chromium:945033
TEST=clear_clear goes from 980 mpixels --> 6797.90 mpixels
     on Nami

Change-Id: I2dcb78366c2d2d83d64bb23f6da1f07c8747819c
Reviewed-on: https://chromium-review.googlesource.com/1538463
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Chia-I Wu <olv@google.com>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
2019-03-26 17:27:02 -07:00
Daniel Prilik
db4721d870 crosvm: add memfd for GuestMemory
Building off CL:1290293

Instead of having a seperate GuestMemoryManager, this adds SharedMemory
as a Arc'd member of GuestMemory. This is nice since it removes the need
to plumb the Manager struct throughout the codebase.

BUG=chromium:936567
TEST=cargo test -p sys_util

Change-Id: I6fa5d73f7e0db495c2803a040479818445660345
Reviewed-on: https://chromium-review.googlesource.com/1493013
Commit-Ready: Daniel Prilik <prilik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-03-25 17:43:50 -07:00
Miriam Zimmerman
63e3a83a37 Move split_irqchip_common to devices/.
Previously, code in devices/ couldn't use split_irqchip_common, since
x86_64/ already has a dependency on devices/.

TEST=Built.
BUG=chromium:908689

Change-Id: I481514ae6bbd68e47feecc6f364ca8f4fd798e67
Reviewed-on: https://chromium-review.googlesource.com/1526762
Commit-Ready: Miriam Zimmerman <mutexlox@chromium.org>
Tested-by: Miriam Zimmerman <mutexlox@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-03-20 08:52:41 -07:00
Zach Reizner
7e622edd00 usb: remove unused/abused fd argument from EventHandler::on_event
None of instances of EventHandler::on_event actually used the fd. The
PollfdChangeHandler::remove_poll_fd callback fabricated a potentially
valid fd (0), which went undetected because nobody used it.
Additionally, using RawFds almost always requires unsafe and should be
avoided.

CQ-DEPEND=CL:1522214
BUG=chromium:831850
TEST=cargo test

Change-Id: I095edbcad317e4832b1fb29fd08d602fbde4fd5d
Reviewed-on: https://chromium-review.googlesource.com/1525135
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2019-03-18 07:05:10 -07:00
Zach Reizner
a6b9ca3388 usb: remove unused usb-emulation feature flag
This cleans up some feature flag plumping for libusb sandboxing as well.

BUG=chromium:831850
TEST=cargo test
CQ-DEPEND=CL:1512762

Change-Id: Ic70784db204ddced94498944b021bcb7dd708bb1
Reviewed-on: https://chromium-review.googlesource.com/1522214
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2019-03-17 21:33:08 -07:00
Jingkui Wang
100e6e48ad implement xhci and add it to pci bus
Implement xhci controller, setup seccomp filters and add xhci to pci
bus.

CQ-DEPEND=CL:1512761
BUG=chromium:831850
TEST=local build
Change-Id: I5c05452ece66e99d3a670e259e095fca616e835d
Reviewed-on: https://chromium-review.googlesource.com/1512762
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2019-03-17 21:33:08 -07:00
Jingkui Wang
257d004b0c usb: add host backend
Host backend implement backend device. It will attach a read device to
xhci controller.

Also squashed from ce6b35, author: zachr@.

CQ-DEPEND=CL:1510820
BUG=chromium:831850
TEST=local build

Change-Id: Idcf2d7d6aca92de9859b7c38d1bf1d98032eae91
Reviewed-on: https://chromium-review.googlesource.com/1512761
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-03-16 15:25:23 -07:00
Jingkui Wang
874f2e83ed usb: Add device slot, command ring and transfer ring
Device can be assigned to slot. Command ring handles usb commands,
transfer ring handles usb transfers.

CQ-DEPEND=CL:1510819
BUG=chromium:831850
TEST=cargo test

Change-Id: Ib0836ee518d1c7a3e902630c7ea04e29b9496c80
Reviewed-on: https://chromium-review.googlesource.com/1510820
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-03-16 15:25:23 -07:00
Jingkui Wang
bbd77ff220 usb: add usb hub, transfer and usb backend interface
Those are bridges between xhci and backend.

CQ-DEPEND=CL:1510818
BUG=chromium:831850
TEST=cargo test

Change-Id: I04feab449d48b0c908aeebfda08d1869239cbe6f
Reviewed-on: https://chromium-review.googlesource.com/1510819
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-03-16 15:25:22 -07:00