Commit graph

745 commits

Author SHA1 Message Date
Zach Reizner
304e731cdb make hypervisor traits object safe
This allows code to create references to traits such as `&dyn Vcpu` for
`&dyn IrqChip`. This also allows keeping such traits inside of opaque
`Box` like wrappers.

To achieve this, trait methods referencing `Self` have an additonal
`where` clause that restricts them to sized types. Associated types are
removed and replaced with their trait equivalents (as parameters) or an
opaque Box (as return values).

To work around certain cases where a concrete type is needed, such as
for KVM based `IrqChip` impls, the `downcast_rs` trait is used to allow
`dynamic_cast` style casting.

The binary size impact of this change is small. For comparison, here is
the size change with this commit:

armv7a  -0.49% (-9 kiB)
aarch64 -0.17% (-3 kiB)
x86_64  +1.77% (+40 KiB)

BUG=None
TEST=build_test

Cq-Depend: chromium:2466660
Change-Id: I1a408734832d2971ea2979c1bc64b2ffe051b02d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2439298
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-10-15 14:31:20 +00:00
Victor Hsieh
7ab6aac800 device: fs: replace read_obj with from_reader in server
BUG=b:168305155
TEST=./build_test

Change-Id: I6874c325ef0f614e449fb3177ba5edb8dc0f3364
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2469501
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Victor Hsieh <victorhsieh@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-10-14 23:15:31 +00:00
David Stevens
27fdbba0d2 devices: virtio: video: Ensure failures are logged
BUG=b:170062417
TEST=Compiles

Change-Id: I12236ce7cb5498086f9ede0e3c3de4aff7d4b78e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2461150
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2020-10-14 16:17:19 +00:00
Chih-Yu Huang
65687c376b virtio: video: call set_output_buffer_count() just before passing the first buffer
GAVDA checks if the client sends any buffer between 2
AssignPictureBuffers() call. To guarantee crosvm always passes buffers
after AssignPictureBuffers() call, this CL moves the call just before
passing the first buffer to VDA session.

BUG=b:168557465
TEST=run android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrcEarlyEos
     and not see GAVDA's error log mentioned at commit message

Change-Id: I777ff914688ea589a4cf8921fc05ad59d3161b5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2463052
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-14 05:27:27 +00:00
Chih-Yu Huang
3db25abe21 virtio: video: Check queue type when cancelling Clear tag
AsyncCmdTag::Clear tag contains the queue type information. This CL
checks if the queue type matches the target when cancelling the
command.

BUG=b:168557465
TEST=android.media.cts.AdaptivePlaybackTest#testVP8_flushConfigureDrc

Change-Id: I8960ebaebc48c4fffbc8aaa326edeab449284c09
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437685
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-10-14 05:27:26 +00:00
Noah Gold
ee71c80b08 Mark MsgSocket as !Sync.
Semantically, MsgSocket is !Sync: multiple threads reading/writing to
the same end of the socket will result in U.B.. This CL brings the
syntactic definition of MsgSocket in line with its semantic meaning by
marking it as !Sync. While earlier work caught one of the other
consumers that was using a socket end in a Sync manner, this CL has
found another: the usb crate.

The fixes proposed for the usb crate are mostly for compilation's sake,
and should have little material effect on the operation of crosvm. Note
that they will assure correctness, since the send/recv for the socket
end involved are in the same critical section.

BUG=None
TEST=builds

Change-Id: I38469d9ed3228a43457b7d43879a6b4fff97b9a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2466960
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-10-14 01:36:09 +00:00
David Stevens
0b668f6054 devices: gpu: send resource info response for blobs
BUG=b:169212117
TEST=Play YouTube in ARCVM

Change-Id: Ica6cb900a939a368e3a73d739616d4f55c92c6f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2430874
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2020-10-12 18:16:39 +00:00
Gurchetan Singh
79bf5c6151 devices: virtio: gpu: rustify error handling
- Reduces lone error! statements
- Reduces the number of match arms

BUG=b:169212117
TEST=compile and run gpu

Change-Id: I8eac2f1dd93e058a50212e33e4379dd96df9f184
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2462552
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-10-12 18:16:37 +00:00
Chirantan Ekbote
b696d4feb2 fs: Don't use path-based operations
There are no *at variants for the xattr syscalls so we were using the
path-based variants by reading the /proc/self/fd symlink.  While this
symlink can track renames it cannot track if the user hard links the
file to some other location and then unlinks the original location.  In
this case the symlink simply shows that the path was deleted even though
the fd is still valid.

To deal with this, stop using the path-based method.  For regular files
and directories, we can simply open them and then make the appropriate
f{get,set,list,remove}xattr syscall.  For non-regular files and
directories we can emulate an *at syscall by changing the CWD to /proc
and then making the path-based syscall via the self/fd path.  Even
though the symlink is no longer valid, manipulating the fd via this path
still works.

BUG=b:168689429
TEST=Create a file, set an xattr, hard link it to a new location,
     unlink the original, and then verify that {get,set}fattr still
     works on the new link

Change-Id: Ic291f432b96f18e3e7ccbcf27737d5f8fd240a65
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437684
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-10-12 15:45:19 +00:00
Judy Hsiao
03cd6684c9 ac97: Support multi sample rate for playback
Enables VRA mode to support different sample rates for playback.
With the change, the resampling can be reduced in the GuestOS.

BUG=b:168082107
TEST=`sox -n -t s16 -c2 -r${RATE} synth sine 440 vol 0.1\
      | aplay -D hw:0,0 -r${RATE} -f S16_LE -c2` works
      correctly in the GuestOS.

Cq-Depend: chromium:2434114
Change-Id: I7d254173d41ac6b4688894113808785de9162b50
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2399167
Tested-by: Judy Hsiao <judyhsiao@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Judy Hsiao <judyhsiao@chromium.org>
Auto-Submit: Judy Hsiao <judyhsiao@chromium.org>
2020-10-09 12:59:33 +00:00
Alex Lau
aba864281b devices: virtio: video: Re-add queue_type to AsyncCmdTag::Clear
The queue_type field was removed in crrev.com/c/2408597 as
decoder is no longer using it, but it will be used by the encoder.

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

Change-Id: Iae552cc05b82eea67a7cff854ba350fb579a8f5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2456226
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-10-08 19:49:00 +00:00
David Stevens
32f4c4cfdd devices: virtio: video: cancel after clearing output queue
A recently introduced workaround for a VDA limitation caused clearing
the output queue to be handled synchronously instead of going through
the Async path used when clearing the input queue. This change makes
sure that we still cancel any pending resources on the output queue.

BUG=b:170053625
TEST=arc.VideoDecodeAccelPerf.vp9_2160p_60fps_vm 20 times w/o warnings

Change-Id: Ib24bdc3053c40ffb6f953021f29ef7a31ea216a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2452313
Tested-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2020-10-07 09:59:25 +00:00
Michael Hoyle
685316f0bd base: EventFd -> Event renaming
Note the CL size is large entirely due to the rename,
the changes are mostly negligible.

Also making a few small additional changes in sys_util
areas that don't need much attention in base. This includes
typedefing and adding specific imports for areas that don't
require significant interface changes.

BUG=b:162363783
TEST=./build_test

Change-Id: I4a2c9c4cdce7565806ed338e241c6b8c82c855c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2415180
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-06 13:50:09 +00:00
Chih-Yu Huang
8683e8e0a9 devices: virtio: video: handle ResourceDestroyAll for in/out queue separately
Originally we clear all the fields about both input and output
resource when either input or output queue gets ResourceDestroyAll
command.

In this CL, we handle this command for the input or output queue
separately.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrc

Change-Id: Ib7873a8192e9e0d01d6ea869eb8ea8661b6d1060
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2417793
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-01 18:53:46 +00:00
Chih-Yu Huang
0ebb18ce3f devices: virtio: video: split InputResources out of Context struct
At crrev.com/c/2416067 we split OutputResources out of Context struct.
Similiarly, this CL splits the fields that related to the input
resource to a dedicated struct `InputResources`.

Note that the field `res_id_to_res_handle` was shared by both input
and output resources. This CL split this field into both InputResources
and OutputResources struct.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrc

Change-Id: I664815078e08f1e78ec9de2f6674dbdedd7fd482
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2428486
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-01 18:53:45 +00:00
Chih-Yu Huang
7f880974e5 devices: virtio: video: re-design the methods of OutputResources
At crrev.com/c/2416067 we split the fields that are related to output
resource from Context struct out to OutputResources struct. Also, we
move the methods that only interact with these fields to the
OutputResources's implementation. However, these methods are designed
from the aspect of Context struct, not OutputResources.

In this CL, we re-design the method of OutputResources to make the
interaction between Context and OutputResources more clear.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrc

Change-Id: Ib9a3fad8e0d71159c07ce5345b067a2c9924a119
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2417791
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-01 18:53:44 +00:00
Chih-Yu Huang
3c77612eb3 devices: virtio: video: split OutputResources out of Context
Some fields of the `Context` struct are related to the output
resources. These fields should be cleared together. This CL
consolidates these fields to another struct to make the code clear.

