Commit graph

273 commits

Author SHA1 Message Date
Dmytro Maluka
bc62540f31 x86_64: acpi: support for assigning physical ACPI fixed events
Just like with GPE, wire up ACPI fixed event forwarding eventfd and
crosvm's ACPI fixed event emulation.

This patch allows to provide ACPIPMResource with the list of fixed
events which should work as direct physical (passthrough) events rather
than purely emulated ones.

BUG=b:228445196
TEST=compiles

Change-Id: I6f50f24fc0b9c187e48140dbafb7926ece4b9961
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3791194
Commit-Queue: Dmytro Maluka <dmaluka@google.com>
Tested-by: Dmytro Maluka <dmy@semihalf.com>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
2022-08-09 17:04:13 +00:00
Daniel Verkamp
cd251b3067 Reformat imports with tools/fmt --nightly
A few new grouped imports have made it in since the tree-wide
reformatting.

BUG=None
TEST=tools/presubmit

Change-Id: I93af3c741f57c1da73d4c9e8a28be424c1ea45fe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3818244
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-08-08 20:29:50 +00:00
Tinghao Zhang
e931dee2a6 devices: pci: impl pci root worker
Hotplug command is facing dead lock issue when it tries to acquire
the lock for pci root in the vm control thread. Dead lock could
happen when the vm control thread(Thread A namely) is handling the
hotplug command and it tries to get the lock for pci root. However,
the lock is already hold by another device in thread B, which is
actively sending an vm control to be handled by thread A and
waiting for response. However, thread A is blocked on acquiring the
lock, so dead lock happens. In order to resolve this issue, we add
a new pci root worker thread and push all work that locks pci root
to this thread.

BUG=b:199986018
TEST=tools/presubmit

Change-Id: I11552a1c9c626035d0ca01ce2835fd8b6c067a67
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3765366
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-08 18:22:50 +00:00
Zide Chen
69775f0346 x86_64: add new option enable-hwp to expose HWP feature to guests
Expose HWP (HW P-State) feature to the guest if enable-hwp is present
and implement these dependencies:

- enable-hwp depends on host-cpu-topology option
- itmt depends on enable-hwp option

Group the CPU configuration entries to a new struct CpuConfigArch,
to simplify APIs in the vCPU configuration path.

BUG=b:199380745
TEST=boot Redrix manatee and verified that intel_pstate driver works

Change-Id: Icdd19190f6a7518492ff5fc54708af40288a1422
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3771065
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2022-08-05 20:33:12 +00:00
Alexandre Courbot
4c4ee4543c main: convert battery options to use serde_keyvalue
This requires the introduction of a BatteryConfig structure to parse,
which is probably a good idea anyway as it reserves some space to add
more battery-related options.

BUG=b:218223240
TEST=cargo test parse_battery

Change-Id: I82db7fe7ce2daeca004e734aaafa542583998561
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784661
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-08-02 07:06:10 +00:00
Daniel Verkamp
f0c62bd6fd resources: add allocate_mmio() and AllocOptions
This allows SystemAllocator users to specify the properties of the
allocation they want rather than explicitly picking between
MmioType::Low and MmioType::High. That way, we can rearrange the
location of the prefetchable/cacheable MMIO region to accomodate use
cases like running 32-bit guest kernels without adjusting all allocation
call sites.

BUG=b:178000549
TEST=Boot x86_64 Linux in crosvm

Change-Id: I691393202c9841f4c687be55a9404fe619790634
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784342
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2022-08-02 00:49:14 +00:00
Daniel Verkamp
600ad38ff8 Remove redundant {self} imports
- Remove trailing ::{self} on all use statements
- Remove any resulting single-level use statements (e.g. use libc;)
- Reformat with `tools/fmt --nightly`

BUG=b:239937122
TEST=tools/dev_container tools/presubmit --all

Change-Id: I8afd1b0458ca6d08d9b41a24583f7d4148597ccb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3798973
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-08-01 21:27:54 +00:00
Daniel Verkamp
0076579e95 arch: allocate reserved PCI addresses first
Add a new PciDevice::preferred_address() function, which allows devices
to report a PCI address where they would prefer to be allocated.

This lets the arch layer pick out the devices that need to have their
addresses reserved before allocating the remaining addresses to device
that don't care about their assigned PCI address.

For now, the returned preferred_address value is not actually used aside
from checking is_some(), but it will be used in upcoming cleanups.

BUG=b:237415650
TEST=Run x86-64 bzImage

Change-Id: Ia323274dcf801a8fe1959287bcc791ca32ce4e18
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3781441
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-08-01 18:57:44 +00:00
Vikram Auradkar
925ba7a1fb crosvm: Fix clippy related warnings
Ran clippy with features that are enabled downstream. Those features
will be enabled upstream in later cls when crosvm starts building.

BUG=b:213146388
TEST=presubmit

Change-Id: I67cb74127a349b572e573c350d69d1611533d961
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3793690
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: Vikram Auradkar <auradkar@google.com>
2022-07-29 17:49:31 +00:00
Dennis Kempin
4fea399df9 Reformat imports
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.

Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.

BUG=b:239937122
TEST=CQ

Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-28 00:15:50 +00:00
Junichi Uekawa
fa0370918f crosvm: Make ProxyDevice to be safer.
Do not use a reference when it's not safe to call minijail.fork() multiple
times.

BUG=b:238646369
TEST=build

Change-Id: I91def471ef64ef11ba32032ccc095d5282362d62
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3779079
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: Junichi Uekawa <uekawa@chromium.org>
2022-07-25 05:44:36 +00:00
Mike Gerow
0c49f872a1 devices: add pflash to provide NVRAM for OVMF
This change adds a pflash implementation similar to the the one QEMU
has[1] for the purpose of giving OVMF a place to store BIOS settings and
UEFI variables. Unlike the QEMU version, though, this one only
implements the parts that OVMF relies on[2], and is therefore much simpler.

[1]: https://github.com/qemu/qemu/blob/HEAD/hw/block/pflash_cfi01.c
[2]: https://github.com/tianocore/edk2/tree/master/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c

