Commit graph

3534 commits

Author SHA1 Message Date
Douglas Anderson
5124d62f86 seccomp: Fixes needed for aarch64 to allow arcvm to start
With these changes arcvm starts when running with 64-bit userspace and
this grep turns up blank:
  grep SECCOMP /var/log/audit/audit.log

Generated by:
* Hacking minijail0 to always log <https://r.android.com/2072091> and
  making sure it was compiled in debug mode.
* Hacking "crosvm run" to be "crosvm run --seccomp-log-failures". I
  don't truly know if this is needed but it didn't hurt.
* Diffing arm vs. arm64

From comparing arm vs. arm64 there could still be some things missing,
or it's possible that arm has simply accumulated some cruft. More can
be added later if we find it's needed.

BUG=b:223410173, b:230609113
TEST=Start arcvm; start android-sh; run tast arc.VMConfig

Change-Id: Ib5407ddecc3d19f43e14e5b036ac64baee9335bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3543889
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Douglas Anderson <dianders@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Douglas Anderson <dianders@chromium.org>
2022-04-29 00:05:48 +00:00
Anton Romanov
ed50691066 crosvm: ignore certain tests on wine
Use target_env as heuristic to detect wine as we build wine tests with
mingw while real tests use msvc

BUG=none
TEST=cargo test --target x86_64-pc-windows-gnu -- --test-threads=1

Change-Id: I96afd964d52539ab40b56d236442aa3651637991
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3615511
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2022-04-28 23:50:58 +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
Dennis Kempin
91ad3eb689 Add autoroll configuration
We want to auto-submit trivial rolls and send non-trivial ones
to denniskempin@ for now. This will later be replaced with
a rotation.

BUG=None
TEST=None

Change-Id: I57c4707262cc3a09a70dff9013b9e1c8c434eef0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3615514
Reviewed-by: Yuanjun Huang <yuanjunh@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
2022-04-28 22:32:31 +00:00
Vikram Auradkar
05ef6b1679 base: fix doc error
BUG=b:213153157
TEST=`cargo test` from base/

Change-Id: I38d682a10d2183dd51713d631886d752bb23e832
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3614854
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Vikram Auradkar <auradkar@google.com>
2022-04-28 22:24:43 +00:00
Dennis Kempin
f5f508630a Add recipe-mega-autoroller to OWNERS
So the bot can submit the recipes.

BUG=None
TEST=None

Change-Id: I498606b77d0fec4f8f3b955b21414b3b936a5f5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3615512
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
2022-04-28 21:57:30 +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
Dennis Kempin
4ebb928ea4 build-chromeos.sh: Clean up cros repo after build
Kokoro will treat the files as build artifacts and tries to rsync
the ~80GB to the executor. See b/30309837.

BUG=b:2089374426
TEST=None

Change-Id: I71df011025a7cff664a134bdfbf5783709365358
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3611872
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-04-28 18:01:47 +00:00
Anton Romanov
2c4f981ae4 crosvm: only compile out trace statements in release builds
At least for now, to keep previous behaviour fully.

BUG=none
TEST=cq

Change-Id: Idb6114d1ea5145cdafa9ab25e4e5f2f9887e8dc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3611465
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-04-28 17:00:47 +00:00
Haiwei Li
013d26be5c devices: virtio: iommu: remove virtio-iommu option
Hotpluggable devices are always automatically attached to virtio-iommu.
There's really no reason virtio-iommu needs to be its ovwn flag. So
remove the '--virtio-iommu' option and automatically instantiate a
virtio-iommu device if hotplug is supported.

BUG=b:185084350
TEST=Boot on manatee and a virtio-iommu device can be seen through lspci
command in CrOS

Change-Id: I42dce58d60d2f04e37279d5623fc52829946e5d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3595226
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2022-04-28 04:43:12 +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
Daniel Verkamp
b5a2771f6c Revert "x86_64: Redesign MTRR setting"
This reverts commit e93b16cefc.

Reason for revert: breaks starting VMs with less than 256 MB of memory (b/230653701)

