Commit graph

1439 commits

Author SHA1 Message Date
Long Cheng
1d32cd6312 Only ingore first set_config to active config
When a usb device is attached to guest kernel, guest kernel will
Try to set the usb configuration to value returned by
usb_choose_configuration. Unless the device has multiple configurations
and host side set it before attach to guest os, it will be same value
as what host kernel would set it during initialization. This would casue
a device reset and for Android devices in adb mode it will cause a
disconnect and reconnect.

Also we should allow user space trying to reset the device by setting
device configuration to active configuration.

BUG=b:123374026
BUG=b:232272092
TEST=Able to attach Pixel2 and Pixel4 to vm
TEST=Run CTS usb device verifer test on both phones
TEST=adb from crostini to test phones

Change-Id: I0e30aaa1b42a18741a2981e256d2268c1a70c46f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3631026
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Long Cheng <lgcheng@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-11 20:02:03 +00:00
Ryan Neph
4b23ee78bc gfxstream: enable async_fence_cb
Flip the switch for Gfxstream to stop using timer-based fence
polling and start using async fence handling callback.

BUG=b:175527587
BUG=b:192614792
TEST=cargo build --features=virgl_renderer,virgl_renderer_next,gfxstream
TEST=Run glxgears and vkcube in a crosvm guest VM with virglrenderer

Change-Id: I5f00f44d29bd584ad554d8892e9f13448c29c712
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3628303
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Ryan Neph <ryanneph@google.com>
2022-05-11 19:44:16 +00:00
Ryan Neph
d5fa537753 rutabaga_gfx: avoid fence_poll() if all components use async_fence_cb
An optional performance optimization that almost completely avoids the
wakeup cost of timer-based fence polling when all RutabagaComponents use
async_fence_cb. There is still a small overhead from the per-loop
virtio_gpu.needs_fence_poll() tests. This overhead will be removed in
later CLs, when timer-based fencing support is removed.

BUG=b:175527587
TEST=cargo build --features=virgl_renderer,virgl_renderer_next,gfxstream
TEST=Run glxgears and vkcube in a crosvm guest VM with virglrenderer

Change-Id: Id9f14bcbdaa4dcdc42b24be12d85cad2ea0efed5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3628300
Commit-Queue: Ryan Neph <ryanneph@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-11 19:44:15 +00:00
Ryan Neph
e246fff20c rutabaga_gfx: support fence handling via async callback
Adds another method for fencing where a rutabaga component may provide
an asynchronous callback for fence completion. When this method is
enabled, fences no longer need to be polled on the main thread.

When async_fence_cb is enabled, optional polling still occurs for
Rutabaga Components that still rely on it for other purposes (e.g.
virglrenderer for GL query checking).

Both the old and new methods of fence handling are supported with this
CL; e.g. timer-based polling and async callback, but timer-based polling
is the only one active. Follow-up CL(s) will switch to using the async
callback for each RutabagaComponent. Support for the old timer-based
polling will be removed after the async callback method stabilizes in
production.

Also, use a BTreeMap rather a HashMap since we only expect a dozen or so
entries at most. In such cases, a BTreeMap is faster.

* v1 (lfrb@collabora.com): remove all polling + add async_cb
* v2 (ryanneph@google.com): re-introduce optional polling to fix
  virglrenderer that relies on it for GL query checking.
* v3 (ryanneph@google.com): replace timer-based polling with
  eventfd-based poll() signaling for components that want to use it.
* v4 (ryanneph@google.com): add async fence handling beside timer-based
  polling to support both for a short time.

This is a pseudo-reland of commit
a999284da2, but modifications have been
made to support both fencing methods simultaneously.

BUG=b:175527587
TEST=cargo build --features=virgl_renderer,virgl_renderer_next,gfxstream
TEST=Run glxgears and vkcube in a crosvm guest VM with virglrenderer

Change-Id: I28f754aeef01972a01dab7990267415814a36c77
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3628299
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Ryan Neph <ryanneph@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-11 19:44:13 +00:00
Zyta Szpak
467430613a virtio: video: Increase command queue size
The queue size defines the number of available descriptors, that can be
used for exchanging messages between guest and hypervisor. Each
virtio-video command uses at least 1 descriptor (eg. CMD_QUEUE uses 2).
The amount of descriptors in use depends on the number of sessions and
buffers in input and output video queue.
In the worst case scenario the peak number can reach over 672 for 8
simultaneous streams, with 26 + 16 buffers each just for CMD_QUEUE
commands alone.