TEST=tools/presubmit --all; boot VM under OVMF and confirmed UEFI
variables can be set and are persistent
BUG=b:238344840

Change-Id: I83bebb57006f39c6f0eb7ee4986c6af0e64de0bc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3764374
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Mike Gerow <gerow@google.com>
Commit-Queue: Mike Gerow <gerow@google.com>
2022-07-21 23:17:32 +00:00
Noah Gold
46b9f75a36 arch: split platform serial code into sys mod.
As part of the split, we're re-enabling the Windows code (it was
commented out as part of earlier refactoring).

BUG=b:237597358
TEST=builds

Change-Id: I04554b109033b4616c0a6521757c4aeb70d2ea5d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3767462
Tested-by: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-07-19 18:20:59 +00:00
Noah Gold
6952be0328 arch: split platform pstore code into sys mod.
BUG=b:237597358
TEST=builds

Change-Id: I6d12ebc088dd04aed36ab312d1312873813357d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3741685
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-07-14 00:08:34 +00:00
Noah Gold
637b1ee1d1 arch: split platform lib code into sys mod.
Highlights:
* goldfish battery never worked on Windows, but it sort of compiled
  anyways downstream. This CL makes it unix only because it never worked
  on Windows as a device anyway.

BUG=b:237597358
TEST=builds

Change-Id: Ia5fc3b5e5fcd243d8454646b00a6857085d018ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3741432
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2022-07-14 00:08:33 +00:00
Noah Gold
f234eaf752 arch: enable tests on Windows.
This shuts off some of the Windows serial code beacuse it's blocked on a
separate CL that upstreams bits of the serial device. (It doesn't work
in this repo yet anyway.)

BUG=b:237597358
TEST=builds

Change-Id: If6b223ff29d55f44bff7d006c1e0b5db3733a4ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3741429
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-07-13 23:11:29 +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
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
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
Noah Gold
3fd26a58b3 arch: fix file permissions for Windows pstore.
Without setting the share mode, we can't do occasionally useful things like
tail the pstore file.

BUG=b:237597358
TEST=builds + tested downstream on Windows

Change-Id: I893d0e52a671eeec5981527c1009b9d188110534
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3736759
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-30 20:34:14 +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
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
Daniel Verkamp
1b7d5b8fba arch: provide one vcpu_init per vcpu
Rather than having a single vcpu_init instance that is used for all
VCPUs, make vcpu_init into a Vec so it can store different initial state
for each VCPU. This allows us to set up e.g. bootstrap processor state
differently than other processors, and it also means that the VcpuInit
struct doesn't need to be Copy.

BUG=b:237095693
TEST=Boot Linux with >1 CPU

Change-Id: I0ebfdc2dbd84d0817e3f75c2c852e4320b9e77c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723798
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-29 18:14:49 +00:00
Noah Gold
4ea25d1e33 x86_64: add TSC leaf synthesis.
There have been two evolutions of providing the TSC cpuid leaf
(aka 0x15) to the guest.

a) For CrosVM on Windows, we have been providing the leaf
   unconditionally.  Furthermore, we've not been using the
   exact host leaf; instead, we calibrate the TSC frequency
   and provide that value in the leaf. This was done because
   the actual cpuid leaf values are not as accurate as
   we needed them to be to drive a guest clocksource.

b) In CrosVM mainline, 4080aaf9b3
   introduced the flag enable_pnp / enable_pnp_data, and
   provides the exact host 0x15 leaf to the guest if the
   flag is enabled.

This CL adds a new hypervisor capability (CalibratedTscLeafRequired) to control
whether or not the calibrated TSC leaf should be used, in addition to a new CLI
option to force it on hypervisors where it isn't enabled by default. The new
option is `--force_calibrated_tsc_leaf`.

BUG=b:213152505
TEST=builds upstream, battletested downstream on WHPX.

Change-Id: I611422808a9e10578c0ddcbd211ae902f937685f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3698993
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-28 02:23:55 +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
Junichi Uekawa
3d6c9542a7 crosvm: Reland "crosvm: split up --no-legacy flag"
This is a reland of commit 7110d673f2

Replace --no-legacy flag, which implied the removal of both i8042 and
rtc devices, with separate --no-i8042 and --no-rtc flags. The old
flag is still supported and implies the other two.

Because the original landing of this flag didn't protect it as an x86
specific option, this change just leaves that alone. But the new flags
are added as x86-only, because they are very x86 specific.

BUG=b:223443221
TEST=crosvm run --bios u-boot.rom --disk kernel
TEST=boot volteer-manatee

Change-Id: I57f9328483f24da29db663e261b3ccc2a97c3239
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3715083
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-21 17:59:38 +00:00
Junichi Uekawa
7e7412a86f Revert "crosvm: split up --no-legacy flag"
This reverts commit 7110d673f2.

Reason for revert: Needs to preserve --no-legacy flag for a while though deprecated

Original change's description:
> crosvm: split up --no-legacy flag
>
> Replace --no-legacy flag, which implied the removal of both i8042 and
> rtc devices, with separate --no-i8042 and --no-rtc flags. The old
> flag is still supported and implies the other two.
>
> Because the original landing of this flag didn't protect it as an x86
> specific option, this change just leaves that alone. But the new flags
> are added as x86-only, because they are very x86 specific.
>
> BUG=b:223443221
> TEST=crosvm run --bios u-boot.rom --disk kernel
>
> Change-Id: I4bbea2d0a38fdd3a5d69d12ca79fa360f0460358
> Signed-off-by: Alistair Delva <adelva@google.com>
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3510982
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
> Tested-by: kokoro <noreply+kokoro@google.com>

Bug: b:223443221
Change-Id: I022cff96f4508713c15973ee37a57e7fdc8c14e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3715073
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-21 01:46:58 +00:00
Daniel Verkamp
77abcb0d0a arch: add VcpuInit data to provide initial values
This will be used to pass the initial register values for each vcpu.
Each architecture can define its own variant of the initial vcpu state.

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

