Commit graph

4120 commits

Author SHA1 Message Date
Daniel Verkamp
970811a704 hypervisor: x86: remove apic_base and interrupt_bitmap from Sregs
These are only used in KVM, not the other x86 hypervisors, and they
don't really fit into the same category as the rest of Sregs. The
apic_base can be set via set_msrs(), and the interrupt_bitmap is
part of the irqchip state.

To enable this removal, we change the KVM set_sregs() call to retrieve
the current state and use the existing apic_base and interrupt_bitmap.

BUG=b:237095693
TEST=Boot x86-64 kernel on KVM

Change-Id: I275eec83b74f1c364b7a543882f3ac5960201143
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3728988
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-07-07 23:24:09 +00:00
Daniel Verkamp
0367dadf7f x86_64: pass Sregs via vcpu_init
Now that we have a Default implementation of Sregs that sets the
architecturally defined reset values, we can initialize the Sregs values
during build_vm(). This allows removal of the set_reset_vector()
function, as all of the values it set are now the defaults in Sregs and
Regs.

This also lets us set up the page tables and GDT only once during
build_vm() instead of rewriting them for every configure_vcpu() call.

This allows consolidation of the BIOS and non-BIOS configure_vcpu()
code.

BUG=b:237095693
TEST=Boot x86-64 Linux kernel
TEST=Boot --bios u-boot.rom

Change-Id: Ief19f983fd252dffa668ff2cfe96a64298e06cf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723802
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-07-07 23:24:08 +00:00
Daniel Verkamp
0cba994f32 x86_64: expose setup_sregs steps as pub
This will be used to move the page table initialization out of the
per-vcpu setup in an upcoming commit.

The names of the individual steps are a slight improvement over the
previous setup_sregs() as well, since that doesn't really say what it
does in any detail.

BUG=b:237095693
TEST=Boot x86-64 Linux kernel
TEST=cargo test -p x86_64

Change-Id: Ifecf00107d923d0c37389956a1b006fe370e2591
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3735641
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-07-07 23:24:07 +00:00
Daniel Verkamp
91a4b090da hypervisor: x86_64: add Default impl for Sregs
Replace the Sregs Default implementation with one that provides the
register values at reset, based on the Intel software developer
manual.

The x86_64 tests need to be adjusted to only check the CR0 bits they
intend to match, since the default Sregs value now includes other set
bits.

BUG=b:237095693
TEST=Boot x86-64 Linux kernel
TEST=cargo test -p x86_64

Change-Id: If966941df43225572e79ebd9213671348e2846f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3735640
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-07-07 23:24:06 +00:00
Daniel Verkamp
6f576dd813 hypervisor: x86_64: default Regs::rip to reset vector
This matches the reset value of the registers defined by the Intel
manuals. It is currently overwritten on all paths initializing Regs, but
it will be used in an upcoming commit to simplify the BIOS boot path.

BUG=b:237095693
TEST=Boot x86_64 Linux
TEST=cargo test -p x86_64

Change-Id: I7a96882fad05440c98bde2fad7ad15c0890f1cfa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3735639
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-07-07 23:24:05 +00:00
Daniel Verkamp
814114c64c x86_64: call set_lint() for BIOS as well
This configures the IRQ chip and is not called anywhere else for the
normal BIOS path, so it should be moved above the `if has_bios` check.

BUG=b:237095693
TEST=crosvm run --bios u-boot.rom --disk test.img # virtio-blk works

Change-Id: I1813d59d7921a824c46a49de98d272f639cc5c07
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723801
Reviewed-by: Steven Richman <srichman@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-07-07 23:24:04 +00:00
Daniel Verkamp
ad3914cd9a x86_64: move MSRs to vcpu_init
The MTRR-related MSR setup is split out into its own pub function for
clarity and to allow future reuse. The maximum variable MTRR check is
split out so we can generate MTRRs before having a valid VCPU object.

This unifies the MSR set calls in configure_vcpu() so that the BIOS and
non-BIOS cases use the same code.

BUG=b:237095693
TEST=Boot x86-64 Linux kernel
TEST=Boot x86 u-boot.rom

Change-Id: Ifa0020257a043190de69b7192c2d6b35c01d216e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723800
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-07 23:24:02 +00:00
Dennis Kempin
aef95d2078 infra: Repeat tests in post-submit
This will help us find flaky test. Runtime increase is not that
significant (~10min).

