Commit graph

1961 commits

Author SHA1 Message Date
Chirantan Ekbote
370ee0fb75 io_uring: Pin iovecs in memory
Pointers to the iovec structs are shared with the kernel for the
duration of an I/O operation and so must be pinned in memory.  Use
Pin<Box<[iovec]>> instead of Vec<iovec> to express this and also to
prevent any changes made in the future from accidentally doing something
that causes the memory location of the iovecs to change.

BUG=none
TEST=unit tests

Change-Id: I317f3a6f68d457b0b0a6c86494d506b0e978b5fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2387823
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-09-12 09:42:37 +00:00
Chirantan Ekbote
b6c1eba580 cros_async: Don't implement IoSource for pointer types
We can use Pin::as_ref to go from a Pin<P> to a Pin<&<P as
Deref>::Target>, which doesn't require <P as Deref>::Target to be Unpin.
So let's have callers use that method rather than implementing the
IoSource trait for different pointer types.

BUG=none
TEST=unit tests

Change-Id: I45f54e70fe81bc0ceac3f038db47aef50201daa2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2387821
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-09-12 09:42:36 +00:00
Chirantan Ekbote
8ea889fccf cros_async: Refactor executors
This CL includes several smaller changes to how executors work:

  * Replace BTreeMap with Slab, which should give us some small
    performance benefits by giving O(1) lookups and reducing memory
    allocations when adding new I/O operations. It also gives some
    improvements to readability as we no longer have to carry around
    "next_*" variables. Slab has no dependencies and we're already
    pulling it in via the futures crate.
  * WakerToken no longer implements Clone.
  * Merge pending_ops and completed_ops in URingExecutor into a single
    `ops` Slab and introduce an OpStatus enum that indicates whether an
    operation is pending or completed.  This also fixes a resource leak
    where an operation that was canceled before completion would end up
    staying in completed_ops ~forever. Add a test for this leak.
  * Add a generation number to RingWakerState and include it in all
    RegisteredSources. Since a RegisteredSource can outlive the
    RingWakerState that created it, the generation number ensures that
    it will only affect the RingWakerState that created it. Add a test
    for this.
  * Poison RegisteredSource so that it doesn't implement Send or Sync.
    Since it's associated with a thread-local executor, sending it
    across thread boundaries is not ok.

BUG=none
TEST=unit tests

Change-Id: I43dcfbb8166002995ec8773522c22fab8fb2da9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2374885
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-12 09:39:26 +00:00
Daniel Verkamp
c677fb49ce crosvm: allow setting VCPU affinity per VCPU
Allow separately specifying each VCPU thread's affinity, extending the
existing --cpu-affinity option so that it can parse a new format:

  <GUEST-CPU>=<HOST-CPU-SET>[:<GUEST-CPU>=<HOST-CPU-SET>[:...]]

This can be used to pin each VCPU thread to a single host core, for
example.

Tested with this command to verify the affinity of the VCPU threads:

  ps -C crosvm -T | grep vcpu | awk '{print $2}' | xargs -n1 taskset -p

BUG=b:167714813
TEST=cargo test
TEST=Run crosvm with new --cpu-affinity option; verify with taskset -p

Change-Id: Ie6c1acf954931c12b9eaa74c6ae3f67c3f062ef6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2399639
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-09-11 22:38:03 +00:00
Alex Lau
47f24c914e devices: virtio: video: Move response logic to decoder.
This CL moves the remaining response logic from Worker to be done
by the decoder or encoder Device. Currently Worker matches on the
returned responses from Device's process_cmd and process_event_fd,
and adds additional responses when the Device already knows the
responses to send. This allows the encoder and decoder to send
different responses when the same AsyncCmdTag is returned, and to
remove the `take_resource_id_to_notify_eos` Device trait function.

BUG=b:161774071
BUG=b:161782360
TEST=USE=test emerge-$BOARD crosvm
TEST=play multiple YouTube videos to completion

Change-Id: I3b210b59f528df473a03657af76b5b8df488f7f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2352269
Tested-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alex Lau <alexlau@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-09-10 05:10:30 +00:00
Alex Lau
e37b4d3771 devices: virtio: video: add AsyncCmdDescMap.
This CL is a refactoring that moves out cancel_pending_requests as a
function of the descriptor map so that it can be shared with the
decoder and encoder implementation.