Change-Id: I696a5ecda202c1ff0681f0b89b89b9eec11e27e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3673615
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-17 20:50:51 +00:00
Vaibhav Nagarnaik
b8bfdb496f irqchip: Add IrqEventSource for each event
This allows irq processing thread to log statistics and metrics and
track them using the source of the device. To be upstreamed later.

Introduce `PCI_VENDOR_ID_CROSVM` which identifies devices created by
crosvm. And introduce `CrosvmDeviceId` which adds a unique device ID for
each type of crosvm device.

BUG=b:213149158
BUG=b:213152505
TEST=Compiled.

Change-Id: Ica1374d8a2d8fd627c9397553bb7fb62baeaff7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3687418
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-17 18:44:20 +00:00
Tinghao Zhang
9b7e350656 devices: pci: introduce pci device hierarchy
To add support for pcie switch, we need to make crosvm support pci
device tree. This patch introduces a new structure PciBus which
stores topology information of a pci bus using a tree-like structure,
so that we can handle bridge window/MMIO allocation properly before
boot up. That is, we have to allocate device MMIO based on their
pre-order in the device tree, otherwise some pci bridge's bridge
window would intersect and guest won't boot. This PciBus structure
is stored in PciRoot later, make it possible for us to modify pci
topology during runtime.

BUG=b:199986018
TEST=run crosvm to see if pci device model has any issues

Change-Id: Ieb677cb7787650804051c43355ba27ce7926819a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3503103
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-16 22:40:48 +00:00
Daniel Verkamp
fb641f67e4 resources: introduce AddressRange type
The AddressRange type is used for representing contiguous memory or I/O
address ranges, mostly equivalent to RangeInclusive<u64> but with the
added benefit of implementing Copy and not carrying an extra field used
only for iteration, which we don't need.

Using an inclusive range means we can represent the full address space
with no weird corner cases around the upper limit of the range (for
example, an AddressRange covering the full 64-bit space can be
represented as start: 0, end: u64::MAX).

AddressRange also replaces the previous MemRegion type, which was a
start/size pair.

This normalizes the interface of the resources crates to use
AddressRange rather than a start/size pair; more cleanups throughout the
tree may be possible, but this commit attempts to be somewhat smaller to
have a hope of being reviewable.

BUG=b:222769529
TEST=tools/presubmit --all
TEST=cargo test -p resources

Change-Id: I8c90bdc28456221b5107ef7e589233315ea739c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696671
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-16 20:29:26 +00:00
Alistair Delva
7110d673f2 crosvm: split up --no-legacy flag
Replace --no-legacy flag, which implied the removal of both i8042 and
rtc devices, with separate --no-i8042 and --no-rtc flags. The old
flag is still supported and implies the other two.

Because the original landing of this flag didn't protect it as an x86
specific option, this change just leaves that alone. But the new flags
are added as x86-only, because they are very x86 specific.

BUG=b:223443221
TEST=crosvm run --bios u-boot.rom --disk kernel

Change-Id: I4bbea2d0a38fdd3a5d69d12ca79fa360f0460358
Signed-off-by: Alistair Delva <adelva@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3510982
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-15 22:27:40 +00:00
Masami Hiramatsu
eb83ee79b6 aarch64: Add Goldfish battery to aarch64 crosvm
Add Goldfish battery to aarch64 crosvm. The guest kernel will
see the goldfish battery node on the FDT.
This copies the seccomp policy for the battery from x86-64.

BUG=b:214124318
TEST=create VM with parameter "--battery" or "--battery=type=goldfish"
TEST=android-sh -c 'dumpsys battery'
TEST=tast run ${DUT} arc.PerfBoot.vm

Change-Id: I8212e760db5ffbc5d01442cfa7930baa5962ef6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3686713
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Masami Hiramatsu <mhiramat@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Masami Hiramatsu <mhiramat@google.com>
2022-06-15 02:46:45 +00:00
Junichi Uekawa
af9d617e2d crosvm: Simplify Msr set up loop and MsrFilter.
Name the enums instead of bool so that it's easier to reason, and factor
out the MSR loop.

BUG=b:229770963
TEST=build

Change-Id: I7d2306472bdf7482479b40b0ef00f378754a811f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3685671
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-06-03 00:00:04 +00:00
Dapeng Mi
4080aaf9b3 crosvm: expose cpu frequency and temperature CPUID bits to guest
Turbostat detects if CPU frequency and temperature features are
supported by reading several CPUID entries bits. Expose these
CPUID bits to guest when enable-pnp-data option is enabled.

Several MSR registers which turbostat depends on have been already
passed through when ITMT is enabled. Adding code to detect this and
avoid to doubly pass through.

BUG=b:229770963
TEST=Run "turbostat" in Chrome OS guest and show correct value.

Change-Id: Ieebaf616d544cb187a80ec6f3313a246ebf54bb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3641466
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-31 02:03:38 +00:00
Dapeng Mi
38208040ff crosvm: add missing doc comments for configure_vcpu method.
BUG=None
TEST=Run "cargo doc" generate documents and check the arguments
description is correct.

Change-Id: I481d950928587728fdb69215b867561d6752f4aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3670720
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-31 02:03:36 +00:00
Dapeng Mi
a5d52312d5 crosvm: implement KVM_X86_SET_MSR_FILTER ioctl
turbostat shows cpu freq/c-state/thermal statistics data by reading
some related MSRs. Unfortunately some MSRs such as MSR_IA32_POWER_CTL
are already emulated by KVM. The emulated value are not what we want
to expose to Chrome OS guest. KVM_X86_SET_MSR_FILTER ioctl provides
a way to skip KVM's emulation and let user space handle the MSR.

We added two MSR actions "MsrPassthroughFilter" and "MsrEmulateFilter"
to indicate the corresponding MSR needs to be filtered.

BUG=b:229770963
TEST=Run "turbostat" in Chrome OS guest and show correct value.

Change-Id: I5920ddba091589170dc326e10187aec66f75df79
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3641465
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-30 06:35:12 +00:00
Anton Romanov
f66af4f3f8 crosvm: jail sandboxed devices before calling .on_sandbox on rest
Some non-jailed devices may spawn threads. Do this to prevent threads
interferring with jails