BUG=b:238232551
TEST=Builder config needs to be tested in luci

Change-Id: Ie75cc9620177115623500fe2206f33464f4c8580
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3751831
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-07 23:00:04 +00:00
Dennis Kempin
b1abe58649 infra: Optimize cache usage among builders
Then 'builder' cache dir is set up by default to be a cache directory
for each builder, so luci will try to schedule a builder to run on
the same bot as before.
We can optimize that by sharing the cache among all linux builders.

BUG=b:238333690
TEST=lucicfg validate main.star

Change-Id: If4639658271881f1bf1ad001ae54f50645e8890a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3751828
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-07 23:00:04 +00:00
Dennis Kempin
909f10fef5 infra: Repack repo before running container
gclient will cache objects in a separate repo and points to them
via .git/objects/info/alternates

That cache won't be available in the container, which will prevent
us from properly using the repo.

git repack will ensure all those objects are brought into the
main repository.

BUG=b:238328665
TEST=led get-build 8809354906626249393 | led edit-recipe-bundle | led
launch

Change-Id: Iba1374a4d34e410e2d2b565cbf5cfbaa0be2fe5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3751827
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-07 23:00:04 +00:00
Dennis Kempin
123061360a infra: Fix container cache after bad rebase
An early return snuck in during a rebase.

BUG=b:233230027
TEST=./recipes.py test run

Change-Id: I152281dd55148ca56fc7300a66b6bdcc1eef0ada
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3751830
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-07 23:00:04 +00:00
Dennis Kempin
0c09cdbdbc cros_async: Fix windows timer flake
The test is flaky by nature since there is no API guarantee on how
long SetWaitableTimer will sleep. This is flaky on our Luci bots, so
increase the permitted deviation a bit.

BUG=b:238232551
TEST=./tools/run_tests --build-target=mingw64

Change-Id: Ib227be097a0a5559898571cb6b77c37e7fd61cff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3749936
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2022-07-07 22:23:08 +00:00
Dennis Kempin
5e7c6b1ab8 infra: Add email notifications for postsubmit and infra
Both only notify myself for now as the luci infra is not
launched yet.

BUG=None
TEST=None

Change-Id: I4794bb118f6c27f145af9027ec317da2fb578af7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739370
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-07-07 21:08:19 +00:00
Dennis Kempin
aa52701db6 infra: Use latest version of github secret
The previous token expired and a new one was created and added to
GCP secrets manager.
This CL updates the script run by CI to always use the latest
secret instead of a fixed version.

BUG=None
TEST=sh push_to_github.sh

Change-Id: I7eff1a8b385b5cd48206ef54aad65151dfbbc961
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3751430
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-07 20:26:46 +00:00
Dennis Kempin
365c8f9201 dev_container: Allow cargo home to be cached between runs
This Allows Luci builders to cache cargo home between builds. So we
do not have to download so many third party crates with each build.

CARGO_HOME is specifically intended to be cached in CI systems.

BUG=b:233230027
TEST=CROSVM_CONTAINER_CACHE=/tmp/test ./tools/dev_container --clean
cargo build

Change-Id: I11580c5ed3151519ece4a651cb22d059c7c3eb87
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739368
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-07 17:49:47 +00:00
Dennis Kempin
a8552e6de4 infra: Drop crosvm_ prefix of builder names
Builders are already scoped to the crosvm.ci/try buckets, so there is
no need for the prefix.

BUG=None
TEST=lucicfg validate main.star

Change-Id: I997442e12c14d35e52b1a2c5bf145f0dc5bfd8f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3749938
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-07 17:48:51 +00:00
Dennis Kempin
e3db2b5638 Add crosvm_linux_x86_64_direct builder
Similar to the one we added to kokoro, run tests with --crosvm-direct.

BUG=b:238234098
TEST=recipe tests included

Change-Id: I2b03ca02fbfb577fd5cebf346eec468ebd625626
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3749937
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-07 17:48:49 +00:00
Daniel Verkamp
fa0dd194c1 tools: fix triple shorthand error printing
The format string wasn't actually formatted, so it just printed out the
literal "{shorthand}" string in the error message.

BUG=None
TEST=tools/run_tests --target=host --build-target=bogus

