Commit graph

592 commits

Author SHA1 Message Date
Mattias Nissler
de2c640f17 Add stub PCI device implementation.
Introduce a very simple stub PCI device that can be added to the bus
at a specified address with given PCI config parameters (vendor,
device, etc.). This is useful for cases where we just require a device
to be present during PCI enumeration.

The case that motivates this is a vfio device passthrough
configuration that passes only selected functions of a given device at
the original addresses, but function 0 is not passed through. Absence
of function 0 would be interpreted in enumeration as the entire device
being absent (in accordance with the specification). Putting a stub
device at function 0 fixes this.

BUG=b:167947780
TEST=New unit test, boot minimal Linux image and verify enumerated PCI device.

Change-Id: Iaedffe1c4ac2ad8f6ff6e00dfeebbbfeb5490551
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3245497
Auto-Submit: Mattias Nissler <mnissler@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Mattias Nissler <mnissler@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-27 14:06:35 +00:00
Mattias Nissler
1afcde90c2 Command line key=value option parsing helpers
Many command line options take comma-separated key-value pairs. A lot
of the parsing boilerplate is duplicated for various options in
main.rs. This change introduces generic helpers to make this easier.
Subsequent changes will convert the existing option parsing to make
use of this infrastructure.

BUG=b:167947780
TEST=New unit tests.

