Commit graph

1604 commits

Author SHA1 Message Date
David Stevens
b60cbbf0f6 devices: vvu: use mmap instead of vfio write
Access notification configuration area via mmap instead of via vfio-pci
driver. With this, all accesses to vvu bar 2 are done via mmap.

BUG=b:237647217
TEST=boot sibling VM, observe /sys/kernel/debug/x86/pat_memtype_list

Change-Id: Id73530accad97af2e6cbb3480f2c9859e9d0688a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739562
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-07-06 00:46:27 +00:00
Alexandre Courbot
d84f8b5f14 virtio: vhost-user: cras: fix build
Another one in the long tradition of forgetting to update cras...

BUG=None
TEST=emerge crosvm passes for Hatch.

Change-Id: Id2a2675ffbc7bcd2908f4682055b7848321bbe0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3744915
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-07-05 11:36:28 +00:00
Alexandre Courbot
78709b185c virtio: vhost-user: console: add type to reset stdin to canon mode
Add a type that, when dropped, resets the standard input to canon mode
if needed. We were doing it manually so far, which is error-prone if we
exit early due to an error.

This new type is also required for properly implementing the new
`devices` command.

BUG=b:217480043
TEST=vhost-user console device works on Linux.

Change-Id: I36d55f248198dc6383ae8e5557ac394baaab6e70
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3725736
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-07-05 08:17:03 +00:00
Alexandre Courbot
b5cc1dcc62 devices: vhost-user: handler: unroll guest memory creation functions
These functions are now called from only one point, and can be unrolled
without any harm to readability.

BUG=None
TEST=cargo build

Change-Id: I97c110d80f8f81c2c66eed48ae042e160535cec6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3599231
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-07-05 08:17:00 +00:00
Alexandre Courbot
1379a39567 devices: vhost-user: handler: define trait for platform-dependent ops
The DeviceRequestHandler used to differenciate between regular
vhost-user and VVU using an internal enum. This doesn't scale and makes
platform-dependent code visible in the handler code.

Improve this by introducing a VhostUserPlatformOps trait that is
implemented by vhost-user and VVU supporting structs. This will allow us
to move these structs into a sys directory in the future, and to add
support for new platforms without it being intrusive.

As a nice side-effect, the trait can also be used for free in the vsock
device, removing some technical debt there.

The Doorbell also happens to be platform specific, so put it behind the
platform module too.

BUG=b:229554679
BUG=b:230665747
TEST=vhost-user console device works.
TEST=VVU console device works.
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: I8d9faece7e5631921e0b622efaafba5b7fa2df8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3599230
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-07-05 08:16:58 +00:00
Alexandre Courbot
c771a1dc1a virtio: vhost: user: introduce VhostUserListener platform type
Vhost-user transport can be implemented differently depending on the
system ; on Unix it can work through a socket or a VFIO device, whereas
Windows will use a Tube. This CL introduces a platform-specific
VhostUserListener type that we will use to abstract this part and
increase the part of shared code between Unix and Windows. It is also
useful to abstract the difference between the different kinds of
listeners on a same system, as it is able to create the right type from
an input string.

This type will also be important to implement jailed vhost-user devices.

The Windows implementation is still a TODO ; this is ok for now as only
the Unix code makes use of it.

BUG=b:217480043
TEST=vhost-user console device works on Linux.

Change-Id: If2f308ce7f71420012ebd2d49361454706f8a6ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706489
Reviewed-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-07-05 08:16:57 +00:00
David Stevens
c6dfb309d2 devices: vvu: set interrupt vector before enable
According to the virtio spec, drivers must configure other virtqueue
fields before enabling the virtqueue.

BUG=None
TEST=boot manatee sibling

Change-Id: I7431682a351269a3c45a508848ae6e9992ab0c10
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3737408
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-07-05 04:32:03 +00:00
David Stevens
7a64a8ecf3 devices: pci: fix typo in pci bridge window allocation
Fix an error where window_base was updated instead of pref_window_base.
Since the calculations for the two windows are the same, refactor it out
into a separate function. Also, return an error on allocation failure,
instead of just printing an error.

BUG=b:237576651
TEST=boot brya-manatee on primus