BUG=b:161774071
BUG=b:161782360
TEST=USE=test emerge-$BOARD crosvm
TEST=play YouTube video

Change-Id: I32cd7f5ced855cc42baa2d6d3d1a9db802433412
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2379572
Tested-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-09-07 14:23:03 +00:00
George Burgess IV
61126c786c fuzz: fix build
A recent API change made `{Reader,Writer}::new` take `GuestMemory` by
value instead of reference. Since `GuestMemory` is just a pair o'
`Arc`s, this appears to be an easy fix.

BUG=chromium:1125394
TEST=`emerge-amd64-generic crosvm` with a `--profile=fuzzer`'ed board

Change-Id: I964f284134241f958456f87912334a387dfcf61e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2394756
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: George Burgess <gbiv@chromium.org>
2020-09-07 13:15:32 +00:00
Jason Macnak
23400524e9 devices: gpu: Check /dev/dri exists before mount
GPU in 2D mode does not need this and /dev/dri may not
exist (Nvidia startup failure after forced workstation
updates?).

BUG=b:166180769
TEST=boot Cuttlefish

Change-Id: Iaf80fc0f8f031270267df18d61964f8a648920b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2381892
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Jason Macnak <natsu@google.com>
2020-09-03 17:07:44 +00:00
Kansho Nishida
ab205af96c main: Allow some vcpus to be real time
Add an option to set some vcpus as real time. With a cooperative guest,
this allows for getting real time behavior for a subset of guest
threads.  The guest will use cpusets to ensure that only real time tasks
are run on the real-time CPU, and that vcpu thread is real-time on the
host leading to behavior close to host real-time threads.

BUG=b:142777321
TEST=crosvm --rt-cpus 1 [OPTION]...
     ps -AT -eo comm,sched,rtprio | grep crosvm_vcpu
     then check the sched policy of vcpu1 is 2 (SCHED_RR)

Change-Id: Ic8e7a6840bdbce2c90e518458f6d0c50a65ca3f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2152167
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Suleiman Souhlal <suleiman@chromium.org>
Tested-by: Kansho Nishida <kansho@chromium.org>
Commit-Queue: Kansho Nishida <kansho@chromium.org>
2020-09-03 07:20:02 +00:00
Paul Kirth
6e1260face Revert "msg_socket: Fixed bug with all skipped fields in struct"
This reverts commit ca3817bda3.

Reverting prevents these errors when starting the vm:

[ERROR:src/linux.rs:2324] failed to recv VmMemoryControlRequest:
msg buffer size too small
[ERROR:src/linux.rs:2324] failed to recv VmMemoryControlRequest:
msg buffer size too small
[ERROR:src/linux.rs:2350] failed to recv VmIrqRequest:
msg buffer size too small

BUG=b:162032986
TEST=manual

Change-Id: I22a31fa36274d3b6dd4ebc7431ab9ac3878b735b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2380301
Reviewed-by: Richard Zhang <rizhang@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-09-02 23:20:22 +00:00
Daniel Verkamp
8c2f000917 linux: replace sort with sort_by_key and Reverse
Use the _by_key variant of the sort function as recommended by
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by
and replace the potentially easy-to-miss swap of the two compared values
with an explicit call to std::cmp::Reverse (also recommended by the same
clippy lint).

Fixes a clippy warning with Rust 1.46.0.

BUG=None
TEST=docker/wrapped_smoke_test.sh (with Rust 1.46.0)

Change-Id: I682652736a27cb09111dbc813e654b17269670da
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2386479
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-09-02 18:41:25 +00:00
Dylan Reid
371a021f69 devices: Add ability to consume descriptor offsets
When switching to async usage of descriptor queues, it is more useful to
consume the offsets and lengths of the descriptor buffers instead of the
buffers mapped as `VolatileSlice`s. Having the offset,length pair and
the guest memory it refers to is enough to initiate async ops.

Async versions of non-offset read/write case aren't possible as using
the existing "seek" offset of the file doesn't make sense with async IO.

Adding the new version modifies the existing API. This is necessary as
now `Reader` and `Writer` own `GuestMemory`, which makes async possible.

TEST=unit tests and new test to exercise the async functions.

