Commit graph

2751 commits

Author SHA1 Message Date
Keiichi Watanabe
91019884bb sys_util: Replace unsafe use of iovecs
`sys_util::recv_iovecs_with_fds` was implemented as a safe function, but
it was actually unsafe because it assumed that the caller would give a
slice of `libc::iovec` where each `iov_base` points a valid memory
region with `iov_len`.

To make the function truly safe, it should take a slice of IoSliceMut
instead.

BUG=none
TEST=cargo test in sys_util/vmm_vhost
TEST=vhost-user block still works

Change-Id: I45458ee4545af13ce7e0955fb67b3703b147e7df
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288733
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-26 14:28:28 +00:00
Chirantan Ekbote
2533dd15bf fuse: Set max_pages in InitOut
This field acts as a global upper bound on the size of any request so
read and write requests are truncated to fit this size even if
`max_readahead` and `max_write` are set to larger values.  Initialize
this field to the number of pages needed to fit the largest supported
requset size.

BUG=none
TEST=arc.PlayStore.vm

Change-Id: Ia82d3e5709971c642312c45b26c288a953dedb18
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3299973
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-11-25 03:56:08 +00:00
Keiichi Watanabe
af095c0fe4 tools: clippy: Enable --all-features
BUG=none
TEST=./tools/clippy

Change-Id: Ibf673de1a76e529fc350999531d7a198a318be2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3295302
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-25 03:15:49 +00:00
Daniel Verkamp
869411ddd1 devices: vhost-user: create executor inside Worker::run()
This is repeated for each Worker struct creation, so deduplicate it
inside of the run function.

BUG=None
TEST=tools/presubmit --quick

Change-Id: If96ed9cf04f3a57070dfa6018678d5cda51db7f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3299122
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-24 21:45:35 +00:00
Daniel Verkamp
d78d1e48e9 devices: refer to vmm_vhost via path dependency
Remove the crates.io patch from the top-level Cargo.toml and make
devices point to the third_party/vmm_vhost location directly, since
vmm_vhost has been forked in crosvm and cannot be replaced by the
crates.io version anymore.

Incidentally fixes this warning from cargo:

  warning: patch for `vmm_vhost` uses the features mechanism.
  default-features and features will not take effect because the
  patch dependency does not support this mechanism

BUG=b:205511695
TEST=cargo build
TEST=tools/presubmit --quick

Change-Id: Id29578b57f7540805cf85a3db9a09542b7b84825
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3299125
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-11-24 19:12:47 +00:00
Junichi Uekawa
67e9fe7372 crosvm: Document the pupr process.
'pupr' and 'uprev' are terms that we use quite often, add some documentation.

BUG=None
TEST=read it.

Change-Id: I888d024b0cffabd43beadce0d76a1cc3644a39e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3292385
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-24 06:37:00 +00:00
Xiong Zhang
ffe10b7909 Mmap: Ignore MADV_DONTDUMP warn message
Some devices file like /dev/mem and vfio don't support MADV_DONTDUMP,
in order to avoid the warn flood, this commit ignore the MADV_DONTDUMP result.

BUG=b:19935428
TEST=boot manatee image with platform devices enabled

Change-Id: I779188cf768b4c3e8444781932260ef4bce36029
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3259932
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2021-11-23 20:16:55 +00:00
Xiong Zhang
46471a03e1 Devices: Use mmap for direct mmio r/w
write_all_at()/read_exact_at() fail to access pmc_mux through /dev/mem.
while devmem2 tool success to access them through /dev/mem, so this
commit reference devmem2 implementation and use mmap to access direct
mmio.

BUG=b:199354528
TEST=Apply https://chromium-review.googlesource.com/c/chromiumos/platform/initramfs/+/3194150
, then verify platform device (like typec) function in ManaTEE CrOS