If the entire queue is overfilled with CMD_QUEUE for OUTPUT queue only,
the driver has no free descriptors for INPUT queue buffers. This leads
to encoder/decoder starvation, hence no OUTPUT buffer can be produced
and no CMD_QUEUE will finish, which leads to dead locking the device.

This patch increases the queue size with consideration of above details
with some headroom to avoid driver's deadlock.

BUG=b:204055006
TEST=App from https://github.com/chromeos/video-decode-encode-demo.git
with 8 simultaneous stream runs without blocking the device.

Change-Id: If51e340dd501b5b261518fba23fc541e3b55af8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3606869
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Emilie Roberts <hadrosaur@google.com>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Marcin Wojtas <mwojtas@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-11 08:05:32 +00:00
Daniel Verkamp
5297fadcc9 devices: virtio: clean up unsupported flags
Several devices were accepting virtio ring flags that they don't
actually support; remove these, as well as the common base_features
flags that are provided by the generic virtio device infrastructure.

The features removed from device implementations are:
- VIRTIO_F_VERSION_1: set by base_features()
- VIRTIO_RING_F_EVENT_IDX: set by base_features()
- VIRTIO_RING_F_INDIRECT_DESC: unsupported
- VIRTIO_F_NOTIFY_ON_EMPTY: unsupported
- VHOST_F_LOG_ALL: unsupported
- VIRTIO_F_ANY_LAYOUT: unsupported; transitional devices only

BUG=None
TEST=tools/presubmit --all

Change-Id: I9619d9bb784cb47ec85ffa4e25b7a743284d6da6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3582525
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-05-10 21:00:11 +00:00
Daniel Verkamp
3b98d5476a devices: virtio: mask bits in driver ready check
Previously, the check would only accept exactly the combination of bits
we specify in ready_bits due to the == comparison; the second check for
the failed bit would never be reached. Instead, mask off only the bits
we are interested in checking before comparing them.

BUG=None
TEST=tools/presubmit --all

Change-Id: Ib6cccdb249adeb267282ec0e5b51c0ac6b572490
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3582524
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-10 21:00:09 +00:00
Daniel Verkamp
78c474d423 virtio: create a DeviceType wrapper enum
This makes the VirtioDevice::device_type() function return type more
descriptive, and it lets us implement fmt::Display for the type instead
of a custom type_to_str() function.

BUG=None
TEST=tools/presubmit --all

Change-Id: Icfc2be37cf31ecab5e73f4b29c2eaaaa417317ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3582523
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-10 21:00:07 +00:00
Tinghao Zhang
7f1b94e96a devices: pci: use msi for pcie bridge
This patch split msi emulation from vfio-pci to a seperate file
msi.rs and make it usable for other devices. And we make pcie
bridge use msi instead of msi-x. The reason to use msi is that
msi-x would need extra mmio bar allocation, which does not work
when bridge is hotplugged into the system.

BUG=None
TEST=check msi functionality in both pcie root port and vfio device

Change-Id: Id262e4635d074c2a952807a625c8a0bf0afbf86a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3591961
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Xiong Y Zhang <xiong.y.zhang@intel.corp-partner.google.com>
2022-05-10 20:02:51 +00:00
Daniel Verkamp
3fab3baecc virtio-sys: add virtio_config and clean up imports
Restrict the bindgen patterns so that only the declarations from the
appropriate header are included in each binding, and add the
virtio_config binding to get the source of the VIRTIO_F_ and
VIRTIO_CONFIG_ #defines.

BUG=None
TEST=tools/presubmit --all

Change-Id: I216bd8d3540d918ad9bba162db0ae86b76d73f31
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3582522
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-09 21:20:27 +00:00
Lepton Wu
97a8f891a8 devices: vhost-user: fs: support VVU
Device can be started with

    crosvm device fs --vfio <PCI ID> --tag <TAG> --shared-dir <DIR>

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