Change-Id: I82ffdea00156a95886a0a5913552f3fd6e77a2fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739712
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-04 10:22:41 +00:00
David Stevens
4a62a8ee3f irqchip: disable flaky unit tests
Disable tests which rely on sleep for correctness.

BUG=b:237977699
TEST=kokoro

Change-Id: I37f467f5385de4e70c31f5ce7c815d3ba4dd83d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3740226
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-04 09:42:25 +00:00
Dmitry Torokhov
264c805f04 devices: vvu: do not try to change driver for VVU devices
It is not the task of crosvm, which is usually unprivileged process, to
mess up with the system configuration, so it should simply expect that
VVU devices are already bound to vfio-pci driver and stop trying to do
it itself.

BUG=b:196186396
TEST=Boot redrix-manatee, start crostini.

Change-Id: Icb777cf66fd54bd74d656821fb76587c7ee70ca3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3712552
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2022-07-02 19:33:21 +00:00
Richard
1b0f01be24 devices: Enable mods that already build or had a trivial fix
BUG=b:213149155
TEST=built and presubmits

Change-Id: I42065bb583aed2ed3ad85b2c4189cb5d86aacfd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3736924
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-07-02 00:00:29 +00:00
Richard
5d77466913 virtio-vhost: Enable block tests
Commented out code reference sandbox crate, which still needs to be
upstreamed

Still need to enable:
 * balloon (try_clone not implemented)
 * console (Need to enable Serial)
 * snd (Unix code not conditionally compiled out)
 * gpu (Waiting for graphics team to upstream)

BUG=b:237011316
TEST=ran "./tools/run_tests --target=host --arch=win64 --verbose"

Change-Id: I1b5f7ae575365351184042bc65cffcfd7efe999a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3721870
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-07-01 23:44:09 +00:00
David Stevens
9df3eb7ef2 devices: virtio: disallow modification of ready queues
Disallow modification of a queue configuration's after it has been
enabled, since the spec states drivers MUST configure the other
virtqueue fields before setting enabling the virtqueue. This allows the
queue validation to be done once and then saved, instead of requiring
validation for every peek.

Before this change, modifications of running virtqueues were not well
defined, since the Queue instance owned by the VirtioPciDevice is not
the same as the Queue instance owned by the VirtioDevice implementation.

BUG=None
TEST=boot ARCVM and crostini on ManaTEE and non-ManaTEE

Change-Id: Ibd1f2bdb0a49865cedd8a0424199a72316696b4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3737409
Commit-Queue: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-07-01 06:03:56 +00:00
David Stevens
3b6c7295e3 vm_memory: move udmabuf support to vm_memory
Refactor udmabuf support out from virtio_gpu into the shared vm_memory
target, so that can be used for vvu.

BUG=b:201745804
TEST=compiles
TEST=./tools/bindgen-all-the-things

Change-Id: I2944f0cb8c75e4320400bfb9f7026dc1efe0c12b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716339
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-07-01 05:29:23 +00:00
David Stevens
48b0b429d6 vhost_user: refactor device activation
Move worker thread creation from frontend device into handler. This
removes the need to duplicate the worker thread boilerplate in each
individual device.

BUG=b:201745804
TEST=compiles

Change-Id: Ib6567402a809b9cafe286f575751419e31469d76
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716338
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-07-01 04:44:36 +00:00
Daniel Verkamp
98fcb96d6b Cargo: bump all rand dependencies to 0.8
The previous configuration made us pull in three different versions of
rand, and depending on "*" is a recipe for API incompatibility.

crosvm-fuzz needs to match its rand version to the rand_core used in
common/cros_fuzz, so that will be upgraded separately.

BUG=b:236978141
TEST=cargo build
TEST=emerge-hatch crosvm

Change-Id: I655ed3f156e4ac43afa3122596f62e9caa43b4f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3722184
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-30 23:22:37 +00:00
Noah Gold
b273d2f30b arch: upstream Windows support.
Fix various odds and ends that don't build / work properly on Windows.

BUG=b:237597358
TEST=builds