BUG=b:234169724
TEST=run with shared dir locally

Change-Id: I0164a56e4d60ac8358ffc368021cf6b8e9a11eb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3673787
Reviewed-by: Lepton Wu <lepton@chromium.org>
Commit-Queue: Anton Romanov <romanton@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-27 23:05:50 +00:00
Mike Gerow
539ba3dcc9 Reland "devices: debugcon: add bochs-style debugcon device"
This is a reland of commit 129840471d

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

Bug: b:233610263
Change-Id: I2f2125da95e8907f4f0c16930952e9b765d33e6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671087
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Mike Gerow <gerow@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-26 19:25:02 +00:00
Mike Gerow
d46572f47e Revert "devices: debugcon: add bochs-style debugcon device"
This reverts commit 129840471d.

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

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

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

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

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

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

BUG=b:233610263

Change-Id: I73238e5c35925668d133bfaa542fcbcf1e28765f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3661255
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Mike Gerow <gerow@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-26 17:13:59 +00:00
Vineeth Pillai
81b5e616d6 crosvm: vm_events: consolidate vm events into one framework.
crosvm waits on events like exit, reset, crash, guest panic etc and
uses eventfd to wait on these events. As of now, we have 4 eventfds
and may increase.

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

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

Change-Id: I313d428de5e3ce3b879982f913918ec0a4a72c35
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3480577
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vineeth Pillai <vineethrp@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-05-20 18:04:21 +00:00
Junichi Uekawa
e96813e469 crosvm: reorganize MsrRWType.
To simplify the construction and parsing, and put the impossible values
checking at parameter parsing time.

BUG=b:215297064
TEST=build

Change-Id: Ic601d61a73dba9e3ec40f3589c62a586e1c7a8c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3655032
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-05-20 00:31:59 +00:00
Xiong Zhang
8c97db443b x86_64: Add parameter to specify pci low mmio start address
In order to let host and guest have ths similiar pci mmio layout in
manatee, this commit add a pci-start parameter.

BUG=b:197877871
TEST=boot vm with --pci-start and check vm's mmio layout

Change-Id: I0e83dfb3ab3c3b2ea1b0a1554d532e8414924b36
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578017
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2022-05-19 07:47:18 +00:00
Junichi Uekawa
8a2188ae51 crosvm: Sort VmComponents and RunnableLinuxVm.
BUG=None
TEST=build

Change-Id: I64ebd32a24e28fdc7417b53a19c1ec94c833674d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3649385
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2022-05-16 23:49:22 +00:00
Xiong Zhang
1b27aef288 x86_64: Add parameter to speicify pcie cfg mmio base and size
Previous pcie cfg mmio is predefined as constand to avoid conflict with pci mmio,
this has two issues:
a. The size of pcie cfg mmio is limited to 64MB, so the max pci bus number is 64.
This isn't ennough for vfio-pci device, as such device's bus number is same as
host bus number, it may be above 64.
b. In manatee, CrOS may be required to have the same pcie cfg mmio base and size
as host.

So this commit add a parameter and let user could specify pcie cfg mmio base and
size. Then the guest memory layout will be adjusted to avoid conflict between
guest ram and pci low mmio.

BUG=b:197877871
TEST=run crosvm with --pcie-ecam=xxxx,xxxx, check vm's memory layout and pcie
ECAM function

Change-Id: I22cf7e2b3f01ab3f48dff9f5246cb1c24faa9703
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3305948
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-13 00:19:52 +00:00
Zhao Liu
b48571dee5 x86_64: Deprecate old userspace-msr cmd format
The old format is like:
--userspace-msr=0x10,action=r0

Now this format can be deprecated. Please use the new format like:
--userspace-msr=0x10,type=r,action=pass,from=cpu0

Also ask the MSR to be handled in crosvm must be unique in order to know
which MSRs have been handled in more complex scenarios.

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

Change-Id: I3c31affb738c558aaf4da5cea8d17b74428708a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3610843
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-10 03:13:52 +00:00
Junichi Uekawa
78a12954cf crosvm: Keep one MsrFileType per vcpu.
Each vcpu has a vcpu->MsrDev file mapping. Instead of trying to create
an instance at first use, just keep an empty map in the beginning.

BUG=b:215297064
TEST=boot volteer-manatee

Change-Id: Ic5a63b0427a6441f190da3917b5f272bbb8ec778
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3611369
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-09 08:11:40 +00:00
Daniel Verkamp
45b0920767 doc: add a top-level comment to all crates
This provides at least a minimal one-line description to show what each
crate is about.

BUG=None
TEST=tools/cargo-doc

Change-Id: I26732e8c29062e622d5be09bdc120a49d564b9fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3630422
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-06 20:46:57 +00:00
Shikha Panwar
dac771b644 Add --unprotected-vm-with-firmware flag to simulate protected mode.
This runs an unprotected VM but uses the same memory layout as for a
protected VM, loads pVM firmware, disables the same devices as for
protected mode. This is useful for debugging pVM firmware and other
protected VM issues.

TEST=crosvm --extended-status run --disable-sandbox --serial=stdout,hardware=serial,num=1 --unprotected-vm-with-firmware=pvmfw --bios=test_bootloader
TEST=tools/dev_container tools/run_tests --target=vm:aarch64
BUG=b:230475926

Change-Id: I9a8077d76874f10221071ea312291659d81da3d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3623760
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Andrew Walbran <qwandor@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-04 09:36:08 +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
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
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
Elliot Berman
53d9530f36 linux: Drop kvm_ prefix from vcpu_ids
Simple rename to emphasize that vcpu_ids are not KVM-specific.

Change-Id: Icaf8a5f15a83021cf48467b0b8d0042ab0ab4a92
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3586010
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Steven Moreland <smoreland@google.com>
2022-04-15 22:23:32 +00:00
David LeGare
740c824fe8 Update to gdbstub 0.6.1
Update the GDB stub implementation to the 0.6 version of the gdbstub
crate API, attempting to preserve the current behavior as much as
possible. Hardware breakpoints and single stepping still work, but some
existing issues with software breakpoints are still present.