Change-Id: I199113b1837686d78140936adcd8741a8c2b066e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3631019
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Lepton Wu <lepton@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Lepton Wu <lepton@chromium.org>
2022-05-09 18:06:31 +00:00
Daniel Verkamp
c7e45226be devices: pci: fill out the PciAddress docs
More or less fully document this file to make it a good documentation
example.

BUG=None
TEST=cargo doc
TEST=cargo test -p devices --doc pci_address

Change-Id: I9a02c057135bc684ccc7897a07cb8cfce77dd388
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3630423
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-06 20:46:58 +00:00
Daniel Verkamp
132957468f devices: pci: fix markdown quoting in doc comments
Escape the square brackets in doc comments to resolve the rustdoc
warning.

BUG=None
TEST=tools/cargo-doc

Change-Id: I78f60ef65f57b213da2f0e687ee295b7e046db9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3630421
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-05-06 20:46:56 +00:00
Daniel Verkamp
5e43f03d80 Fix rustdoc bare URL warnings
BUG=None
TEST=cargo doc

Change-Id: Ib9d14d8aa38eef97c02c60fca3928b70a833b6bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3630420
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-06 20:46:55 +00:00
Xiong Zhang
314dbc3afe pcie: Hotplug out interrupt for multi devices
When multi pcie endpoint devices are connected to one virtual pcie
root port as pcie multi function device, virtual pcie root port couldn't
inject hotplug out interrupt for each removed pcie device. Only one
hotplug out interrupt is needed for all the removed pcie devices.

When the first vfio-pci device send hotplug out vfio command, virtual
pcie root port will inject hotplug out interrrupt. Other vfio-pci device's
hotplug out vfio command just clean virtual pcie root port's structure,
and let virtual pcie root port prepare for the next hotplug in.

BUG=b:185084350
TEST=Check TBT dock's hotplug out function, TBT dock has multi pcie
devices.

Change-Id: I15c2807097c0065d2a78ef269720e57d15eeaf9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3604291
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-06 20:33:16 +00:00
Xiong Zhang
7245ebd353 pcie: hotplug in interrupt for mutli devices
When multi pcie endpoint devices are connected to one virtual pcie
root port as pcie multi function device, virtual pcie root port couldn't
inject hotplug in interrupt for each added pcie device. Only one hotplug
in interrupt is needed for all the added pcie devices.

So this commit adds a hp_interupt field into VfioCommandRequest, only
the last added pcie device sets hp_interrupt to true and requests virtual
pcie root port to inject hotplug in interrupt. Ohter added pcie devices
just create and configure vfio-pci device.

BUG=b:185084350
TEST=Check TBT dock's hotplug in function, TBT dock has multi pcie
devices.

Change-Id: I5a68ec38af9a32de9d4233b48e0aa3681e5a3ba3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3604290
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-06 20:33:15 +00:00
Noah Gold
f1bd7230be devices: vhost-user net device => multi-platform
Splits out the unix specific code in the vhost-user net device into the
sys module, and adds Windows support.

BUG=b:226233737
TEST=builds

Change-Id: I62690d007700f4ea1f55e1079b18115d6f7e0876
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3621416
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-05-06 18:03:53 +00:00
Xiong Zhang
98f0e3d29f pcie_host: Use pci multi function to attach multi devices under pcei root port
Usually a TBT dock has one pcie switch and one or more pcie endpoint device
which connect to pcie switch's downstream port, when such TBT dock is hotplug in,
crosvm will find the first pcie endpoint device, passthrough it into guest and
put it under virtual pcie root port in guest, as one pcie root port could
connect one device only, This means only one pcie endpoint device could work
in guest now.

In order to let all the TBT dock's pcie endpoint devices work in guest, virtual
pcie switch is needed. But virtual pcie switch need more development work, as a
short solution, this commit mark all the pcie endpoint devices as multi pci
function device, then all of them could connect to one virtual pcie root port.

This commit do the following three things:
1. Search all the pcie endpoint devices under host pcie root port.
2. Record all the pcie endpoint devices attached to virtual pcie root port,
so that they could be removed in hotplug out.
3. Allocate pci function number to all the pcie endpoint devices.

BUG=b:185084350
TEST=Check TBT dock's function in guest, the TBT dock has multi pcie
endpoint device.