Change-Id: Id69c44444e2dc1ef6d40cb7b36febda38848d4f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3259931
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-23 20:16:54 +00:00
Xiong Zhang
db749f37d6 vfio-pci: Emulate msix mask all bit
msix vector table is stored in mmio, its contents is saved and restored by pci bus
dirver during device PM. With vfio-pci device, msix is virtualized and guest pci
bus driver could maintain virtualized msix vector table. But vfio-pci device maybe
poweroff and the physical msix vector table will be lost, crosvm couldn't maintain
physical msix vector table during vfio-pci device suspend and resume.

kernel vfio-pci set msix message for each enabled vector which is specified in
VFIO_DEVICE_SET_IRQS() ioctl, this commit use this to restore physical msix vector
table during vfio-pci device's resume.

__pci_restore_msix_state() is called during device resume, this function set enable
and maskall bit first, then restore msix vetor table, finally set enable bit and
clear maskall bit.

so when enable and maskall bit is set, virtualized msix could be disabled. When enable
is set and maskall is cleared, vituallized msix will be enabled through
VFIO_DEVICE_SET_IRQS() ioctl, and kernel restores vfio-pci device's physical msix table.

BUG=b:185084350
TEST=verify vfio-pci device's suspend and resume function in vm, this device should have
msix capability like TBT controller.

Change-Id: I0a9e91874a9d1ec4b0bb9ff655b83a293daa6865
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3291758
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-23 19:10:13 +00:00
Christian Blichmann
1a2cfa90c3 dev_container: Improve support for podman
Commit 95b80d1 made the dev container persistent between invocations,
but hard-coded `docker` again. This change fixes that and also adds
further improvements:
- Do not use `--privileged` with podman. If the rootless user has
  permissions to access `/dev/kvm`, so will the container.
- Map `/dev/vhost-net` and `/dev/vhost-vsock` as well.
- Use `BASH_SOURCE` to find this script's directory. As we're using Bash
  to start with, this is more robust than using plain `$0`.

BUG=None
TEST=Run `./tools/dev_container cargo build` with Podman and Docker

Change-Id: I05c699f327c8e1c4f3c4df9679ee92bf7e609e2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3295372
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Christian Blichmann <cblichmann@google.com>
2021-11-23 08:41:17 +00:00
Xiong Zhang
2d45b91e00 resources: Release pci slot when vfio pci device is removed
Each vfio pci device has a pci address, in order to support vfio
pci device hotplug repeatedly, its pci address should be returned
to system, so it could be hotplug in the next time.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio pci device repeatedly

Change-Id: I0daf5bae9695c4ac87ac09581b80b69048538c0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955578
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:15 +00:00
Xiong Zhang
48937f791d devices:pcie: Remove downstream device when guest poweroff root port
When guest poweroff root port, its downstream device could be destroyed
safely, so put the downstream device into
PciDevice->get_removed_children_devices(), then the downstream device
will be removed by pci root.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio pci device repeatedly

Change-Id: Icb8104a2417832864d8dbe4947895028dabb46d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955577
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:15 +00:00
Xiong Zhang
55d5cfb659 devices:pci: Destroy the children devices at specific config write
When PCIE root port receives poweroff config register write, its
downstream devices could be removed. So get_removed_children_devices()
in PciDevice trait is used to get removed downstream children devices
pci address, then these children devices will be destroyed by pci root.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio device repeatedly

Change-Id: Iea861459b3cbabd7a9daf639ed4b7ad181a81e01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955576
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:14 +00:00
Xiong Zhang
4d3dfc9e44 devices:pci: Add destroy_device() into BusDevice and PciDevice trait
When vfio-pci device is hotplug out from guest machine, guest will
write some registers to notify the device could be removed from
crosvm, then destroy_device() is used to destroy vfio pci device
from pci_root.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio device repeatedly

Change-Id: I40f72aeb2c12d885f5cf5c8189238bd1cea0c1e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955575
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:13 +00:00
Xiong Zhang
22dc9f80c4 devices:vfio-pci: Add close() for vfio pci device
When vfio pci device is hotplug out from the guest machine, vfio device's
resource should be returned to system, so vfio pci device's close() is
needed.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio pci device repeatedly