BUG=None
TEST=Manual

Cq-Depend: chromium:3578400
Change-Id: I522242a1a2055ecdf47b2010a615dc9e0136ebd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578025
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: David LeGare <legare@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-13 12:52:24 +00:00
Dmitry Torokhov
a4a3b1dd6c devices: irq_event: implement as_raw_descriptors() and use them
This implements AsRawDescriptors trait for IrqEdgeEvent and
IrqLevelEvent and updates the users.

BUG=None
TEST=./tools/presubmit

Change-Id: I879531e98396f1eb8e99db73cb00d7b3330101a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3552317
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-07 01:41:56 +00:00
Dmitry Torokhov
7997f0c28f devices: vfio_platform: add specialized assign_{edge|level}_platform_irq()
The new specialized functions take IrqEdgeEvent and IrqLevelEvent
arguments, so that callers can use them directly.

BUG=None
TEST=./tools/presubmit

Change-Id: I2e5c5d92a6c292f31ad6cfb8652f0c46f0a7a958
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548067
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-07 01:41:53 +00:00
Dmitry Torokhov
f021a62130 devices: irqchip: add specialized register_{edge|level}_irq_event()
The new specialized functions take IrqEdgeEvent and IrqLevelEvent
arguments, so that callers can use them directly.

BUG=None
TEST=./tools/presubmit

Change-Id: I2c1272e31f6b20eb22743b003bd23b9c1105cda6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548066
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-07 01:41:52 +00:00
Dmitry Torokhov
c11a18b713 devices: vfio_platform: change assign_platfrom_irq() to accept events refs
This is in preparation for callers to use IrqEdgeEvent and IrqLevelEvent
and follows general principle in crosvm that if entity needs to hold on
to an event, the entity is responsible for cloning it.

BUG=None
TEST=./tools/presubmit

Change-Id: I9da9a5156108355449b290a2a848257816370fb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548064
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-07 01:41:51 +00:00
Dmitry Torokhov
99067756fb devices: vfio_platform: make assign_platform_irq() return errors
This allows to make the code more concise and gives callers a chance
to act upon errors.

BUG=None
TEST=./tools/presubmit

Change-Id: Ibd9d53270bc21f90fcb44c673d2c7f3763a44c3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548063
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-07 01:41:50 +00:00
Dmitry Torokhov
dd21595173 devices: pci: change assign_irq() to accept IrqLevelEvent
This continues conversion from a pair of Event objects to single
IrqLevelEvent.

BUG=None
TEST=./tools/presubmit

Change-Id: Iec7e94f4c40cc29fa612cc3ae364cc6f8b0d0177
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548061
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-06 18:54:49 +00:00
Dmitry Torokhov
bcc5368cc1 devices: goldfish battery: convert to using IrqLevelEvent
Use IrqLevelEvent instead of 2 separate event for interrupt handling.

BUG=None
TEST=./tools/presubmit

Change-Id: I56e57044b665565cf1b42831e8ac2240e41bd102
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3536894
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2022-04-06 18:54:40 +00:00
Pierre-Clément Tosi
bdef378a27 arch: fdt: Pass &[&str] to property_string_list
Make the function take the more versatile slice of string slices,
instead of requiring caller code to generate the dynamic Vec and String
types, which can easily be converted back into those primitive types.

Note: no functional change intended.

BUG=b:227142928
TEST=booted a protected VM from the AOSP fork

Change-Id: I61701700efdacab4cfc5f5dd3df761e06a372065
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3560154
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
2022-04-05 13:26:21 +00:00
Keiichi Watanabe
ba0e3dbcb8 arch: Don't set up serial device when vhost-user console is set
crosvm sets up an emulated serial device for ttyS0 as a default device
unless virtio-console is specified.
The setup should be skipped when a vhost-user console is specified as well.

BUG=b:196186396
BUG=b:227407433
TEST=no serial output when one vhost-user console is specified.

Change-Id: Ib17e218fd01a13c109fc1246fd3a6d99031d3181
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3557729
Reviewed-by: Morg <morg@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-03-30 07:43:42 +00:00
Vikram Auradkar
3a29174a7b Upstream windows serial device
Bug: b:213149155
Test: cargo test and presubmit
Upstream-Crate: devices
Change-Id: I1420fee814271dae9502878963872449dae8218e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3527444
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-03-24 23:45:10 +00:00
Dmytro Maluka
74031b483f x86_64: acpi: support for assigning physical GPEs
Wire up GPE eventfd forwarding and crosvm's GPE emulation.

This patch allows to provide ACPIPMResource with the list of GPEs
which should work as direct physical (passthrough) GPEs rather than
purely emulated ones.

BUG=b:205072342
TEST=see CL:3492224

Change-Id: Idb8ef36299c793f56d73246d15ff89f495bb30ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3492223
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-21 09:16:38 +00:00
David Stevens
e4db417895 pstore: reserve ramoops region in system allocator
Remove the ramoops region from high_mmio when constructing the system
allocator. This means the aarch64 code no longer needs to manually
adjust high_mmio when determining the pci regions.

BUG=b:181736020
TEST=Check arcvm pstore still works

Change-Id: I81ca398a1984f0efb30c0a4d4b620bd50fe9df85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3516667
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-03-17 01:58:13 +00:00
David Stevens
097623dce4 arch: return system allocator config
Have the arch code return the SystemAllocatorConfig instead of a
SystemAllocator. This will be used to allow the core code to apply
additional restrictions on top of the arch code's restrictions.

BUG=b:181736020
TEST=compiles

Change-Id: I4d9ca277f039586e664648492c8744967dcd2ee5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3516665
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-03-17 01:58:11 +00:00
Dennis Kempin
ef516189db Refactoring: Move common/base into base
Executes the script in https://crrev.com/c/3530502

BUG=b:223206469
TEST=presubmit