Change-Id: I07df3b556ba1ac8f7a7a3e49f221f0bf6c7ce97b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3604289
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-05 22:35:39 +00:00
Xiong Zhang
1756efb801 Pcie: Bind hotplug vfio pci device into vfio-pci-pm driver first
This commit use the same logic as in initramfs, let hotplug vfio
pci device bind to vfio-pci-pm driver first, if it fails, then
bind to vfio-pci driver.

Without this, there are error message about hotplug vfio pci device's
pm_ops.

BUG=None
TEST=Check hotplug vfio pci device's driver in hypervisor

Change-Id: I8330c7859dff2b8b2db1baa67c16181e2de66ae1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3595227
Reviewed-by: Micah Morton <mortonm@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-05 22:35:38 +00:00
Daniel Verkamp
9ab4f29e7a devices: vhost-user: fs: keep executor fd inside jail
A previous commit moved the creation of the executor for the vhost-user
device processes before the minijail jail_and_fork() call, and the file
descriptor of the executor was not marked for preservation when entering
the jail, so running the vhost-user-fs device would result in errors
like this:

  [WARNING:cros_async/src/sys/unix/uring_executor.rs:343] Failed to
  submit NOP for waking up executor: Failed to enter io uring: 9

This is because the io_uring context file descriptor was no longer
valid, so uring system calls would return 9 (EBADF).

Add AsRawDescriptors implementations to UringExecutor and FdExecutor so
we can preserve the fd across the minijail fork.

Other vhost-user devices were not affected because they don't enter a
jail; the fs device requires this so it can do uid/gid remapping.

BUG=b:231396155
TEST=crosvm device fs --socket /tmp/vhost.sock --tag test --shared-dir /

Fixes: d368c1520a ("devices: vhost-user: fs: remove global executor variable")
Change-Id: I38cf02034bbc28de2582e2ea92bdc13b1d6055d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3628292
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Lepton Wu <lepton@chromium.org>
2022-05-05 20:03:03 +00:00
Vikram Auradkar
cdb9e125ae base: rename EventFd to Event
Note that
- the file/symbols within `src/sys/unix/eventfd.rs` have not
  changed yet.
- base still exports EventFd to keep common/cros_asyncv2 happy

BUG=b:213153157
TEST=presubmit

Change-Id: Ie0a4308e8501d2e91364b049e6575d656af866cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3624568
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-03 21:04:19 +00:00
Vikram Auradkar
cceb96ee3c base: add from_safe_descriptor to SharedMemory
from_safe_descriptor is used by both windows and unix - windows has to
supply size because the way `handle`s are treated. So make size
optional.

BUG=b:213153157
TEST=presubmit

Change-Id: I984b706852f91f5df6b8701df09526f40068f8fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3621211
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-05-03 18:55:32 +00:00
Grzegorz Jaszczyk
ae70c7f3e9 acpi: add support for generating fixed sleep button event from cmd line
Add support for injecting an ACPI sleep button event using the command
line. Upon receiving crosvm sleep command, emulate vPM1 accordingly and
trigger vSCI to the guest if ACPI fixed sleep button event is enabled.

Additionally do not mask the ACPI sleep button event in FADT flags for
the guest anymore. Quoting ACPI specification regarding the sleep button
flag: "If the system does not have a sleep button, this value would be
“1” and no sleep button device would be present".

BUG=b:194391015
TEST=Boot the VM, issue "crosvm sleepbtn /run/vm/vm.<hash>/crosvm.sock",
check guest /sys/firmware/acpi/interrupts/ff_slp_btn counter and if vSCI
was injected. With some additional changes (e.g. acpid on the guest)
suspend guest by issuing sleepbtn command from the host.

Change-Id: Ie50a3a781ba4fbfa04da75186fb5549919a5bd68
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3602867
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
2022-05-01 20:29:35 +00:00
Noah Gold
dd26934e16 net_sys: add constants used on Windows.
The constants herein are used on Windows. Normally we'd prefer to get
them from libc, but on Windows, these constants aren't available. For
consistency, cross platform code has been adjusted to use the net_sys
versions of the constants.

BUG=b:213151463
TEST= builds

