Commit graph

1497 commits

Author SHA1 Message Date
David Stevens
6e13a86d25 devices: virtio: iommu: fix vfio device removal
Make sure the endpoint is removed from the endpoint and domain maps when
a vfio device is removed.

BUG=b:232161488
TEST=Boot a guest, hotplug in and out a vfio-pci device repeatedly

Change-Id: Ie9838b412cac22a9e14bb6e986be39303aeb01e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3676692
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-01 08:46:40 +00:00
David Stevens
6374a3a370 devices: virtio: iommu: refactor shared state
Refactor shared state so that it can be shared between multiple async
callbacks. This moves all state from the Worker to a dedicated State
struct, which allows it to be passed via Rc<RefCell<>> to the various
async callbacks. The collection of endpoints can also be passed as part
of the shared state, rather than as its own dedicated argument.

There should be no behavioral changes in this CL.

BUG=b:232161488
TEST=Boot a guest, hotplug in and out a vfio-pci device repeatedly

Change-Id: I1e65ef3e4048bf0889fdee0f18fa5b58be264666
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3659554
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-01 08:46:39 +00:00
David Stevens
35ce872a45 devices: virtio: iommu: check for invalid attaches
Check that the same mapper isn't used for multiple domains. This ensures
that there won't be mapping collisions/leaks if the guest tries to use
the same mapper with multiple domains.

BUG=None
TEST=Boot ManaTEE with devices managed by viommu

Change-Id: I45889e6fe020c3a24b355fc05a8f74734bece78a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3641221
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-01 08:46:38 +00:00
David Stevens
fef85d48c8 devices: virtio: iommu: fix detaching issue
Remove incomplete support for detaching a virtio endpoint from domains
with multiple endpoints. We could technically handle this by checking
domain mappings when handling TranslateRequests, but there are no use
cases for this at the moment.

BUG=None
TEST=Boot ManaTEE with devices managed by viommu

Change-Id: I9d1cb86f246f7d8639058eaaf158f6538f1c1c57
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3676697
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-01 08:46:37 +00:00
David Stevens
a334b0931a linux: refactor create_vfio_device
Refactor create_vfio_device so that it returns the created viommu
related mapper, if any. This allows add_vfio_device to be written more
cleanly.

BUG=None
TEST=Boot ManaTEE with devices managed by viommu

Change-Id: Ieaa345ed5f9146fde8e305fc7bc37001ff708683
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3676698
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-01 08:46:36 +00:00
David Stevens
5d6d595116 devices: vfio: use VFIO_TYPE1v3_IOMMU if available
For vfio devices which we expect to have granular, dynamic IOMMU
mappings (i.e. passthrough devices using viommu/coiommu), use the
ChromeOS specific VFIO_TYPE1v3_IOMMU if available, as it is optimized
for that use case.

BUG=b:217479627
TEST=boot ManaTEE, observe reduced hypervisor memory usage after IO

Change-Id: I7b3a04adb5049c165885917fa29cedf2ccdee1d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3675885
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-01 05:47:40 +00:00
David Stevens
569a58490e base: clarify SharedMemory API
When creating shared memory, 'name' can have one of two meanings. It
could either be a debugging tag with no semantic meaning, or it could
uniquely identify a shared memory object within some namespace. Linux
memfd uses name in the first meaning, whereas Windows (and Linux shm)
uses it in the second meaning.

Currently, crosvm has no use cases for the named shared memory of the
second type, so it is not supported. Make it clear that the SharedMemory
APIs treats name as a debugging-only name. Remove the "anon" and "named"
constructors, since they had no semantic meaning. Also require a name
when constructing a SharedMemory, since there's no reason not to provide
one to make debugging easier.

The only semantic change is setting the name of GuestMemory's underlying
shmem to "crosvm_guest", which it was until recently. This fixes some
ManaTEE tests which use the name to determine CrOS guest memory usage.

BUG=None
TEST=compiles

