Commit graph

2510 commits

Author SHA1 Message Date
Adrian Ratiu
b08a9e2953 seccomp: allow fstatat64/statx syscalls on arm
On 32bit arm systems, starting with glibc 2.33, the fstatat64
syscall is used to fix a y2038 bug and statx is also called
for 64bit->32bit datastructure conversion.

See this upstream glibc 2.33 commit range for more details:
d892723830..aa03f722f3.

Example failures (only on 32bit arm):
type=SECCOMP comm="mtpd" exe="/usr/sbin/mtpd" sig=0
arch=40000028 syscall=327 code=0x7ffc0000
type=SECCOMP comm="mtpd" exe="/usr/sbin/mtpd" sig=0
arch=40000028 syscall=397 code=0x7ffc0000

BUG=b:187795855
TEST=Local builds; CQ.

Change-Id: I003feeaa75552770920cdf9969a393940c5e997b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3113972
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-08-26 20:59:21 +00:00
Daniel Verkamp
5e9b5dfe58 virtio: video: use iter .any() to check presence
Rather than using .find().is_none(), use !.any() to fix a new clippy
warning.

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

Change-Id: I7e3de6b8e864f74300956c43dffaa033c58b7eb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108617
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
2021-08-25 23:02:29 +00:00
Daniel Verkamp
7cca590593 devices: use mem::take to replace with default
mem::take() can be used in place of mem::replace() when replacing with
the default value, fixing a new clippy warning.

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

Change-Id: I7289515eece30b9e294046930aa863a1ceab4de4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108616
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-25 23:02:29 +00:00
Daniel Verkamp
e73249af06 devices/register_space: use Copy rather than Clone
Fixes a new clippy warning with Rust 1.54.0.

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

Change-Id: I42cf6e380900ea4bb245629b56b0be5c75e2099d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108615
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
2021-08-25 23:02:28 +00:00
Daniel Verkamp
63db2893e2 devices/irqchip: deduplicate statements inside if
Pull the duplicated first statement out of the IRQ triggering sequences
to placate clippy's new warning.

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

Change-Id: I8cd8577af35990522e198f97f3a666ad6730e31b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108614
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Colin Downs-Razouk <colindr@google.com>
2021-08-25 23:02:27 +00:00
Daniel Verkamp
35712b20d8 devices, gpu_display: use Iterator flatten()
Instead of checking each item for Some/Ok-ness, filter down to just the
desired items using flatten() on the iterator.

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

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

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

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

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

Change-Id: I80b8a5e4a90f2d6aefafd3d0d4b64b6751163b25
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108611
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
2021-08-25 23:02:25 +00:00
Daniel Verkamp
166d1ddfbe crosvm: fix needless_borrow clippy warning
Tree-wide cleanup of new clippy warning in Rust 1.54 that warns about
needless borrows:

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

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

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

Change-Id: Ib702ec524d4623d264a00ec11dbc2150c411a67b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108321
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-25 23:02:23 +00:00
Woody Chow
e0f96c5930 Add cros_async to patches.crates-io
to avoid version conflict

BUG=None
TEST=CQ

Change-Id: If640e6288430213c104d95eb00cf0cb01c64b6d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3113245
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Woody Chow <woodychow@google.com>
2021-08-25 07:58:15 +00:00
Adrian Ratiu
48486f9248 seccomp: make consistent use of faccessat/2
In some places the faccessat and faccessat2 syscalls were
added only for arm64 but starting with glibc 2.33 they are
required on all architectures, so add them to arm and amd64.

BUG=b:187795855
TEST=Local builds; CQ.

Change-Id: Ica4755844fbbd29d31df2967724abe735ab59f7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3111369
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
2021-08-24 23:12:34 +00:00
Junichi Uekawa
25724e2ccc integration_test: Check file system before running test.
We need a file system that supports O_DIRECT. We know ext4 to work and
tmpfs not to work. Try out O_DIRECT before running the individual tests.

Follow up to changing the configuration so that the next time I can notice the
failure reason faster.

BUG=b:190435784
TEST=integration_tests/run

Change-Id: I7f8a97005dd959a5d0af4d1a91459b7bffc0fa9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3096427
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-08-24 21:56:52 +00:00
Victor Hsieh
5c4e0347e1 Drain the read buffer of DevFuseReader
In some circumstances, it's possible that the buffered data isn't fully
consumed by the filesystem. Before handling the next request, we need to
drain the residual.

