Commit graph

2813 commits

Author SHA1 Message Date
Allen Webb
89759de1d1 sys_util: Remove extra semicolon to fix warning on nightly.
Nightly rust generates errors of the following form:
warning: trailing semicolon in macro used in expression position
   --> /home/allenwebb/external/NoBackup/chromiumos/src/platform/crosvm/common/sys_util/src/syslog.rs:193:10
    |
188 | / macro_rules! lock {
189 | |     () => {
190 | |         match lock() {
191 | |             Ok(s) => s,
192 | |             _ => return,
193 | |         };
    | |          ^
194 | |     };
195 | | }
    | |_- in this expansion of `lock!`
...
336 |       let mut state = lock!();
    |                       ------- in this macro invocation
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>

BUG=None
TEST=cargo test

Change-Id: I323d5a4d88d1e2fe4b7745d3f49adef808ee7016
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3318767
Auto-Submit: Allen Webb <allenwebb@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-12-06 23:06:23 +00:00
Dennis Kempin
0830e2f11c chromeos: Add script for merging from cros/main
This script can be used to manually create merge
commits to be uploaded to gerrit, and will also
be used by the buildes doing automatic uprevs.

The main purpose of the script is to create a helpful
commit message describing the commits included.

BUG=b:209034086
TEST=./tools/chromeos/create_merge

Change-Id: I65715ebefb182a5287b5052b6af56361e41d8efd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3315374
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-12-06 21:19:19 +00:00
Junichi Uekawa
b6a6e94382 crosvm: Allow hex values in direct-io command-line options.
The configuration file is written in hex but what is passed through in
and command-line is decimal. Usually we think in hex, allow passing hex
into the command-line options.

BUG=b:188011323
TEST=cargo test --features=direct

Change-Id: I6e3589815fdd17c8d90bac1f9064f3abd352177d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3319036
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2021-12-06 21:17:15 +00:00
Junichi Uekawa
de923289a5 crosvm: Add _ every 4 digits.
Hex memory regions usually are better expressed with 4 digits as one
compound.

BUG=b:188011323
TEST=None

Change-Id: Ic42fcbb6fd8c4ada5f0fb18c2ff41e3dbffb3408
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3312863
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-12-06 21:07:57 +00:00
Mattias Nissler
58fc0682c1 Correct subsystem_{vendor,id} mixup in StubPciDevice
BUG=None
TEST=New unit test.

Change-Id: Idfe19e5d2f1625e7c76f390928342f02f0d17cff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3308807
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-12-06 21:05:30 +00:00
Daniel Verkamp
3d0e51f71c sys_util: ignore seek_hole tests for kokoro uprev
These tests were failing when upgrading to the new Ubuntu 16.04
environment, so temporarily disable them while we diagnose the problem.

BUG=b:208901617
TEST=cargo test -p sys_util seek_ # check for "ignored"

Change-Id: Ia1152f98b0a6e88db02fb23ce8f61f663fa74ad5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3318783
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-12-06 20:53:03 +00:00
Daniel Verkamp
d572d8dda0 OWNERS: add dtor@
BUG=None
TEST=None

Change-Id: I457dcebd97a8108b448afcf0334125cc511c3202
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3315402
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-12-06 20:36:52 +00:00
Keiichi Watanabe
4b34573b46 devices: vfio: Define IommuType enum
BUG=none
TEST=build

Change-Id: Ia6de8f19cfc335a86bc5ba4d88f29e1839bd6ba7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3310340
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-12-06 14:58:11 +00:00
Keiichi Watanabe
7b80554473 devices: vfio: Add new constructor for VFIO driver
The current `VfioDevice::new()` definition is assuming that it's a VFIO
passthrough device that takes a VM guest. To reuse the `VfioDevice` for
cases other than passthrough, this CL rename that method to
`VfioDevice::passthrough()` and adds a simpler constructor.

BUG=b:194137301
TEST=build

Change-Id: I2bd420b17ed8675c1630c8fc41f47485351d8bb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3149874
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-12-06 14:58:10 +00:00
Keiichi Watanabe
9c95cd2f8a vmm_vhost: Add VFIO backend for virtio-vhost-user
BUG=b:194137301
TEST=cargo test --all-features