Change-Id: I78d5046df04d6f19640abbbc67af6bd433a177b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3676695
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-01 03:55:47 +00:00
Daniel Verkamp
5fa53bc27a devices: vvu: wl: do not hold RefCell borrow across await
Change the comparison from an `if let` into a regular `if ... ==` by
implementing `PartialEq` for the relevant types. This makes the lifetime
of the `wl_state.borrow_mut()` end before calling
`kick_evt.next_val().await()`.

Fixes a new clippy warning from Rust 1.61.0:
<https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref>

BUG=None
TEST=tools/clippy # with Rust 1.61.0

Change-Id: I067c2ab532d753306cd5334df5bb4f2c7c2e6584
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671130
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Anton Romanov <romanton@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-01 00:32:58 +00:00
Daniel Verkamp
900237a541 devices: virtio-iommu: do not hold RefCell or lock across async
Retrieve the translation response, which involves taking a mutable
borrow of a RefCell as well as locking a Mutex, inside its own block so
that the references are dropped before using await again.

Fixes two new clippy warnings from Rust 1.61.0:
- <https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref>
- <https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock>

BUG=None
TEST=tools/clippy # Rust 1.61.0

Change-Id: If573af56968dceeae72a61a74f9f69dad8730364
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671596
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Anton Romanov <romanton@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-01 00:32:57 +00:00
Alexandre Courbot
ed66850d92 devices: pit: avoid storing raw file descriptor
The Worker struct is storing a Descriptor obtained from a timer for the
sole purpose of adding it to a WaitContext when the worker thread starts
running. Instead of doing this, create the WaitContext and pass it as
part of the worker data, so all ioctls involving that descriptor are
performed directly on the timer, guaranteeing that the descriptor is
valid.

BUG=233968702
TEST=Linux VM starts and boots with `--split-irqchip` specified.

Change-Id: Ie5da1e9866742108f52c526100e936d292167ab7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3670105
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-05-28 07:29:02 +00:00
Alexandre Courbot
756c0bea9b devices: bat: remove unneeded use of Descriptor
WaitContext::build_with expects an array of &dyn AsRawDescriptor, which
the events we pass to it all implement. There is no need to use a
temporary Descriptor here.

BUG=233968702
TEST=cargo build

Change-Id: Ie39e1683ed13e474ef43bdad9375d60c6bf55f5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3670104
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-28 07:29:01 +00:00
Alexandre Courbot
c9a294ced7 devices: usb: host: don't use Descriptor as temporary descriptor storage
We can avoid temporarily storing the descriptor by passing a reference
to the providing device directly to EventLoop::add_event().

BUG=233968702
TEST=cargo build

Change-Id: I78ce17b8a2c7c8a695cf65597459719812c175a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3670103
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-28 07:29:00 +00:00
Alexandre Courbot
9be279ca5f devices: input: stop using Descriptor in evdev
Descriptor here was used to pass a raw descriptor from a type that
implements AsRawDescriptor to a function that takes an AsRawDescriptor
as argument. Passing the provider directly is strictly equivalent.

BUG=233968702
TEST=cargo build

Change-Id: I638d01f1d5b47eb9773e7b1ad3802f6d8d0e5f6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3670102
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-05-28 07:28:59 +00:00
Daniel Verkamp
16f42b2337 devices: vvu: cras: update to SocketListener
Fixes the build with cras enabled.

BUG=b:229554679
TEST=emerge-trogdor crosvm

Fixes: b524833ab8 ("devices: vhost-user: handler: use vmm_vhost's socket listener")
Change-Id: I8237bc6d2b50a5f3bb150ae5ddc2920999b4b658
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3673020
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-05-27 19:34:39 +00:00
Alexandre Courbot
22ba1728be devices: vvu-proxy: remove obsolete comment
We don't use `expect` in this block code anymore.

BUG=None
TEST=cargo build