Change-Id: I0a5e50694f40217e5d6ac40f5fcb82944a4c117e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2306784
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-09-02 10:07:32 +00:00
Xiong Zhang
78782db936 vfio-pci: Add one missed msi cap structure
Msi capability structure for 32-bit message address and per vector
masking is missed, so vfio pci device with such cap couldn't receive
msi interrupt in guest.

BUG=None
TEST=Pass pci device with such msi cap into guest, then check this
device function in guest.

Change-Id: If89c5392af72a5bd1165c53a6857c24fe067e29c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2381399
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
2020-09-02 09:15:22 +00:00
paulhsia
ce17e6e51c ac97: Fallback to null audio if connection refused by CRAS
When getting "connection refused" or other errors in CRAS back-end,
fallback to null-audio-device and keep booting.

- Add `backend` attribute to `Ac97Dev`
- Add function to return minijail policy file path in `Ac97Dev`
- Provide fallback mechanism in `try_new`
- Refactor: change `Ac97Dev` to `Self` in `Ac97Dev`'s `impl` block

BUG=chromium:1116468
TEST=`stop cras` && `vmc start termina`
TEST=`cargo test --workspace devices`

Change-Id: Ic60d993473dab69ec2b8b41ec859fa1c012d8334
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2379586
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Auto-Submit: Chih-Yang Hsia <paulhsia@chromium.org>
2020-08-29 20:47:27 +00:00
Gurchetan Singh
6951fca9fb docker: build against virglrenderer master
Requires Meson, python3-setuptools, epoxy update too.

This, too, should keep kokoro happy.

BUG=chromium:924405
TEST=./wrapped_smoke_test.sh

Change-Id: Ib1ca1bcca7b21f76e74c8e4dca9f96e84154b9e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2379995
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-08-28 23:26:34 +00:00
Dylan Reid
7ca98fb599 devices: queue: Keep clone of mem instead of Rc
GuestMemory is just Arcs, cloning it is as cheap as keeping an Rc.

Change-Id: I160585ce0cf70aa0ec33897b550b82fe09bde2a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2364992
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-08-28 18:22:01 +00:00
Daniel Norman
2e8f355ba0 Adds more keys to the default virtio keyboard.
These keys are frequently found as hardware keys on mobile devices.

BUG=b:163628929
TEST=Use crosvm to launch AOSP Cuttlefish and send volume key events.

Change-Id: I9175d32cfd4060abd74f0fde4100284483f13102
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2369357
Tested-by: Daniel Norman <danielnorman@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Norman <danielnorman@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Jorge Moreira Broche <jemoreira@google.com>
2020-08-28 13:08:54 +00:00
Alex Lau
8db592593b devices: virtio: video: Remove bitrate control query type.
It's not supported by the protocol and unused by the virtio-video
kernel driver.

BUG=b:161774071
TEST=USE=test emerge-$BOARD crosvm

Change-Id: I5d28072618187b90acb29fbb4b4272f644ebf1d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2361543
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-08-28 06:59:51 +00:00
Daniel Verkamp
f4a260d3df Simplify tests with tempfile::tempfile()
Where it simplifies the code, use tempfile() rather than TempDir to
create temporary files in tests.

BUG=None
TEST=./build_test

Change-Id: I5caff512a38a3b94556b0c72693e432503d6e679
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2360459
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-08-27 00:39:03 +00:00
Daniel Verkamp
62fb00d4bb tempfile: add tempfile() and NamedTempFile
This simplifies the common case of creating a temporary file whose path
does not need to be known, as well as a a temporary file with a known
name.

BUG=None
TEST=cargo test -p tempfile

Change-Id: I664b6097b5ae44ae3f1aa7f6c366271375a8df46
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2360458
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-08-27 00:39:02 +00:00
Gurchetan Singh
fb72b4708b devices: gpu: virgl_renderer_resource_export_blob
With blob resources, there's a new export API.

BUG=chromium:924405
TEST=local testing with blobs

Change-Id: I4a6a48608fd6910b6deea53ef54f94def1799950
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2349395
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-08-24 17:46:51 +00:00
Richard Zhang
ca3817bda3 msg_socket: Fixed bug with all skipped fields in struct
Fixed a bug where RecvZero would be thrown when sending a struct with
all it's fields being skipped. Added a test for this too.