This change also moves the reader/writer/mapper out of the loop, since
we intend to not duplicate the FDs for each interation, and prefer to
reuse the buffer / avoid re-allocation anyway. This allows us to
implement `drain` in DevFuseReader.

BUG=b:196264590
TEST=fsverity measure a filesystem without ioctl impl, the filesystem
     does not crash any more

Cq-Depend: chromium:3105916
Change-Id: Ib758c98e6d7b4ce1391c51db19c120a4cec09dff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3092409
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-24 18:41:30 +00:00
Ryo Hashimoto
8f9dc1d55e aarch64: Support pstore
Add necessary kernel cmdlines for aarch64.
Adjust PCI address to make room for ramoops on aarch64.
Move the code from x86_64 to common places.

BUG=b:153934386
TEST=vm_pstore_dump

Change-Id: I8f92a7fd04a49afd7e8be9e7cf1901ef70b88d65
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3103131
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Kansho Nishida <kansho@chromium.org>
Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
2021-08-24 14:31:44 +00:00
Xiong Zhang
e19ab750bc devices:vfio-pci: Assign vfio-pci device pci address
For vfio-pci devices created during vm setup period, they have the same pci
address as host.

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

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

Change-Id: Ia314cb74b15de374de540e440a91374a6538af54
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955568
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-24 00:56:32 +00:00
Xiong Zhang
544fb027c7 devices:pci: Pass pci bus number into allocate_pci()
Pci BusNumber is allocated by guest kernel, the BusNumber should be 0
for all the integrated pci devices and vfio-pci device, but pci bridge
and vfio-pcie device may have BusNumber > 0, so caller should know its
device BusNumber and pass it into allocate_pci() and get the desired
PciAddress.

BUG=b:185084350
TEST=None

Change-Id: I3cb18212e6c168c047f655a5f425abdeccbaae55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2954678
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-24 00:56:31 +00:00
Xiong Zhang
2ec87968d5 devices:pcie: Implement HotPlugBus trait on PcieRootPort
PcieRootPort is used to notify hotplug event into guest,
so implement HotPlugBus trait on it.

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

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

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

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

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

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

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

Change-Id: Ibcb5f4a849134f64fbceeac645bebd80d6ca72d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2954672
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-08-24 00:56:28 +00:00
Chirantan Ekbote
b56de80b07 fs: Support fs-verity
Needed by arcvm.

BUG=b:141632062
TEST=Run `fsverity enable $FILE` and `fsverity measure $FILE` inside a
     VM on a virtio-fs mountpoint

Change-Id: Ifb9e7e9c8b924a835971bf298256495d8dc81733
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2387820
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-08-23 16:15:03 +00:00
Chirantan Ekbote
f4d6014c41 data_model: Don't heap allocate in DataInit::from_reader
We can use MaybeUninit instead of heap allocation to ensure that our
buffer has the proper size and alignment. `from_reader` is used for
every message in the fs device and this saves us some unnecessary small
heap allocations.

Switch Reader::read_obj to use this method so that we don't have
multiple implementations of the same thing. This also fixes some
unsoundness in read_obj where we were creating a `&mut [u8]` out of
uninitialized data.

BUG=none
TEST=unit tests

Change-Id: I1fa66de11974e2fe3a8dfb4b7ab4b210ecf395d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3109088
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-08-23 11:59:16 +00:00
Chirantan Ekbote
98aeeff782 fuse: Implement Reader and Writer for mutable references
This way we're not required to transfer ownership every time we call
`handle_message`.

BUG=none
TEST=unit tests

Change-Id: Ia0cc10c7b5431e8bb90afbc0b658efac33eef6c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105916
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-08-23 09:20:11 +00:00
Keiichi Watanabe
48473283aa README: Add TOC
BUG=none
TEST=none

Change-Id: Id2a6af763bb891e95001a40b435f029f85eb7df9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3109172
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-08-20 07:57:34 +00:00
Adrian Ratiu
a0320d286d crosvm: seccomp: allow faccessat2 syscall if it exists
Starting with glibc 2.33 the faccessat2 syscall is used and
only if it doesn't exist (eg kernel older than 5.8) glibc will
default to the older faccessat syscall, so we need to allow it.

Previously this syscall has been enabled on a per-component
basis after testing, but this one does a bulk enable when
faccessat is used on all architectures.