Change-Id: I899c579779d51b7712ce4030856dfbe683c99df2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3270300
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-06 14:23:20 +00:00
Keiichi Watanabe
91f1262bcf sys_util: sock_ctrl_msg: Use IoSlice when sending buffers
Make `send_bufs_with_fd(s)` take `IoSlice` instead of `&[u8]`.
Note that no Chrome OS-side is needed for this API change because these
methods aren't used in any other Chrome OS projects.

BUG=b:204720423
TEST=cargo test in sys_utils and vmm_vhost

Change-Id: I02701d9c4e964ea95f0746b17254fa029fee7531
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3302696
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-06 14:23:19 +00:00
Chih-Yu Huang
d2c2bd1ba3 linux: mount all possible render nodes
Originally, we only mount 1 render node "/dev/dri/renderD128".
However, the working node might not be this one. This CL mounts all
the possible render nodes.

BUG=b:202352463
BUG=b:201738023
TEST=tast run $(DUT) arc.Boot.vm and confirm all render nodes are bound

Change-Id: I10331a1fba724ae2f75a96f59b1a9931e108e213
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3317006
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2021-12-06 08:06:41 +00:00
Dmitry Torokhov
4eec83452d x86: make iterating through SDTs more Rusty
Instead of open coding a loop, use any() method to check if we have
matching entries.

BUG=None
TEST=./tools/presubmit

Change-Id: Ib1fe7e65436bc3c8cca99be69855eb0ebc3cf096
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3313842
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2021-12-06 03:29:47 +00:00
Abhishek Bhardwaj
ff0337423f crosvm: vvu: proxy: Implement notifications region read and write
This change implements read and write for notifications region in the
bar.

BUG=b:194136484
TEST=lspci in the guest and look for the proxy device.

Change-Id: I06a98e5cbabc01d8799a033cd1ad916d14de1644
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288868
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-04 03:49:26 +00:00
Daniel Verkamp
a8dc35123a x86_64: acpi: deduplicate PCI IRQs in MADT
The pci_irqs list contains an entry for each PCI device, but IRQ numbers
may be reused, so the MADT would contain duplicate interrupt override
entries in this case. This doesn't cause a problem in practice (the
duplicates are all identical and the guest kernel does not complain),
but it makes sense to remove the duplicates and only add a single
IOAPIC interrupt override entry per unique IRQ number.

BUG=b:207551552
TEST=x86_64 guest kernel only has 4 INT_SRC_OVR logs in dmesg

Change-Id: Iba4c57ca93d4be6c21e087b2f3f416fe022e8d35
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3315408
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
2021-12-04 00:18:01 +00:00
Daniel Verkamp
754068786a Revert "x86_64: remove acpi=noirq kernel option"
Basic functionality works with a purely ACPI-based boot (no MPTable),
but something is still missing in the ACPI tables for describing the
full interrupt routing configuration. The guest kernel complains:

  virtio-pci 0000:00:01.0: can't derive routing for PCI INT A
  virtio-pci 0000:00:01.0: PCI INT A: no GSI

Restore the acpi=noirq option for now until we fill out the ACPI IRQ
descriptors correctly; this was a cleanup only and not required to fix a
bug.

This reverts commit cb464a7c08.

BUG=None
TEST=Boot Crostini; no interrupt routing failures in dmesg

Change-Id: Ib73c5749b48134124b3ebcb472706f087e8a85a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3315226
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-12-04 00:16:50 +00:00
Dennis Kempin
39c2a45469 seccomp: Remove readlink from remaining aarch64 policies
Missed a couple that do not inherit from common_device.policy.

BUG=b:209021536
TEST=Cq

Change-Id: I672af4e7746bbf971193a10031f0ac27302ef3b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3314284
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
2021-12-03 22:49:04 +00:00
Abhishek Bhardwaj
362d410255 crosvm: vvu: proxy: Allocate device capabilities
This change allocates device capabilities as per the VVU proxy device
spec.

BUG=b:194136484
TEST=Compile.

Change-Id: I6f8858468466278d6ce845ce21f431222ba66557
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288867
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-03 22:06:37 +00:00
Daniel Verkamp
cb464a7c08 x86_64: remove acpi=noirq kernel option
Now that we provide a correct MADT ("APIC" table ID), there is no need
to override the kernel ACPI option that made it ignore these tables.

BUG=None
TEST=Boot crosvm with setup_mptable() call removed, ACPI only