Change-Id: Ibeffdc8de0b2270f070e60bb2de8d9fdc78a2a6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3530503
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-03-17 00:01:27 +00:00
Peter Fang
6ca0323c87 acpi: support fixed power button event in command line
Support injecting an ACPI fixed power button event using "powerbtn" in
the command line.

BUG=b:199383670
TEST=boot Linux kernel and trigger a power button event

Change-Id: I5ed57f533fa3d91043491fd1f0695223a139fc7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350492
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:20 +00:00
Paramjit Oberoi
449dd6b709 Don't add ramoops parameters except addr and size
BUG=b:218891911
TEST=manual testing

Cq-Depend: chromium:3491214
Change-Id: If2b7e4856ac497f2c3b277ed02bd96c9e629aa2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3491603
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Paramjit Oberoi <psoberoi@google.com>
2022-03-09 18:34:50 +00:00
Anton Romanov
bed40ad547 crosvm: migrate to Rust 2021 edition
BUG=none
TEST=cq

Change-Id: I0059c970879b78bfd40b6ce58b10debcf154b50f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508322
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-03-09 01:16:03 +00:00
Haiwei Li
e35d46529c devices: vfio_pci: MMIO BAR allocation for devices on non-root buses
Since we'll be putting all PCI devices on non-root buses behind virtual
PCI-E root ports, MMIO BARs in such devices must be inside the forward
windows of their root ports. This presents additional requirements for
their MMIO BAR allocation:

1. All non-prefetchable BARs must be inside the same 32-bit MMIO window
2. All prefetchable BARs must be inside the same MMIO window, but
   different than the non-prefetchable MMIO window
3. Both windows must be 1MB-aligned
4. No other PCI devices should occupy MMIO space in these windows

Allocate the entire window from the system resource allocator to prevent
any space within the window from being used elsewhere. To maximize
memory space efficiency, use VfioResourceAllocator for BAR allocation.

BUG=b:185084350
TEST=passthrough a vfio-pci device with bus_number > 0 and static connet it
behind a pcie root port, then check pcie RP and vfio-pci device function in
guest.

Change-Id: Ic9865afc48eb3ff9fa475dbcfdf90642b012980c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3166888
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-02-28 21:55:09 +00:00
Haiwei Li
a79e14bad5 devices: refactor the return of allocate_io|device_bars
Introduce the struct BarRange{addr, size, prefetchable} to indicate the
return of allocate_io|device_bars. So it is readable and easy to use.

BUG=b:185084350
TEST=boot Linux kernel and check dmesg

Change-Id: I0073f20401816f60c131bf15a9bc196e5fcba6d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3455126
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-02-28 21:55:08 +00:00
Grzegorz Jaszczyk
d33874ea04 acpi: x86: add option for setting LP S0 capable flag for guest ACPI tables
Fixed ACPI Description Table (FADT) contains Low Power S0 Idle Capable
Flag. This commit introduces "--s2idle" argument allowing to set proper
bit in the guest FADT table. This is required to inform guest OS to use
s2idle instead of traditional S3 power mode.

BUG=b:194391015
TEST=Build crosvm and run "crosvm run --s2idle ..", dump FADT table and
     confirm that proper flag was set.

Change-Id: I243bfe2cc4840278fcdbf33dcb147b2eda50856d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3457402
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
2022-02-21 20:41:08 +00:00
Vikram Auradkar
ae5118f5c7 Enable windows tests for a few crates
Run tests for sys_util_core, poll_token_derive and balloon_control on
windows.

Using dotfiles to disable/serialize test runs of a subset of crates does
not work well with third party crates as it forces us to commit the dot
file to the crate.

The patch modifies and uses the script that runs linux tests.
This patch also allows us to
- build/test child crate even if parent crate has disabled build/test.
- avoid building crosvm if it is not explicitly specified.

RIP short lived .windows_build_test_skip. You allowed us to run noop
kokoro tests.

Test: py .\tools\impl\test_runner.py --arch x86_64
Bug: b:215610772
Change-Id: Icc6d04ffd7c0c33d4f60aeac16fc7d23881c387d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3459809
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-02-18 03:18:58 +00:00
Vikram Auradkar
0108238474 Upstream windows build/test script
The patch also adds files to skip building and testing crates on
windows. When we run
```
tools/windows/build_test.py --skip_file_name .windows_build_test_skip
```

the build/test succeeds without actually doing anything as build/test
for all crates is skipped by creating '.windows_build_test_skip'.

Bug: 213170957
Test: Ran script on downstream repo
Change-Id: Iebd2cea463ee722be4feaed88229e1fb5e9fd6c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3417918
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-01-28 00:55:08 +00:00
Daniel Verkamp
6f4f8223b8 hypervisor: add API to query VM physaddr size
Add a function that returns the size of guest physical addresses. This
wraps KVM_CAP_ARM_VM_IPA_SIZE on aarch64 and CPUID to query host
physical address size on x86_64. This replaces the phy_max_address_bits
function from x86_64, and all callers are migrated to use the new Vm
function instead.

BUG=b:210727578
TEST=check on trogdor64 with debug prints

Change-Id: I3107fe6357fcf166b7ad0e2a7c55919705da3b0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3364971
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-01-11 22:41:38 +00:00
Andrew Walbran
00f1c9fd46 Update to the latest pKVM ABI.
This involves two main changes:
 * Protected VMs must be created with KVM_VM_TYPE_ARM_PROTECTED.
 * pVM firmware is now loaded by IPA rather than memslot ID.

There are also a lot of trivial changes because the ProtectionType enum
was moved from the devices crate to the hypervisor crate.

BUG=b:209794844
TEST=Will tested manually with patched kernel and dummy firmware

Change-Id: I1dd75e20063ca4736f155292ca5f70b94664fdd9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3330204
Auto-Submit: Andrew Walbran <qwandor@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-01-04 19:35:27 +00:00
Xiong Zhang
0b8318a2be Linux: Change root_config from PciConfigArch to PciRoot
Since PciRoot has been modified into Arc<Mutex<>>, RunnableLinuxVm->root_config
could be changed from PciConfigArch to PciRoot also, this could simplify code
and reduce two functions from PciConfigArch.