Change-Id: I5c1887a42a0922f7b5d9d850d9c94dff8dc0d2f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3664171
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
2022-05-27 15:17:38 +00:00
Alexandre Courbot
b524833ab8 devices: vhost-user: handler: use vmm_vhost's socket listener
vmm_vhost comes with its own set of listeners that implement the same
interface. Switch to use its socket listener as that will allow us to
further factorize code.

BUG=b:229554679
TEST=vhost-user console device works.
TEST=vvu console device works.

Change-Id: I19d0c9b95a0cca57eefd6c72b875e8a166d06b89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3591110
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-27 06:53:07 +00:00
Alexandre Courbot
64a3fc2d08 devices: vhost-user: remove Arc from SlaveListener and SlaveReqHandler
The SlaveReqHandler should be the sole owner of a VhostUserBackend since
it calls its mutable methods, so we shouldn't need an Arc here. If
sharing is necessary users can use their own locking mechanism.

Single ownership will help to retrieve the backend after a client
disconnects, to reuse it for another connection if needed.

BUG=b:229554679
BUG=b:216407443
TEST=cargo test -p vmm_vhost
TEST=vhost-user console device works.
TEST=cargo test -p devices

Change-Id: I2358c807ac3ddb1ee4b29d97df0ade5a3e30a85a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3591108
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Richard Zhang <rizhang@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-27 06:53:06 +00:00
Kaiyi Li
d6b6a991df virtio-gpu: move parameters to a separate file
BUG=b:233676779
TEST=build on Android

Change-Id: I20cf4c330844f5048553ba44e002747c874b54bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3668927
Auto-Submit: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Jason Macnak <natsu@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-26 20:19:46 +00:00
Jeffrey Kardatzke
dd94f70697 crosvm: Add support for HEVC profile
Submit after crrev.com/c/3664859 is merged.

BUG=b:215043150, b:183217901
TEST=HEVC playback works in ExoPlayer on guybrush w/ full set of changes

Change-Id: If775435040a77f4620a55d6838353836c40291c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3664289
Commit-Queue: Jeffrey Kardatzke <jkardatzke@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-05-26 20:09:50 +00:00
Mike Gerow
539ba3dcc9 Reland "devices: debugcon: add bochs-style debugcon device"
This is a reland of commit 129840471d

Original change's description:
> devices: debugcon: add bochs-style debugcon device
>
> This allows for creating a simple write-only debug connection that uses
> a single IO port. This method is supported by both bochs and qemu[1].
>
> The main motivation here is to help in improving crosvm's ability to
> boot OVMF, which makes use of this simple debug device on port 0x402.
> For that one would use `--serial
> type=stdout,hardware=debugcon,debugcon_port=1026` or something similar.
>
> Note that serde_keyvalue doesn't support parsing hex values, hence the
> need to use `1026`, but I intend to address that as well to allow the
> more natural `debugcon_port=0x402` phrasing.
>
> [1]: https://github.com/qemu/qemu/blob/master/hw/char/debugcon.c
>
> BUG=b:233610263
>
> Change-Id: I73238e5c35925668d133bfaa542fcbcf1e28765f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3661255
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: Mike Gerow <gerow@google.com>
> Tested-by: kokoro <noreply+kokoro@google.com>

Bug: b:233610263
Change-Id: I2f2125da95e8907f4f0c16930952e9b765d33e6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671087
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Mike Gerow <gerow@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-26 19:25:02 +00:00
Richard
b22eff068e devices: upstream virtio balloon for Windows
BUG=b:213149162
TEST=built and presubmits

Change-Id: I4323cbe8457501ab6988110b53b2c790a51ce8b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3655755
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-05-26 18:23:34 +00:00
Mike Gerow
d46572f47e Revert "devices: debugcon: add bochs-style debugcon device"
This reverts commit 129840471d.

Reason for revert: This conflicts with https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600167 breaking the build