Change-Id: I4686d737e93ae6db6078851e2add3275b9faaa84
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955574
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:12 +00:00
Xiong Zhang
436fa1b807 devices:vfio: Delete vfio group from kvm vfio device at group destroy
When vfio group is opened at the first time, group is added into
kvm vfio device. In order to support vfio device hotplug repeatedly,
vfio group should be deleted from kvm vfio device when group is
closed.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio device repeatedly

Change-Id: I4a8a18a6a890846f514df12b48a7440786e4e74c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955573
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:11 +00:00
Xiong Zhang
5865a65180 devices:vfio: Remove vfio group when vfio device is closed
One container could contains multi groups, one group could contains
multi devices, when all the devices in the group are closed, the
group itself should be removed also.

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

Change-Id: Ia43da3e2e9ad58d0a7596141645926931c0bcc5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955572
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:10 +00:00
Xiong Zhang
3897cd0a2c devices:vfio-pci: Handle vfio pci device bar reallocation
Vfio pci device's bar are mapped into ept and iommu page table for
hardware acceleration, when vfio pci device is hotplug in the guest,
guest kernel will reallocate the bar, so the old bar address should
be deleted from ept and iommu, and the new bar address should be
added.

BUG=b:185084350
TEST=Boot a vm and hotplug add a device

Change-Id: Icc489917f4c241180bbef412a17917b34fafe7e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955571
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:09 +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
Xiong Zhang
f67785e9e4 devices:pcie: Specify Bus number at pci bridge creation
When pci bridige is created, caller should specify its primary bus
number and secondary bus number. And supposing kernel won't modify
them as the current pci device topology is simple enough, once
guest modify them, warn message will be printed.

The secondary bus number shouldn't be assigned to any other device,
so this patch loop the bus number to find a free bus number.

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

Change-Id: Iae72a0e0401a6e75c62582456b92792a1a36211a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955569
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:07 +00:00
Dennis Kempin
89ea04b4da ./tools/presubmit: Parallel execution and use dev container
The updated presubmit script allows parallel execution of checks
with --tmux.

It will also try to detect if the host is set up for aarch64 builds
and use the dev container if needed.

BUG=None
TEST=./tools/presubmit --tmux

Change-Id: I0247c39d826ee38d5f7f689de5e63380fe789cf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3292101
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-19 20:09:40 +00:00
Dennis Kempin
95b80d13b2 dev_container: Preserve container between calls
This vastly improves iterative build times and enables more flexible
usage of the container.

BUG=None
TEST=./tools/dev_container cargo build
First run will build everything. Second run will finish right away.

Change-Id: I9b4eeee0689f0e9d07f0a32f846d21ab42f689f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3292100
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2021-11-19 20:09:39 +00:00
Dennis Kempin
d012f3ddcf test_runner Use workspace for building and testing
Instead of enumerating crosvm crates separately, we can now use
the workspace to build all tests for crosvm.

This enables the vmm_vhost tests.

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

Change-Id: I2af84ad8111e874ddea5e438bda41599caf1fd30
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3287463
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-19 20:09:38 +00:00
Jordan R Abrahams
ff7f1ae9fe seccomp: Add statx to video_device.policy for glibc
With the new glibc 2.33 roll, we're seeing crashes live relating to
statx (syscall 397). The process that's crashing is pcivirtio-video,
so we suspect video_device.policy is the breaking policy.

Crash report: http://shortn/_4EWpF4q77O

This was very recently fixed in arm (where the original crash occured),
however, it's still missing in the amd64/x86_64 policy file. It's
very feasible we'll see a similar case in the future with this arch.

BUG=b:187795909
TEST=CQ

Change-Id: I7b02ccf02d214590aadc37dc53e00ad34e178a4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3291890
Auto-Submit: Jordan R Abrahams <ajordanr@google.com>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2021-11-19 04:18:27 +00:00
Christian Blichmann
50f9591b6a devices: vhost: Allow vhost-vsock fd from command-line
Passing an open FD is necessary to avoid racing for vsock context IDs:
On Borg, we first want to generate a random, unused CID and pass this to
crosvm. This requires us to open `/dev/vhost-vsock` and call the
`VHOST_VSOCK_SET_GUEST_CID` ioctl on it. Closing the device and simply
assing its path to crovm opens up a time window where an overlapping VM
creation request may set a different CID on the device.