Note that we add `keep_resources` and `set_output_buffer_count` fields
into OutputResources struct. Originally these two fields are not
cleared with other fields together. So this CL is not just a refactor
CL, it changes the reset logic.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_adaptiveDrc

Change-Id: I6843e835b6c488e74623704618ee54a5273eb7ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2416067
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-10-01 18:53:43 +00:00
Daniel Verkamp
10154a9310 devices: vfio: use separate MSI and MSI-X sockets
Previously, the VFIO code was using a single IRQ VM control socket
within an Arc<> container for both MSI and MSI-X; however, MsgSocket is
not technically Sync.  In order to remove the Sync trait from MsgSocket,
split the MSI and MSI-X uses into two separate sockets and remove the
Arc wrapper.

BUG=None
TEST=./build_test

Change-Id: Ib620521be3d02bc9b66c1cc771c34feb8622993c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2436399
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-09-30 20:08:13 +00:00
Michael Hoyle
08d86a44a0 base: Add timer package
Very little of substance is added here, just the base boilerplate

BUG=b:162363783
TEST=./build_test

Change-Id: I2e3b3b45cf1d7234784d769b4dced31f10a8774d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2366110
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-09-30 19:44:42 +00:00
Michael Hoyle
a7e38ab421 base: Add shared memory layer to base.
This is very largely boilerplate, but changes some interfaces
to accept different parameters, esp using Descriptor.

BUG=b:162363783
TEST=./build_test

Change-Id: I81b513c0de9448c2de505fe5d3a61a29f4eccb78
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2342591
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-09-30 19:44:40 +00:00
Chirantan Ekbote
48537d43b6 fs: Reduce unnecessary map lookups
Change the inner helper methods to take an &InodeData instead of an
Inode.  This removes the need to fetch the data from the map, which can
reduce unnecessary lookups when the calling method already has the data
on hand.

BUG=none
TEST=cargo test

Change-Id: Ia57a543e68d7aa63544f187bdefefe5a4d20c6a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437683
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-30 15:02:29 +00:00
Chirantan Ekbote
e367a1d0a4 fs: Drop unnecessary extra readdir function
Now that readdirplus is handled by the server there's no need to have a
separate do_readdir method. Just merge it into the readdir method.

BUG=none
TEST=cargo test

Change-Id: I77475a64a13316bfbcd97a91610c6aa2ec0a9aae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437682
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-30 15:02:28 +00:00
Chirantan Ekbote
53377a8495 fs: Add helper functions for common operations
Add helper functions for common operations so that we don't have to
copy-paste the same thing everywhere.

BUG=none
TEST=cargo test

Change-Id: Ia9dd132336470cdaa5ecef72945f23f6d1dd4401
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2437681
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-30 15:02:25 +00:00
Alistair Delva
a5b30b2eea devices: gpu: fix 64/32 compat issue with blob
Bug: b/169430664

Cq-Depend: chromium:2437134
Change-Id: I4b9fa7fe3f985abe803878a4b974e33214ff5fcb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2436998
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alistair Delva <adelva@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-09-29 23:12:59 +00:00
John Bates
b220eac0d3 devices: gpu: add support for mesa gpu shader cache
When requested with the --gpu=cache-path=/path arg, crosvm
will pass it to Mesa via env var MESA_GLSL_CACHE_DIR. In
addition, the cache-size will also be passed along if
provided.

BUG=b:168540438
TEST=run with --gpu=cache-path=/tmp,cache-size=50M and
 confirm that files are created in /tmp/mesa_shader_cache.

Change-Id: I2525597749d654a65373a723cefeab6cf2be62d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2415509
Tested-by: John Bates <jbates@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Riley <davidriley@chromium.org>
2020-09-29 19:02:24 +00:00
Alex Lau
ac010c3a8e devices: virtio: video: Implement Display for Format.
BUG=b:161774071
TEST=USE=test emerge-$BOARD crosvm

Change-Id: I3e6c338d72dadff7b998ba291a8b64741e4ff766
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2435034
Tested-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-09-29 17:02:47 +00:00
Chih-Yu Huang
2296c987cd devices: virtio: video: Fix QueueClear for output queue.
Originally crosvm calls VDA::reset() when either QueueClear the input
or output queue. However, VDA::reset() only drops input buffers,
not guarantee if drop output buffers.

This CL removes the VDA::reset() call when QueueClear output queue.
Instead, we only clear the records of all the queued output buffers.
Note that it's still a workaround. The correct solution is to expose
VDA::DismissPictureBuffer() to libvda, and then clear the record of
the dismissed output buffer.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_eosFlushSeek
     with related CLs

Change-Id: Ic88b8b9bb14e4b29f7859bf06bd2231cecc85776
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2408597
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-09-25 07:21:45 +00:00
Chih-Yu Huang
23885c9f87 devices: virtio: video: Clear output resource in ProvidePictureBuffers()
When ProvidePictureBuffers() is called, it means the VDA already drops
the previous set of output buffers. This CL clears the variables that
are related to the output resource in ProvidePictureBuffers().

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_eosFlushSeek
     with related CLs

Change-Id: I0e562fd216c6f2b91e4cbbe3ad174bca99003a0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2404511
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-09-25 07:21:44 +00:00
Chih-Yu Huang
d9f640c59d devices: virtio: video: Use the fixed buffer for notifying EOS
When VDA requests crosvm to allocate N output buffers, crosvm will
request the userspace to allocate N+1 output buffers. Then crosvm
keeps one output buffer for notifying EOS.

Originally, after the preserved buffer is dequeued to notify EOS,
crosvm might keep another output buffer for next EOS. If so, then
crosvm will register all the N+1 buffers to VDA.

This CL changes to fix the preserved buffer until VDA requests another
set of output buffers. Also, it introduces another variable to track
the resource ids of queued buffers.

BUG=b:168557465
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP8_eosFlushSeek
     with related CLs

Change-Id: I8a6018f9e889dc6a2b6ef67d4915d6202858a42a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2404512
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
2020-09-25 07:21:43 +00:00
Judy Hsiao
b4b94c7d64 ac97: Enables AEC when capture with the dedicated MIC
1. Captures with the AC97 dedicated MIC will have the AEC effect enabled.
2. Removes the "capture_effect" option in --ac97.

BUG=b:167946783
TEST=Record in the VM by `arecord -D hw:0,1 -f S16_LE -r 48000 -c 2\
     /tmp/a.out` and verify the opened stream has effect = 0x01 by
     `cras_test_client --dump_a`.
TEST=`cat /proc/asound/I82801AAICH/codec97#0/ac97#0-0 | grep \
     Capabilities` in the VM and verify "dedicated MIC PCM IN
     channel" is supported.
TEST=`amixer controls` and verify that 'Mic Capture Switch'
     and 'Mic Capture Volume' mixer controls show up.
TEST=Unit test.

Cq-Depend: chromium:2395855
Change-Id: I67bff9528175528e284f409fac1f51ecaaa89427
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2394983
Tested-by: Judy Hsiao <judyhsiao@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Judy Hsiao <judyhsiao@chromium.org>
2020-09-18 15:37:41 +00:00
Chirantan Ekbote
b52768cfb7 p9: Use crate from platform2
It doesn't make sense to have 2 versions of this crate as we end up
missing bug fixes like chromium:2324089.  Use the version from platform2
as that's updated more regularly.

BUG=b:167166153
TEST=Start a vm with a virtio-9p device and verify that it still works

Cq-Depend: chromium:2404987
Change-Id: I54abd88f64d599b68974c09a393c18ec830ecd76
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2404516
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-17 08:09:40 +00:00
Alexandre Courbot
ec48dd5304 devices: virtio: video: use filter iterator method
Use the filter iterator method instead of a specific in-block check to
filter out tags we want to keep.

BUG=None
TEST=Video plays in Youtube.

Change-Id: I8c34fadb548c26762e077a3ba6dde822b2fb864a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2409491
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-09-17 05:41:54 +00:00
Alexandre Courbot
615de2eb90 devices: virtio: video: move session creation to its own method
This makes the code a bit clearer.

BUG=None
TEST=Video plays in Youtube.

Change-Id: Ia904e693b692d70949afd529218dfc0aed7ec1b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2409490
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-09-17 05:41:54 +00:00
Alexandre Courbot
54dce6fb9c devices: virtio: video: remove redundant clone
We are taking ownership of params here, so no need to clone.

BUG=None
TEST=Video plays in Youtube.

Change-Id: I1013e669cde7e5d0001992d7620643054c03d87d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2409489
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-09-17 05:41:53 +00:00
Chirantan Ekbote
09357c8fb8 fs: Add case insensitive lookup
Needed by ArcVm.

BUG=b:162388795
TEST='echo foo > test.txt; stat TEST.TXT` works when ascii_casefold is
     enabled

Change-Id: Id2e720d6e9e9e511ee4ec6bb619a9fdbe2aa5d6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2403421
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-17 03:51:51 +00:00
Chirantan Ekbote
bf2c3eb497 fs: Clean up readdir handling
Switch from an FnMut for adding entries to an iterator-like approach.
We can't use the Iterator trait directly because the DirEntry struct has
a generic lifetime parameter and generic associated types are not
currently supported by the language.

Also provide an automatic implementation of readdirplus so that file
systems don't have to deal with some of its fiddly details.