Original change's description:
> devices: debugcon: add bochs-style debugcon device
>
> This allows for creating a simple write-only debug connection that uses
> a single IO port. This method is supported by both bochs and qemu[1].
>
> The main motivation here is to help in improving crosvm's ability to
> boot OVMF, which makes use of this simple debug device on port 0x402.
> For that one would use `--serial
> type=stdout,hardware=debugcon,debugcon_port=1026` or something similar.
>
> Note that serde_keyvalue doesn't support parsing hex values, hence the
> need to use `1026`, but I intend to address that as well to allow the
> more natural `debugcon_port=0x402` phrasing.
>
> [1]: https://github.com/qemu/qemu/blob/master/hw/char/debugcon.c
>
> BUG=b:233610263
>
> Change-Id: I73238e5c35925668d133bfaa542fcbcf1e28765f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3661255
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: Mike Gerow <gerow@google.com>
> Tested-by: kokoro <noreply+kokoro@google.com>

Bug: b:233610263
Change-Id: Ia70540c3041611f59968cb7929b238eecfe2530d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671082
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Mike Gerow <gerow@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-05-26 18:23:30 +00:00
Mike Gerow
129840471d devices: debugcon: add bochs-style debugcon device
This allows for creating a simple write-only debug connection that uses
a single IO port. This method is supported by both bochs and qemu[1].

The main motivation here is to help in improving crosvm's ability to
boot OVMF, which makes use of this simple debug device on port 0x402.
For that one would use `--serial
type=stdout,hardware=debugcon,debugcon_port=1026` or something similar.

Note that serde_keyvalue doesn't support parsing hex values, hence the
need to use `1026`, but I intend to address that as well to allow the
more natural `debugcon_port=0x402` phrasing.

[1]: https://github.com/qemu/qemu/blob/master/hw/char/debugcon.c

BUG=b:233610263

Change-Id: I73238e5c35925668d133bfaa542fcbcf1e28765f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3661255
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Mike Gerow <gerow@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-26 17:13:59 +00:00
Alexandre Courbot
532cce15b1 devices: vhost-user: console: poll input asynchronously
Using the new `SerialInput` trait, we can create an async input source
and get rid of the polling thread.

BUG=b:228912920
TEST=vhost-user console device is working (with input) on Linux.

Change-Id: I1be9ae499f9c782b4aacba44e1eca524f1b701c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600168
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-26 11:17:52 +00:00
Alexandre Courbot
738adc7072 devices: serial: introduce SerialInput trait
Introduce a new dedicated trait for types that can be used as serial
input. This trait adds the requirement that the type must implement
`AsRawDescriptor`, which will allow us to use the input as a poll source
instead of having to spin a dedicated thread to call `read()` on it.

BUG=b:228912920
TEST=cargo build

Change-Id: Ib07f7b4e63545fa0f27940553ad6124796f5b3cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600167
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-26 10:09:52 +00:00
Daniel Verkamp
e84d9c1d7c devices: pci: PciBarIndex API cleanup
Everything that takes a PCI BAR index should use the appropriate
PciBarIndex type rather than u8 (or usize) for better type safety and
descriptiveness.

BUG=b:232838930
TEST=tools/presubmit

Change-Id: I0a918a6da6327c963fb297ba765563774a7e5e49
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3664282
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Anton Romanov <romanton@google.com>
2022-05-25 20:36:40 +00:00
Daniel Verkamp
18203fa00f devices: virtio-pci: refactor BAR lookup
The read_bar() and write_bar() functions had an open-coded equivalent of
BAR lookup to find out if the access was intended for the settings BAR
or one of the device-specific extra BARs. Instead, we can reuse the same
BAR lookup code to find the index of the relevant BAR and compare it
against the settings_bar field.

BUG=b:232838930
TEST=tools/presubmit