Original change's description:
> x86_64: Redesign MTRR setting
>
> Currently MTRR setting is: the default cache type is write back and the
> pci low mmio range is uncache, then guest memory is WB by default, but
> pci high mmio and the gap between ram end and pci start below 4G are WB
> also, this part is wrong. In order to fix it, var mtrr should be used to
> set pci high mmio as uncache, but pci high mmio is too large to have
> enough var mtrrs.
>
> This commit change MTRR setting as: the default cache type is uncache,
> and the guest memory is WB. So memory range below 4G and above 4G are
> passed into setup_msrs(). And the variable MTRR registers are limited
> and have base and length requirement, so guest memory size is aligned
> to 256MB to avoid MTRR failure.
>
> BUG=None
> TEST=check guest mtrr setting with different guest memory size
>
> Change-Id: I4c18e83ce5e7fac9ac1bf6e174116a69924184ac
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578015
> Tested-by: kokoro <noreply+kokoro@google.com>
> Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
> Commit-Queue: Junichi Uekawa <uekawa@chromium.org>

Bug: None
Change-Id: If183f028da2081ccedbbdc847311cf12081e569d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3612468
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-04-28 03:46:15 +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
Vikram Auradkar
09a0f438f4 base: Add Serialize and Deserialize to Priority and PriorityFilter
Downstream uses this to dump Config found in /src/crosvm

BUG=b:213153157
TEST=presubmit