Change-Id: I9048269483b9553f316aa8690da3ba4acdc8272a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3609236
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-04-29 21:03:57 +00:00
Daniel Verkamp
9975e79f78 devices: vsock: simplify device path to a PathBuf
The vhost-vsock device had some special-case code to handle a file
descriptor as the vhost device rather than a path. However, crosvm
already has base::open_file(), which has special handling for magic
/proc/self/fd/<N> paths and treats them as already-open file descriptors
without requiring a separate command-line option.

This change converts the vhost vsock device to accept only a path
instead of a special path/fd enum, using base::open_file() to support
passing already-open file descriptors via the /proc/self/fd path format.
The existing --vhost-vsock-fd option is kept for compatibility, but it
now just creates a /proc/self/fd path from the passed fd. Existing users
are encouraged to migrate to --vhost-vsock-device.

BUG=b:218223240
TEST=cargo test -p devices vsock::tests::params

Change-Id: Ifad2b7ad0824d4f24d9b12a4af1448557fadcdc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3564224
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-28 23:05:29 +00:00
Ryan Neph
13108989b1 rutabaga_gfx: create_context with an optional name
RutabagaComponents receive an Option<String> with calls to
Rutabaga::create_context(). This is desirable for virglrenderer so that
the guest application name can be used by the host renderer,
particularly to enable application specific GPU driver configs based on
program name matching. It is ignored by other RutabagaComponents for
now.

BUG=b:230678191
TEST=emerge crosvm
TEST=vkcube in VM

Change-Id: Ic08a02040ecc1d2e62795c248a66a88394b268e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3612467
Commit-Queue: Ryan Neph <ryanneph@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-04-28 21:41:29 +00:00
Noah Gold
9bc5fdf2d2 devices: reorganize vhost-user net for styleguide.
The early cross platformization work was done prior to finalization of
the styleguide. This CL reorganizes the files to match the intended long
term state.

BUG=b:226233737

TEST=bots

Change-Id: If2058aa69122606071b3fc26fd85bbd31f5977fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3597037
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-04-28 20:16:57 +00:00
Tina Zhang
c834b038c2 devices: virtio: iommu: get iova_max_addr according to ranges' info
Previously the iova_max_addr was got according to the cpu physical
address size. Since the cpu physical address is no more than the maximum
iova size provided by hardware iommu, the iova space size can work for
any passthrough devices. But it may not utilize the whole iova space, as
the iova size isn't got from the underlying hardware iommu.

This patch introduces a way to get iova_max_addr according to the iommu
ranges' info, therefore the iova_max_addr can be precisely calculated.

BUG=b:185084350
TEST=Boot a crosvm guest with vIOMMU enabled

Change-Id: I4ed37bf158208d61663a4bf474549df4fce3adf5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3580373
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-04-28 04:43:11 +00:00
Tina Zhang
349247860c devices: virtio: iommu: assign a sensible default value to page_size_mask
Assign a sensible default value to page_size_mask and reject the empty
page_size_mask case.

BUG=b:185084350
TEST=Boot a crosvm guest with vIOMMU enabled

Change-Id: Id711c9ff25265f707618a58eb212fd5ca16383e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3580372
Reviewed-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-04-28 04:43:10 +00:00
Richard
8b62a101cf vhost-user handler: Upstream Windows handler.rs device implementation
Also update vsock handler enum usage

Bug: b:228081882
Test: built and presubmits
Change-Id: I7c771a84632c1acb819ecb7eb93b7351468ffa8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600919
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-04-28 00:55:47 +00:00
Alexandre Courbot
8452002639 devices: vhost-user: handler: use the same run loop for all handler types
The VVU runner had to use a dedicated run loop as the event signaling
availability of vhost-user commands required being explicitly read to go
low. Fix this by decreasing the event counter when reading buffers on
the VvuDevice. On top of allowing the handler event to behave as
expected (i.e. being readable iif there is input pending), this is also
safer as one buffer write does not necessarily correspond to exactly one
vhost-user command, as the previous code assumed.

As it turns out, this also produces a run loop that is generic enough to
be reused with the vhost-user VVU device, reducing some more technical
debt along the way.