Change-Id: I2e5f3ccff47d31718e835ccb745db75dbda2e4ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3664281
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-25 20:36:40 +00:00
Daniel Verkamp
19da3a6c48 devices: virtio: clean up write_bar/read_bar matches
Define constants for the end of the ranges that exist within the
settings BAR so we can use the range syntax in the match instead of
manually checking against the start and end.

This uses inclusive range (..=) syntax, since exclusive range pattern
syntax (..) is experimental. Therefore, each range has a `_LAST`
constant that is equal to the address of the last valid byte in that
range (first + size - 1).

Rewriting the matches in this way allows us to clean up the two clippy
ignores and makes the code a bit easier to read.

BUG=b:232838930
TEST=tools/clippy
TEST=Boot x86-64 Crostini

Change-Id: Ibb8b5ea055e598c19504b7b1b6753706ad458875
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3664280
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Anton Romanov <romanton@google.com>
2022-05-25 20:36:40 +00:00
Lepton Wu
911a2d0671 devices: vhost-user: fs: open vvu device outside jail.
We need to open vvu device before we go to jail since we don't have
access to sysfs in jail.

BUG=b:233690640
TEST=manual - fs is usable from a sibling guest when using VVU.

Change-Id: I0340d105b667cce2ba88d7557e64771fa2bedf9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3665907
Auto-Submit: Lepton Wu <lepton@chromium.org>
Commit-Queue: Lepton Wu <lepton@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-25 16:44:13 +00:00
Alexandre Courbot
1f486e2313 gpu: fix (again) unused_mut warning when no gpu feature is enabled
This was fixed in crrev.com/c/3659824, but a subsequent commit somehow
reverted that line.

BUG=None
TEST=`cargo build` does not display any warning.

Change-Id: Id50ee4f615117ada8c27552e073f7fb04d8d009e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3664166
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-25 09:14:18 +00:00
Alexandre Courbot
4212e80393 devices: vhost-user: console: make async functions generic
We want to eventually reuse these functions in the regular virtio device
code, which uses a different kind of interrupt, so make that parameter
generic.

BUG=b:228912920
TEST=cargo build

Change-Id: I1139ce6626ac7b952b7769db6e66d677607d3307
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600166
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-05-25 09:12:23 +00:00
Alexandre Courbot
8477c44059 virtio: console: simplify process_transmit_queue
The error path reproduces the code outside of the match arm, so it can
be removed.

BUG=b:228912920
TEST=cargo build

Change-Id: Ibd485a52441be03501041bc4136bab9293c7066b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600165
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-25 09:12:23 +00:00
Alexandre Courbot
e8d53e8ee6 virtio: console: clarify process_transmit_queue
Used tx buffers are returned to the driver with 0 bytes written by the
device. The current code makes it look like we return the number of
received bytes, even though this is not the case since
process_transmit_request always returns 0 for some reason.

Make this more clear by explicitly setting 0 bytes used, and making
process_transmit_request return nothing.

BUG=b:228912920
TEST=cargo build

Change-Id: I9094f7a43847d7e29d5390f274d6650ca5ec7c4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600164
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-05-25 09:12:23 +00:00
Richard
a19d6ce89c devices: Update rng devices to be platform agnostic
On Unix, instead of getting random data from `/dev/urandom`, it will get
it from the `rand` platform agnostic crate instead.

OsRng.fill_bytes on unix will make a syscall to getrandom(2) if
available, otherwise it will read from `dev/urandom` after a succesful
poll to `dev/random`. Regardless of which way a random data is
retrieved, if the entropy pool is not intialized, `fill_bytes` will
block until it is intialized. This shouldn't be a problem because it is
a one time cost.

This CL will also upstream the Windows implementation of the rng device.

BUG=b:213149162
TEST=built and presubmits

Change-Id: Ic017f11795f8006e0bf2a04eb0478b3a3d336507
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3657812
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-05-25 01:35:13 +00:00
Vikram Auradkar
91d4199d4e crosvm: move unix specific code into sys/unix/
- move command args that have unix specific help messages
- move wait_all_children. Call it through cleanup function.
- move parse_gpu_display_options
- impl Default for DiskOption