Move the directory entry enumeration code into a separate re-usable
struct as we will need it for the casefold support in the next change.

BUG=b:162388795
TEST=vm.Virtiofs

Change-Id: I40c92468a4852f1e302c2e67877b7189268e9c9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2403420
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-09-17 03:51:49 +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
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
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
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
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
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
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
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
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
Steven Richman
24a89faeb3 Fix hypervisor and devices test compilation on ARM
Run unit tests for the old ioapic only on x86.  Fixes use statements in
hypervisor tests.  Run the hypervisor vcpu enable_feature test only on
x86, like in the kvm crate.

TEST=cargo test --no-run --target=aarch64-cros-linux-gnu
TEST=cargo test --no-run --target=aarch64-cros-linux-gnu -p devices
TEST=cargo test --no-run --target=aarch64-cros-linux-gnu -p hypervisor
BUG=1112839

Change-Id: Ie8dc152de6acd37b93e394642208a86a746c9308
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2337151
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Steven Richman <srichman@google.com>
Commit-Queue: Steven Richman <srichman@google.com>
2020-08-06 04:28:37 +00:00
Daniel Verkamp
379702c402 block: only send config interrupt on successful resize
If the resize failed (for example, if the block device was read only),
there is no need to notify the guest of a change in configuration space.
This prevents potential confusion due to the guest printing a capacity
change message even when the resize was unsuccessful.

BUG=None
TEST=`crosvm disk resize` a read-only disk (--disk)