Change-Id: I5a6393cc15b3775f8d35b147498210ffc096cd10
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3736758
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2022-06-30 20:34:12 +00:00
Vaibhav Nagarnaik
45fb59a2bb Enable irqchip and tsc for windows
Enable most of modules under `irqchip` as well as `tsc` to work with
windows since all their dependencies have been completed. They were
already working for unix.

The test `irqchip::userspace::tests::irq_event_tokens` fails on wine,
however, it work on windows and unix natively.

The test `tsc::calibrate::tests::test_frequency_higher_than_u32` fails
for hosts with cpu>64, since the windows implementation for setting
thread affinity does not support cpu>64.

BUG=b:237024070
TEST=Ran `tools/run_tests --target=host --arch=win64`

Change-Id: I15d8f3c3256e89f89efbe64dbe2ad809fcd90a72
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3737456
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-30 19:24:08 +00:00
Vikram Auradkar
1295a6af47 crosvm: add serde to arg types
Windows serializes/deserializes these types to send over a Tube.

BUG=b:213146388
TEST=built on downstream windows and presubmit

Change-Id: Ib9ca4cbb2758a997788c4bab46d573a532e8e3d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3735635
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-30 17:47:59 +00:00
Richard
b9ddd723ce virtio-vhost: Enable handler to be built and tested on Windows
Still need to enable:
 * balloon (try_clone not implemented)
 * console (Need to enable Serial)
 * snd (Unix code not conditionally compiled out)
 * gpu (Waiting for graphics team to upstream)
 * vhost-user block

BUG=b:237011316
TEST=ran "./tools/run_tests --target=host --arch=win64 --verbose"

Change-Id: If2b69250477f88ded7176054196107733736786e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3721868
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-06-30 00:48:02 +00:00
Daniel Verkamp
e5c6e65731 devices: pit: remove clock_gettime() usage
The original Pit code encoded the start value of a timer into the
count_load_time field as a number of nanoseconds since the start of
the host's monotonic time value. Instead, we can use the PitCounter's
creation_time as the epoch. This makes the math look a bit more sensible
and removes the use of the non-portable clock_gettime() function.

Before
======

get_channel_state():
    count_load_time = get_monotonic_time() - start.elapsed()
=== count_load_time = now() - (now() - start)
=== count_load_time = start

set_channel_state():
    start = now() - (get_monotonic_time() - count_load_time)
=== start = now() - now() + count_load_time
=== start = count_load_time

After
=====

get_channel_state():
    count_load_time = start - creation_time

set_channel_state():
    start = creation_time + count_load_time

BUG=chromium:908689
BUG=b:213149155
TEST=cargo test -p devices pit
TEST=tools/run_tests --target=host --arch=win64

Change-Id: I5468d1d964a04b1ce96979ed583b729d139e1005
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723804
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-29 22:08:44 +00:00
Alexandre Courbot
d8842cf3aa virtio: vhost: user: handler: make sys module follow style guidelines
Export the platform module under the `platform` name as requested on
https://google.github.io/crosvm/contributing/style_guide_platform_specific_code.html#platform-specific-symbols

BUG=None
TEST=cargo build

Change-Id: Ic4fa198a39d9435879e3bccf3e2fc80378c5737e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3729248
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-29 13:23:06 +00:00
Zihan Chen
0423074861 fs: Fix compiler warnings for feature chromeos
Compiler warnings that only occur when compiled with feature chromeos are fixed.

Fixed=b:235772995
TEST=none

Change-Id: Ie1f120798d0812e7e54984292ccccdac2477a030
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3731294
Commit-Queue: Zihan Chen <zihanchen@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-06-29 07:44:09 +00:00
Richard
efde16f4d2 virtio: Enable build and tests for some virtio mods
Still need to enable:
 * balloon (try_clone not implemented)
 * console (Need to enable Serial)
 * snd (Unix code not conditionally compiled out)
 * gpu (Waiting for graphics team to upstream)
 * vhost-user block and handler

The vhost mod is also being built now, but the vhost devices that don't
build on Windows have been disabled.

BUG=b:237011316
TEST=ran "./tools/run_tests --target=host --arch=win64 --verbose"