Change-Id: Ia2495df278f7213f50cecfa107717e03b504cca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3649738
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-05-24 17:44:01 +00:00
Gurchetan Singh
d18f0bac4d devices: gpu: conditionally enable capsets if context_mask is specified
This allows finer grain selection of context types, and eventually deletion
of preprocessor flags and "default component type".

BUG=b:173630595
TEST=compile

Change-Id: I5669911dfd4d6a7fd290e73ed3939d54fabdb89f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3655287
Reviewed-by: Rob Clark <robdclark@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-24 15:27:36 +00:00
Gurchetan Singh
3c77043c19 rutabaga_gfx: consolidate flags into the rutabaga builder
A lot of these flags can be deprecated over time.  For example,
specifying the context type and "use_vulkan" is a bit redundant.
Things like "use_syncfd" and "use_guest_angle" can also be removed.

BUG=b:173630595
TEST=compile

Change-Id: I77bff7f02ebfd3b0e65145d144bfc15afa50f386
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3655286
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Commit-Queue: Rob Clark <robdclark@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-24 15:27:36 +00:00
Rob Clark
6d7a90be3a rutabaga_gfx: add context type mask
A way to control exposed capsets.

BUG=b:230100768
TEST=gfxbench, android games in arcvm

Change-Id: I91616405b695be73d6cc872aa5ae2a9dcecd0fb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3636799
Commit-Queue: Rob Clark <robdclark@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Rob Clark <robdclark@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-05-24 15:05:16 +00:00
Anton Romanov
9453959c4c crosvm: rework logging
Motivation:
    * simplify and unify, align more with standard log facade
    * code reduction
    * remove hardcoded platform-specific things
    * a little more flexibility
    * easily allow lov level/filtering config as cli argument

Note that there is more code removal than simply loc as updating tests
added few loc

Change-Id: I7beb4b2c28c3462553c6663b234ee38df79f59f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3657053
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-23 21:11:49 +00:00
Keiichi Watanabe
8736f39fe5 devices: vvu-proxy: Handle sibling disconnection
Detect sibling's disconnection and send 0-byte data to the guest.

BUG=b:216407443
TEST=run vvu on workstation

Change-Id: I33142998e5d823226970f865c0e3de6cb2c8a492
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3591103
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
2022-05-23 11:33:18 +00:00
Alexandre Courbot
6cabd03d60 gpu: fix unused_mut warning when no gpu feature is enabled
These variables will be left untouched if no GPU feature is enabled,
triggering a compiler warning.

BUG=None
TEST=`cargo build` does not display any warning.

Change-Id: Id1c80bd8f21272dce9e3a3f37cd3350727e5bc9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3659824
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-05-23 08:21:26 +00:00
Vineeth Pillai
81b5e616d6 crosvm: vm_events: consolidate vm events into one framework.
crosvm waits on events like exit, reset, crash, guest panic etc and
uses eventfd to wait on these events. As of now, we have 4 eventfds
and may increase.

This is an attempt to consolidate all Vm events into one framework.
Use Tube instead of Event to get consistent behavior between OSes.
Implement a wrapper over Tube to have a consistent API for events.

BUG=None.
TEST=Built crosvm. Ran a minimal vm to panic and verified that crosvm
received the panic event. cargo test on devices.

Change-Id: I313d428de5e3ce3b879982f913918ec0a4a72c35
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3480577
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vineeth Pillai <vineethrp@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-05-20 18:04:21 +00:00
Devin Moore
cbc8d507d0 virtio: Remove default case from fmt() function
The default case can't call format! with the unexpected type because it
will end up back in fmt until the stack overflows.

BUG=b:232259781
TEST=build and boot Cuttlefish in aosp which uses the unhandled type

