Commit graph

2780 commits

Author SHA1 Message Date
Abhishek Bhardwaj
693396eb41 vhost_user: Expose members to be used by crosvm VVU proxy device
This change exposes members from the vhost_user implementation to be
used by the crosvm virtio-vhost-user proxy device.

BUG=b:194136484
TEST=Compile.

Change-Id: Ib2748f4e19138e08baaa6b2e8ae45f1b44c42cb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3285627
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-12-02 05:52:11 +00:00
Alexandre Courbot
307168a1eb virtio: video: fix decoder backend documentation
Fix a few references to obsolete parameter names and rephrase a few
ambiguous statements.

BUG=b:161774071
TEST=cargo build --features="video-decoder"

Change-Id: I583206502ddccadd00dfa7e5d8125a4ab0aa1c42
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3308314
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-12-02 03:35:37 +00:00
Alexandre Courbot
c02960d6b2 virtio: video: make libvda a selectable feature
For the crosvm externalization project, we want to be able to compile
video support without libvda, which is only supported on Chrome OS.

Add an explicit "libvda" feature to crosvm and make all the libvda code
depend on that feature, so any trace of libvda can effectively be
compiled out.

For compatibility, the "libvda" feature is selected by the
"video-decoder" or "video-encoder" features.

BUG=b:161774071
BUG=b:169295147
TEST=`cargo build --features="video-decoder,video-encoder"` results in a
     crosvm binary with libvda enabled.

Change-Id: Ice3d3089b73b77f6b009400953063f2cf8f385da
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026351
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-12-02 02:19:34 +00:00
A. Cody Schuffelen
eae320e85b Only create the virtio-console read thread once
The virtio-console device implementation was losing track of the host
input stream when it reset. This change only creates the read thread
once and reuses it for all worker threads.

Test: Run with a virtio-console device that resets
Bug: b/208540565
Change-Id: I6abcd35a7e7664f2bbdc0d977c2eacad49e50378
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3309208
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2021-12-02 01:52:00 +00:00
A. Cody Schuffelen
e86184d692 Keep track of the host output side on virtio-console reset
The previous implementation would lose track of the host output
io::Write stream on receiving a virtio reset request, due to how the
output instance was being passed around through Option instances.

This change replaces one level of Option state with a reference instead,
so the Console instance retains ownership over the output instance and
the virtio-console Worker instance only holds a mutable reference.

Test: Run with a virtio-console device that receives a virtio reset
Bug: b/208540565
Change-Id: Ib672ac244a7209797e1d64feca913b12f31a66d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3309207
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2021-12-02 01:51:59 +00:00
Gurchetan Singh
7d5f0fef45 devices: gpu: update protocols
- F_CONTEXT_INIT is in Linux 5.16 now
- F_RESOURCE_SYNC should come before other features now.

BUG=b:208516032
TEST=compile

Change-Id: I8dfed584b544d6140ba80c2d474dedfcb679417e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3309197
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2021-12-01 19:34:00 +00:00
Dapeng Mi
6087a79074 Devices: vfio: Fix the PCIe BAR region mmap issue
Intel SSD 660P Series NVME block device has an overlapping msix
table and msix pba table as the following information shows.

ab:00.0 Non-Volatile memory controller: Intel Corporation SSD 660P Series (rev 03)
Capabilities: [b0] MSI-X: Enable- Count=22 Masked-
                Vector table: BAR=0 offset=00002000
                PBA: BAR=0 offset=00002100

In curruent add_bar_mmap_msix function, these two table would occupy
the same page. So when add_bar_mmap_msix trys to find the msix table
corresponding pages for the second time, it fails to find the page and
lead to the entire mmaps are cleared and return null mmaps. Thus, there
is no real memory region are mmaped and lead to quite low I/O performance
for this pass-through NVME disk.

BUG=None
TEST=Unit test
TEST=pass-through the 660P SSD into guest and run FIO read/write test,
the throught increases to ~500MBps form ~20MBps.

Change-Id: I1571e694b0a1f01a738650b361eaef93554a8c55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3213315
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-12-01 18:25:26 +00:00
Tina Zhang
e2a3e29ec6 devices: virtio: iommu: add default value to page_size_mask
Virtio-iommu might be created without any endpoints. In this case, we
need to assume a default page_size_mask default value. 4K is a
reasonable value to devices.

BUG=b:185084350
TEST=Boot a guest with a pass-through device which has the "iommu=on"

