Assign the result of function calls that take closures to an
intermediate variable rather than matching on it directly to simplify
the complexity from clippy's point of view.
BUG=b:344974550
TEST=tools/clippy
Change-Id: I0e4b4201b59d8bd972c1f18e65bfd501893d58e5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5617618
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
The vcpu.run() is only ever executed once due to hitting either a break
or a panic; remove the loop {} to avoid a clippy::never_loop warning.
BUG=b:344974550
TEST=tools/clippy
Change-Id: I8a21ebcb2eb8aaba9d84b22c2368fb73cbf25742
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5617617
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Return a Result to simplify the error!() + return pattern used in the
virtio-tpm device's run() function.
Incidentally fixes a clippy::blocks_in_condition warning since the
.and_then() is no longer necessary.
BUG=b:344974550
TEST=tools/clippy
Change-Id: I3810759ab2e56facb248b6cf5def08ccd0870265
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5617616
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
The process_tx_ctrl_*() functions don't need the Vec, just the elements
it contains.
BUG=b:344974550
TEST=tools/clippy
Change-Id: I4d0c475dbe1aa8c0f990d301d77a5b163435eb2e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5609079
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
This loop always ran exactly once, so it doesn't need to be a loop.
BUG=b:344974550
TEST=tools/clippy
Change-Id: I6fe2620d4ba712b573515122720caeafc44081cf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5609075
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Avoid .get()ting something just to check if it's present; use
.contains_key() instead (or .entry() in the case where we want to insert
an item if the key is not present).
BUG=b:344974550
TEST=tools/clippy
Change-Id: I78ee9e5a7ad9ffd693d9a50a347663444e1516a2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5609074
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
.map_or(..., Ok) can be replaced with the simpler .ok_or(...)
BUG=b:344974550
TEST=tools/clippy
Change-Id: I6bd50845e06b228e3c16a29fa15af1b1f5ffb68a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5609072
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Use .create_new() rather than .create() for cases where we always want
to ensure that the file does not already exist, and add .truncate(false)
for a case where we do want to open an existing file and don't want to
overwrite it.
BUG=b:344974550
TEST=tools/clippy
Change-Id: Ie82a6db306532c600c140efab3d310b6c7cf25a7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5604660
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Use the potentially more efficient clone_from() function when cloning
and assigning.
BUG=b:344974550
TEST=tools/clippy
Change-Id: I0601b59a80fdebbc09b212110c6e68e23a52bcfe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5604659
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Under the hood, both AMD [1] and Intel [2] only accept 8 bit vector for event injection, so it's highly likely that all hypervisor implementation to encounter an error when we pass in values greater than 0xff as the vector.
From the source we can tell that KVM rejects any value greater than 0xff, HAXM has some strange unwanted behaviors with invalid vector values. From testing, we can tell WHPX also rejects invalid vector values right away.
[1]: Figure 15-5. EVENTINJ Field in the VMCB of AMD64 Architecture Programmer’s Manual, Volumes 2.
[2]: Table 25-17. Format of the VM-Entry Interruption-Information Field of Intel 64 and IA-32 Architectures Software Developer's Manual Volume 3.
TEST=./tools/dev_container cargo nextest run --workspace --profile=default -E 'package(hypervisor) & binary(hypervisor_virtualization)' --retries 0 --no-capture
BUG=b:334055761
Change-Id: Ied118f0df10e4a1c973b5b26327c24f45064d56c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5602270
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Judson Powers <judsonp@google.com>
For emulated instructions, the hypervisor normally needs to intercept
the instruction, emulate it and advance the rIP afterwards. This test
makes sure that the interruptibility is correctly handled in this case.
Particularly, if an instruction is emulated after an sti when FLAGS.IF
is cleared or a mov ss, after the emulation. The interruptibility should
be restored.
Change-Id: Ib1e897b5d4dd97b2877814a6e7bff56e222d13d2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5610292
Reviewed-by: Judson Powers <judsonp@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
The maximum command line length accepted by the guest kernel is a fixed
per-architecture constant; it is unrelated to the (host) page size,
which was used as the limit on aarch64 and riscv64 before this change.
Making crosvm limit the command line to the correct maximum length
allows for a more useful error message to be printed if the user tries
to use an overly-long command line; without this change, it would not be
apparent that the guest kernel was truncating the command line, leading
to unexpected behavior at runtime.
BUG=b:345478075
TEST=Boot Crostini and ARCVM on arm64
Change-Id: I207bda318b60d207ccb1ef5df1e59f30be238126
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5606562
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This test ensures that we don't deliver an interrupt if the guest is not
interruptible even when we call vcpu.interrupt() with
vcpu.ready_for_interrupt() returning false.
Below is the actual behaviors of different hypervisors, but our test
doesn't test against specific behaviors:
* For KVM, the interrupt injection succeeds, but the following VCPU run
fails
* For WHPX, the interrupt injection fails as if we never try to inject
the interrupt.
* For HAXM, the interrupt will be pending and will be delivered once the
interrupt is reenabled.
TEST=./tools/dev_container cargo nextest run --workspace --profile=default -E 'package(hypervisor) & binary(hypervisor_virtualization) & test(test_interrupt_injection_when_not_ready)' --retries 0 --no-capture
BUG=b:334055761
Change-Id: I06d6f662457860a6fc1b2c7a657dfb42bb3c9b07
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5584661
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Judson Powers <judsonp@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
The vfio code previously managed singleton instances of VfioContainer
using thread-local variables hidden inside the implementation of
vfio_get_container().
Make the caller hold onto a VfioContainerManager rather than implicitly
mutating global state inside a library function in the vfio crate. This
also removes the possibility of accidentally creating new VfioContainer
instances by calling from a different thread, since the containers were
previously thread-local rather than truly global for some reason.
This requires threading the vfio_container_manager variable through a
few function calls, but this also helps clarify ownership and lifetime
of the objects involved.
BUG=None
TEST=tools/dev_container tools/presubmit
Change-Id: I2ba1be561c48143ff14e391c23bad1c6783b73ec
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5601348
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Pierre-Clément Tosi <ptosi@google.com>
`base::Tube` probably ought to require `&mut self` (or be `!Sync`) since
it isn't safe to concurrently send or recv. Let's try to be stricter in
the new API, esp. since it requires non-trivial effort to port code to
this library, needing to manage tubes slightly differently shouldn't be
a big deal.
BUG=b:338274203
Change-Id: I7caf743744393aedf0a346ca23e970d15020704c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5604651
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
BTreeMap implements an Entry API to allow efficiently checking whether
a key exists and retrieving it or inserting it if not:
<https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.entry>
Using this API avoids the expect() calls since there is no need to
insert and then re-get the same entry.
This also fixes new clippy warnings from Rust 1.77.
BUG=b:344974550
TEST=tools/dev_container tools/presubmit
Change-Id: I97c556376bdb27180232f6234820659360b72380
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5545765
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Merge the `where` clause bounds into the ones in the generic type
definitions. This is also more consistent with the other functions in
this file.
BUG=b:344974550
TEST=tools/clippy
Change-Id: Ie4d33ae0c204dab6279607aa0b181768b42c75eb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5599145
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>