Change-Id: I3d06a9d49b4bdae14dea47fcfa030834b55925ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723797
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-28 00:46:27 +00:00
Alexandre Courbot
4f902ffc9e ffmpeg: specify supported resolution range for input formats
This is required so the guest can know which resolutions are supported
for encoded formats.

BUG=b:169295147
TEST=ffplay from Linux guest can start streaming.

Change-Id: I6f86108efbc8971f3ee4b9ec494cec16ebce323d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716017
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-28 00:45:55 +00:00
David Stevens
8b9fc10192 vm_control: use Protection in mapping requests
Switch VmMemoryRequest and FsMappingRequest to use base::Protection to
express permissions, in preparation for unifying the APIs.

BUG=b:201745804
TEST=boot ARCVM and crostini

Change-Id: Id001abbd2dde19aa14fcf1643f25abafdd66a2e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716337
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-27 00:51:20 +00:00
Pattara Teerapong
5cf9a8fb87 devices: virtio: snd: Support num_{output,input}_devices
Add support to create multiple PCM devices in virtio-snd
in addition to multiple streams support. Android will
use different PCM devices for different use cases.

Change num_{output,input}_streams to number of streams
per device.

Changes:
- Add num_{output, input}_devices support in ChromeOS's backend
- Update num_{output, input}_streams in ChromeOS's backend
- Update help message

BUG=b:236924546
TEST=unit test for Parameters parsing
TEST=`aplay -l` with different number of output devices/streams
TEST=`arecord -l` with different number of input devices/streams

Change-Id: I29a3ecc6002ce669c5f771ef490f10419848380e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3722007
Commit-Queue: Pattara Teerapong <pteerapong@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-24 16:04:19 +00:00
Alexandre Courbot
8297d745c6 devices: virtio: console: use ReadNotifier trait for polling
AsRawDescriptor is a very generic trait and some of the types we want to
use as input sources already implement it for other purposes.
ReadNotifier makes the purpose of the returned descriptor obvious (wait
for some data), so use it instead.

BUG=b:228912920
TEST=console device works in both regular and vhost-user modes.

Change-Id: I68a4ce05be449e07ea71e7cb472e8cda00e9d84d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671059
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-24 03:19:46 +00:00
Alexandre Courbot
947754f011 devices: virtio: console: add async console device shared with vhost-user
Move the async runner of the vhost-user console device into its own
module and implement a regular VirtioDevice on top of it. This makes
both the virtio and vhost-user console devices use the same
ConsoleDevice struct and runner code, and also removes the input reader
thread from our virtio implementation.

The Windows support cannot use async and thus still needs the older
console device, so keep it around for now even though it is not used on
Linux.

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

Change-Id: I0a8dfe6c507ef9b765d8d1cdf9870cdcd128a9aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600172
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-24 01:56:17 +00:00
Junichi Uekawa
6af7ff8540 crosvm: Pass down CpuidResult instead.
So that a copy becomes a straightforward copy.

We were copy-pasting eax ebx ecx edx many times here.

BUG=None
TEST=build

Change-Id: Ibdabdd0da3876159bda3d29aa2a3927b9a3f40ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3717927
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-23 22:17:13 +00:00
Vaibhav Nagarnaik
ab004ddc01 irqchip: Upstream tests
Also remove `dead_code` annotation from `apic.rs` since the consumers
have been added.

BUG=b:213149158
TEST=Ran `cargo test -p devices irqchip -- --nocapture`

Change-Id: Ifda216e23f52ce05b5fee7e80a0751cb3524cf1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3722189
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-23 21:43:11 +00:00
Richard
ff3a722691 devices: Upstream virtio console Windows implementation
This CL also changes the Console::new constructor to only contains
variables in its parameters that it needs.

BUG=b:213149162
TEST=built and presubmits

Change-Id: Iab2a7e7b90cc3f203b8d9ae72320a0c2c50d81f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671594
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Richard Zhang <rizhang@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 20:57:43 +00:00
Tinghao Zhang
b6ef09ecc5 devices: pci: don't reserve bridge window for hot added bridges
We do not need to reserve bridge window for hot added bridges
because guest will do that for us. This chunk of bridge window is
also reserved by pcie root port, so no extra MMIO allocation is
needed. So we config zeros sized window here for hot added bridges.