Change-Id: I9f4589738462c5693f151f60180c79d054a9084d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3313841
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-12-03 21:25:34 +00:00
Daniel Verkamp
0708961098 x86_64: acpi: report presence of 8259 PICs
KVM's irqchip emulation provides the traditional PC-style pair of 8259
PICs, so report this by setting the appropriate flag in the MADT (APIC)
table.

BUG=b:207551552
TEST=Boot crosvm with setup_mptable() call removed

Change-Id: Ib5adf7ac717156deb3cd19d74873c9745ae826ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3313840
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
2021-12-03 21:25:33 +00:00
Daniel Verkamp
5ceeda7964 x86_64: acpi: add PCI IRQs to MADT
Add interrupt redirection entries to MADT so that the legacy pin-based
interrupts are correctly reported as level triggered. This matches the
entries in the existing MPTable, but those are not availble when booting
with OVMF, which only provides ACPI tables.

This fixes an issue where USB device sharing was failing in some cases
when booted with ACPI only, since our xhci controller emulation only
supports pin-based interrupts (not MSI-X) and would not work correctly
when the guest incorrectly treated its IRQ as edge triggered.

BUG=b:207551552
TEST=Start crosvm with setup_mptable() call removed
TEST=Share USB device when booted with ACPI via OVMF

Change-Id: Id3e4ff5ba9587aadbeadbcc8eceaa771c4c2d5df
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3312577
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
2021-12-03 21:25:33 +00:00
Daniel Verkamp
ee12ec1bdf x86_64: mptable: make pci_irqs a slice instead of Vec
This function doesn't need to consume the pci_irqs vector, just iterate
over it.

BUG=None
TEST=tools/presubmit

Change-Id: Ibb66fa6ab8c45f58eeb89b976bcfc57e00d718a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3313996
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2021-12-03 21:25:32 +00:00
Dennis Kempin
e6ad05efc0 seccomp: Remove readlink from aarch64 policies
aarch64 only has the readlinkat syscall.

BUG=b:209021536
TEST=Cq

Change-Id: I0a6a76bbc388f598f639a97832269256f6e9a61e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3314710
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-12-03 19:35:07 +00:00
Xiong Zhang
5d8d238b6a vfio-pci: Don't call enable_intx if device doesn't support intx
Pci spec defines Interrupt Pin register that devices don't use an interrupt pin
must put a 0 in this register. The values 05h throgh FFh are reserved. So if
vfio-pci reads interrupt pin register and gets value like 0, 0x5~0xFF, it means
vfio pci device doesn't support legacy intx, then interrupt_evt and
interrupt_resample_evt don't need to be saved, finnaly enable_intx ioctl won't
be called into kernel vfio.

This fixes an error message during CrOS reboot, poweroff, xhci controller's
suspend and resume on Brya ManaTEE:
ERROR: vfio 0000:00:0d.0 device Intx enable failed: failed to enable vfio device's
irq: Invalid argument (os error 22).

BUG=None
TEST=check vfio-pci xhci controller (00:0d.0)'s function during suspend and resume.

Change-Id: Ib25c8877f0e10431c097914aa5cc7b7ad0e24612
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3312579
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-12-03 19:17:39 +00:00
Abhishek Bhardwaj
5c86fef96d crosvm: vvu: proxy: Allocate bar and add handler stubs
This change allocates the additional resource bar for the VVU proxy
device and adds read / write stubs for the notification region.

BUG=b:194136484
TEST=Compile.

Change-Id: Ia7b0e522462aea68fb6ccf11037320393cc4ffd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288866
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-03 13:04:35 +00:00
Abhishek Bhardwaj
00d939bc88 crosvm: vvu: proxy: Fix constants and add VVU proxy type
This change separates the number of queues of the proxy device from the
number of queues of the actual VVU device. It also fixes the device type
constant to the number specified by the spec. Also, change PciClassCode
for legacy devices. The guest VFIO driver code doesn't enumerate the
proxy device without it.

BUG=b:194136484
TEST=Compile.

Change-Id: I105a46168302b1cc53a7c61c55019d8b1e703b40
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3288865
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
2021-12-03 01:53:35 +00:00
Daniel Verkamp
6a7fdb4510 seccomp: add getcwd and readlink to common policy for panic
The panic handler uses getcwd and readlink to print out the executable
name in the backtrace. Allow these for all devices so that panics
actually work instead of crashing the process.