BUG=b:197877871
TEST=tools/presubmit

Change-Id: Ibc18587900d6f8259ac1d6f8fe7b3ea4fedad07e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3305942
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2021-12-08 12:30:28 +00:00
Dmitry Torokhov
f75699f59c crosvm: return 32 exit code when guest issues reset request
Instead of returning 0 for both shutdown and reset/reboot, let's have
shutdown continue returning 0, but reset will now return 32 exit code,
so that callers will have an option to handle this case differently.

BUG=b:3169569
TEST=Examine crosvm exit codes when resetting and shutting down VM

Change-Id: I2c7c11b7f8c8528744f7e25e5d17c6fa9810f409
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3316835
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2021-12-08 06:33:02 +00:00
Xiong Zhang
f82f2dcfa0 devices:pcie: Add PcieRootPort into hotplug bus
PcieRootPort implement hotplug_bus trait, it should be added into
RunnableLinuxVm->hotplug_bus, so create pcie root port when
RunnableLinuxVm->hotplug_bus is ready.
Many hotplug bus may exist, when a hotplug device is added, is_match()
should be called on each hotplug bus before attach that device to
the bus.

BUG=b:185084350
TEST=Boot a vm with passthrough device and check its function

Change-Id: I89dbc091f336b3f9d0435b52963f7cf62d408a67
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955570
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-19 22:10:08 +00:00
Dennis Kempin
8a1c50d5cd Refactoring: Move various general purpose crates to common/
This change contains the results of running

./tools/contib/cargo_refactor.py

This will break the next uprev, and needs to be synchronizized
with the corresponding ebuild changes in https://crrev.com/c/3248925

BUG=b:195126527
TEST=./tools/run_tests

Change-Id: Ied15a1841887bb8f59fba65b912b81acf69beb73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3248129
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-29 22:31:43 +00:00
ZhaoLiu
2aaf7ad9fc x86: Support Host exposes CPU topology to Guest VM
At present the Guest generates its own CPU topology. To mitigate
cross-hyperthread speculative execution side channel attacks, allow
Guest to use mirror CPU topology of Host is needed for future scheduling
optimization.

Add a config option "--host-cpu-topology" to ask the vCPU number to be
identical to physical CPUs, and make the vCPU has the same APIC ID in
MADT and CPUID as the corresponding physical CPU. The same APIC ID can
ensure the same topology.

"--host-cpu-topology" requires vCPU number must equal to pCPU number,
and it has the default vCPU number setting, which equals to pCPU number.

"--host-cpu-topology" also defaultly sets CPU affinity for each vCPU to
the pCPU which has the same processor ID, like 1=1:2=2:3=3:4=4, so that
the vCPU and its corresponding pCPU will have the same processor ID and
the same APIC ID. User can't set CPU affinity if "--host-cpu-topology"
was set.

BUG=b:197875305
TEST=Set "--host-cpu-topology" option and check Guest's /proc/cpuinfo,
  lscpu, CPUID for different vCPU

Change-Id: Ibc4eb10649e89f43b81bde6d46d6e0e6c7234324
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3217035
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-10-25 04:19:45 +00:00
Xiong Zhang
3022a234b0 devices: Use Mutex to protect bus->devices
With vfio pci device hotplug, bus->devices will be inserted and removed at
runtime in different vcpu threads, so mutex should be used to protect it.

Both each vcpu thread and pci_root share mmio_bus and io_bus, so use Arc
for mmio_bus and io_bus. But pci_root is inserted into io_bus for pci cfg io,
in order to resolve reference loop and memory leak, weak is used for
pci_root.mmio_bus and pci_root.io_bus.

BUG=b:174705596
TEST=boot a vm and check its function

Change-Id: I7b3e63db76a90bc3873619b4d80a66db741ce78f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3184724
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-21 05:42:49 +00:00
Tomasz Nowicki
b8957f90a8 devices: vfio: Add VFIO platform support
Platform device is another type of device which might be assigned
directly to VM by using the same IOMMU DMA isolation technique.
In contrary to PCI, platform device has no config space which
describes device resources and makes it self-contained and
self-discoverable. Therefore, platform device resources are described in
FW and host is the one who enumerates/probes devices by parsing DT/ACPI.
We have ioctl i/f which allows to expose all that info to VMM.
Add platform bus specific calls to interact with host properly and
plug in to aarch64 bus creation code.

Note, for now all IRQs are abstracted to wired line (SPI in ARM GIC world)
which means guest wont see MSI-X for platform devices.

BUG=b:185504618
TEST=trogdor64-manatee SDHCI and GENIQUP device passthrough boots/works

Change-Id: Id0e9efde3586af77ed1d0b8bf79ca485906afb83
Signed-off-by: Tomasz Nowicki <tn@semihalf.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2961216
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
Commit-Queue: Micah Morton <mortonm@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-04 17:06:19 +00:00
Tomasz Nowicki
ab86d52fba arch: Generalize PCI device box for build_vm
Before we call build_vm we are creating devices and there is no reason
to assume those have to be PCI only. In preparation for VFIO platform
device support, add super trait which allows to pass generic device
structure around and still be able get back to our original type.

BUG=b:185504618
TEST=manatee PCI device passthrough boots/works

Change-Id: I500f44af430f5f06299f20fc4ca17ca008a7e0c5
Signed-off-by: Tomasz Nowicki <tn@semihalf.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2961210
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-01 08:46:21 +00:00
Udam Saini
38fedb73e5 Revert "vm_memory: Add from_desciptor() in MemoryMappingBuilder"
If we need descriptor for things that aren't file or other shared_memory objects, we can create a separate descriptor change, but it shouldn't be the default.

This reverts commit 533c5c8258.

Reason for revert: this causes conflicts with other platforms.