BUG=b:199986018
TEST=./tools/presubmit

Change-Id: I7e64b7596e1b5c060cf628a488e2399ae9c257fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3709794
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 17:52:57 +00:00
Tinghao Zhang
4d854e80b4 devices: pci: support hotplugged pci bus to be removed from tree
When pcie switch get removed from the system, we need to remove
their pci buses. This patch adds a new bool field in PciBus
structure to mark it as a hotplug bus and add support to remove
a pci bus from a pci bus tree. Also some other helper functions
is added for hotplug out usage.

BUG=b:199986018
TEST=./tools/presubmit

Change-Id: I71064127345424bf050d993f60f9d766a299de8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3709793
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 17:44:21 +00:00
Tinghao Zhang
0e1faf9898 devices: pcie: make pcie root port use PciePort
Since we've had a common code base PciePort for all pcie ports, pcie
root port should also use this code base. This patch refactored pcie
root port to let it use this code base.

BUG=b:199986018
TEST=./tools/presubmit

Change-Id: I9e1d3f3ebe0a0d89a947771306f4a819e106d30c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3692431
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-23 17:31:45 +00:00
Tinghao Zhang
61052012a4 devices: pcie: add pcie upstream and downstream port
To support pcie switch, we need to add both pcie upstream and
downstream port. This patch adds a new file pcie_switch.rs and add
basic implementation for pcie upstream and downstream port.

BUG=b:199986018
TEST=./tools/presubmit

Change-Id: I7cc40d4fd0f017e06c5a0e8b0e3b68a8df9ee185
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508737
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 17:31:43 +00:00
Lepton Wu
1973802bea crosvm: Add a flag to disable INTx for virtio devices.
Sometimes we got buggy interrupt entries in ACPI table which
could confuse linux kernel. Add a new flag to disable it so
virtio devices can skip this part of initialization since they
should all support MSI-X.

BUG=b:236206320
TEST=manual - Run crostini on volteer-manatee

Change-Id: I98764b7cd31a2e68ddcd78d8175442f90ad8b164
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3719139
Commit-Queue: Lepton Wu <lepton@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-23 00:59:52 +00:00
Vikram Auradkar
32cabe0cd4 devices: enable tests
BUG=b:213149155
TEST=presubmit

Change-Id: Iff1a721dddfaed3e2728222a75348745be9ef05a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3710851
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 00:26:06 +00:00
Daniel Verkamp
959a05e7cc devices: virtio-tpm: pass base_features to constructor
Allow the device_helpers code to evaluate base_features() with the value
of protected_vm from the configuration to match the pattern used with
other devices.

BUG=b:227283268
TEST=emerge-hatch crosvm # board with chromeos and tpm features enabled

Change-Id: I15b73bbb32d684c1f29130929ec25c4dc9644967
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3717184
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Yi Chou <yich@google.com>
2022-06-22 15:20:13 +00:00
Noah Gold
f54f7ed040 devices: fix double init of logging on blk for Windows.
BUG=235867298
TEST=tested downstream

Change-Id: I81ff30c9c953b8f2674e1fd8f258a90aad92282a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3712543
Commit-Queue: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-06-22 01:05:50 +00:00
Daniel Verkamp
19fc097eb8 crosvm: replace lazy_static with once_cell
We depend on both lazy_static and once_cell, which do basically the same
thing.