BUG=none
TEST=tools/presubmit --quick

Change-Id: If053e26ba93ab357b06e8cf07798679c8ad06c9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3263933
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Christian Blichmann <cblichmann@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-18 15:19:29 +00:00
Keiichi Watanabe
6f5193e2cb devices: vfio: Use DataInit for {read, write}_config()
BUG=none
TEST=build

Change-Id: I23d00352dbeb82f6a4356f038942b66dce9b22f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3245355
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-18 15:11:11 +00:00
Pierre-Clément Tosi
6e2d770d91 crosvm: arm64: Pass pVM image size through x2
Extend the ABI in protected mode to provide the protected VM firmware
with the size of the loaded image by using register x2.

BUG=b:203505371
TEST=presubmit

Change-Id: Ib01b88dcce2f3fbfba759599d7fce9de62de720c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3259937
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-18 11:34:24 +00:00
Pierre-Clément Tosi
ab8889c2f0 crosvm: arm64: Move image loading code in lib.rs
Move the block handling image loading above the code initializing vCPUs
to make an upcoming patch clearer: no functional change intended.

BUG=b:203505371
TEST=presubmit

Change-Id: Ie215a58de942dd5eceff5df46016bd17fafcf5ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3259936
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-18 11:34:23 +00:00
Lepton Wu
fbb368a9f7 seccomp: Allow statx for video device on arm
I guess this was caused by libc uprev so the actual used
system call changed.

BUG=b:206348631
TEST=manual - Run arc.Boot.vm on kukui-arc-r with updated policy