BUG=b:162032986
TEST=cargo test -p msg_socket

Change-Id: I01ba17593df24564786bcbf7b35312d61e3bb3f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2339311
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2020-08-23 00:24:47 +00:00
Richard Zhang
649f116d9d msg_socket: delete impl for Mutex
The MsgOnSocket impl for Mutex contains a threading bug where it's
possible for the object inside the Mutex to mutate after msg_size()
and/or fd_count() has been called.

Also it's not being used.

BUG=b:162032986
TEST=cargo test -p msg_socket

Change-Id: I41188547152236c8124d9ac9593deea93dc02c73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2339308
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2020-08-23 00:24:45 +00:00
Suleiman Souhlal
14fa6bdf5a balloon: Use different method for sizing balloon.
Use free + cached memory in the guest instead of available
reported through the balloon stats, which uses some strange heuristics,
for sizing the balloon. This brings it more in line to what
the ChromeOS available counter does.

Also, change the way the memory is balanced such that the
balloon is sized so that the "available" memory in the guest
would be equal the host's available memory.

BUG=b:160826299
TEST=arc.MemoryChromeOSPerf.vm tast test improves to be closer to
 container ARC: 1900MB -> 2400MB on 4GB machine.
 No difference in arc.MemoryAndroidPerf.vm.

Change-Id: Idddf1e5f5d75ea4d1ebb190b60dd785bbe2327df
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2299279
Auto-Submit: Suleiman Souhlal <suleiman@chromium.org>
Tested-by: Suleiman Souhlal <suleiman@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Suleiman Souhlal <suleiman@chromium.org>
2020-08-22 12:51:37 +00:00
Chirantan Ekbote
f9038f464b cros_async: Delete IoOperation
This seems like an unnecessary extra layer of indirection.

BUG=none
TEST=unit tests

Change-Id: If63bf06fed6a0bc99f075b3b34a5d7998e9865b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2369053
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-08-22 10:39:59 +00:00
Alex Lau
38e8750176 device: virtio: video: Add dead_code attribute to SetControl
BUG=b:161774071
TEST=None

Change-Id: Ia9c9ba1a316a409c17ac601e94bd3f6a75b24af5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2355847
Tested-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-08-18 11:54:02 +00:00
Gurchetan Singh
3035dd87df devices: gpu: gfxstream: use MemSlot
Not strictly necessary to build gfxstream, but the MemSlot abstraction
was recently introduced and it makes sense to use it everywhere.

BUG=b/153580313
TEST=gfxstream builds

Change-Id: I06c2ca15edd39c553eacf1256dd95c2fc72f67dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2349394
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-08-18 08:34:27 +00:00
Andrew Walbran
02a17bb588 sys_util: Log to logd via liblog on Android.
The Linux syslog hack won't work, as Android doesn't use the same syslog
interface.

This introduces a Syslog trait to abstract over the syslog interface for
the target platform, which is implemented for Linux and Android.

BUG=b:158290206
TEST=cargo test && cargo build --target=aarch64-linux-android

Cq-Depend: chromium:2355628
Change-Id: Ib7a86b37a1526a3ba9f7a0fdb47f1b959caf7c7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2302469
Tested-by: Andrew Walbran <qwandor@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Auto-Submit: Andrew Walbran <qwandor@google.com>
2020-08-18 06:20:00 +00:00
Daniel Verkamp
1972b6855a protos: add arch = x86 guards around CPUID helpers
The CPUID-related KVM structs are only available on x86; don't try to
compile the helper functions that use these structs on other platforms.

This is slightly nonsensical, since plugin is already only compiled on a
few specific x86 platforms, but it allows the unit tests to build on
other platforms (e.g. when using `cargo test --all-features`).

BUG=chromium:1112839
TEST=FEATURES=test emerge-kevin crosvm

Change-Id: I413ac757f27c987133bdb265f203f0d6eb3a0b21
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2347077
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-18 05:30:38 +00:00
Daniel Verkamp
482874c248 disk: qcow: fix unit test build on 32-bit platforms
The previous disk size (0x1_0000_0000 = 4 GiB) would overflow usize on
32-bit platforms, causing a unit test build failure.  Shrink it to half
the size, which is still plenty for the purposes of the tests.