Change-Id: I5ff1e4a09ac92c10d99b0b81d7d7cd7ce153fadb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3245494
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Mattias Nissler <mnissler@chromium.org>
2021-10-27 13:06:53 +00:00
Woody Chow
f5db3e5186 Add missing HwBreakpointOps impl to GdbStub
Migration to gdbstub 0.5.0 broke hardware breakpoints.
(https://crrev.com/c/3071900). This fixes it.

BUG=chromium:1259868
TEST=Manually with `hbreak start_kernel` on a volteer device

Change-Id: I35097b4ad2ec9990e78e68c3274c12ba7a5dbea9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3244555
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Woody Chow <woodychow@google.com>
2021-10-26 07:12:23 +00:00
Xiong Zhang
9557588786 Devices: Allocate non pci bar mmio at top of HighMmio
Some devices like virtio-pmem, intel host bridge need private mmio, these private
mmio isn't exposed to Vm through pci bar, and crosvm use mmio allocation interface
to allocate them, so guest OS pci bus driver couldn't detect them, and once guest
OS reallocate pci mmio, these private mmmio could be assigned to pci device bar.
then resource conflict happens.

This patch allocates these non pci bar mmio at the top of HighMmio, since HighMmio
is large enough and OS allocates pci mmio from low to high. So these non pci bar
mmio won't conflict with pci bar.

BUG=b:199442120
BUG=b:185084350
TEST=crosvm run --pmem-device xxxx

Change-Id: I615d7901d595dd46ba6362f88b71d96baa9c4c8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3184549
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-10-25 22:03:12 +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 Jeznach
9e6c633ada crosvm: MMIO forwarding.
BUG=b:188011323
TEST=None

Change-Id: I93b722893c29add6e5de173d40ff1523d2b3a687
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2925137
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-20 05:35:59 +00:00
Dennis Kempin
65740a6842 Uprev to rust 1.55.0
Includes some fixes for new clippy checks. A rebuilt
dev_container that ships the new toolchain.

This allows us to get rid of the annoying cargo clean
before running clippy.

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

Change-Id: I9d486fbcf7b2d468f6a1375ac7df95091a2c1465
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3232277
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-10-19 19:12:52 +00:00
Woody Chow
1b16db18bd devices: Add vhost-user snd vmm
BUG=b:184322202
TEST=tast run $DUT_IP vm.Audio*.vhost_user_cras
     (with https://crrev.com/c/3185059)

Change-Id: Icb3b2dd1268f183bf57754345b9302fd5e78a7ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2801654
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Woody Chow <woodychow@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-10-15 04:51:19 +00:00
Chirantan Ekbote
84091e5331 Add vhost-user vsock vmm
Add the vmm side for the vhost-user vsock device.

BUG=b:179756331
TEST=Connect to vshd inside a VM with a vhost-user vsock device

Change-Id: I332adbb6f8d6cfc8dff16375e93d946ecad2e84b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3153213
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-10-08 07:00:06 +00:00
Chirantan Ekbote
f08bdddf58 Add vhost-user vsock device
Since vhost-user messages have a 1:1 mapping to vhost ioctls, this
device doesn't use DeviceRequestHandler but processes incoming messages
directly.

BUG=b:179756331
TEST=Connect to vshd inside a VM with a vhost-user vsock device

Cq-Depend: chromium:3105429
Change-Id: I9811e29282f7e79140be1203bce9030ec37a3343
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3153212
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-08 07:00:04 +00:00
Yusuke Sato
31e136aeda crosvm: Allow all vCPU threads to share same cookie for core scheduling
This CL adds --per-vm-core-scheduling command line option to crosvm
to allow ARCVM to use per-VM core scheduling for better performance.
Note that per-VM core scheduling makes all vCPU threads to share the
same core scheduling cookie.

The feature is disabled by default, and does not change Linux VMs
behavior unless the new command line flag is explicitly passed in.
Also, this CL never affect Parallels since it uses the plugin
infrastructure (src/plugin/).

For ARCVM, the feature will be enabled by default via Chromium's
base::Feature (see crrev.com/c/3207747) as an interim solution until
the optimized two-level core scheduling is ready. This is based on
the latest recommendation from the security team (newfel@, resch@,
and others) at go/arcvm-core-scheduling-recommendations.

Credit: This CL is based on an idea from joelhockey@ and bgeffon@
at go/exawj

BUG=b:194022819
TEST=boot ARCVM with the new flag and verify all vCPU threads have
  same cookie.

Change-Id: Ib97ab9942b2516df9fbffe35517919f29b309a83
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3101607
Commit-Queue: Yusuke Sato <yusukes@chromium.org>
Owners-Override: Yusuke Sato <yusukes@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
2021-10-07 21:34:10 +00:00
Daniel Verkamp
31b6a00062 argument: convert to ThisError and sort
BUG=b:197143586
TEST=cargo check

Change-Id: I8d75003c65e647f1cf4962f390823d5c15169a57
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105434
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2021-10-06 21:38:37 +00:00
Daniel Verkamp
8eda3ea975 plugin: convert to ThisError and sort
BUG=b:197143586
TEST=cargo check

Change-Id: If39509d73741df08fdc876431dfc096ee0b8d158
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105433
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2021-10-06 21:38:36 +00:00
Keiichi Watanabe
fe64430445 main: Don't initialize syslog twice for device command
Remove `syslog::init()` in `start_device(), as it's called in
`crosvm_main()`.

BUG=none
TEST=cargo build

Change-Id: Ibe2fe08382525c8eee8dfe33b7949c0f8b0f545e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3165617
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-10-06 17:02:58 +00:00
Tomasz Nowicki
344eb144bc linux: Instantiate VFIO platform device
Extend VFIO command line option to specify full path to VFIO platform
device that is going to be assigned.

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

Change-Id: Iad6a24124b383fadb9e025dc64f8a90fa8763ff8
Signed-off-by: Tomasz Nowicki <tn@semihalf.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2961217
Commit-Queue: Micah Morton <mortonm@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-04 19:02:18 +00:00
Chirantan Ekbote
f1cd8d7a66 fs: Make posix acl support optional
Google drive and file systems used for external media (like FAT32) don't
support xattrs, which means they also don't support posix acls.
However, we unconditionally enable FUSE support for posix acls
preventing us from using virtio-fs for those mount points.

Make posix acl support optional so that we can also use virtio-fs for
gdrive and external media.  This feature is on-by-default since we
currently use it for every other virtio-fs mount point.

BUG=b:196946147
TEST=arc.PlayStore.vm

Change-Id: I9139852d6dceb46bef21af43f77fc527f3fa58d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3168564
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-10-04 03:18:26 +00:00
Tomasz Nowicki
71aca792b3 crosvm: Introduce VfioParam structure to recognize VFIO device type
VFIO-PCI device type is not the only one. To manage VFIO device type:
- add new structure to keep device type, its sysfs path
- refactor VFIO command line parser and let parameter options to be
extensible

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

Change-Id: I8f3226d388267e1a15dc537e37bb2054e3c6e486
Signed-off-by: Tomasz Nowicki <tn@semihalf.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2961211
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-01 19:02:51 +00:00
Chirantan Ekbote
1b2d8dc856 fs: Make DAX optional
We don't currently have it enabled anywhere but we still always allocate
PCI shared memory regions for it.  Instead make it optional and off by
default.  We can re-enable it on a per-device basis.

BUG=none
TEST=arc.PlayStore.vm

Change-Id: Icf122a561251a3e55757a9ffe4633b96adc4066d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3168563
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-10-01 10:33:18 +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
Junichi Uekawa
52437db2e9 crosvm: Add more information of adding block device.
Trying to chase down what is failing in the bots that cannot be
reproduced.

BUG=b:199094605
TEST=tast run localhost:2229 arc.Boot.vm
shows:
2021-09-30T00:51:27.843991Z INFO ARCVM(34)[23414]:  [src/linux.rs:228] Trying to attach block device: /opt/google/vms/android/system.raw.img
2021-09-30T00:51:27.844122Z INFO ARCVM(34)[23414]:  [disk/src/disk.rs:283] disk size 648871936,
2021-09-30T00:51:27.844456Z INFO ARCVM(34)[23414]:  [disk/src/disk.rs:283] disk size 648871936,
2021-09-30T00:51:27.844753Z INFO ARCVM(34)[23414]:  [src/linux.rs:228] Trying to attach block device: /opt/google/vms/android/vendor.raw.img
2021-09-30T00:51:27.844785Z INFO ARCVM(34)[23414]:  [disk/src/disk.rs:283] disk size 139890688,
2021-09-30T00:51:27.844998Z INFO ARCVM(34)[23414]:  [disk/src/disk.rs:283] disk size 139890688,

Change-Id: Ief63cf75ba86e5324c6cc65a825c2717d3a0cb18
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3195154
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2021-09-30 07:53:06 +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
Dmitry Torokhov
cc03cdbecc plugin: capture stderr when spawning/jailing plugin binary
While minijail uses syslog to log errors during jail setup, ld.so simply
dumps error into stderr. When debugging plugin startup issues it is
beneficial to see what ld.so might be upset about, so let's capture
stderr of the child and log it.

BUG=None
TEST=removed /opt/pita/lib symlink, tried starting Parallels VM,
observed meaningful error message captured from stderr.

Change-Id: I7e57e110a969653e0d27e6e93f4a8104efeca978
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3170589
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2021-09-23 04:57:15 +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
Daniel Verkamp
127a90ff3e linux: disable PCI to PCI bridge
The presence of the PCI bridge introduces a regression when booting
OVMF:

  PciHostBridgeDxe: IntersectMemoryDescriptor: desc [0, A0000) type 2 cap
  800000000002600F conflicts with aperture [0, D0021000) cap 1

The root cause is that the bridge does not correctly populate the memory
base/limit and prefetchable memory base/limit PCI bridge configuration
registers.

For the short term, since this bridge is only needed for the PCI hotplug
feature that is not enabled yet, remove the creation of the bridge from
the startup code.  Fixing the bridge will be done in another commit to
keep this change small and easy to backport.

BUG=b:199442120
BUG=b:185084350
TEST=crosvm run --bios OVMF.fd

Change-Id: I91b2cc6628e320ac2403bd8b74d18ef5a26d7c0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3158942
Reviewed-by: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-09-22 01:04:31 +00:00
Chirantan Ekbote
44292f58f3 Support out-of-tree vhost-user-gpu
BUG=b:179755651
TEST=`glxinfo -B | grep virgl` inside a crostini vm

Change-Id: I37b98fcccfb8e56af4d07a2afe828ca3b5087b1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987595
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-09-21 10:08:51 +00:00
Abhishek Bhardwaj
7a1a6cd58b crosvm: Implement communication logic in virtio-vhost-user PCI device
This change adds the PCI device that will act as the conduit between
vhost vmm and vhost device in a virtio-vhost-user
specification. It only implements the communication logic i.e. rx / tx
from the vmm socket and virtio queues associated with the device.

BUG=b:194136484
TEST=Compile.

Change-Id: Ib47045b7633b77b73ed7bd428ca981caa6645275
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3146213
Auto-Submit: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-09-17 22:07:55 +00:00
Chirantan Ekbote
3e8d52b802 vhost: Don't require GuestMemory in ::new()
GuestMemory is only needed for the set_mem_table and set_vring_addr
methods so take it in as a parameter there rather than storing it in the
struct.  Vhost-user devices don't have access to GuestMemory when the
vhost device is first constructed.

BUG=b:179756331
TEST=unit tests

Change-Id: Id446db43777c26b0dfbe8b37366f2da93de53b23
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3153211
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-09-17 12:21:30 +00:00
Daniel Verkamp
eb1640e301 disk: limit maximum nesting depth
Impose a limit on the maximum nesting of file formats that can open more
files. For example, a qcow2 file can have a backing file, which could be
another qcow2 file with a backing file (or even the same file as the
original), potentially causing unbounded recursion.

BUG=b:198326611
TEST=cros_fuzz

Change-Id: I2f8573a7c71c6d8b310f2c2a75a240f2f8f0c9b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3146214
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-09-17 02:55:04 +00:00
Federico 'Morg' Pareschi
a1184822c7 Add vhost-user-fs device
This CL adds a vhost user FS device to crosvm. The implementation
requires the following arguments:

--socket = a path to a unix socket crosvm is going to connect to
--tag = a virtio fs tag to mount within the VM
--shared-dir = path to the shared directory

Optional arguments are:
--uid-map = UID translation from inside the VM to the outside
--gid-map = GID translation from inside the VM to the outside

Example command:
crosvm device fs --socket $HOME/test --tag fs-tag --shared-dir $DIR
crosvm run --vhost-user-fs=$HOME/test:fs-tag ...

BUG=b:179636297
TEST=launch fs device and verified that mounted directory works

Change-Id: Icab9e4be65092ef817006408b50bb3bf35033c62
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3062161
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Morg <morg@chromium.org>
Commit-Queue: Morg <morg@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-09-15 02:06:49 +00:00
Woody Chow
0b2b606c93 Add capture, client_type and socket_type options to cras snd device
They are needed to run virtio-snd with concierge

BUG=b:198730031
TEST=vm.Audio.virtio_cras_snd (https://crrev.com/c/3119399)

Cq-Depend: chromium:3141054
Cq-Depend: chromium:3143588
Change-Id: I9a53afe527a4533c0fa4ce54040d7c48651bc599
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3141086
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Woody Chow <woodychow@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2021-09-14 08:49:37 +00:00
Woody Chow
b27dea4c36 Add socket_type to AC97Parameters
to allow testing ac97 with raw crosvm

BUG=b:195267672
TEST=Unit test, CQ

Change-Id: I49e2eefba76a5c3e9e1c6c213a00904162bcee08
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3146700
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Woody Chow <woodychow@google.com>
2021-09-14 08:45:10 +00:00
Chirantan Ekbote
7822529aad Add vhost-user-gpu-device
BUG=b:179755651
TEST=`glxinfo -B | grep virgl` inside a crostini vm

Cq-Depend: chromium:2988140
Change-Id: Ib4102e887650b9dda97debb4c6b4737f0b0a642f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987594
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-09-09 08:26:47 +00:00
Chirantan Ekbote
e1663eeae4 Only change uid/gid when it's not 0
Only change the device uid/gid in the sandbox when it is not 0.
Otherwise, running crosvm as root makes minijail complain:

   libminijail[16370]: useless change to uid 0

BUG=none
TEST=run crosvm as root

Change-Id: Ida4b0e772ed000d3e42f77012af9d2505f64d92a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3141297
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Fergus Dall <sidereal@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-09-03 22:08:16 +00:00
Daniel Verkamp
3eeaf6a339 linux: fill pmem alignment area with anon map
Rather than mapping past the end of the file when using a pmem backing
file that is not 2 MiB aligned, use an anonymous mapping to fill the
remaining part of the arena.

This partially reverts https://crrev.com/c/2153103 while keeping the
effective change: the anonymous mapping used to fill the padding is now
added with the same protection as the file mapping.

Also handle images that are not a multiple of the page size (typically
4096 bytes) - the memory mapping on the host will handle zero-filling
reads and discarding writes past the end of the mapped file as long as
we map a size containing the partial last page.

BUG=chromium:1244217
TEST=Boot crosvm with non-2MB aligned pmem disk; read the last few bytes
TEST=./test_all

Change-Id: Ibe8da170175bb9befce924122b912a28a6dc0e7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3131444
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-09-03 20:00:13 +00:00
Ryo Hashimoto
6d9243865b fs: Support setting quota project ID
A new command line parameter to specify privileged UIDs.
If the requester UID is privileged, PassthroughFs uses D-Bus to set
quota project ID.

BUG=b:190791826
TEST=build

Cq-Depend: chromium:3129049,chromium:3129048
Change-Id: Ie27f200e8c651be6a5503f69e7b784c5e8f968ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3014623
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-09-03 00:47:25 +00:00
Woody Chow
737ff125ca Add virtio-snd device with CRAS backend
Enable with `--cras-snd`.

Verified:
Basic playback and capture

Missing features:
* Getting chmap/jack/stream info from CRAS. They are hardcoded for now.
* Jack connect/disconnect notifications from CRAS
* Reporting latency bytes to the driver. It is currently hardcoded to 0.

BUG=b:179757101
TEST=`aplay` and `arecord` inside a debian img with a 5.10 kernel built
     with virtio snd support. Launched with crosvm on rammus/kukui/hatch

Change-Id: I240000a92418b75b3eb8dcd241ff320214b68739
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2777991
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Woody Chow <woodychow@google.com>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2021-09-02 04:29:55 +00:00
Fergus Dall
51200519a2 Don't rely on being able to look up users/groups
Some devices need to have their current uid mapped in their sandbox
for bind mounts to work as expected. Currently crosvm looks up the
uid/gid for "crosvm" and maps that.

This logic is dubious anyway, since crosvm should be using whatever
user/group it was started under rather then trying to switch (which is
a priviliged operation), but putting concierge in a user namespace
breaks it entierly because the crosvm user gets remapped to a
different numeric value.

Replace the current approach with mapping the current euid/egid,
whatever it may be.

BUG=chromium:1240116
TEST=Manually tested

Change-Id: I0e9b95ed04834da1adedb72bee52ac4359f06041
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105907
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Allen Webb <allenwebb@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-27 17:57:57 +00:00
Daniel Verkamp
cfe494661d linux.rs: add clippy allow for manual_map
This only triggers when the powerd support is compiled out, so just
ignore it.

While we're here, fix the name of the power-monitor-powerd feature in
the line just below (drop the extra "d"); it would always apply, since
the feature name was misspelled.

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

Change-Id: I1b8ef3732c3d5968a9e230216f8f727bd1445609
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108612
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
2021-08-25 23:02:26 +00:00
Daniel Verkamp
5e9959e8f5 main: replace assert_eq!(..., true/false) with assert!()
BUG=b:197251702
TEST=bin/clippy # with rust-toolchain = 1.54.0

Change-Id: I80b8a5e4a90f2d6aefafd3d0d4b64b6751163b25
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108611
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
2021-08-25 23:02:25 +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
e19ab750bc devices:vfio-pci: Assign vfio-pci device pci address
For vfio-pci devices created during vm setup period, they have the same pci
address as host.

For hotplug in vfio-pci device, caller should assigh the bus number,
so it could be associated with a pcie root port or pcie downstream port, but
devfn should be 0, as pcie root port driver scan it children device at devfn=0.

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

Change-Id: Ia314cb74b15de374de540e440a91374a6538af54
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955568
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-24 00:56:32 +00:00
Xiong Zhang
262e618b04 devices:pcie: Add and emulate pcie root port
Pcie root port implements pcie cap register, but it is wrapped as a pci
bridge to VM, the pci bridge implements PciDevice trait.

BUG=b:185084350
TEST=Boot a guest with pcie root port and check its status

Change-Id: I739e878846f4b35d58e4d213caafe30196a27ccb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2954676
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-24 00:56:30 +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
ee4b58ef42 main: Add 'device' subcommand for vhost-user devices
BUG=b:195495971
TEST=Run `crosvm device block <options>`

Change-Id: I93c9a4f9bef895edecc850e59cda155e10b6a444
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3070724
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-18 16:44:28 +00:00
Keiichi Watanabe
fb36e0cfa4 devices: virtio: Rename vhost::user module to vhost::user::vmm
Rename `devices::virtio::vhost::user` to
`devices::virtio::vhost::user::vmm` so that we'll be able to put
device-side code in the same module later.

BUG=b:195495971
TEST=cargo test

Change-Id: Ice039125bcba61555c7a58fa0ca46aaa643ee605
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3096440
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:24 +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
9568bb44b8 main: Add make_rt's usage
BUG=b:142777321
TEST=cargo check

Change-Id: I22b8f90d681961466e6e0c925a0d193809661e36
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3096437
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:21 +00:00