Change-Id: Ica86654bf38d9fae9d681955438f52bce96dc427
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2324063
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-08-06 02:02:14 +00:00
Chirantan Ekbote
b9966c96c1 devices: Remove lifetime parameter from DescriptorChain
The lifetime parameter on the DescriptorChain struct ensures that it
doesn't outlive the GuestMemory that it references.  However, this has
the unfortunate effect that DescriptorChains cannot be sent across
thread boundaries (because they don't have a static lifetime).

Instead, have the DescriptorChain clone the GuestMemory instead.  This
ensures that the DescriptorChain will not outlive the GuestMemory while
also allowing it to be sent across thread boundaries.

dgreid - re-base and modify `next_async` to remove lifetime as well.

BUG=b:150264042
TEST=unit tests

Change-Id: I745d80d640c9766cbf36db0419c48fe077e0080d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2103601
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-08-05 22:35:16 +00:00
Daniel Verkamp
5f3931874b block: remove unnecessary drop
Clippy warns that this drop is not doing anything:

  error: calls to `std::mem::drop` with a reference instead of an owned
  value. Dropping a reference does nothing.

The code compiles without the drop, and resizing still works, so just
remove it.

BUG=None
TEST=bin/clippy
TEST=`crosvm disk resize 1 $((10*1024*1024*1024)) $SOCKET`

Change-Id: I1abf26fcd517a76b3007b70eb73545812a0dd79a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2324062
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-08-04 23:29:31 +00:00
paulhsia
36067153bf ac97: Skip flaky reg check in unit test
If the builder context switch to other tasks right after the
`bm.writeb`, then the results from `bm.readw` could be unexpected.

BUG=chromium:1086337
TEST=Build

Change-Id: I708b11ad3a556069a7b514f072222e913d91d643
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2330879
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
2020-07-31 23:30:56 +00:00
Zach Reizner
ff1194a0b5 block: make control_socket optional for worker thread
The Block device constructor takes an optional control_socket, but it
can't spawn worker threads without a control_socket. This change makes
the control_socket truly optional by allowing the worker thread to not
have a control_socket.

BUG=None
TEST=crosvm run && crosvm resize

Change-Id: I887e32cfb532e14c249340702ebc85101486a36e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2318368
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-07-28 12:35:12 +00:00
Alex Lau
640ef0fdc7 devices: virtio: video: convert VideoError to CmdResponse
This cleanup makes CmdResponse the only response type, rather than
writing VideoErrors directly. In addition, this makes all responses
easily cloneable for async event responses, which was not the case
before as VideoError encapsulates many uncloneable errors.

BUG=b:161774071
BUG=b:140082257
TEST=cargo clippy
TEST=USE=test emerge-$BOARD crosvm
TEST=play a YouTube video

Change-Id: Ife40e4d833899aae2e12612a12d277178c225ce2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311496
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-07-25 11:41:03 +00:00
Alex Lau
1fb6557c86 devices: virtio: video: allow sending multiple async responses on event
This will be used by encoder by allowing multiple responses from a mojo
VEA RequireInputBuffers event, as well as moving virtio-video specific
logic for sending EOS buffers and cancelling pending requests from
Worker::handle_event_resp.

BUG=b:160730771
BUG=b:140082257
TEST=cargo clippy
TEST=USE=test emerge-$BOARD crosvm
TEST=play a YouTube video

Change-Id: I19bce3b04e736aac0e686d9cb309976108e61033
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2309893
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-07-25 11:41:03 +00:00
Alex Lau
4b9b7ea604 devices: virtio: video: Pass DescPool by reference
This does not change any behavior.

BUG=b:140082257
BUG=b:161774071
TEST=cargo clippy
TEST=USE=test emerge-$BOARD crosvm
TEST=deploy and play YouTube video

Change-Id: I3a649ee0657a53deaf8ab40471bb9440b06807e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2305500
Reviewed-by: Alex Lau <alexlau@chromium.org>
Tested-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-07-25 11:41:01 +00:00
Dylan Reid
ec058d6c46 vm_memory: A crate to hold vm-specific memory objects
Move GuestAddress and GuestMemory to a new crate for VM memory. This
will make separating sys_util and crosvm independent making it easier
to use sys_util functions outside of crosvm.

Change-Id: I12e14948ea85754dfa6267b3a3fb32b77ef6796e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311251
Auto-Submit: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-24 21:42:34 +00:00
Daniel Verkamp
0c40f609d2 gfxstream: remove unused Unsupported error variant
This was introduced in a CL that did not use it, so it seems to be
unnecessary (maybe copy-pasted from another error enum).

Fixes a clippy warning:

  error: variant is never constructed: `Unsupported`

BUG=None
TEST=bin/clippy

Change-Id: Iaccf6c86a5ef9e36efad1053776b6ee2db53a2cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2316379
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-24 05:10:25 +00:00
Colin Downs-Razouk
9e0a85e664 devices: pit lazy thread creation
Currently the PIT creates a thread when the Pit object is instantiated,
but this is a problem when sandboxing is enabled, because minijail does
not want to fork when there is more than one thread.

This change updates the PIT to only create the woker thread once the PIT
has been read from or written to.

Split irqchip mode still does not seem to quite work in sandbox mode,
there appears to be some other sort of bug, but when run with the
hypervisor abstraction it does run. So this fix is mostly applicable
once hypervisor abstraction has been integrated.

BUG=chromium:1077058
TEST=ran test VM with --split-irqchip without --disable-sandbox and it
gets further than before, plus ran cargo test -p devices.

Change-Id: Idf511bde825d4a004f1492dcbd27f6829e872735
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2304258
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-07-23 20:38:45 +00:00
Alexandre Courbot
cd0b65f3a5 devices: video: do not request the context several times in a method
In some methods the context was queried several times, which complicates
the code a bit and potentially generates error-handling code that cannot
possibly be used once the context has been successfully obtained once.

Merge all these context requests into a single one for each method.

BUG=b:161774071
TEST=crosvm builds

Change-Id: Ia4a5036a0ed0fd20a928c448e62fdd8e37e8a914
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311497
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-07-23 10:21:26 +00:00
Lingfeng Yang
745081a31f gfxstream: Add submit cmd support
Needed for syncfd support (transfer doesnt come with fence
import/export)

Needed for address space graphics protocol on virtio-gpu

BUG=b/156130048

Change-Id: If6f55985f04fd8a2862650b2cbd37a3ab816fb90
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2224015
Commit-Queue: Lingfeng Yang <lfy@google.com>
Tested-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-23 04:15:07 +00:00
Gurchetan Singh
f2b29b8dfb devices: gpu: set scanout blob
Blobs contain explicit metadata about scanout buffers that is
only inferred otherwise. This is useful for possible YUV with
virtio-gpu-2d or compressed 3d formats. The format modifier is
intentionally left out since virtualized KMS can not guarantee
that the host compositor will support a certain modifier at any
particular moment -- this can be queried from virglrenderer if
need be.

BUG=chromium:924405
TEST=compile and test

Change-Id: I3130df18378f40193118b78d03f564b7f5984d67
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2250460
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-07-21 20:59:41 +00:00
Daniel Verkamp
da6a1ddda4 devices: pci: add function to iterate over BARs
The new get_bars() function will be used to find all of the memory
and/or I/O BARs that need to be added to or removed from the bus objects
(mmio_bus and io_bus) and KVM mappings to handle guest-initiated
remapping of BAR locations.

BUG=None
TEST=cargo test -p devices
TEST=Boot vm_kernel in crosvm

Change-Id: Ic559abc2a22dee7c3d5c96d242ceaf2154135eb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2300693
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-21 20:24:34 +00:00
Daniel Verkamp
de0bbc9fab devices: pci: store BAR configurations
This simplifies the code that wants to access per-BAR properties like
size and type; rather than recalculating it from PCI register contents,
it can directly access the data that is already in the desired Rust
types.

BUG=None
TEST=cargo test -p devices pci

Change-Id: I073d39c605899053ad3497c4d0140432b343b793
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2308075
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-21 20:24:33 +00:00
Daniel Verkamp
de06f15777 devices: pci: enforce minimum valid BAR sizes
PCI BARs have a minimum size based on the number of bits reserved for
the type bitfield, which is stored in the low bits of each BAR.  The
minimum size is derived from the number of bits used to store the type:
2 bits (4-byte minimum) for I/O bars and 4 bits (16-byte minimum) for
memory BARs.

Previously, since the minimum size was not enforced, callers could
create invalid configurations that would allow the guest to overwrite
the type bits of the BARs.  Luckily, this only happened in the unit
tests, which are fixed in this change.

BUG=None
TEST=cargo test -p devices

Change-Id: I30d65485254b49655c9ad7bec51e43533fe2c01d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2300692
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-07-21 20:24:30 +00:00
Alex Lau
6fc81e1cd1 crosvm: Fix H264 profile conversion in decoder.
Decoder currently ends up converting from H264 baseline profile provided
by virtio-video to H264 main profile to libvda.

BUG=b:161421220
BUG=b:140082257
TEST=cargo clippy
TEST=emerge-$BOARD dev-rust/libvda crosvm, start arcvm and play video in YouTube

Cq-Depend: chromium:2299802, chromium:2299604
Change-Id: I946af99b918b22b4dcb0e9ebab044c83f39ed9bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2301325
Tested-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-07-17 23:21:13 +00:00
Alex Lau
48a494bafd crosvm: Add missing virtio-video profiles and convert to correct virtio profile in decoder.
Add missing virtio-video profiles and convert to them from libvda profiles.

BUG=b:161261612
BUG=b:140082257
TEST=cargo clippy
TEST=emerge-$BOARD dev-rust/libvda crosvm, start arcvm and play video in YouTube

Cq-Depend: chromium:2299802, chromium:2301325
Change-Id: I061c7eddc881eb785aa7c06cf587cc747007cb74
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2299604
Reviewed-by: Alex Lau <alexlau@chromium.org>
Tested-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-07-17 23:21:11 +00:00
Chirantan Ekbote
2135787b74 devices: fs: Support FS_IOC_{GET,SET}FLAGS
Needed by arcvm.

BUG=b:159870893
TEST=`lsattr foo` and `chattr +S foo` inside a VM.  Check with strace
     that it's making the ioctl.

Cq-Depend: chromium:2297090
Change-Id: I11b490062b3c777c0cf4543f3d09f94e3790453b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2297004
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Lepton Wu <lepton@chromium.org>
2020-07-17 22:30:32 +00:00
Colin Downs-Razouk
e00cd6826c devices: irqchip: kvm: route and event issues
Fixes for several bugs found in the KvmKernelIrqChip and the
KvmSplitIrqChip that were found while testing the hypervisor abstraction
layer integration:
  - Fixed determination of which routes are MSI routes when setting
  routes in KVM.
  - Fixed issue with setting conflicting routes.
  - Updated service_irq_event to read the associated EventFd that
  triggered the irq event, and updated the documentation. Also updated
  KvmKernelIrqChip's implementation to simply print an error because
  that function should never be called on KvmKernelIrqChip.
  - Fixed a bug with add_vcpu in both KvmKernelIrqChip and
  KvmSplitIrqChip.

BUG=chromium:1077058
TEST=added a new test, ran devices tests, ran a VM with abstraction
  integration changes with both irqchips

Change-Id: I255fbe498f6586d90cb196ff173a574a2cae0453
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2300843
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-07-16 21:13:28 +00:00
Andrew Scull
1590e6fb3e Add feature flag for audio.
This will allow it to be disabled for Protected KVM usecases on Android.

BUG=b:158290206
TEST=cargo test

Change-Id: Ibddd8a98c42bb0847aba804f5e33df29feedd783
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2292372
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2020-07-16 17:57:55 +00:00
Colin Downs-Razouk
fe368791f8 devices: irqchip: KvmSplitIrqChip impl
Implementation of a KVM split irqchip. KVM's "split irqchip"
functionality only works for x86/x86_64 so this is implemented in the
kvm/x86_64.rs sub-module. The chip has a userspace Pic, Ioapic, and Pit.

This change necessitated a couple modifications to the irqchip traits:
  - The create_pit function has been removed, and it's now implied that
  the creation of the irqchip handles the creation of the pit.
  - A finalize_devices function has been added. This function will need
  to be called on the irqchip after all devices have been setup. The
  purpose of finalize_devices is to allow the irqchip to register any
  userspace devices with the io_bus or mmio_bus, and for the irqchip to
  supply any necessary EventFds to these devices.
  - A service_irq_event function has been added. This function works a
  lot like the service_irq function, except it's specifically designed
  to work the same way an IRQFD works: it first asserts then immediately
  deasserts the line. If a resamplefd is associated with the irq line,
  the deassert doesn't happen immediately, but happens when an EOI
  occurs for a vector associated with the line. The service_irq function
  will still exist for unittests.
  - A process_delayed_irq_events function has been added. There
  is a case where a deadlock can occur if the main thread blocks on
  locking the ioapic in order to service an irq event, while a vcpu
  thread holding the ioapic lock waits on the main thread to process the
  addition of a MSI route. So the irqchip delays the servicing of irq
  events if it finds a locked ioapic, and the
  process_delayed_irq_events function should be called regularly
  by the main thread in order to re-try servicing any delayed irq events.

Bug: chromium:1077058
Test: split irqchip runs all available x86-specific irqchip tests.
  Also added some tests specific for the split irqchip. Ran these tests
  and cargo test -p hypervisor -p devices

Change-Id: I14866645b86b3bf318440051069ff165e2cf9d88
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2290192
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-07-16 00:45:31 +00:00
Gurchetan Singh
7b652a3011 devices: gpu: send back map response
To validate caching from the host.

BUG=chromium:924405
TEST=compile and test

Change-Id: I3292c938df442d1162ad994103ba3fd7e6f2f16c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2160032
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-07-15 23:54:19 +00:00
Gurchetan Singh
2ced42be12 devices: gpu: src: v2 to blob
- Use upstream's preferred nomenclature
- Move to create blob to 2D hypercall group

BUG=chromium:924405
TEST=compile and test

Change-Id: I8676cd5d24e80009266c7bbf8c4b8d734b932672
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2160031
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-07-10 22:26:54 +00:00
Kaiyi Li
6c52a2e0c8 gpu_renderer: add vulkan flag for gfxstream
Add a gpu argument to control whether vulkan support should be enabled
for gfxstream backend. Default to enabled.

BUG=None
TEST=launch_cvd

Change-Id: Icf9b24890f7c0da30f6c64326391037c6df1c853
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2286238
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-10 20:01:56 +00:00
Kaiyi Li
6404e457b5 gpu_renderer: add syncfd flag for gfxstream
Add a gpu argument to control the syncfd of gfxstream implemented in
these CL: https://android-review.googlesource.com/q/topic:%22gfxstream-sync-fd%22+(status:open%20OR%20status:merged).
Default to enabled.

BUG=None
TEST=launch_cvd

Change-Id: Id4933b8654fc1b1bb73784bd8e1a85e73d0266d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2286237
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-10 20:01:54 +00:00
Colin Downs-Razouk
963e2ddcf2 devices: irqchip: lapic state
Added get/set_lapic_state functions to KvmKernelIrqChip and KvmVcpu.
Added tests for the KvmKernelIrqChip.

BUG=chromium:1077058
TEST=added associated tests for get/set_lapic_state

Change-Id: I0f1cebd9db370b5453a951f7827de511399cddf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2260929
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-07-08 01:36:24 +00:00
Alex Lau
3ce03649ad crosvm: Fix compiling video decoder with updated libvda decode bindings
BUG=b:140082257
TEST=emerge-$BOARD dev-rust/libvda crosvm

Cq-Depend: chromium:2282874
Change-Id: I7379209d49c8d4eea51788ccfcbed08242994712
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2282873
Tested-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-07-07 22:24:50 +00:00
Colin Downs-Razouk
0ae7c7c765 devices: irqchip: mp state
Added an emum for MPState, and functions to translate between MPState
and kvm_mp_state. Added get_mp_state and set_mp_state functions to KvmVm
and the IrqChip interface.

BUG=chromium:1077058
TEST=added associated tests for get/set_mp_state

Change-Id: I0825f81b1b4d85884690606d691e8b88e8306ae1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2261293
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-07-07 19:49:41 +00:00
Colin Downs-Razouk
ce34d94b0e devices: irqchip: make generic x86 irqchip tests
In preparation of the KvmSplitIrqChip, moving tests out of the
irqchip::kvm module and into the irqchip::x86_64 module. This is because
the tests should be valid for any implementation of the IrqChipX86_64
trait.

Bug: chromium:1077058
Test: cargo test -p devices -p hypervisor
Change-Id: I57a15b275bce5e7d96f2736367b7aaef6b069fec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2276322
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-07-06 19:12:10 +00:00
Colin Downs-Razouk
52e0cbf40c devices: pit updates for hypervisor abstraction
Update the pit to have get/set functions so it can be used as part of an
irqchip. Some of this translation is imprecise because we use a rust
Instant for storing the timer start time, where the PitState expects it
in terms of the host's monotonic clock, but it shouldn't really matter
because getting/setting the pit is only exposed as a plugin feature.

This also required adding some convenience functions to the sys_util
Clock.

Bug: chromium:1077058
Test: cargo test -p devices
Change-Id: I761747cd03ed123a2d2e685e0679a3d025a165ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2265043
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-07-06 19:12:08 +00:00
Dylan Reid
95f1bca33a devices: interrupt: add simple resample
Instead of coupling the reading of the event fd and the resampling of
the interrupt, add a separate member to just do the resample.

This will be used by async code that waits for and reads the event fd in
one step.

Change-Id: Ic5b1fd9adf8e32a572f31dc1c0c5ab32e94f4981
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2268978
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-06-30 09:00:50 +00:00
Chirantan Ekbote
44336b9131 devices: fs: Fix posix acl handling
Posix acls are a truly incredible example of API design.  The presence
of a default posix acl in a directory completely changes the meaning of
the `mode` parameter for all system call that create inodes.  However,
this new behavior only applies when the inode is first created and not
for any subsequent operations that use the mode, like fchmod.

When a directory has a default posix acl, all inodes created in that
directory get the permissions specified in the default acl.  The mode
parameter is treated like a umask where any permissions allowed by the
default acl that are not allowed by the mode parameter are blocked.  The
actual umask is ignored in this case.

So to handle this properly we need to set FUSE_DONT_MASK to prevent the
kernel driver from preemptively applying the umask.  Then we have to
check if the parent directory has a default posix acl and only apply the
umask to the mode if it does not.  This also means that we cannot use
`mkdtemp` because that always creates directories with a mode of 0o700
and since the default posix acl calculation only applies on creation and
not on later operations, we need to apply the proper mode in the very
beginning.

BUG=b:159285544,b:152806644
TEST=vm.Virtiofs.  Use a test program to create files/directories in
     directories that have a default acl and ones that don't, and verify
     that the mode is correctly set after creation

Change-Id: Ieca8ac9db391feebe5719630c5f3b57b04b71533
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2260253
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
2020-06-29 10:14:42 +00:00
Judy Hsiao
fedb4eddbf ac97: Support 2, 4 and 6 output channels
1. Turn on the Extended Audio ID Register D6-8 to indicate the capability to
   support PCM Center DAC(CDAC), Surround L&R DACs (SDAC), PCM LFE DAC
   (LDAC).
2. Turn on the Global Status Register D21:20 to support 4 and 6 channels
   on PCM out.
3. Read the Global Control Register to configure the output channel count.
4. Enable start_playback unit test, and add assert for output stream channel count.

BUG=b:157433024
TEST=`sox -n -t s16 -r48000 -c2 - synth sine 440 vol 0.1 | aplay -D
hw:0,0 -f S16_LE -r 48000 -c 2`
TEST=`sox -n -t s16 -r48000 -c4 - synth sine 440 vol 0.1 | aplay -D
hw:0,0 -f S16_LE -r 48000 -c 4`
TEST=`sox -n -t s16 -r48000 -c6 - synth sine 440 vol 0.1 | aplay -D
hw:0,0 -f S16_LE -r 48000 -c 6`
TEST=cras_test_client --dump_a to check the num_channels of the opened
stream matches the aplay -c param.
TEST=cargo test

Cq-Depend: chromium:2259312
Change-Id: I2e1e48e78387b1b4bba72c63e6c93bf7b8012ea8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2256078
Tested-by: Judy Hsiao <judyhsiao@chromium.org>
Auto-Submit: Judy Hsiao <judyhsiao@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2020-06-28 06:22:36 +00:00
Dylan Reid
81a87845b0 devices: queue: Add async descriptor fetching
Allow `Queue` to return descriptors asynchronously.

Asynchronous descriptors can be used by devices to replace their poll
loops with async functions.

TEST=cargo test.

Change-Id: I93ba4612ccf2f8ba8e77458fd5474cada705a9b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2167692
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-06-26 18:22:10 +00:00
Allen Webb
f3024c8976 io_jail: Remove now that the code lives in aosp/external/minijail
io_jail has been migrated to aosp/external/minijail/rust/minijail.
This removes the crosvm copy and updates the references to use the new
location.

BUG=chromium:1096175
TEST=cargo test

Cq-Depend: chromium:2254418
Change-Id: I29d5c6178b6faf5e52671cfbe6fc7e51f0d21dd2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2254298
Tested-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Allen Webb <allenwebb@google.com>
2020-06-26 17:27:44 +00:00
Chirantan Ekbote
dc82c819f6 devices: fs: Implement FS_IOC_FSSETXATTR
Needed by arcvm.

BUG=b:159297591
TEST=run a test program that calls the ioctl

Change-Id: I1f8c17fa2b2457f5a9e73045c3dbee3440eb943d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2265932
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-06-26 09:10:32 +00:00
Chirantan Ekbote
d8447077f0 devices: fs: Fix linkat impl
Using AT_EMPTY_PATH with linkat requires the caller to have
CAP_DAC_READ_SEARCH in the init user namespace.  Since the fs device
isn't going to have this when run in a sandbox, switch to using
/proc/self/fd with AT_SYMLINK_FOLLOW instead, which is documented in the
manpage as an alternative to AT_EMPTY_PATH.

BUG=b:159861594
TEST=`touch foo; ln foo bar` succeeds

Change-Id: I944d80d955742d653e36d245024adc48cf77d77e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2265933
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-06-26 06:23:50 +00:00
Colin Downs-Razouk
b865569893 devices: irqchip: updated ioapic implementation
Modified ioapic implementation for the hypervisor abstraction layer.
This implementation has the same functionality and tests as the existing
one, but accepts a vec of resample_events instead of a GsiRelay. It also
takes a list of irqfds instead of creating them itself.

This will be used by the KvmSplitIrqChip, and will eventualy be modified
again to support an ApicBus when we want to support a UserspaceIrqChip.

Bug: chromium:1077058
Test: cargo test -p hypervisor -p devices
Change-Id: I306724266511a7975a25a34955651ea6f53e1c4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2255303
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-06-25 18:15:30 +00:00
Colin Downs-Razouk
6583fa8d6a devices: irqchip: updated pic implementation
Copied and slightly modified pic implementation in the irqchip
submodule. It uses the PicState defined in the hypervisor crate and has
a register_resample_events function instead of a register_relay
function.

Some function signatures have been slightly changed to take &self and
&mut self where before they would take a PicState. This was done so
that the Pic struct itself would be the only object that needs access
to the resample_events rather than each PicState needing it's own copy
or clone.

This will later be used by the the KvmSplitIrqChip.

Test: cargo test -p devices -p hypervisor
Bug: chromium:1077058
Change-Id: Ia15ea1800b4339d3ad38d88d8ec6ace8ca5ea67a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2255302
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-06-25 18:15:24 +00:00
Steven Richman
07a0706829 hypervisor: add vcpu new and run
Vcpus are created on the Vm object, instead of with Vcpu::new.  Vm keeps
a copy of the Hypervisor to support create_vcpu.  Otherwise the methods
are the same as the kvm crate.

BUG=chromium:1077058
TEST=cargo test

Change-Id: I6fbd0e5fb5d81d4362a259e85eb392d8edbfff1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2247366
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Steven Richman <srichman@google.com>
2020-06-25 14:38:18 +00:00
Chirantan Ekbote
5d6a17f4b2 devices: fs: Enable posix_acl support
Advertise that we support posix acls in the response to the init
message.  Since the VM does access checks before sending the request to
the server, having this disabled meant that the VM was rejecting
requests that should have been allowed to succeed.

BUG=b:159285544
TEST=touch test
     setfacl -m u:crosvm:rw test
     su -s /bin/bash -c 'echo hello > test' crosvm
     cat test # check that it contains "hello"

Change-Id: I047b590e4caf0f2883b3f6198b9bc071e9e40a93
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2253494
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-06-21 20:33:09 +00:00
Chirantan Ekbote
91dc84471f devices: fs: Respect setgid bit on directories
The switch to 2 stage mkdir + create broke setgid bit handling on
directories.  When this bit is set in a directory all inodes in that
directory should be created with the gid of that directory rather than
the gid of the process that made the call.

BUG=b:152806644
TEST=Set the sgid bit on a directory and verify that new files and
     directories inherit the directory's group rather than the group of
     the process that created them.

Change-Id: Iafce9fbb4281b2dc84e052e0a703745dde4b817b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2253493
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-06-21 20:33:08 +00:00
Chirantan Ekbote
ad356fb327 devices: fs: Ignore umask
We don't set FUSE_DONT_MASK so the guest kernel will apply the umask
to the mode before sending the request.  Just pass it on unmodified.

BUG=b:152806644
TEST=vm.Virtiofs

Change-Id: Id0c138e9ccc3a361a2772ac144f1d3413b545d99
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2253492
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-06-21 20:33:07 +00:00
Gurchetan Singh
9fd8540ab0 devices: virtio: use device specific shm regions
Mostly to stop using virtio-fs region IDs in virtio-gpu.

From the spec:

"A device may have multiple shared memory regions associated with
it. Each region has a shmid to identify it, the meaning
of which is device-specific."

BUG=chromium:924405
TEST=compile and test

Change-Id: I5b938a1dbe8747812d77384f1781ccc1bd883e9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2160030
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
2020-06-20 08:39:35 +00:00
Colin Downs-Razouk
6364823093 devices: irqchip: finish KvmKernelIrqchip impl
Implemented the remaining IrqChip trait functions for the
KvmKernelIrqChip, including register/unregister_irq_event and irq
routing functions.

Added some irqchip tests for setting irq routes and servicing irq lines.
Also added tests for registering irq events.

BUG=chromium:1077058
TEST=cargo test -p devices -p hypervisor

Change-Id: Ia04c927b663ebdcacc88bc61d746077aa5b02514
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2246648
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-06-17 23:49:31 +00:00
Chirantan Ekbote
d994e51b28 devices: fs: Add option to rewrite security xattrs
Writing xattrs in the security namespace requires CAP_SYS_ADMIN in the
namespace that mounted the file system.  The fs device doesn't have this
capability when run in a sandbox (and in the case of the /home directory
on chrome os, will never be able to gain it).

We've been able to set selinux xattrs so far because the selinux module
relaxes the capability check in favor of an selinux-based MAC check.
However, android also wants to be able to set the "security.sehash"
xattr, which is described in the manpage as a "performance optimization"
when recursively relabeling files.

Unfortunately since the android team nacked the kernel patch[1] that
would have relaxed the requirements for just the "security.sehash"
xattr, the only option for us is to rewrite the xattr name and prefix it
with "user.virtiofs" so that it ends up in the "user." xattr namespace.
The server should always have permission to create xattrs there.

BUG=b:155443663
TEST=start a vm and successfully set the security.sehash xattr then
     check on the host side that it is actually stored as
     user.virtiofs.security.sehash

[1]: https://www.spinics.net/lists/selinux/msg32330.html

Change-Id: Icd17b76c946c92d92009f0cc2b8b50c92ac580c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2243111
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-06-17 15:19:40 +00:00
Chirantan Ekbote
df71719d7f devices: fs: Support FS_IOC_FSGETXATTR
Arcvm needs this ioctl for looking up the project id of an inode.

BUG=b:157189438
TEST=Call the ioctl inside a vm and verify that it succeeds

Change-Id: Ib178cf32b09056f9b1e9acedb49de068d5525a66
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2214964
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Matthias Springer <springerm@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-06-16 11:13:14 +00:00
Colin Downs-Razouk
3f786c1716 devices: irqchip: Aarch64 trait and impl
Split the KvmKernelIrqchip struct definition and constructor between
x86_64 and aarch64 because aarch64 has an extra fd for the vgic device.
Constructor on x86_64 simply calls create_irq_chip while aarch64
constructor needs to call create_device and configure that device.

Also needed to split the try_clone implementation because the structs
have different fields.

Bug: chromium:1077058
Test: ran build_test, but I haven't been able to actually run the tests
  on aarch64

Change-Id: I20e81a7ccedaf077d682055717caf05a94d54423
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2239976
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-06-15 04:44:37 +00:00
Keiichi Watanabe
4ffb3d06bd devices: video: dec: Support arbitrary buffers to be mapped as resources
Support a case where a guest client who may use arbitrary numbers of
buffers. (e.g. C2V4L2Component with default pool in ARCVM)
Such a client is valid as long as it uses at most 32 buffers at the same
time.

More specifically, this CL allows the guest to call ResourceCreate for an
output resource_id which was already processed by the host. Such
ResourceCreate calls will be handled as reassignment of DMAbuf to a
FrameBufferId.

BUG=b:157702336
TEST=Play a YouTube video on ARCVM w/ C2V4L2Component using default pool

Change-Id: Ie9c457867abd91b6b7a17a5bca4a1a1e9f53c1ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2198327
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-06-12 00:53:24 +00:00
Steven Richman
7c359d617f hypervisor: add Vm user memory region functions
The separate Vm functions for MemoryMappings and MemoryMappingArenas
have been combined and now use a MappedRegion trait that the mappings
implement.  msync_memory_region replaces the get_mmap_arena function,
which is used by VmMsyncRequest.  Since Vm uses mutexes for cloning, it
can't return mem region references.

BUG=chromium:1077058
TEST=cargo test, cargo test -p sys_util, cargo test -p hypervisor

Change-Id: If257b16ee34d07820ae7ebdb9a3a598a41df013c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2202845
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-06-10 17:08:55 +00:00
Colin Downs-Razouk
2a0ce34f31 devices: irqchip: KvmKernelIrqchip x86_64 impl
Implemented get/set_pic/ioapic/pit functions for the KvmKernelIrqchip.
Added respective functions on KvmVm for interacting with the underlying
KVM API.

Added associated tests for get/set functions.

BUG=chromium:1077058
TEST=ran devices tests and added get/set function tests

Change-Id: I66a29828fe2f1fbdf54d7325656a003ac09e36d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2219422
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-06-10 16:33:35 +00:00
Colin Downs-Razouk
ba76624370 devices: irqchip: IrqChipX86_64 trait
This trait handles the x86-specific features of an irqchip, including
getting and setting the state of the pic, ioapic, lapics, and pit.

Also includes an empty implementation of this trait for the
KvmKernelIrqChip.

BUG=chromium:1077058
TEST=cargo test -p devices

Change-Id: I36034661f4a2baedc7ac2b8f311cab6327afefba
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197717
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-06-04 19:17:44 +00:00
Chirantan Ekbote
814a8da0ed devices: fs: Use 2 stage create and mkdir
When creating a file or directory the virtio-fs server changes its
effective uid and gid to the uid and gid of the process that made the
call.  This ensures that the file or directory has the correct owner and
group when it is created and also serves as an access check to ensure
that the process that made the call has permission to modify the parent
directory.

However, this causes an EACCES error when the following conditions are
met:

  * The parent directory has g+rw permissions with gid A
  * The process has gid B but has A in its list of supplementary groups

In this case the fuse context only contains gid B, which doesn't have
permission to modify the parent directory.

Unfortunately there's no way for us to detect this on the server side so
instead we just have to rely on the permission checks carried out by the
kernel driver. If the server receives a create call, then assume that
the kernel has verified that the process is allowed to create that
file/directory and just create it without changing the server thread's
uid and gid.

Additionally, in order to ensure that a newly created file appears
atomically in the parent directory with the proper owner and group,
change the create implementation to use `O_TMPFILE` and `linkat` as
described in the open(2) manpage.  There is no `O_TMPFILE` equivalent
for directories so create a "hidden" directory with a randomly generated
name, modify the uid/gid and mode, and then rename it into place.

BUG=b:156696212
TEST=tast run $DUT vm.Virtiofs
TEST=Create a test directory with group wayland and permissions g+rw.
     Then run `su -s /bin/bash -c 'touch ${dir}/foo' - crosvm` and
     `su -s /bin/bash -c 'mkdir ${dir}/bar' - crosvm`.

Change-Id: If5fbcb1b011664c7c1ac29542a2f90d129c34962
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2217534
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-06-04 12:49:49 +00:00
Chirantan Ekbote
c4707badd0 devices: fs: Refactor ioctl handling code
Now that the ioctl number method is const we can use a match statement
rather than a series of if-else expressions.

BUG=b:157189438
TEST=unit tests

Change-Id: I9839f2de842ec512811101c07445ca5f99f3fe2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2214963
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-06-04 06:09:31 +00:00
Dylan Reid
2705264dc6 pci: ac97: Fix unused import warning
The Error type is not used, remove it.

Change-Id: Ibcc1328b62635dd62a666412eb0f56a8c2f4fc93
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2224013
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
2020-06-01 22:12:23 +00:00
Judy Hsiao
04a2881b03 ac97: Uses audio_streams::BoxError
audio_streams export BoxError which can be passed between threads.
Adopts the API change accordingly.

BUG=b:149437381
TEST=emerge-{BOARD} crosvm

Cq-Depend: chromium:2215772
Change-Id: I524e9d7ab3c16b7b6d3714187f166dce72d243cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2214971
Tested-by: Judy Hsiao <judyhsiao@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Judy Hsiao <judyhsiao@chromium.org>
2020-06-01 09:58:50 +00:00
Chirantan Ekbote
1a9f2a5454 sys_util: Refactor IntoIovec
The original stated purpose of this trait was to reduce memory
allocations but having the `into_iovec` method return a Vec kind of
defeats that purpose.

Refactor the trait so that it can either convert a T into an iovec or
convert a &[T] into a &[iovec].  Implement the trait for VolatileSlice,
IoSlice, and IoSliceMut and update all the callers.

BUG=none
TEST=unit tests

Cq-Depend: chromium:2210272
Change-Id: I9d0d617a23030d241d50411f4a5a16e7cba4bcee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2208527
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-05-28 07:14:58 +00:00
Daniel Verkamp
247134fe68 devices: usb: add unit test for ring buffer cycle
Validate that the toggle_cycle code works as expected.

I initially misunderstood the behavior of toggle_cycle in the Link TRB,
but it appears to work correctly as written after writing a unit test to
verify my understanding.  Add the unit test anyway to be sure the
behavior doesn't regress in the future.

BUG=None
TEST=cargo test -p devices

Change-Id: I9dbc34b26225945fa6d31c34261f53d5b64ba259
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2199956
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-05-27 06:03:49 +00:00
Daniel Verkamp
ddd8180a13 Fix VolatileSlice calls in all modules
The VolatileSlice API changed, but some callers were not updated to
match.  Fix them up so that builds with additional features enabled
(e.g. kokoro) pass again.

BUG=None
TEST=cargo test -p disk --features=composite-disk
TEST=docker/wrapped_smoke_test.sh

Change-Id: I97b3cd04549af30b7dc1515245f025d9439669bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2216399
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-05-27 04:46:31 +00:00
Chirantan Ekbote
e7d1221c9d Make VolatileSlice ABI-compatible with iovec
Change VolatileSlice so that it is ABI-compatible with iovec.  This
allows us to directly pass in a VolatileSlice for a C function that
expects an iovec without having to create temporaries that convert from
one to the other.

Also change all the parameters from u64 to usize.  It's not possible to
address more memory than fits into a usize so having u64 here didn't
really provide much benefit and led to a lot of tedious casting back and
forth all over the place.

BUG=none
TEST=unit tests

Cq-Depend: chromium:2206621
Change-Id: I258f9123c603d9a4c6c5e2d4d10eb4aedf74466d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2203998
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-05-25 19:14:07 +00:00
Keiichi Watanabe
be5824412c devices: virtio: video: Implement video decoder device
Implement virtio-video decoder which supports hardware-accelerated video
decoding backed by libvda.

Note that this implementation assumes that a guest client uses a fixed-size
set of output buffers. We support a case where arbitrary numbers of buffers
are used by a client like C2V4L2Component in the next CL.

BUG=b:147465619
TEST=Run v4l2-decoder-sample on ARCVM R
TEST=Play YouTube videos on ARCVM R with C2VDAComponent

Change-Id: I3a19381f923ba9c9c0d587dc4ff2c2ee3b31269d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1991380
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-05-23 09:55:43 +00:00
Keiichi Watanabe
57df6a0ab2 devices: virtio: Initial implementation of virtio-video device
This CL adds a fundamental part of the virtio video device, which will
be shared between the encoder and the decoder.
Both devices uses the virtio-video protocol proposed as RFC v3 [1,2].
The corresponding driver code is at CL:2060327 and its children CLs.

The actual decoding and encoding logic will be implemented in different
CLs.

[1]: mail: https://markmail.org/thread/wxdne5re7aaugbjg
[2]: PDF: https://drive.google.com/file/d/1jOsS2WdVhL4PpcWLO8Zukq5J0fXDiWn-/view

BUG=b:147465619, b:140082257
TEST=cargo check --features=video-decoder,video-encoder
TEST=ARCVM started with --video-decoder --video-encoder

Cq-Depend: chromium:2203997
Change-Id: I01999eea218ba0f3aaed1558ca2311a57d0c6819
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1973973
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-05-23 09:54:13 +00:00
Gurchetan Singh
b2ca24c97b devices: gpu: random cleanup
- Remove unused phantom data
- scannout --> scanout

BUG=none
TEST=compile

Change-Id: I5054833025eef5be766b547fa3e61d2ca46e226f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2211154
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-05-22 03:19:02 +00:00
Colin Downs-Razouk
43b1bc8f8f devices: irqchip: new irqchip module
This new module contains the irqchip trait and it's implementations. The
irqchips will work with the new hypervisor crate to abstract the
interaction between crosvm and kvm.

This just defines the irqchip trait and an empty implementation of the
KvmKernelIrqChip.

BUG=chromium:1077058
TEST=added test for creating a KvmKernelIrqChip and adding a Vcpu to it

Change-Id: Ic1609c965e0a057f5a9d4d74f1cae46edb46dcb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197398
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-05-18 23:56:23 +00:00
Daniel Verkamp
9a0ffde053 devices: usb: ignore busy flag in interrupter
This works around an issue where the xhci controller hangs from the
guest's point of view, with the guest kernel eventually timing out and
disabling the controller.

The xHCI spec says that the EHB (Event Handler Busy) bit should be
cleared before signalling another interrupt.  This bit is set by the
controller before triggering an interrupt, and it is meant to be cleared
by the guest (via write-1-to-clear) when it is done handling the
interrupt.  However, it seems that there is a race going on between the
clearing and setting of this bit.  Removing the check seems to avoid the
issue, since we never get into the state where we think EHB is set but
the guest thinks it is clear (where no further interrupts would be
triggered).  This will potentially trigger more interrupts than strictly
necessary, but the Linux kernel xhci driver handles interrupts with no
events available gracefully.

BUG=chromium:1082930
TEST=`while adb shell echo hi; do : ; done` for 8+ hours without hangs

Change-Id: I3c08f0c5675be10d8e46f73714d684f7ba3a3903
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2202745
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-05-16 01:12:26 +00:00
Daniel Verkamp
1182090a3e devices: usb: remove interrupter pending variable
The pending variable was just duplicating state that can easily be
determined based on whether the ring is empty.  Remove the variable and
replace it with an equivalent check in interrupt_if_needed() to avoid
the possibility of accidentally getting these out of sync.

BUG=chromium:1082930
TEST=cargo test -p devices

Change-Id: Icb90e3d09c43de244f5fecffb0e55d4635be6d2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2202744
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-05-16 01:12:25 +00:00
Chirantan Ekbote
c569a579fe descriptor_utils: Remove need for temporary vectors
Refactor the DescriptorChainConsumer, Reader, and Writer structs so that
we don't have to allocate a Vec on the heap every time we read or write
from a DescriptorChain.  This should hopefully give us some small
performance improvements as well as simplify the code in some places.

Also switch from VolatileSlices to iovecs so that it's easier to use
these structs with io_uring.  Otherwise we would end up allocating
temporary vectors to convert from VolatlieSlice to iovec.

BUG=none
TEST=unit tests

Change-Id: I1657bc76cfff084df825dbbdc8ff414740b71a8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2190106
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-05-14 17:09:56 +00:00
Chuanxiao Dong
6db9f9f58a acpi: refactor the ACPI PM device
Add the AML support to generate the S1 table instead of hard coding.
Also use the IO allocater to allocate the IO resouce for ACPI PM.

BUG=None
TEST=boot crosvm by command "crosvm run -s crosvm.sock -m 4096 --cpus 4
--rwdisk rootfs.img -p "root=/dev/vda rootfstype=ext4" vmlinux".
Check the S1 capability by "#echo standby > /sys/power/state" from guest
side. Linux guest is suspended. And resume linux guest by "#crosvm resume
crosvm.sock" from host side.

Change-Id: I75b484c44db05f98d49557ba694a1531b57871c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2119571
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
2020-05-11 13:43:59 +00:00
Kaiyi Li
a7469062a2 Extract the DisplayBackend build process into BackendKind build function
All 3 different virtio gpu backends share the same process of creating
the GpuDisplay instance, so move that process out of their separate
build functions and put it in the shared BackendKind build function.

BUG=None
TEST=build_test

Change-Id: Ie15bae48c8f1b75df49ba066a677020ec5dbf744
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2182041
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
2020-05-08 21:11:56 +00:00
Zach Reizner
a1c0e3c680 remove instantes of using IntoRawFd in unsafe blocks
The trait IntoRawFd isn't marked unsafe, but its documentation says that
an impl must return a uniquely owned RawFd. Some code blocks depended on
that behavior to ensure safety with the unsafe File::from_raw_fd, but
this leads to a soundness hole where a nominally safe impl of IntoRawFd
can lead to unsafety in functions that had been left as safe.

This change sidesteps the issue by not using IntoRawFd, and using only
safe conversions instead.

BUG=None
TEST=cargo build --features='wl-dmabuf plugin'

Change-Id: I9b357e5592be21189fb96e343823dd63000aac30
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2185580
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-05-07 22:59:35 +00:00
Tomasz Jeznach
e94b5f84da pci: refactor FDT/MPTABLE creation to use PciAddress.
Simple refactor of FDT and MPTables generation to use PCI device
addressing and allow declatation of non-zero PCI bus ids for x86
architectures. It also allows non sequential IRQ allocation for
PCI devices.

BUG=None
TEST=build_test & tast run crostini.Sanity

Change-Id: I6cc31ce412199a732499b2d8d18d99f08d765690
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2175739
Tested-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
2020-05-05 00:03:46 +00:00
Chirantan Ekbote
9fec3733af descriptor_utils: Add write_iter method
Add a method to write a series of objects produced by an iterator.
Unlike the current `consume` method, this doesn't require the caller to
first store the objects in an intermediate collection.  Also change
`consume` to be implemented using `write_iter`.

This is the Writer equivalent of the `iter` and `collect` methods of the
Reader struct.

BUG=none
TEST=unit tests

Change-Id: I36bf2fef4d40e13a4741fa55fc35dd556c13a53b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2172841
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-05-01 09:43:10 +00:00
Tomasz Jeznach
da0e0f939b devices: pci: refactor PCI devices to use PciAddress.
Simple refactor of PCI device addressing to use
PciAddress type providing bus:device.function number.

BUG=None
TEST=build_test & tast run crostini.Sanity

Change-Id: I7755ad6b31aa8c882475cd8212630e1cc86ef49e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2172766
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
2020-05-01 05:49:39 +00:00
Tomasz Jeznach
d4cc9108cf devices: pci: refactor device location address.
Simple refactor of PCI device addressing to use
bus:device:function notation, including change
allowing sparse alloction of device addresses in
PCI topology.

BUG=None
TEST=build_test && cargo test

Change-Id: I9ff02dd6b67b6784eac8c3d348661789fca3f422
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2171037
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Tomasz Jeznach <tjeznach@chromium.org>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
2020-04-29 17:35:07 +00:00
Chirantan Ekbote
2d9dde9ee7 Stop tracking sub-mappings in MemoryMappingArena
The kernel already takes care of tracking all our memory mappings.
Doing it again ourselves doesn't provide any benefit and also adds
additional restrictions (like not being able to overlap with existing
mappings or partially remove mappings).  Additionally, the
`MemoryMappingArena` will already unmap the entire memory mapped region
so there is no need to individually unmap the sub-mappings.

The kernel's mmap api doesn't have these restrictions and as far as I
can tell there are no safety concerns with allowing this behavior so
just stop tracking the sub-mappings.

Safe use of MAP_FIXED only requires that the address is part of a
previously mmaped region so allow any MemoryMapping to be converted into
a MemoryMappedArena.

BUG=b:147341783
TEST=unit tests

Change-Id: Iaf944a971b8ba9333802aab73c1d184fe388af89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2162542
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-04-29 07:36:36 +00:00
paulhsia
7b8f776cb8 ac97: Create CrasClient with unified socket
Since Termina and ARCVM need both playback and capture functionalities,
we create CrasClient with CrasSocketType::Unified.

BUG=b:155048379
TEST=Apply full patch set and test with VMs

Cq-Depend: chromium:2165697
Cq-Depend: chromium:2167813
Change-Id: Id4fb12423eb05859528406ae7ed5e62b46909a56
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2167312
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
2020-04-29 00:12:33 +00:00
Daniel Verkamp
f75810f7ff Remove unnecessary parentheses in consts
Fix clippy "error: unnecessary parentheses around assigned value."

BUG=None
TEST=bin/clippy

Change-Id: I31e61c770c62d7ff2ca8525bf754bd615e24c349
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2163204
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-04-26 00:15:38 +00:00
Daniel Verkamp
e1952dd7d4 Remove redundant single-component imports
Fix clippy 1.43.0 clippy::single-component-path-imports warnings.

BUG=None
TEST=bin/clippy

Change-Id: I3f4f54138bedce16dc1ca937bb8bc00a94594f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2163203
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-04-26 00:15:36 +00:00
Daniel Verkamp
9f22e23996 devices: usb: allow arbitrary control request size
Previously, the maximum control request length that could be passed
through the USB host_backend layer was limited to 1024 bytes.

To lift this limit, remove the fixed-length ControlTransferBuffer
structure definition and replace it with manual buffer allocation.  This
mirrors the behavior of the later part of this function, which already
indexes into the control_buffer to copy the data back from a device to
host transfer.

BUG=chromium:1073503
TEST=Verify adb logcat still works

Change-Id: I7354f6fa237b4df6db7898f27be76ab10faed9f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2161440
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-04-23 21:29:12 +00:00
Daniel Verkamp
b865810340 devices: add SerialDevice trait
This will be used to allow generic code to create serial devices as well
as virtio-console devices.

Also remove the new_in_out, new_out, and new_sink constructors for
Serial and Console, since they are not used anywhere.

BUG=chromium:1059924
TEST=cargo build

Change-Id: I76da343e347aed36dabd3aa0541acf24c64fe122
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2127321
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-04-23 07:17:58 +00:00
Daniel Verkamp
fbd6122f0b arch, devices: move serial creation to arch
Split the serial code  into two parts:

- Configuration and setup: arch/src/serial.rs
- Serial device emulation: devices/src/serial.rs

No change in functionality - this is just preparation for generalizing
the command line parsing/setup code so that it can be used with virtio
console devices as well.

BUG=chromium:1059924
TEST=emerge-nami crosvm
TEST=emerge-kevin crosvm

Change-Id: I0aaf9dd6f8096eac4a17077ab5bf569f57d64ff5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2127319
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-04-23 07:17:55 +00:00
Iliyan Malchev
2c1417b43a Serial: add input path overriding stdin for --serial
Allowing the input to be specified for file-based serial ports allows
the user of pipes as input/output. That enables kgdb over serial.

TEST=
Build a kernel with support for gdb

```
make x86_64_defconfig
make kvmconfig
./scripts/config --enable GDB_SCRIPTS
./scripts/config --enable KGDB
./scripts/config --enable KGDB_SERIAL_CONSOLE
./scripts/config --enable KGDB_LOW_LEVEL_TRAP
./scripts/config --enable KGDB_KDB
./scripts/config --enable KDB_KEYBOARD
./scripts/config --enable GDB_SCRIPTS
./scripts/config --set-val KDB_CONTINUE_CATASTROPHIC 0
make -j33
```

Setup devices for PTYs

To make sure crosvm doesn't create an ordinary file if socat is started
after it, create these named pipes first:

```
mkfifo ~/console_{in,out} ~/kgdb_{in,out}
```

Set up two PTYs: ~/kgdb for the debugger, and ~/serial for the console.
PTY ~/kgdb connects to ~/kgdb{in,out}, and ~/serial connects to
~/console{in,out}

```
socat -d -d -d \
    'PIPE:$HOME/console_out,rdonly=1,nonblock=1,ignoreeof=1!!PIPE:$HOME/console_in,wronly=1' \
    PTY,link=$HOME/serial,ctty,raw,echo=0

socat -d -d -d \
    'PIPE:$HOME/kgdb_out,rdonly=1,nonblock=1,ignoreeof=1!!PIPE:$HOME/kgdb_in,wronly=1' \
    PTY,link=$HOME/kgdb,ctty,raw,echo=0
```

Start crosvm with serial ports pointed at ~/console{in,out} and ~/kgdb{in,out}.

```
cargo run run -p 'init=/bin/sh panic=0 kgdboc=ttyS1,115200 kgdbwait kgdbcon' \
    --serial type=file,path=$HOME/console_out,num=1,console=true,stdin=false,input=$HOME/console_in \
    --serial type=file,path=$HOME/kgdb_out,input=$HOME/kgdb_in,num=2,console=false,stdin=false \
    -r ~/rootfs.img \
    ~/src/linux/arch/x86/boot/bzImage
```

Start GDB

```
gdb vmlinux -ex "target remote /home/dgreid/kgdb"
```

To break into gdb, open up the serial console, mount /proc and send a SysRq

```
minicom -D ~/serial
mount -t proc none /proc
echo g > /proc/sysrq-trigger
```

Change-Id: I18a9c1087d38301df49de08eeae2f8559b03463a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2151856
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-04-19 22:22:46 +00:00
Chirantan Ekbote
a896213151 devices: fs: Fix potential resource leak
During a readdirplus call if we fail to add an entry to the response
buffer, which can happen if the buffer doesn't have enough space to hold
the entry, then the lookup count for that entry on the server will not
match the lookup count in the kernel driver.

Fix this by calling `forget_one` on that entry when this case happens.

BUG=none
TEST=vm.Virtiofs

Change-Id: I66205ba94b451a726ddcde2376d731251eb7545f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145548
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-04-16 06:32:43 +00:00
Chirantan Ekbote
80d61873eb devices: fs: Strip padding from directory entry names
When calling `getdents64`, the kernel will add additional nul bytes to
the name of the directory entry to make sure the whole thing is 8-byte
aligned.

Previously we would pass on this padded name to the kernel driver.
However, this seems to prevent the driver from detecting the "." and
".." entries, leading to the driver printing warnings like

  VFS: Lookup of '.' in virtiofs virtiofs would have caused loop

Strip out the padding so that the kernel detection of the "." and ".."
entries can work properly.

BUG=b:153677176
TEST=vm.Virtiofs and manually start a vm and check that the kernel
     doesn't print warnings about lookups causing loops

Change-Id: Id015182186cc3cb076e27556a1ab0a2de710aa59
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145547
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-04-16 06:32:41 +00:00
Ryo Hashimoto
e17b2b9059 devices: virtio: wl: Stop using non-blocking sockets
Non-blocking sockets require proper EAGAIN handling in crosvm and the
guest kernel.
Without it, guest writing data faster than host reading results in the
guest kernel returning ENODEV.

Use blocking sockets to avoid this problem, and to be consistent with
pipes which are blocking in wl.rs.

BUG=b:153858766
TEST=Launch ARCVM

Change-Id: If795ee0035dc057de0e155470e231d41f30d3a0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2148985
Tested-by: Ryo Hashimoto <hashimoto@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
2020-04-16 04:53:32 +00:00