Seek offsets are natively 64 bits wide, even on 32-bit platforms,
whereas usize can be only 32 bits wide, so rearrange the casts such that
the final seek offset and intermediate values used to calculate it are
stored in u64 instead of usize.

BUG=chromium:1112839
TEST=cargo test -p disk
TEST=FEATURES=test emerge-kevin crosvm

Change-Id: Ia25762541104124960d9298e6ad7e56f71aa3031
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2347076
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-18 05:30:36 +00:00
Chirantan Ekbote
be48c252db fs: Fix {GET,SET}FLAGS ioctls on arm
crosvm runs as a 32-bit binary on arm devices but arcvm has a 64-bit
kernel with a 64-bit userspace.  Since the {GET,SET}FLAGS ioctls use a
c_long as part of the encoding, the encoded value changes based on
whether a long is 4 bytes or 8 bytes. This causes a mismatch where the
server expects the 4 byte encoding while the VM sends the 8 byte
encoding.

Check for both encodings when handling ioctls.  The actual flag value
itself is actually just a c_int and not a c_long as you might expect
from the encoding. Since that has the same width on both 32 and 64 bit
systems we don't have to change the actual value that's returned.

BUG=b:163729385
TEST=lsattr and chattr still work inside the VM. Also use a test program
     to check that the 64-bit versions also work inside the VM.

Change-Id: I77e98ea83372306597f7b3eb2bd675035be98d5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2352281
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-08-14 17:41:35 +00:00
Daniel Verkamp
32f423723a gpu_renderer: remove redundant -> () from fns
Fixes clippy "unneeded unit return type" warnings.

Also apply rustfmt.

BUG=None
TEST=bin/clippy
TEST=bin/fmt --check

Change-Id: I139c22e1f867de45cc1a5f4f460f08699d1007a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2349954
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-13 01:28:52 +00:00
Dylan Reid
d086568932 cros_async: Fix reference to mem being dropped early
The Rc to BackingMemory that is passed in to memory operations was being
dropped before it is safe, The kernel can still access it until the op
is completed, so keep the reference in the pending_ops map.

Add tests so that this safety guarantees made by the executor are
exercise in unit tests.

Thanks to nkgold for finding the issue via code inspection.

BUG=none
TEST=cargo test dont_drop_backing_mem, cargo run with uring block and
run fio tests.

Change-Id: I8e4efedbbafefcbd57d7d7c340dc91a9b159b38c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2345377
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-08-13 00:04:56 +00:00
Dylan Reid
1330619561 sys_util: Add ability to set the depth of a pipe
It will be useful to set the pipe depth in unit tests. The first use
will be to set the depth before filling the pipe so the pipe can be used
to test blocking writes.

Change-Id: Ia8c2b01f7f4b08bd59a0442c5e7bff02bf25c77c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2345376
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-08-13 00:04:54 +00:00
Alex Lau
e0b29ad24d devices: virtio: video: Add SetControl response enum
BUG=b:161774071
BUG=b:140082257
TEST=emerge-$BOARD crosvm

Change-Id: I779074edd33a33b2398bd7f3e70945f78a08085c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2345990
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
Tested-by: Alex Lau <alexlau@chromium.org>
2020-08-12 14:21:12 +00:00
Alex Lau
b35b0ae21d devices: virtio: video: Add missing DataInit for virtio_video_set_control_resp
BUG=b:161774071
BUG=b:140082257
TEST=emerge-$BOARD crosvm

Change-Id: I8833871a7925781f37f8279e29ead8c7be5e2327
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2345989
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
Tested-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-08-12 14:21:11 +00:00
Alex Lau
2cb3fedbb8 devices: virtio: video: Add missing H264 levels
BUG=b:161774071
BUG=b:140082257
TEST=emerge-$BOARD crosvm

Change-Id: Ia440818360c083611ef9e9c7416999f4cbb367b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2345988
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-08-12 14:21:09 +00:00
Chirantan Ekbote
ba3269fd39 devices: fs: Initialize security context on creation
Set the security context (via /proc/thread-self/attr/fscreate) before
creating files, directories, nodes, or symlinks.  This ensures that
these entries appear atomically with the correct selinux labels.

BUG=b:155441848,b:158326112
TEST=vm.Virtiofs, arc.PlayStore.vm
TEST=Use strace to verify that selinux contexts are written to the
     fscreate proc file before creation.