BUG=b:229554679
TEST=vhost-user console device works.
TEST=vvu console device works and does not receive spurious events from
the vhost-user request handler.
TEST=vhost-user vsock device works (tested with socat on both ends).
TEST=VVU vsock device works (tested with socat on both ends).

Change-Id: I54e53087bf9e3447d0ab4a8a0ae26079a439f97c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3585202
Reviewed-by: Richard Zhang <rizhang@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-27 00:07:57 +00:00
David Stevens
1af4dcd7fd devices: virtio: iommu: reset on detach
Add support to virtio-iommu for detaching virtio device endpoints from
their domains. Passthrough devices do not support detaching due to VFIO
limitations.

BUG=b:230065032
TEST=start VVU block backend, connect and kill sibling, restart backend

Change-Id: Ie54fa5f4ecc732d41061eaaca36ed616a112124b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600173
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-04-26 09:30:21 +00:00
Alexandre Courbot
f82754c78c virtio: console: inline write_output function
These two lines are called from one place and do not justify having a
dedicated function.

BUG=b:228912920
TEST=cargo build

Change-Id: Ia57b8f74bb6fa9c7b78e7caa56ea3f7c3ce259db
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600163
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-04-23 03:51:53 +00:00
Richard
6601d6cf36 vhost-user handler: Upstream Windows handler.rs vmm implementation
System specific code refactored into "sys" module

Bug: b:228081882
Test: built and presubmits
Change-Id: Id9caacb23cc7fcd8ca8640ce7292562809f0f71e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3601236
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-04-22 18:27:10 +00:00
Pierre-Clément Tosi
5edab50b7c virtio: Add default VirtioDevice::supports_iommu()
Introduce a way for virtio devices to broadcast their need for a
virtio-iommu without relying on parsing their feature bits, as
VIRTIO_F_ACCESS_PLATFORM may be set for other reasons than needing an
IOMMU.

Bridge the gap between PciDevice::supports_iommu() and that new method
in VirtioPciDevice.

Use the new method to enable virtio-iommu support in VirtioVHostUser.

BUG=b:223546213
BUG=b:226644087
TEST=tools/dev_container tools/run_tests --target=vm:aarch64

Change-Id: I5c20def2b96ee971f3d56776095635a984feccfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3571561
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-22 10:07:35 +00:00
Noah Gold
486fa03648 net_util: refactor unix for cross platforming.
BUG=b:213151463

TEST=bots

Change-Id: I67d43171df084392175261de98c8dc0404a933d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3598233
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-04-22 01:37:58 +00:00
Noah Gold
78ef113617 cros_async: make AsyncTimer use base::Timer
TimerFd is the sys_util era Unix-specific timer, which doesn't support Windows.
This CL moves us to base::Timer, which is the cross platform equivalent.

Thanks to acourbot@ for suggesting the splits in this series.

BUG=b:213147081
TEST=see final CL in series.

Change-Id: I41c8ad88da77c48397ed466ff11aecd703c470a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3583612
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-04-19 05:37:41 +00:00
Noah Gold
084aa95af1 cros_async: make AsyncEvent use base::Event
EventFd is the original sys_util era Unix-specific Event. We need to use
base::Event, which is the cross platform event that works on Windows.

Thanks to acourbot@ for suggesting the splits in this series.

BUG=b:213147081
TEST=see final CL in series.

Change-Id: I174313cb544c5fc3768810365a42e6eaac1ca91a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3583611
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-04-19 05:37:40 +00:00
Risan
ab11843e86 fs: Support setting project inheritance flag
This CL allows passthrough to set project inheritance flag through
cryptohome since setting project inheritance flag cannot be done in
user namespace.

BUG=b:226908517
TEST=atest android.appsecurity.cts.StorageHostTest

Change-Id: Icdde5164e2e6f8655fff28748f6bc18449ad36c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3585215
Reviewed-by: Ryo Hashimoto <hashimoto@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Risan <risan@chromium.org>
2022-04-19 00:18:41 +00:00
Shao-Chuan Lee
105d68747b Revert "rutabaga_gfx: remove fence polling and enable async callback"
This reverts commit a999284da2.

This also introduces two extra `use` statements to fix the corresponding
errors in the LUCI build, which did not occur in local builds.