Change-Id: I29344f8ef52e3358198dd5a917083244310ffaaa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3297406
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-12-01 17:38:51 +00:00
Tina Zhang
03196819bb devices: vfio: Remove vfio-mapping for their bars' memory
Pass-through PCI devices don't need vfio to do the iova mapping for
their bars' memory, because when accessing their bars' memory,
pass-through PCI devices' DMA requests don't travel to RC. Therefore,
keeping the mapping relationship is useless.

BUG=b:185084350
TEST=Boot a guest with a pass-through device

Change-Id: I7944183553518437d03bdfcfebf3790268bbd9e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3284012
Reviewed-by: Xiong Y Zhang <xiong.y.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-12-01 17:38:50 +00:00
Keiichi Watanabe
b3f4433512 vmm_vhost: Rename features to "vmm" and "device"
Rename feature names:
* vhost-user-master -> vmm
* vhost-user-slave -> devicwe

BUG=b:206900656
TEST=kokoro

Change-Id: I84b627b757421a2ea9f56018ad44e227df20ab8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3295220
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-01 09:45:48 +00:00
Keiichi Watanabe
40327e983a vmm_vhost: Simplify a match for error conversion
BUG=none
TEST=cargo test --all-features

Change-Id: Iec4d46b3d715c1c57a899a8c41df84d6a72e1b41
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3302695
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-01 09:45:47 +00:00
Keiichi Watanabe
6238a54f4a vmm_vhost: Flatten vhost_user module
Since vhost_user is the only module in vmm_vhost now, remove this module
and have everything in the top-level module.

BUG=b:206900656
TEST=cargo check

Change-Id: I6663a93654e5d692efc7d9904fff0d207144c352
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3295219
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-01 09:45:46 +00:00
Keiichi Watanabe
320203dcaa vmm_vhost: Expose vhost_user::Error directly
Remove the previous vmm_vhost::Error enum, as most of its variants are
no longer used. Instead, expose vhost_user::Error as the top-level one.

BUG=b:206900656
TEST=cargo check

Change-Id: Ic5d9f7dcc6e2986d7b51885e2c0f44aa4e012e5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3295218
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-01 09:45:45 +00:00
Keiichi Watanabe
48643234da vmm_vhost: Delete vhost-kern and vhost-vsock
Since we're using vmm_vhost only for vhost-user, we can delete
vmm_vhost's vhost-kern/vhost-vsock parts.
Note that we own vhost crate, which vmm_vhost was copied from.

BUG=b:206900656
TEST=cargo test --all-features in vmm_vhost

Change-Id: I622fbb856fb99fc2cb078d79f79491fa35ede8e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3295217
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-01 09:45:44 +00:00
Keiichi Watanabe
d7db2a7fea vmm_vhost: vhost_user: Drop recv_data() from Endpoint trait
By modifying the interface of `Endpoint::recv_into_bufs()` slightly,
`Endpoint::recv_data()` can be moved to `EndpointExt` trait.
This means a new device struct will be required to implement less
methods.

BUG=none
TEST=run vhost-user block device

Change-Id: I141eed0ff91aded5df5827cbc6965905820dac2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288735
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-01 09:45:42 +00:00
Keiichi Watanabe
f7db2d5344 vmm_vhost: vhost_user: Change interface of Endpoint::recv_data
Stop returning the number of bytes along with data, as the value should
be obtained by `data.len()`.

BUG=b:204720423
TEST=cargo test --all-features

Change-Id: I0c9d143b2d9e657d61cc2469ba7270a170401b2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288734
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-01 09:45:41 +00:00
Keiichi Watanabe
580d9f90f1 vmm_vhost: Avoid unnecessary Vec allocation
BUG=none
TEST=cargo test --features=vhost-user

Change-Id: I606a69244a3922a47298e4930732f04e337e1525
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3302694
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-01 09:45:39 +00:00
Keiichi Watanabe
a6da8a5406 vmm_vhost: vhost_user: Use IoSliceMut in recv_into_bufs()
Replace `&mut [u8]` in recv_into_bufs() with IoSliceMut.
Note that recv_into_bufs_all()'s interface is unchanged as it changes
internal cursor with advance().

BUG=none
TEST=cargo test --features=vhost-user-master,vhost-user-slave

Change-Id: I74666cd2472f879a473c07dbe617add79d0ca903
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3302693
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-12-01 09:45:38 +00:00
Keiichi Watanabe
dc069ba021 vhost_user: Introduce Endpoint trait
Introduce `Endpoint` trait and add `EndpointExt` trait as its blanket
implementation.
This trait generalizes the existing socket-based endpoint struct and
allow us to add a new VFIO device backend later.