Change-Id: I80d9b745cf78859bc7e7e939fcc5f9955507241c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3655281
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Steven Moreland <smoreland@google.com>
Commit-Queue: Devin Moore <devinmoore@google.com>
2022-05-19 23:38:47 +00:00
Anton Romanov
56c0d02760 crosvm: remove balloon stats request timeout
It was done to avoid deadlock when stats are requested before guest is
up. Implement a stub BalloonStats::NotReady replier until host is up so
that timeout is no longer necessary.

BUG=b:232289535
TEST=few tast crostini/arc tests

Change-Id: I6731b4ee9eaecdd65aebdd3f530f0932b0660c85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652887
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
2022-05-19 23:34:28 +00:00
Gurchetan Singh
c1a2fa27b4 rutabaga_gfx: stop unconditionally advertising the cross domain capset
Currently, there are two use cases for the cross domain capset:
   (1) Sommelier
   (2) minigbm

Niether is used by a production VM yet and it was unconditionally
enabled only to enable testing.  To effectively productize, it should
be conditionally enabled, which is done later in this patch series.

BUG=b:173630595
TEST=compile

Change-Id: I736f58065c692d7ee4736f28da30fa28de43f0c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3655285
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-19 22:39:47 +00:00
Dmytro Maluka
d61e24be2c Revert "direct_irq: Add support for host wakeup capable IRQs"
This reverts commit 0ac97979b6.

Reason for revert: This static configuration for wakeup IRQs is
no longer needed since we have a mechanism for automatic dynamic
configuration of wakeup IRQs based on requests from ChromeOS VM.

BUG=b:228449597
TEST=Boot ManaTEE and verify wakeup from touchpad and other devices.

Change-Id: Ifce6919d3c3ab9e677ee0a6566aba4d720168db5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3593741
Reviewed-by: Tomasz Nowicki <tnowicki@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Micah Morton <mortonm@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-05-19 14:28:46 +00:00
Daniel Verkamp
0809b02831 devices: switch Timer::wait to Timer::mark_waited
All of these call sites are used in cases where a Timer has triggered
a WaitContext because it has expired, so we don't actually want to wait,
just mark the timer expiry as acknowledged.

BUG=b:213153157
TEST=tools/presubmit --all

Change-Id: If91ca66e1810756c0b441e1253f0022870ce1a3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652886
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-05-18 17:47:05 +00:00
Keiichi Watanabe
416a9cdd85 devices: vvu-proxy: Reports an error happening in worker thread
BUG=none
TEST=run vvu

Change-Id: I80f05c7c0d066f458279f6908b4ba7296f873e49
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3640878
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-05-18 16:57:10 +00:00
Anton Romanov
0124707336 Revert "crosvm: remove balloon stats request timeout"
This reverts commit 716b698659.

Reason for revert: this is wrong in multithreaded mode

Original change's description:
> crosvm: remove balloon stats request timeout
>
> It was done to avoid deadlock when stats are requested before guest is
> up. Implement a stub BalloonStats::NotReady replier until host is up so
> that timeout is no longer necessary.
>
> BUG=b:232289535
> TEST=few tast crostini/arc tests
>
> Change-Id: Ieb6888487ea5b10664b76d8f94330564e7a3c726
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3647161
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Auto-Submit: Anton Romanov <romanton@google.com>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Anton Romanov <romanton@google.com>

Bug: b:232289535
Change-Id: I11faa967d6030ad4a0c292069b0678260757fda8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3651672
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-05-17 19:23:48 +00:00
Anton Romanov
716b698659 crosvm: remove balloon stats request timeout
It was done to avoid deadlock when stats are requested before guest is
up. Implement a stub BalloonStats::NotReady replier until host is up so
that timeout is no longer necessary.

BUG=b:232289535
TEST=few tast crostini/arc tests

Change-Id: Ieb6888487ea5b10664b76d8f94330564e7a3c726
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3647161
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-05-17 17:45:21 +00:00