Change-Id: I191a799d7cce84e27c3b4c4aa2d6f8e939439ac6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3611468
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-04-27 23:44:01 +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
Maciek Swiech
0dc385a1f8 crosvm: p9: add support for lock() and getlock() to p9
our current p9 server implementation does not support
fiile locks
(https://www.gnu.org/software/libc/manual/html_node/File-Locks.html).

NOTE: this implementation mirrors the QEMU approach, which defers
locking semantics to the client VFS. This means we do not provide
any guarantees about locks between client/server, nor between
multiple potential clients.

BUG=chromium:1225763
TEST=tests added

Change-Id: I73f04712c7e6869f7679d4f55b2706d21e5cf6b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578027
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
2022-04-26 20:36:58 +00:00
Dennis Kempin
793004384d infra: Add recipes and example builder
Following the onboarding instructions. If everything works we should
have a builder at:
https://ci.chromium.org/p/crosvm/builders/ci/Example%20Builder

BUG=chromium:1300370
TEST=None

Change-Id: I98eeaad6ccffd228fdee116e664c9d2760708e24
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3500817
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-04-26 19:26:47 +00:00
Dennis Kempin
33a368ffaf build-chromeos.sh: Use common.sh
Re-use the existing logic to install python, setup the source and
most importantly, enable SSH debugging.

BUG=b:226975041
TEST=None

Change-Id: I0f8b0251bea163145ba1611b3b36c4bb7c8ee968
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3606979
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
2022-04-26 19:08:45 +00:00
Dennis Kempin
15a4ee3200 Do not run cros_async tests on armhf
The test has been flaking with segfaults occasionally.

BUG=None
TEST=presubmit

Change-Id: Ifbfee7e7ed5de91b7bdf9b25db7983139951f81f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3606751
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-04-26 17:10:09 +00:00
Dennis Kempin
05add11e8f Kokoro: Increase build timeout for ChromeOS builder
The ChromeOS builds take a lot longer than other crosvm builds.

BUG=b:226975041
TEST=None

Change-Id: I2cf9071aebba10e46a7b63fed0cafbec7a8b06b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3606970
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-04-26 15:54:32 +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
Mi Dapeng
158e668dea x86_64: Fix File descriptor sharing in MSR handler
Now the File descriptors aren't stored in MsrHandlers level, for every
passthrough handler, the fd will be refresh in MsrHandlers level.

This can't avoid much File descriptors creation. Fix this error.

BUG=b:225375705
TEST=Set `--userspace-msr=0x1a2,type=r,action=pass,from=cpu0`

Change-Id: I2c67a5c257f545c6469fc71d8b53606256af22c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3606974
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-04-26 05:21:40 +00:00
Dennis Kempin
e40b5b8f4b build-chromeos.sh: Install python 3.9 for depot_tools
Kokoro uses python2 by default, which breaks repo

BUG=b:226975041
TEST=./ci/kokoro/simulate.py ./ci/kokoro/build-chromeos.sh

Change-Id: I2424107c76d52c4bc76cd640114c21fca00f3c44
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3606968
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
2022-04-25 23:01:50 +00:00
Vikram Auradkar
0c0ba1c158 base: fix Event import in clock
The unix clock uses crate::Event. Using crate::Event makes it
consistent and downstream compiler happy.

BUG=b:213153157
TEST=presubmit

Change-Id: Ia03f0eb787eb8eaf344fe4fa25b5a78f705f43c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3606372
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-04-25 22:57:06 +00:00
ZhaoLiu
0c2ce08ca1 x86_64: Preparation for ITMT scheduling in Guest
With Intel Turbo Boost Max Technology 3.0, (ITMT),  the maximum turbo
frequencies of some cores in a CPU package may be higher than for the
other cores in the same package. In that case, make the scheduler prefer
to run tasks on the CPUs with higher max turbo frequencies, to achieve
better performance.

When vCPUs 1:1 map to pCPUs, ITMT scheduling feature can benefit
performance of Guest. So when user sets `--itmt`, crosvm will check if
`--host-cpu-topology` is set or if `--cpu-affinity` is set for 1:1
mapping.

In kernel, ITMT scheduling feature depends on intel_pstate driver and
ACPI CPPC support.

To setup intel_pstate driver and pass CPPC capability check, we need
emulate related MSRs in userspace:

- MSR_HWP_CAPABILITIES and MSR_TURBO_RATIO_LIMIT: intel_pstate driver
  only needs to read. So we passthrough them to Guest. But please note,
  to be compatible with the configuration in initramfs, use `FromCPU0`
  Temporarily.

- MSR_PM_ENABLE and MSR_HWP_REQUEST: they are MSRs to control HWP.
  When intel_pstate driver is initializing, the driver will close/open
  HWP by writing into MSR_PM_ENABLE, and the driver also needs to set
  performance policy by writing some hints into MSR_HWP_REQUEST.
  Note that we don't want Guest's behavior to affect the performance
  control of the host, so use 'emulate' handler for them.

- MSR_PLATFORM_INFO: this MSR is emulated in kernel with a fault value
  by default. intel_pstate doesn't want this fault value, so we ask
  this MSR to exit to userspace and give it a real value.

- MSR_IA32_PERF_CTL: intel_pstate driver use this MSR to set the min
  pstate in the initialization. So use 'emulate' handler for this MSR.

Since of `FromCPU0` setting of MSR_HWP_CAPABILITIES, ITMT scheduling
will set the same priority for each core so optimization will not work.

BUG=b:225375705
TEST=Set `--itmt` and check /proc/sys/kernel/sched_itmt_enabled

Change-Id: Icfa85ffa15c3b977c3b62a1f8a379c4c2f5fc49d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3575511
Commit-Queue: Zhao Liu <zhao1.liu@intel.corp-partner.google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-04-25 08:21:16 +00:00
ZhaoLiu
202d5a549b x86_64: Add kvm MSR_PLATFORM_INFO read control
Add a kvm capability config helper. This helper controls wheter
MSR_PLATFORM_INFO can be read in kernel space.

With this helper, we can ask RDMSR of MSR_PLATFORM_INFO traps to
userspace and emulate this RDMSR in crosvm.

BUG=b:225375705
TEST=Cargo build

Change-Id: Ic3444e678b124c19b600d8b31062a2cbe3a65156
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3575510
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Zhao Liu <zhao1.liu@intel.corp-partner.google.com>
2022-04-25 08:02:09 +00:00
ZhaoLiu
b969ded8a5 crosvm: Support MSR emulation
At present, crosvm can support handle RDMSR in userspace by read MSR of
Host directly. This is the RDMSR passthrough in userpace.

This patch adds more MSR handler support, including:
- WRMSR passthrough: write the corresponding MSR of Host directly in
  userspace; The control of MSR will work on host;
- RDMSR emulation: crosvm uses a dummy MSR value to let Guest reads on.
  This value can be different with real MSR of Host;
- WRMSR emulation: crosvm uses a dummy MSR value to let Guest writes
  into. This means the control of MSR won't really work (on Host).

BUG=b:225375705
TEST=Set `--userspace-msr=0x1a2,type=r,action=pass,from=cpu0`

Change-Id: I3276dd651464ef7b695e2ddd433793d59128af9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3575508
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-04-25 07:50:55 +00:00
Xiong Zhang
e93b16cefc x86_64: Redesign MTRR setting
Currently MTRR setting is: the default cache type is write back and the
pci low mmio range is uncache, then guest memory is WB by default, but
pci high mmio and the gap between ram end and pci start below 4G are WB
also, this part is wrong. In order to fix it, var mtrr should be used to
set pci high mmio as uncache, but pci high mmio is too large to have
enough var mtrrs.

This commit change MTRR setting as: the default cache type is uncache,
and the guest memory is WB. So memory range below 4G and above 4G are
passed into setup_msrs(). And the variable MTRR registers are limited
and have base and length requirement, so guest memory size is aligned
to 256MB to avoid MTRR failure.

BUG=None
TEST=check guest mtrr setting with different guest memory size

Change-Id: I4c18e83ce5e7fac9ac1bf6e174116a69924184ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578015
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-04-25 06:11:45 +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
Dennis Kempin
0a581d64ef Kokoro: Add ChromeOS post-submit builder
This adds an experimental build script that will build crosvm for
ChromeOS. This will allow us to catch issues on the ChromeOS build of
crosvm earlier in the process.

BUG=b:226975041
TEST=./ci/kokoro/simulate.py ./ci/kokoro/build-chromeos.sh

Change-Id: I4a1d906a44191e78f4e656fe76c989bd7e1b6977
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600764
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-04-22 04:41:03 +00:00
Dennis Kempin
ba8f18e671 Adding Noah to crosvm OWNERS
Insert famous spiderman quote here.

BUG=None
TEST=None

Change-Id: I5dca10144b0270c414242ef6533950b3449b2069
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600799
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
2022-04-22 04:40:32 +00:00
Vikram Auradkar
273a9b16b3 base: move timerfd to timer
A series of patches move unix specific code into src/sys/unix/timer.rs,
retain platform independent code in src/timer.rs and then introduces
windows timer.rs.

BUG=b:213153157
TEST=presubmit

Change-Id: I1dad42b112305e70582f0ec8a0e38b7e305783fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600758
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-04-22 02:13:13 +00:00
Vikram Auradkar
5bafb3a3c7 base: Fix doc tests
Some of the fixes are already available for unix code. This change will
make future cls pass doc tests on windows.

BUG=b:213153157
TEST=presubmit

Change-Id: Ie172c1cb253f633628ae9db016fcd259b39b0bfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600757
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-04-22 02:13:12 +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
Vikram Auradkar
d367eff0db Prefer descriptor variants over fd
These are selected few instances where we can use platform independent
raw_descriptor variants over platform specific raw_fd

BUG=b:213153157
TEST=presubmit

Change-Id: Id9e80fb4e9bf6ef9fa059f0324821b82dfd45292
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600756
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-04-22 01:13:52 +00:00
Anton Romanov
3d1c3018d4 crosvm: static INFO as lowest log level for release builds
We do not intend for release builds to be able to log debug/trace
statements

BUG=none
TEST=cq

Change-Id: I963c055de8ac14f5928ef5037caba4ef456f3887
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3598245
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-04-21 22:02:01 +00:00
Anton Romanov
fd71fa1bd4 crosvm: refactor base::syslog and integrate with log facade
Motivation behind this is to greatly reduce code duplication and more
streamlined syslog experience.
Integration with log facade allows us to have logs from 3rd party crates
and better integration into rust ecosystem. As well as getting rid of
our log/warn/etc macros.

Notable changes:
    * Moving to log's levels: info/trace/debug/error/warn. Note that
      none of our code utilizes alert/critical/etc so this is benign
    * Moving windows' syslog implementation filtering into
      cross-platform scope;

BUG=none
TEST=kokoro

Change-Id: I28b3a34a3ddca21af9cc6d191061681a02314f7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3588248
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Anton Romanov <romanton@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-04-21 21:56:09 +00:00
yuankaichen
708161aad7 add release / debug modes to build_test script for building windows
binaries

Test: build locally
Change-Id: I4a9b96a0387c3c26ff2975680851943c2252946b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3598240
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Yuankai Chen <yuankaichen@google.com>
2022-04-21 17:09:29 +00:00
Noah Gold
ab263d1010 disk: fix punch_hole using wrong AllocateMode.
9da4030ab0 migrated consumers to use
AllocateMode, but this method got the wrong mode. This CL fixes that.

Thanks to idanr@ for spotting this during downstream merging.

BUG=NONE
TEST=bots + inspection.

Change-Id: I10792d4f293d7f672d3474288a7f706a5c0fd835
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3597038
Auto-Submit: Noah Gold <nkgold@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-21 02:19:31 +00:00
Keiichi Watanabe
94e753c41e crosvm_control: Skip build.rs when cargo-doc is called
This will fix GitHub Action's failure.
This couldn't be caught in kokoro because kokoro sets correct
environment variables for testing.

BUG=none
TEST=./tools/cargo-doc

Change-Id: I1db2e459422e755f6231cb0a6e5e082ffa0727ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3581449
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kameron Lutes <kalutes@chromium.org>
2022-04-21 00:17:25 +00:00
Keiichi Watanabe
b24aa4cb84 crosvm_control: Use anyhow in build.rs
This provides clearer error message.

BUG=none
TEST=cargo check

Change-Id: I954be94b2961383f2c23da104e695321e49e497e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3581448
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kameron Lutes <kalutes@chromium.org>
2022-04-20 23:53:07 +00:00
Anton Romanov
13c21bdd12 crosvm: tools: Skip non-scripts in tools/
Otherwise tools/[fmt, health-check] crash and burn trying to decode
vim's swap/undo files as utf8 text

BUG=none
TEST=kokoro

Change-Id: I4ebd3fe33484353bddb0ae12054c47ca3ecd6b89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3598242
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-04-20 23:50:38 +00:00
Anton Romanov
c79d5f838c crosvm: crosvm_control: use OUT_DIR instead of CARGO_TARGET_DIR in build script
CARGO_TARGET_DIR is not meant to be used in build scripts as that is an
optional variable that *may* be passed to cargo. The one that is set by
cargo itself is OUT_DIR and is always present to specify where build
scripts are expected to place output

BUG=none
TEST=cq

Change-Id: I118eebf914dbefd93f2cafb6950c7a6b4c01c574
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3598239
Auto-Submit: Anton Romanov <romanton@google.com>
Reviewed-by: Kameron Lutes <kalutes@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-04-20 23:05:48 +00:00
Dennis Kempin
a62858f89d Ensure python doc tests failures will fail health-check.
And fix a nit in the existing tests to make it pass.

BUG=b:219965702
TEST=presubmit

Change-Id: I65fb98b04d7042755930dd34913f679fa129c88c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3594248
Reviewed-by: Maciek Swiech <drmasquatch@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-04-20 19:47:49 +00:00
Keiichi Watanabe
25d7911e8d crosvm_control: Minor style fix
BUG=none
TEST=cargo chekc

Change-Id: I24fa7eced9053eee535778153390f4039044e47f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3581447
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kameron Lutes <kalutes@chromium.org>
2022-04-20 19:33:30 +00:00
Noah Gold
35290a48c0 cros_async: enable tests on Windows.
BUG=b:213147081
TEST=bots

Change-Id: I88ac2eb0c4c9b4f3f77e2b3c0cc994979a14d14c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3585009
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-04-20 18:56:54 +00:00