Change-Id: Ibb8702d9ec6844624c9779088aefcdad34322d80
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3290581
Auto-Submit: Lepton Wu <lepton@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-18 08:50:57 +00:00
Keiichi Watanabe
5c62c01a3f vm_memory: Allow File-backing MemoryRegion
In addition to SharedMemory, we allow File (e.g. mmap'd file) to be an
backing object of MemoryRegion.

BUG=b:194137301
TEST=kokoro

Change-Id: I9dafd028eaf74cf34820ba3f16e458c08ec67cb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3159883
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-18 08:45:19 +00:00
Keiichi Watanabe
961743f797 devices: ac97: Create SharedMemory from GuestMemory's descriptor
This is a preparation for CL:3159883, where GuestMemory will be backed
by `dyn AsRawDescriptor` instead of `SharedMemory`.
So this CL adds a logic to create a SharedMemory from `&dyn
AsRawDescriptor`.

BUG=b:194137301
TEST=cargo test --all-features in audio_streams

Change-Id: I615be5976184696bcb9ae90928e366276467013a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3159882
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2021-11-18 08:45:17 +00:00
Keiichi Watanabe
3893a1dcbe audio_streams: Introduce SharedMemory trait for base::SharedMemory
Define `SharedMemory` trait, implement it for `base::SharedMemory`, and
use it for `ShmStreamSource::new_stream()` so that we can pass on
`base::SharedMemory` without exposing `base` to libcras.

Note that we implement the trait for `base::SharedMemory` in `base`
crate instead of in `audio_streams`, which means `base` depends on
`audio_streams`, because `audio_streams` is available for non-crosvm
projects while `base` isn't.

The corresponding CRAS change is crrev.com/c/3251123.

BUG=b:194137301, b:204444445
TEST=cargo test --all-features

Change-Id: I2430d9881d98032592c9f9202d70deb22e006f63
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3251820
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-18 08:45:14 +00:00
Daniel Verkamp
e5ada8f4a1 third_party/minijail: update to latest ToT
This matches the crosvm submodule to the version currently used in
Chrome OS: https://crrev.com/c/3230048

BUG=None
TEST=cargo build
TEST=tools/presubmit --quick

Change-Id: I7fadc5b1a4ecc26bd0598642966e088f1890a0d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3290322
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-18 08:44:34 +00:00
Keiichi Watanabe
74bfcdba28 vhost_user: Fix cfg for take_single_file
BUG=none
TEST=cargo test --all-features
TEST=cargo test --features=vhost-user passed with no warnings

Change-Id: I98e69309c6ec81ede3e790c9b6b8b79991484cc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288732
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-18 07:57:32 +00:00
Tinghao Zhang
f5a3037eec devices: vfio: Add device label to error messages
Add device label to vfio related error messages to get device name when
debugging

BUG=None
TEST=./tools/run_tests
TEST=./tools/presubmit

Change-Id: I910cbe35dde2d88155f693f90225a2708663d75d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288284
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-11-17 23:16:26 +00:00
Daniel Verkamp
f3df5127f3 third_party/vmm_vhost: switch to our vm_memory crate
This won't actually build as-is if the vhost-kern feature was enabled,
but since we don't use that feature currently, this unblocks building
crosvm without the rust-vmm vm-memory crate.

BUG=b:205511695
TEST=emerge-hatch -C vm-memory && emerge-hatch crosvm

Change-Id: I614616b38e796e28f13f0bb867e97c3be532305b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3290311
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-11-17 23:01:34 +00:00
Keiichi Watanabe
9e37f05611 devices: vfio: Abort if reading/writing VFIO region fails
Cause panic when it failed to read or write VFIO regions because there
are no ways of recovery.

BUG=b:194137301
TEST=build

Change-Id: I0f6296d1835443641a12d5608b774ec35fdea7e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3149872
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-17 22:56:15 +00:00
Dennis Kempin
a1e42f07ea Enable clippy on more workspace crates
As before, some are automatically fixed by clippy, some manually
fixed.

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

Change-Id: Ifcab4cf60775ee6bb7d4530af6406a74958432ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3283683
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-15 23:55:42 +00:00
Dennis Kempin
dc629f5f05 Clippy fixes in common/* crates
Some automatic fixes by clippy, some manual nit fixes.

This enables clippy on all but the cros_async crate, which
is to be replaced with cros_async2 soon.

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

Change-Id: I2b3a09b67ead64f2adb71dd4f94465b0d65a7c65
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3282678
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-15 23:08:55 +00:00
Haiwei Li
e892738ed6 devices: vfio: Fix overlapping only if pba offset is greater than table offset
This fixes a bug introduced by [1] when msix pba table offset is smaller than
msix table offset.

An error may occure when booting guest with some vfio devices:

[ERROR:src/panic_hook.rs:90] thread 'main' panicked at 'attempt to subtract with overflow', devices/src/pci/vfio_pci.rs:274:26

[1] 7458a3a19b

So limit the adjustment of table size only if pba table offset is greater than
table offset.

BUG=b:1971693450
TEST=passthrough a nvme which the msix table offset is greater than pba
table offset, boot and verify MSIX-capable passed-through devices work
properly.

Change-Id: I1432c2290feaa5f6db088ebd416dc346547e7952
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3279957
Reviewed-by: Tina Zhang <tina.zhang@intel.corp-partner.google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-11-15 21:29:24 +00:00
Daniel Verkamp
c13c0c210b enumn: switch to upstream crates.io version
Developers may need to manually clean up the common/enumn directory - it
will be left behind if there are build artifacts (Cargo.lock, target
directory, etc.):

  rm -rf common/enumn

BUG=b:205344148
TEST=cargo build
TEST=tools/presubmit
TEST=emerge-hatch crosvm # with https://crrev.com/c/3265967

Change-Id: I1af3bdd22f40e87895a78a5cbc8033476058c927
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3278774
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-11-15 21:03:25 +00:00
Keiichi Watanabe
eef484c20a tools: chromeos: Use relative path to Cargo.toml in setup_cargo
This change will allow the script to be executed from any path.

BUG=none
TEST=run tools/chromeos/setup_cargo from outside of crosvm directory

Change-Id: I9752f4a41987259f446431bf89c322095ef26e63
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3280361
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-15 18:18:18 +00:00
Dennis Kempin
c3dedf3cc1 cleanup: Fix previously disabled clippy checks
There were not too many cases here. This fixes:

- comparison_chain
- wrong_self_convention
- upper_case_acronyms
- from_over_into
- let-and-return

The collapsible_if check is moved to the permanently
allowed checks. The cases we do have improve
readability or semantics.

BUG=chromium:908640
TEST=Kokoro

Change-Id: I6e905d08e2a87aa0862d4d1cf5ff57b60e95fa7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3278776
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-12 23:23:48 +00:00
Daniel Verkamp
18027ee80a rutabaga_gfx: silence warnings when not building virgl_renderer
Sprinkle cfg checks throughout build.rs to get rid of the compiler
warnings about unused functions when building with the default features
(without --features=virgl_renderer).

BUG=None
TEST=cargo build
TEST=cargo build --features=virgl_renderer

Change-Id: I2a1548ec0de33d958c5cd5b6658ec92cd6840566
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3243013
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-11-12 21:44:18 +00:00
Dennis Kempin
3a6b7f11ce tools/clippy: Move allow-list to .cargo/config.toml
This applies the same clippy config to rust_analyzer
as well.

BUG=b:193893457
TEST=./tools/clippy and VSCode show the same linter results

Change-Id: I5deec4a24d71fec4692ed708664130f46c1311b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3278773
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-11-12 20:55:25 +00:00
Chirantan Ekbote
13f5e9b983 fs: Use openat64 instead of openat
This ensures that we can open files whose sizes may be larger than a
32-bit off_t.

BUG=b:181113648
TEST=emerge-kukui crosvm

Change-Id: I2322480dcf507f83609117b4def40846d619b69b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3270100
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-12 01:11:19 +00:00
Chirantan Ekbote
55bf685478 aarch64: Fix UB in offset__of
This currently gives a compiler warning:

warning: dereferencing a null pointer
   --> aarch64/src/lib.rs:71:19
    |
71  |         unsafe { &(*(0 as *const $str))$(.$field)*  $([$idx])* as *const _ as usize }
    |                   ^^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
...
622 |                 arm64_core_reg!(pc)
    |                 ------------------- in this macro invocation
    |
    = note: this warning originates in the macro `offset__of` (in Nightly builds, run with -Z macro-backtrace for more info)

Fix the UB with an implementation based on memoffset::offset_of and
addr_of_mut! instead.

BUG=none
TEST=`emerge-kukui crosvm` no longer complains about UB

Change-Id: I0ab55dc7527c3a4acffe02ee587742dbddd45a0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3270099
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-11-12 01:10:51 +00:00
Dennis Kempin
10e79005c3 tools: Update clippy and fmt to make use of workspace
We have not been running clippy on many crates before. This CL
does not contain any clippy fixes, but documents how many issues
each disabled clippy check and crate currently has.

Many of them should be easy to fix.

BUG=b:192425184
TEST=./tools/presubmit --quick

Change-Id: I9ea25bc9a24d405700027ca4e72fb2a50e376c9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3276668
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-11-11 23:52:43 +00:00
Daniel Verkamp
f20c1cd1e8 wl: update seccomp policies for SYNC_IOC_FILE_INFO on arm
Fixes https://crrev.com/c/3199298, which only added the new ioctl
argument to the seccomp syscall filters on x86.

BUG=b:169908659
TEST=tast.crostini.SecureCopyPaste.* on scarlet

Change-Id: Ifd44c7b403f862d5528d8cc3655f0cd2c71c6e13
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3276675
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
2021-11-11 19:31:37 +00:00
Dennis Kempin
c8313dc204 crosvm: Use local vmm_vhost when compiling for ebuild
This should fix the current uprev problem.

BUG=b:205997217
TEST=FEATURES=test emerge-amd64-generic crosvm

Change-Id: I0a0bb46fb004a7a057be9b2e4b13878038551e81
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3276714
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-11-11 19:08:32 +00:00