Reason for revert: caused deadlock in virglrenderer

Original change's description:
> rutabaga_gfx: remove fence polling and enable async callback
>
> Now that rutabaga users can provide a callback for fence
> completion, fences no longer need to be polled on the main thread.
>
> Optional polling still occurs for Rutabaga Components that still
> rely on it for other purposes (e.g. virglrenderer for GL query
> checking).
>
> Also, use a BTreeMap rather a HashMap since we only expect a dozen
> or so entries at most.  In such cases, a BTreeMap is faster.
>
> * v1 (lfrb@collabora.com): remove all polling + add async_cb
> * v2 (ryanneph@google.com): re-introduce optional polling to fix
>       virglrenderer that relies on it for GL query checking.
> * v3 (ryanneph@google.com): replace timer-based polling with
>       eventfd-based poll() signaling for components that want to
>       use it.
>
> BUG=b:175527587
> TEST=glxgears and vkcube in a crosvm guest VM.
>
> Cq-Depend: chromium:3555854, chromium:3563893
> Change-Id: I8e0181317e954cd15e2b8dc04c9b1329b0a6e182
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2860746
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Ryan Neph <ryanneph@google.com>

BUG=b:175527587,b:228782431,b:228521246
TEST=arc.Notification.vm on kukui-arc-r
TEST=dEQP-VK.wsi.android.swapchain.create#image_usage on dedede/kukui-arc-r

Change-Id: I616e3f283a60fe6a260f796cddce67c548b5e304
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3584076
Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Ryan Neph <ryanneph@google.com>
2022-04-13 17:46:41 +00:00
Shao-Chuan Lee
a1fac454ed Revert "gfxstream: support async fence cb"
This reverts commit 3c2d5cefa2.

Reason for revert: depends on crrev.com/c/2860746

Original change's description:
> gfxstream: support async fence cb
>
> This adds the asynchronous interrupts in crosvm-gpu for gfxstream.
> This will allow gfxstream to alternate between the main signalling
> method (ASG [1]) and the more traditional interrupts when it
> makes sense performance-wise.
>
> gfxstream also requires new write fence callbacks that take into
> account the ring_idx and ctx_id where the fence is on.
>
> [1] goto.google.com/address-space-graphics
>
> BUG=b:192614792
> TEST=Tested locally with Vulkan cereal
>
> Change-Id: I010d9ebfc71594b393fee062b984a4c6d69404d8
> Reviewed-on:
> https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3027489
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>

BUG=b:192614792,b:228782431,b:228521246
TEST=arc.Notification.vm on kukui-arc-r
TEST=dEQP-VK.wsi.android.swapchain.create#image_usage on
dedede/kukui-arc-r

Change-Id: I4d2c43320880e38e8396cee3b96ce8c32addf39b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3584075
Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Commit-Queue: Ryan Neph <ryanneph@google.com>
2022-04-13 17:46:40 +00:00
Keiichi Watanabe
c59db48131 devices: vvu: Unbind driver first regardless of driver type
When a VVU driver starts, the current implementation tries to unbind
virtio-pci driver unconditionally, but this can fail when no driver is
bounded or another driver is bounded.

Instead of assuming virtio-pci driver is bounded, we should unbind the
bounded driver regardless of its type by writing to
"/sys/bus/pci/devices/${ADDR}/driver/unbind", which is a symlink to the
unbind file of the currently bounded driver.

This change will allow the vvu driver to open a vvu device after a previous
driver exists. (Note that our vvu device hasn't supported
reinitialization yet.)

BUG=b:216407443
TEST=run vvu on workstation

Change-Id: Ib6c3ac1cd51a8018573596eef9fe0fd759450c07
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3581833
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-13 02:27:28 +00:00
Alexandre Courbot
b32bcc4edc devices: vvu: handler: do not run executor within async method
run_vvu() was running the request handling loop on the executor passed
as argument, even though it is an async function that is being run on
the very same executor.

BUG=b:194137301
TEST=VVU console device is working.

Change-Id: I8c79f9285329c07b3411b2d4121c94d0e5c88a49
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578142
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-04-12 02:11:37 +00:00
Daniel Verkamp
f620437e8b virtio_sys: regenerate bindings
BUG=b:218388029
TEST=tools/presubmit --quick