See glibc commit 3d3ab573a5 ("Linux: Use faccessat2 to implement
faccessat (bug 18683")

BUG=b:187795855
TEST=Local builds; CQ.

Change-Id: I1f17e82e8c416b0fa2c43342731e9ea8394c47fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3097212
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
2021-08-19 19:07:35 +00:00
Keiichi Watanabe
ee4b58ef42 main: Add 'device' subcommand for vhost-user devices
BUG=b:195495971
TEST=Run `crosvm device block <options>`

Change-Id: I93c9a4f9bef895edecc850e59cda155e10b6a444
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3070724
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-18 16:44:28 +00:00
Keiichi Watanabe
f1d5a76b77 devices: vhost: user: device: Return failures instead of printing
Make run_*_device() return an error instead of printing error messages
so that the caller of the functions can handle errors from each device
in the same manner.

BUG=b:195495971
TEST=cargo build

Change-Id: I1b464b8bedbe6d4e640084a2ad3b2565d11b9e07
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3099429
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-18 16:44:27 +00:00
Keiichi Watanabe
024784d5c0 devices: Merge vhost_user_devices library to devices crate
We originally created `vhost_user_devices` crate so that we'll be able
to have device executables there.
However, we decided to have vhost-user device as crosvm's subcommand.
So, we have no longer a reason to have vhost-user devices as the
separate crate. As the first step to remove the vhost_user_devices
crate, this CL move its main logic to the devices crate.

Note that we add `vhost_user_devices/src/*_device.rs` in this CL as we
need to keep the device executables for a while.

BUG=b:195495971
TEST=cargo build

Change-Id: I355b9cd35214ac0c3d8ffd6fbebc29dd7548fd61
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3070723
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-18 16:44:26 +00:00
Jordan R Abrahams
6b893cc59f seccomp: Add fstatfs (32bit) to arm policies
This is a commit to future-proof seccomp failures with syscall=100,
fstatfs. On 32bit systems, we've seen programs which use not just
fstatfs64, but also fstatfs. Which one is selected is seemlessly
selected via defines via `statvfs`, depending on the board
(notably scarlet, trogdor, and elm).

See also: https://man7.org/linux/man-pages/man2/statfs.2.html

BUG=b:197006863
TEST=CQ

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

BUG=b:195495971
TEST=cargo test

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

BUG=b:195495971
TEST=cargo test

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

Change-Id: Ib8c07eb54af730c7a0ffaab67c02d6fb14a7efa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3096438
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-18 09:06:22 +00:00
Keiichi Watanabe
9568bb44b8 main: Add make_rt's usage
BUG=b:142777321
TEST=cargo check

Change-Id: I22b8f90d681961466e6e0c925a0d193809661e36
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3096437
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-18 09:06:21 +00:00
Keiichi Watanabe
2400bd5835 main: Reorder subcommand functions
Order subcommands' helper functions by alphabetical order.

BUG=none
TEST=cargo build

Change-Id: Ida9bc28a02ccceef764c7eae49b74a572be57cf3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3070722
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-08-18 09:06:20 +00:00
Xiong Zhang
dea7dbb082 Linux: Make vfio kvm file as global
One vm may have one vfio kvm file only, it could be created at vm
setup or runtime through vfio-pci hotplug, make it as global to
satisfy these two cases.

When vfio pci device is removed throgh hotplug out, the vfio group
will be removed frome vfio kvm file also, so move it into vfio.rs,
so it is could be referenced at vfio group's destroy. And
vfio group's destroy is called from vcpu thread, while vfio kvm file
is created in main thread, so use OnceCall instead of thread_local.

BUG=b:185084350
TEST=Boot a vm with or without passthrough device

Change-Id: I780c43a0ac0265f1e6f62578e134d09cbefc3e2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3062741
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-17 22:46:40 +00:00
Xiong Zhang
da162f29b4 Arch: Add configure_pci_device() function
Hotplugged device will be configured at runtime and configure_pci_device()
will allocate resource for added device and put this device into LinuxVm.

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

Change-Id: I2c77f006d135c1b1487d4e89a50b1b186beeb48e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2954671
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-17 22:46:39 +00:00
Andrew Walbran
bd9b1bc45b Add newlines to end of Cargo.toml files.
Omitting them causes issues with cargo2android.py.

TEST=cargo test

Change-Id: Ib7d62b4218527e436d6b3fc13142e05ed67d2d6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3097680
Auto-Submit: Andrew Walbran <qwandor@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2021-08-17 20:20:41 +00:00
Andrew Walbran
85d6ef16ca Use macros for trait implementations.
The previous implementations were exactly the same as the macro
expansions, so this should be exactly the same but less verbose.

BUG=None
TEST=cargo test

Change-Id: I9c97c4c9cb71491d5f8f5a8ce52e64abdac54245
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026666
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Andrew Walbran <qwandor@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2021-08-17 16:07:51 +00:00
Chirantan Ekbote
056a3ec8fe Use spawn_blocking() in DeviceReqHandler::run
This lets us offload the blocking accept() call to another thread so
that the main thread can continue handling other operations.

BUG=b:179755651
TEST=cargo test

Change-Id: I1372a13e662fe4ad5c99764788550a444d46170d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987588
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-08-17 11:48:08 +00:00
Chirantan Ekbote
af9dccf591 Add try_clone() and FromRawDescriptor for Tube and UnixSeqpacket
BUG=b:179755651
TEST=cargo test

Change-Id: Icf77f7427972b940215a2a4d95aa09ae409e4ff0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987590
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-08-17 11:48:07 +00:00
Chirantan Ekbote
e9778a0b59 pci: Derive Serialize and Deserialize for some types
BUG=b:179755651
TEST=cargo test

Change-Id: I9edbc3869659eb546dd5338c03192693e884c197
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987589
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-08-17 11:48:06 +00:00
Chirantan Ekbote
e4b9f30e24 sys_util: Add UnlinkUnixListener
Like UnlinkUnixDatagram but for UnixListener instead.

BUG=b:179755651
TEST=cargo test

Change-Id: I874ba2c76f525ac6cbc86d16b45dc8ff43d0c7f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2987587
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-08-17 11:48:05 +00:00
Dennis Kempin
b3ccebbf3d Improve build / test documentation
A lot of the information was outdated. The new guide prioritizes
building for linux and testing on linux as the default workflow
for crosvm.

BUG=b:194323235
TEST=None

Change-Id: Idb7cdb07151fc7d7d5466075e316015cf5f4c615
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3098391
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-08-16 20:43:22 +00:00
Dennis Kempin
faee6ce7fa Update setup_cros_cargo.sh to fix all paths for chromeos cargo builds
This allows ChromeOS developers to use cargo to build against the crates
provided by the ChromeOS source tree, instead of using the bundled
submodules.

BUG=b:196585250
TEST=./setup_cros_cargo.sh && cargo build

Change-Id: I02d38784f7a97657c37c267818499efed4ddab47
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3092414
Auto-Submit: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-08-16 19:31:58 +00:00
Peter Fang
218c8f313e devices: pci: mmap non-MSIX areas in MSIX-mappable BAR regions
A MSIX BAR can include both MSIX and non-MSIX registers. The non-MSIX
part of the BAR can be mmaped, eliminating unnecessary slow reads/writes
in userspace.

Add a new struct, VfioMsixAllocator, to keep track of the non-MSIX areas
of a mappable MSIX BAR. Page alignment is imposed to make sure mmap
succeeds.

BUG=b:184904868
TEST=boot Linux kernel and verify MSIX-capable passthru devices work
properly

Change-Id: I1fbf4c710f4bfaffe613d902f27e3bbb558c469e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2972489
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-13 23:24:03 +00:00
Peter Fang
9d614079d0 devices: pci: fix num_pba_entries in msix.rs
num_pba_entries should use rounding instead.

BUG=b:184904868
TEST=boot Linux kernel and verify MSIX-capable passthru devices work
properly

Change-Id: I406c033f59bc50bd767116947525058b74be054f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2972488
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-13 23:24:02 +00:00
Peter Fang
01527e39b3 devices: vfio: add support for VFIO_REGION_INFO_CAP_MSIX_MAPPABLE
For MSIX-capable PCI devices, some BAR regions are described using
VFIO_REGION_INFO_CAP_MSIX_MAPPABLE:

  The MSIX mappable capability informs that MSIX data of a BAR can be
  mmapped which allows direct access to non-MSIX registers which
  happened to be within the same system page.

Add support for this capability so that VfioRegion stores the correct
mmaps information.

Also, fix a couple break conditions to avoid breaking out early.

BUG=b:184904868
TEST=boot Linux kernel and verify MSIX-capable passthru devices work
properly

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

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

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

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

Change-Id: I2d48a7c77740e7f3ad996ad33592f0acd53b7144
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3064198
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Will Deacon <willdeacon@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-08-13 16:12:35 +00:00
Keiichi Watanabe
6ce3da3b42 vhost_user_devices: Remove unused error enum values
BUG=none
TEST=cargo build

Change-Id: I536ac76076f1340443f7efea53915e8628365239
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3070727
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2021-08-13 09:44:05 +00:00