BUG=b:194137301
TEST=vhost-user block device worked

Change-Id: I9c276bbbf14570b67d3c55507054f48e1210d019
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3270299
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-12-01 09:45:37 +00:00
Daniel Verkamp
1bdfb96e2d devices: virtio: do not mutably borrow interrupt
The async interrupt resample thread borrows the interrupt object passed
to it, so borrowing mutably will fail at runtime. The two calls to
interrupt.borrow_mut() were in places that did not need a mutable
reference anyway, so just switch them to interrupt.borrow().

BUG=b:208264646
TEST=Boot crostini on kevin

Change-Id: Ie873273f862b1d4ef11b595596fea51cd202ac6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3309200
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-12-01 00:01:00 +00:00
Daniel Verkamp
1286b48670 linux: only add PCIe root port on x86
Disable the root port creation code for arm, since the required
Arch::register_pci_device() function just returns unsupported on
aarch64.

Fixes crosvm startup on arm.

BUG=b:208503471
TEST=Start crosvm on kevin

Change-Id: I690a3f163b570387a5e58294ba94e496a97da815
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3309199
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-11-30 23:56:44 +00:00
Junichi Uekawa
c14da943eb crosvm: Add a note that MemoryMapping does RAII.
BUG=None
TEST=None

Change-Id: Ie2bf320fd08ab8d52fc3071e825fec91dcb12551
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3267908
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-30 09:24:16 +00:00
Junichi Uekawa
8ed082e917 crosvm: Add link to the chromeos-base/crosvm topic.
The topic is reasonably useful to get a feel of how healthy the current
uprev process is.

BUG=None
TEST=read it.

Change-Id: I6dc329fdb7f1bbb7bea47a156cabf3eb76a3ff9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3302692
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2021-11-30 09:23:55 +00:00
Keiichi Watanabe
383dad84e0 plugin: Update use of sysutil::ScmSocket::recv_with_fd
Follow up of crrev.com/c/3288733.

BUG=none
TEST=cargo check --all-features

Change-Id: Ibd01a0e0efe20b7c6a4b5de79b1127ce7819cc9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3305952
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-30 08:41:31 +00:00
Alexandre Courbot
b42b3e52e5 virtio: video: enable runtime selection of video backend
Make the "video-decoder" and "video-encoder" capable of taking an
argument to explicitly specify which backend should be used. At the
moment there is only one backend (libvda), but this is going to change
soon and this change prepares for that.

The argument-less forms of "video-decoder" and "video-encoder" are also
kept and will select the libvda backend for compatibility.

BUG=b:161774071
BUG=b:169295147
TEST=Android Youtube plays properly on Hatch.

Change-Id: Ia2afd8932dbeabf381a3a2a81424812d50b99d50
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026350
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-11-30 03:56:35 +00:00
Dennis Kempin
b1751f360e seccomp: Allow lseek on cras_audio_device
The syscall is used for the file backed memory region used
by the audio device since https://crrev.com/c/3159883

BUG=b:208264646
TEST=CQ

Change-Id: I02c24da6389d60847996a62ee0eab658f9c4f7cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3307240
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-29 23:28:45 +00:00
Maciek Swiech
c301122d82 [crosvm] use fmt::alternate for anyhow::Error
we would like to have all anyhow::Error instances print out
their full context, thus we need to use `{:#}`

BUG=None
TEST=compiles

Change-Id: Iba3d1757e8816cb5d91aa1b9615e5660125c463e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3300823
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-11-29 22:37:13 +00:00
Daniel Verkamp
0f26a00179 devices: virtio: pmem: convert to async
Replace the event loop with an async executor.

BUG=None
TEST=run crosvm with writable pmem device and sync

Change-Id: Id8c242ff93cc0026bf002585d042f18cc66f6da3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3292634
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-29 21:02:01 +00:00
Daniel Verkamp
a3c7695e87 devices: virtio: factor out common async code
Create an async_utils module and deduplicate the common async helper
functions there.

In particular, this moves wait_kill (renamed to await_and_exit) and
handle_irq_resample into the new module and replaces all uses throughout
the async device implementations.

BUG=None
TEST=tools/presubmit --quick

Change-Id: If3b5b9f71c8553afa5ccd8c57933ca748fc990e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3292635
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-11-29 21:02:00 +00:00
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