Change-Id: I381dbc4d97e3a0a99dedd4416a347388daf4ccf8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3339853
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-04-11 21:14:01 +00:00
Daniel Verkamp
f35f636cc5 Rust 1.60 clippy fixes
BUG=None
TEST=tools/presubmit # with rust-toolchain updated to 1.60.0

Change-Id: I5772e8b0593f8d92003e93aeb2145e87610abe2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3577332
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-04-11 20:40:36 +00:00
Daniel Verkamp
fa0ffe7e81 base: accept AsRawDescriptor in PollContext/EpollContext/mmap
This lets us remove the wrap_descriptor() calls.

A few other places around the tree need to be updated to use Descriptor
instead of RawFd to match the new API.

BUG=None
TEST=tools/presubmit

Change-Id: Ie290f082b50bcf6ae8f77ce6a8b7615fad1be480
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3572770
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-04-11 20:27:06 +00:00
Peter Fang
63c3a69e21 devices: vfio_pci: implement coordinated PM using PCI config accesses
Perform coordinated PM in the hypervisor for vfio-pci devices using
several sysfs interfaces added to the hypervisor kernel.

The interfaces used and the PCI header hacks are identical to the ones
previously added to pcie.

This is only a temporary solution. A proper communication channel should
be implemented in the future.

BUG=b:189182339
TEST=boot manatee and verify the sysfs interfaces are used correctly in
     the hypervisor

Change-Id: I8022ed17e4bf898065b5ebcf8fe09f5c8e3c3fa4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578021
Reviewed-by: Dmytro Maluka <dmy@semihalf.com>
Reviewed-by: Tomasz Nowicki <tnowicki@google.com>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-11 19:09:27 +00:00
Peter Fang
87f947a4ff pcie: implement coordinated PM using PCI config accesses
Perform coordinated PM in the hypervisor using several sysfs interfaces
added to the hypervisor kernel.

- /sys/bus/pci/devices/X/power/coordinated
  Writing "enter" to this file will cause the device to enter PCI
  coordinated PM
  Writing "exit" to this file will cause the device to exit PCI
  coordinated PM

- /sys/bus/pci/devices/X/power/op_call
  A write to this file will cause the device to perform a PCI PM
  operation

- /sys/bus/pci/devices/X/power_state
  A read from this file returns a snapshot of the device's current power
  state, including PCI_D3cold

The guest makes use of these interfaces through a couple of
quick-and-dirty hacks in the PCI header in the guest.

- Byte writes to the "Revision ID" register are interpreted as PM op
  calls
- Reads from the "BIST" register are interpreted as device PCI power
  state

The PCI spec defines the "Revision ID" register as read-only. The "BIST"
register is mostly considered legacy and its use has not been observed
in recent Chromebooks.

The rest of the PCI config accesses remain the same.

This is only a temporary solution. A proper communication channel should
be implemented in the future.

BUG=b:189182339
TEST=boot manatee and verify the sysfs interfaces are used correctly in
     the hypervisor

Change-Id: I7570728257300435d0fc77076d1e3f6bea6af5e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3455125
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmytro Maluka <dmy@semihalf.com>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-11 17:54:51 +00:00
David Stevens
4257919fa7 devices: vvu: poll when opening vvu device
Launching a VVU device requires access to /dev/vfio/$vfio_group. The
permissions on those files can't be set by upstart, since the files
don't exist until a vvu device process binds its vvu pci device to
vfio-pci. Instead, the permissions are set via udev rules.
Unfortunately, there is no good way to wait for udev to modify the
permissions, so the device process just needs to poll until it is
successfully able to open its device.

BUG=b:222424090
TEST=vmc start termina

Change-Id: Id8668c66ff7ddaa7bb43061979ead51d12cde8f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3574422
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-04-11 04:56:18 +00:00
Daniel Verkamp
aebda741ff devices: pci: convert PciAddress::from_string into FromStr impl
Implement the standard FromStr trait, since it has the same prototype as
our existing from_string function.

BUG=None
TEST=cargo test -p devices pci_address

Change-Id: I41bb77638891bfcc39f9fb555b3463f2f92c029f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3576956
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-04-08 19:42:39 +00:00