Original change's description:
> vm_memory: Add from_desciptor() in MemoryMappingBuilder
>
> MemoryMappingBuilder had `from_file()` and `from_shared_memory`, which
> are almost the same. So, this commit adds `from_descriptor()` to replace
> both of the two.
>
> BUG=b:194137301
> TEST=build
>
> Change-Id: Ia13f5e8e0f95a5c32e47dc9b3be13b7a7fa510bf
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3159881
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>

Bug: b:194137301
Change-Id: Ie203ee3eb3dcddd41c5e55b6980dc6292eb24f85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3183183
Auto-Submit: Udam Saini <udam@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Udam Saini <udam@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-09-27 16:36:24 +00:00
Keiichi Watanabe
533c5c8258 vm_memory: Add from_desciptor() in MemoryMappingBuilder
MemoryMappingBuilder had `from_file()` and `from_shared_memory`, which
are almost the same. So, this commit adds `from_descriptor()` to replace
both of the two.

BUG=b:194137301
TEST=build

Change-Id: Ia13f5e8e0f95a5c32e47dc9b3be13b7a7fa510bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3159881
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-09-22 04:37:44 +00:00
Tomasz Jeznach
7ab02aa85b crosvm/pci: update to PCI/INTx allocation
For VFIO devices, allow host interrupt allocation
numbering to match ACPI _CRS.

BUG=b:179648314
TEST=./test_all, boot on sytem with vfio devices connected.

Change-Id: Ied1153f3fc72876d8f3df8822ff6d4e869c40f62
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2893367
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-09-02 10:00:47 +00:00
Daniel Verkamp
e8e871b085 arch: convert to ThisError and sort
BUG=b:197143586
TEST=cargo check

Change-Id: Id02ed4873158e20664b45bf651ba68e0eb715b1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105071
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-08-26 22:28:31 +00:00
Daniel Verkamp
166d1ddfbe crosvm: fix needless_borrow clippy warning
Tree-wide cleanup of new clippy warning in Rust 1.54 that warns about
needless borrows:

  error: this expression borrows a reference (`&...`) that is
  immediately dereferenced by the compiler

https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

BUG=b:197251702
TEST=bin/clippy # with rust-toolchain = 1.54.0

Change-Id: Ib702ec524d4623d264a00ec11dbc2150c411a67b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108321
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-25 23:02:23 +00:00
Ryo Hashimoto
8f9dc1d55e aarch64: Support pstore
Add necessary kernel cmdlines for aarch64.
Adjust PCI address to make room for ramoops on aarch64.
Move the code from x86_64 to common places.

BUG=b:153934386
TEST=vm_pstore_dump

Change-Id: I8f92a7fd04a49afd7e8be9e7cf1901ef70b88d65
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3103131
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Kansho Nishida <kansho@chromium.org>
Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
2021-08-24 14:31:44 +00:00
Xiong Zhang
9fadc3fda0 devices🚌 Add HotPlugBus Trait
Device implement HotPlugBus trait could notify hotplug event into
guest, and such device should be added into RunnableLinuxVm, so it
could be used at device plug in and plug out.

BUG=b:185084350
TEST=Boot a guest with and without passthrough device

Change-Id: I9497f61312582483090ff708d0f37b97d7303811
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2954673
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-24 00:56:29 +00:00
Xiong Zhang
8c9fe3ef34 Arch: Vfio device could be created and configured at runtime
When a vfio pci device is added through hotplug in, it should be configured
at runtime and added into pci_root->devices tree, so pci_root is added
into linux.

BUG=b:185084350
TEST=Boot a guest with and without passthrough device

Change-Id: Ibcb5f4a849134f64fbceeac645bebd80d6ca72d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2954672
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-08-24 00:56:28 +00:00
Keiichi Watanabe
553d219902 arch, devices: Move serial data structures to devices
Move the definitions of SerialHardware, SerialParameters and SerialType
to the devices crate so that they'll be available for code in the
devices crate as well.

BUG=b:195495971
TEST=cargo test

Change-Id: Ieb711bdb18a8afdb28cac262a3355739604d4607
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3096439
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-08-18 09:06:23 +00:00
Keiichi Watanabe
407b320fea arch: serial: Use thiserror and sorted for Error enum
BUG=none
TEST=cargo check

Change-Id: Ib8c07eb54af730c7a0ffaab67c02d6fb14a7efa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3096438
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-18 09:06:22 +00:00
Xiong Zhang
da162f29b4 Arch: Add configure_pci_device() function
Hotplugged device will be configured at runtime and configure_pci_device()
will allocate resource for added device and put this device into LinuxVm.

BUG=b:185084350
TEST=Boot a guest with and without passthrough device

Change-Id: I2c77f006d135c1b1487d4e89a50b1b186beeb48e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2954671
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-17 22:46:39 +00:00
Joel Galenson
06392aabd4 Migrate to gdbstub 0.5.0.
BUG=b:191784608
TEST=Build and run atest in Android tree

Cq-Depend: chromium:3073700
Change-Id: I5fcfa166caf8c5a5f759a8f62ef78a293db95f1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3071900
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-08-13 18:30:47 +00:00
Will Deacon
c48e78344e crosvm: arm64: Populate restricted DMA node based on 'swiotlb=' option
Protected VMs require all virtio data to be bounced through a memory
window shared between the host and the guest. Although this can be
achieved by forcing the guest to use swiotlb bouncing for all DMA
transfers, the recent introduction of "Restricted DMA" in Linux allows
these buffers to be sized and allocated on a per-device basis.

Remove the 'swiotlb=force' option when '--protected-vm' is set in favour
of describing a reserved memory region to be used as the swiotlb buffer
for all virtio-pci devices, adjustable via the new '--swiotlb' option.

BUG=b:190593703
TEST=cargo test on x86 and arm64 machines
Cc: David Brazdil <dbrazdil@google.com>
Cc: Claire Chang <tientzu@chromium.org>
Cc: Quentin Perret <qperret@google.com>
Cc: Andrew Walbran <qwandor@google.com>
Cc: Marc Zyngier <mzyngier@google.com>

Change-Id: I2d48a7c77740e7f3ad996ad33592f0acd53b7144
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3064198
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Will Deacon <willdeacon@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-08-13 16:12:35 +00:00