Cq-Depend: chromium:2291828
Change-Id: Id960dbc821540373f2df073768e3ebfcb1a1c3f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2239728
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
2020-08-12 04:38:27 +00:00
Alexandre Courbot
927c2e499b Revert "devices: video: dec: Support arbitrary buffers to be mapped as resources"
This reverts commit 4ffb3d06bd.

Since ag/12302792 ARCVM now works with a fixed set of buffers, and will
make sure to submit only one given buffer to a given V4L2 index, so we
can revert this patch in order for the crosvm virtual device to work as
per the expectations of V4L2 decoders.

BUG=b:161323057
TEST=arc.VideoDecodeAccel.h264_vm passes on Kukui.

Change-Id: If822f3d23c3dd37a2107db076c91691a0d1b0a00
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2340727
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-08-12 03:13:51 +00:00
Keiichi Watanabe
cdc9f57e47 disk: Make AsyncDisk trait's interface align with sys_util
* Make AsyncDisk as a supertrait of some sys_util's traits
* Rename write_zeroes to write_zeroes_at

BUG=none
TEST=cargo test

Change-Id: I714d82092b3ee2930383541b67b958dc1a7cf441
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2340732
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-08-11 05:05:57 +00:00
Steven Richman
f32d0b48fd Use hypervisor abstraction to run VMs
Calls to the kvm crate have been replaced by calls to hypervisor and
devices::irqchip.  Plugin is unchanged and still KVM-specific.

x86 creates and configures vcpus on the vcpu thread instead of the main
thread.

Code that still depends on kvm or kvm_sys:

  - crosvm_plugin, plugin, and protos use kvm and kvm_sys if built with
    the plugin feature

  - devices::VfioGroup does a kvm_sys ioctl

  - devices::irqchip and hypervisor use kvm_sys.  hypervisor uses
    kvm::Cap and kvm::CpuId internally for now.

BUG=chromium:1077058
TEST=runs es2gears_wayland on kukui
TEST=runs evince on amd64-generic with kernel and split irqchip
TEST=build_test excluding tpm2
TEST=cargo check --features plugin

Change-Id: I0068e34da6a5ff0079b1237be1958933bf12ffe4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2307711
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Steven Richman <srichman@google.com>
2020-08-11 04:51:34 +00:00
Gurchetan Singh
c1a962ed31 devices: gpu: non-exportable virglrenderer_map(..)
Like gfxstream, virtio_3d can also support non-exportable memory
when run in single-process mode.  This is useful for getting
GL4.5/VK on Nvidia, where dma-buf mmap is not supported.

BUG=chromium:924405
TEST=piglit -t arb_buffer_storage

Change-Id: I072803fd414ddd68bcaafc1f17d236680d6aaa67
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2250461
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-08-11 04:24:02 +00:00
Lingfeng Yang
5572c8db3f devices: gpu: Integrate ExternalMapping with virtio-gpu
This CL takes the global map_request and uses it as an Arc<Mutex<>>
reference in virtio gpu, enabling virtio gpu backends to generate
external library mappings.

The workflow is demonstrated in the gfxstream backend:

1. Guest triggers vkMapMemory on host
2. Host generates a blob id, sends back to guest
3. Guest asks to RESOURCE_CREATE_BLOB with the blob id,
creating a resource id
4. Guest asks to RESOURCE_MAP_BLOB with the resulting resource id
5. Host gets hva, size from the backend using the resource id
6. Host maps hva, size via KVM to the guest pci offset via sending a
ExternalMapping over map_request
7. Guest maps that PCI offset, exposing memory to guest userspace

BUG=b/153580313
TEST=dEQP.vk.memory.*

Change-Id: I242beedab1dcaf9eb08d9797ed10dc993b58abde
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035595
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-08-11 04:24:00 +00:00
Daniel Verkamp
1cd8099477 linux: log balloon stats when triggering resize
The balloon policy is based on the guest and host available memory
statistics; add some logs to make it possible to see why the balloon is
being resized when debugging memory balance issues.

BUG=chromium:1097385
TEST=Run crosvm on hatch; verify balloon messages match `free` output