Change-Id: Idad47064db3112a37df3a630b92a4a4da8da82de
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3750069
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-07-07 17:36:27 +00:00
Daniel Verkamp
cd9f1cc7a9 doc: contributing: remove named anchor #presubmit
mdbook apparently does not support this syntax and just includes the
text in the section title.

BUG=None
TEST=mdbook build

Change-Id: I3dc4ae25e392b1260df59889926eba2044c4adc6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3749605
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-07 17:35:57 +00:00
David Stevens
edbaf7e141 virtio: add generic shared memory region APIs
Present a generic shared memory region API to virtio devices, and take
care of pci transport specific parts in the core VirtioPciDevice code.
This will make it easier to share the same device implementation across
different virtio transports (i.e. vhost-user and vvu).

BUG=b:201745804
TEST=builds

Change-Id: Ic08ab3de0440f18aeaf9e946dc83c7565cd32eda
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716341
Commit-Queue: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-07-07 02:04:54 +00:00
David Stevens
bb81820322 devices: vvu: do rx notify after processing vq
Send rx vq notification immediately after copying data out of the
descriptors, rather than later on when the data is actually processed.

BUG=b:201745804
TEST=launch sibling VM on manatee

Change-Id: I387a1573bde0157b1ab6f585fd6bb2a311448f7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716348
Commit-Queue: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-07-07 02:04:53 +00:00
David Stevens
e0293591f4 vmm_vhost: switch listener and endpoint relationship
Make Listener type depend on Endpoint, instead of Endpoint type
depending on Listener. This will allow Endpoints to be used for the
slave_req_fd.

BUG=b:201745804
TEST=compiles

Change-Id: I1a0732bf7477a4e768f348f78e352a3b53607633
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716342
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-07 00:58:11 +00:00
Daniel Verkamp
f16b18f046 crosvm: use anyhow context in device helpers
Use anyhow context consistently rather than logging with error!()
inside the helper functions.

BUG=None
TEST=Run crosvm twice with the same VVU socket name

Change-Id: Idadd4a65f5ce6188e9623b3311842e2f90eb4916
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739586
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-07-06 22:02:20 +00:00
Dennis Kempin
382acd20d3 tools/cl: Support worktree checkouts
CrOS checkouts are experimenting with using git worktree, where
the path to the hook directory is not .git/hooks. So ask git
where the hooks are stored instead.

BUG=b:236645893
TEST=./tools/cl upload in a worktree checkout

Change-Id: Ib353da0aea5d27ce29d1c082268a326adb429d23
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739373
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-06 18:02:43 +00:00
Daniel Verkamp
2689c838af base: simplify Clock/FakeClock API
Clock now has a single now() function that returns a std::time::Instant
rather than wrapping an Instant itself.

FakeClock provides the same now() API, except the Instant it reports is
only advanced when test code calls add_ns(). FakeClock continues to
provide the add_event() and add_ns() APIs used by tests.

The only functional difference is that the epoch used by FakeClock is
now whatever moment in (real) time it is created, rather than a fixed
timestamp, but this should not change the results of the tests. The only
way to observe the contents of an Instant is by comparing it to other
Instants, which should all be derived from the Clock/FakeClock now()
API.

BUG=None
TEST=cargo test -p base -- --test-threads=1
TEST=cargo test -p devices

Change-Id: I9a0ed8d252f213d85dba3dfbbcd1182e2db981f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3736922
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-06 17:44:05 +00:00
Kazuhiro Inaba
8f6f1407cb crosvm: Fix --per-vm-core-scheduling option handling.
Apparently the flag handling was forgotten to be
migrated in the switch to Argh crrev.com/c/3684144.

BUG=b:237216718
TEST=cheets_CTS_R.internal.arm.CtsVideo on Fizz.Kench

Change-Id: Ia967883cd5c4e2efcc1ca2cf97fd6adfc0bf163a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3746902
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Kazuhiro Inaba <kinaba@chromium.org>
2022-07-06 17:23:49 +00:00
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
a99ad34826 crosvm: cmdline: remove JailConfig from run arguments
This member is never used since jail configuration is set up using other
flags to remain compatible with the way `run` was working pre-argh.
Furthermore, having it here makes a `jail-config` command-line option
appears in the help text that is a no-op.