BUG=None
TEST=intentionally panic crosvm on kevin and check /var/log/messages

Change-Id: If64a752a6f0b1f2f6bdd6663ce77078305f38171
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3309201
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-12-02 23:18:03 +00:00
Daniel Verkamp
d2172d435f devices: virtio: async_utils: do not borrow interrupt across await
Update handle_irq_resample() to resemble the previously-removed async
block version, which clones the resample event in a separate block so
that the Rc<RefCell<...>> is not borrowed across await. Otherwise, other
users of the Rc<RefCell<Interrupt>> cannot borrow it mutably.

BUG=b:208264646
TEST=tools/presubmit
TEST=Boot Crostini on hatch

Change-Id: I2505d580ae7813b20fff60e7ced0e4f706339a81
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3311457
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-12-02 23:12:10 +00:00
Jorge E. Moreira
51e0cab41d Revert "Conditionally apply linux-only operations"
This reverts commit 1e3cb9faa1.

Change-Id: I578902056b205089b3af95b8cc85ff6e0f550de6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3310886
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2021-12-02 14:15:17 +00:00
Abhishek Bhardwaj
1de3b5aef8 vhost_user: Modify signature of send_ack_message
send_ack_message used to take a module local Result as a parameter. It
doesn't make sense for other modules to use this. This change makes the
method take a bool instead of the aforementioned Result.

BUG=b:194136484
TEST=Compile.

Change-Id: I475cc39826db94ef2c686e754e13f478f8109d0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3285629
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-12-02 13:26:46 +00:00
Abhishek Bhardwaj
2a0b2fe699 vhost_user: Add helper class to abstract socket communication
This change adds a helper class that talks to the Vhost User Master.
This way the communication logic can be used by a Virtio Vhost User
Slave implementation as well as a Vhost Virtio User proxy device.

BUG=b:194136484
TEST=Compile.

Change-Id: I7d675c6739f7c8675320d956175c63c8d1190b79
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3285628
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-12-02 11:48:02 +00:00
Quentin Perret
2620380106 Revert "vm-memory: mlock2(MLOCK_ONFAULT) guest memory for protected VMs"
This reverts commit b975546c3f.

Reason for revert: mlock is insufficient to prevent migration/compacting of guest memory, and therefore pKVM has been modified to perform pinning in the kernel, making the mlock call superfluous.

Original change's description:
> vm-memory: mlock2(MLOCK_ONFAULT) guest memory for protected VMs
>
> By default, the memory of a protected VM is inaccessible to the host
> and crosvm. Consequently, attempts to access guest memory are fatal and
> must be avoided in order for the guest to run.
>
> Mlock guest pages as they are faulted in for protected VMs, ensuring
> that the host doesn't try to age or swap them out as a result of memory
> pressure.
>
> Bug: b:204298056
> Test: cargo test on x86 and arm64
> Cc: Quentin Perret <qperret@google.com>
> Cc: Andrew Walbran <qwandor@google.com>
> Signed-off-by: Will Deacon <willdeacon@google.com>
> Change-Id: I618ec1e8b1136a47a8b3ef563e45bc41d75ab517
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3257689
> Tested-by: kokoro <noreply+kokoro@google.com>
> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>

Bug: b:204298056
Change-Id: Ibdcc579805c47adf35412b732829c074ce038471
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3310884
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Quentin Perret <qperret@google.com>
Auto-Submit: Quentin Perret <qperret@google.com>
Reviewed-by: Will Deacon <willdeacon@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-12-02 11:28:53 +00:00
Alexandre Courbot
88b671a469 devices: gpu: prevent busy polling if resource bridge becomes faulty
If a resource bridge becomes closed for some reason, it will always get
signaled as ready and will make the poll call return immediately, only
to make us handle an error and go back to the same loop indefinitely.
This results in lots of error messages in the host's log and one CPU
core very busy doing nothing.

Fix this by making `process_resource_bridge()` return a `Result` and
removing the faulty bridge when it returns an error.

BUG=b:161774071
TEST=Make the video process exit after establishing the bridge, notice
that the bridge is properly removed on the GPU process side and the
latter does not flood the host's logs with the same error.

Change-Id: I19767d779a44caccf0870faf422c7234c4232818
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3310341
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-12-02 10:57:54 +00:00
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