The once_cell crate has a few advantages:
- once_cell is on track to be included into libstd.
  (https://github.com/rust-lang/rust/issues/74465)
- once_cell doesn't require macro magic.

Replace the uses of lazy_static with their once_cell equivalents so we
don't need to pull in both crates.

BUG=b:236191006
TEST=tools/presubmit --all
TEST=tools/run_tests --target=host --arch=win64 --build-only
TEST=cargo test --features=plugin

Change-Id: I7cabcd837ef4878e8e8ae635bb4f235a58e4cae3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707624
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-21 23:40:55 +00:00
Vaibhav Nagarnaik
24b9db5095 irqchip: Add WhpxSplitIrqChip implementation
Implement `WhpxSplitIrqChip` for `whpx` (Hyper-V) which has a split IRQ
chip architecture. Add dependencies for the root `whpx` feature on the
`devices/whpx` feature set.

BUG=b:213149158
TEST=Compiled on windows.

Change-Id: I3b0aec441b5abdff3f0266a9467380b0cdc4fdee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3717187
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-21 21:31:21 +00:00
Daniel Verkamp
927488df91 devices: tsc: pass cpuid as a function pointer
Rather than having a global CPUIDS variable that is used by all tests
for the TSC CPUID code, we can pass a function pointer to the
tsc_frequency_cpuid() function to retrieve a specified CPUID value. For
normal use, we provide a host_cpuid_count function that uses the normal
__cpuid_count intrinsic as before. For the tests, we provide a fake
CPUID function that returns the desired test values.

This removes the potential for problems when running multiple tests in
parallel (which was hypothetical, since we only had one test so far, but
worth fixing).

BUG=b:234508273
TEST=cargo test -p devices tsc

Change-Id: Ic963b21f09f8e8d7665386ad134ae5e242b3051d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707623
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-21 21:25:28 +00:00
Daniel Verkamp
d42d2004a1 devices: tsc: move logs to debug level
Don't log the TSC calibration results for every core at the default info
log level, since that can be quite noisy on machines with many CPUs.

The logs can be re-enabled using the `--log-level` option:

  crosvm --log-level=devices::tsc=debug run ...

BUG=b:234508273
TEST=crosvm run doesn't print tsc logs by default

Change-Id: I5051e22740b6b2136d35936c60dee776abd1d00d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707388
Reviewed-by: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-21 21:24:57 +00:00
Daniel Almeida
8062587362 devices: video: decoder: Derive Clone for Capability
In preparation for the upcoming VAAPI backend, derive Clone for Capability.
This is so a Decoder can own a Capability and merely clone it in the
DecoderBackend::get_capabilities call, reducing the number of calls into
the libva driver.

BUG=b:214478588
TEST=None

Change-Id: Ide3d410e0e0a89e774400ea466cac5875ebc8dc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3422777
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-21 16:10:18 +00:00
Junichi Uekawa
ff246f4317 crosvm: Add a better error message.
When resources are overlapping we probably want to know what is
overlapping.

BUG=b:236574949
TEST=boot

Change-Id: I4f99f742bda91945f7fe6e94d60bc8adbfe4326f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3715074
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-21 05:33:52 +00:00
Vaibhav Nagarnaik
0aa44acd7d direct: Fix irq registration for "direct" feature
Create an `IrqEventSource` for each instance of IRQ registration with
the `direct` feature.

This fixes a compilation issue with the `direct` feature.

TEST=Compiled with `cargo build --features=direct`

Change-Id: I691b156f84bc6795c887d5203aad7d15aaad22e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3715270
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-06-20 21:21:45 +00:00
Yi Chou
3f532cd2f6 Remove the useless Mutex in virtio-tpm
BUG=b:227283268
TEST=Build OK.

Change-Id: Ic0f82c3bd09614db569e7bed529e8f41b64e1717
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708380
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Leo Lai <cylai@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Yi Chou <yich@google.com>
2022-06-20 03:41:36 +00:00
Yi Chou
f8dd84e080 Add base_features into virtio tpm device
We need base features to prevent the "virtio: device uses modern
interface but does not have VIRTIO_F_VERSION_1" error in the kernel
driver.

BUG=b:227283268
TEST=Build OK.
TEST=vmc start --software-tpm termina
TEST=ls /dev/tpm0

Change-Id: Icf3c288f2acc39ec1e8e23250a9d0cd6b8f84eb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696295
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Leo Lai <cylai@google.com>
Commit-Queue: Yi Chou <yich@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2022-06-20 03:41:35 +00:00
Yi Chou
12ce514c0f Add VtpmProxy as a new TpmBackend
This CL will introduce a new TpmBackend called VTpmProxy.
This proxy will bridge the VM tpm device and the vtpm daemon on
ChromeOS.

BUG=b:227283268
TEST=Build OK.

Change-Id: Ibfbfdddbaca2af1d066920bb62918d88b0943d59
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696292
Commit-Queue: Yi Chou <yich@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Leo Lai <cylai@google.com>
2022-06-20 03:41:31 +00:00