BUG=None
TEST=cargo build

Change-Id: I715ac80270e7b775926c7ca8759e22e5f7c15014
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3744909
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-07-05 11:36:18 +00:00
Keiichi Watanabe
06e6f41576 OWNERS: Add comments
BUG=none
TEST=none

Change-Id: I18ec0fc387eaab7717cc6e94eb3a865f6b6d5f94
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739573
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-05 10:34:14 +00:00
Alexandre Courbot
8249907797 docs: book: fix instructions for VVU
Fix a few typos in the instructions to start a VVU device.

BUG=b:196186396
TEST=Copy/paste the new instructions and make sure the device starts and
works.

Change-Id: I0726185fc9d7026a7d7d81a5678fb81350cac113
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3744908
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-07-05 10:33:54 +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
c6a73deee8 crosvm: linux: device_helper: add VirtioDeviceBuilder trait
As we are going to jail vhost-user devices, we will need a way to obtain
a Minijail that we can use in that case. This CL introduces a
VirtioDeviceBuilder trait that can be implemented for any device
configuration type and allows to spawn a configured device as well as
its jail, which is created from the correct policy file depending on the
virtio transport desired. In effect, it splits the creation of the
device and jail into two separate methods so the same jail creation code
can be reused with both regular virtio and vhost-user.

In order to illustrate, the console device is converted to this new
scheme. Other devices will follow when relevant.

BUG=b:217480043
TEST=serial device works with `crosvm run`.

Change-Id: I6b59d3794580bbdabce6df290c9ab8262d8e178c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706491
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-05 08:17:01 +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
Junichi Uekawa
9fff598b26 arch: update add_serial_devices comment.
BUG=None
TEST=build

Change-Id: I67b3b9c70cb3599109014e66eb072ead040a5927
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3744904
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-05 06:27:29 +00:00
David Stevens
92fabe33c7 crosvm: remove stray comma in copyright statement
BUG=None
TEST=repo upload

Change-Id: I009cd11f3e0f8463fcd43170ec6f7fc052a2c009
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3744903
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2022-07-05 05:38:34 +00:00
Junichi Uekawa
0b89290a27 arch: Clone jail object for serial.
80690665b8 removed the clone but that
caused sig11 in minijail.

BUG=b:238026909
TEST=tast run rammus-arc-r arc.Boot.vm

Change-Id: Icf887ae62df682d72f2ea469a1d1a15cc303dc1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3744902
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-07-05 05:06:28 +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
Noah Gold
80690665b8 arch: add Windows bits to serial.
BUG=b:237597358
TEST=builds + tested on Windows downstream.

Change-Id: I9a38ddae0e66fdbd491e2c9a0145fdf2407ac812
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3736760
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-02 00:00:32 +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
Vikram Auradkar
b6b4081b76 crosvm: refactor cmdline
Prepares cmdline for upstreaming.

- Removes wildcard import
- Adds empty platform specific command

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

Change-Id: I835101f486e07248d452937589c2268f23f8d0e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739584
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-01 23:12:40 +00:00
Vikram Auradkar
f52e15f2e2 crosvm: move files under src/crosvm from linux/ to unix/
The contents of the mod.rs were moved to unix.rs

BUG=b:213146388
TEST=presubmit

Change-Id: Ib7188dba3bb7b5e7c78b72b39a84f99be67c53ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739365
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-01 22:47:57 +00:00
Daniel Verkamp
eb4bfb26e0 main: accept -h as an alias for --help
This is a widely-used convention, and it's not very helpful to just
print "Unrecognized argument: -h". We won't be able to use -h as a short
argument name for anything else, but that seems like a reasonable
tradeoff.

BUG=b:3739371
TEST=crosvm -h
TEST=crosvm run -h

Change-Id: I6eef06bfd3cf526e54a6904e5085789566dcc958
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739372
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-07-01 21:34:39 +00:00
Daniel Verkamp
3ccb636365 main: accept --arg=options without a warning
The workaround for argh's lack of --arg=option is not a big deal to keep
around permanently; just drop the warning message.

BUG=b:235882579
TEST=crosvm run --root=test.img vm_kernel # runs without warnings

Change-Id: I3ef5e237f80c2df775d684775e67a08f1fd89bf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3739371
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-07-01 21:34:38 +00:00