Change-Id: Ia664d1ece7a5e088253984c9179aa72d42f35ec5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2321331
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-11 02:41:31 +00:00
Daniel Verkamp
603548ac4e docker: upgrade to Rust 1.45.2
This is the version that is already being used, since the rust-toolchain
file is just set to 'stable' now. Update the Docker image so that kokoro
does not have to re-download the new Rust toolchain for every build.

Also, explicitly update the default rustup toolchain to 'stable' in the
Dockerfile - this prevents `docker run` from having to re-download the
toolchain.

While we're on a cleanup spree, remove the addition of rustfmt-preview
from the smoke_test script; rustfmt is now included by default when
installing a toolchain via rustup.

BUG=None
TEST=docker/build_crosvm_base.sh && docker/wrapped_smoke_test.sh

Change-Id: I1359bd7b39dd4ebeaf970a001e0002b3699c9771
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2333116
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-11 00:50:48 +00:00
Dylan Reid
e5a2c4e1d5 kvm: Exclude cpuid unit tests on non-X86
cpuid functions only exist on X86 machines. Don't run their unit tests
on other platforms.

TEST=cd kvm;cargo test --target=aarch64-unknown-linux-gnu
BUG=1112839

Change-Id: I5f7656b41e7143c1833e677669f101a8dead859f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2335448
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-07 23:53:26 +00:00
Daniel Verkamp
5306418bd8 devices: cmos: report 24-hour RTC mode in status
The emulated CMOS RTC device always returns the hour field in 24-hour
format; initialize the Status Register B bit that indicates this to the
guest.

This also lets Linux register the CMOS RTC as an rtc-class device.  It
was previously ignoring it since it was assuming the device was in
12-hour mode.

Also bump the minimum IRQ for the system allocator up to 9 to avoid
sharing IRQ 8, which becomes an issue once Linux tries to enable the RTC
device:

snd_intel8x0 0000:00:0b.0: PCI->APIC IRQ transform: INT C -> IRQ 8
genirq: Flags mismatch irq 8. 00000080 (snd_intel8x0) vs. 00000000 (rtc0)
snd_intel8x0 0000:00:0b.0: unable to grab IRQ 8
snd_intel8x0: probe of 0000:00:0b.0 failed with error -16

On x86_64, only 4 device IRQs are used (for PCI pin interrupts), so this
does not reduce the number of available IRQs for devices.  Most PCI
devices in crosvm also support MSI-X, which this change also does not
affect.

BUG=b:162789858
TEST=Boot Linux 5.8; verify existence of /sys/class/rtc/rtc0
TEST=Boot on x86_64 Chromebook; verify IRQ 8 is not used by PCI devices

Change-Id: I39ca6a823914d2d27caec7812b54bf754ac3db9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2337370
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-06 22:25:39 +00:00
Dylan Reid
e91bbf9d93 devices: virtio: Only validate queues that are used
In the case of multi-queue block, there might be unused queues. This
will be indicated by the driver starting the device without marking
those queues are ready. Ignore validating non-ready queues.

Change-Id: Ifef14e4c4cf96bc01bb1d8b2488a0bbef2f9ec6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2125373
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-08-06 19:15:05 +00:00
Dylan Reid
20e6c5a88c devices: queue: Count the number of notify disables
With multiple async contexts processing requests from the same queue, it
is useful to be able to disable the queue notification until after all
the events have been processed. Keep a count of pending notify disables
to enable this use case.

Provide `NotifyGuard` as a RAII way of letting users disable
notifications for the scope of the guard. Once the non-async users of
queue are removed, `set_notify` can be made private.

BUG=chromium:901139

Change-Id: Id69de408d2ec9b7cec67f54551427af3aa32149b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2306782
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-08-06 19:15:02 +00:00
Michael Hoyle
6b19695c81 Add "base" crate and transition crosvm usages to it from sys_util
For now, this crate simply re-exports all of sys_util, but it will
be updated to provide new interfaces when needed. This is the
first step to making crosvm not directly depend on sys_util, so
that we can make the interface changes we need without fear of
negatively affecting (i.e. completely breaking) other usages
within chromeos.

BUG=b:162363783
TEST=./build_test

Change-Id: I7d0aa3d8a1f66af1c7fee8fd649723ef17027150
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2325168
Tested-by: Michael Hoyle <mikehoyle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-08-06 18:19:44 +00:00