Commit graph

1827 commits

Author SHA1 Message Date
Keiichi Watanabe
0d46a14212 Cargo.lock: Uprev cfg-if and paste crates
Use the latest version of cfg-if and paste, which gdbstub crate will require.

BUG=chromium:1141812
TEST=cargo build

Cq-Depend: chromium:2507270
Change-Id: I9187cfc9a880f62b2aa1fcf5e5d47a720e5fbe60
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2499241
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-11-11 08:08:49 +00:00
Dylan Reid
3d63706dee linux: Wrap messages to vcpus in an enum
This change will allow sending messages other than the run state to
vcpus. Different messages will be used to interrigate and set the state
of the vcpu from the debugger.

BUG=chromium:1141812
TEST=run a VM

Change-Id: Ied6c8b6ee5a037e5593087ca665a84fdb462c287
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2440220
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-11-11 08:08:42 +00:00
Dylan Reid
b04926680c linux: Switch from a run mutex to a channel
Using a channel will allow for more complicated messages to be sent to
the vcpu thread. Adding debug support will require being able to process
each message from the main thread. The atomic state worked well when
every CPU needed a message and when transient state changes can be
dropped. Neither of those assumptions will hold true when using this
communication channel for debugging message such as setting and getting
vcpu registers or single stepping a particular cpu.

The run state is now per-cpu so that individual CPUs can be stopped and
stepped by GDB in later commits.

BUG=chromium:1141812
TEST=run a VM

Change-Id: Ibe3b71af0c99057666d30e302090a8a4364c064a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2440219
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-11-11 08:08:40 +00:00
Noah Gold
b3fca20e24 Refactor cros_async interface to avoid RawFd.
Instead of creating IoSourceExt from AsRawFd implementers, we've
switched to creating from a marker trait `IntoAsync`. This lets us use
other types like RawDescriptor easily with this crate.  By using the
marker, we also provide some type safety by requiring consumers of
IoSourceExt to declare that their type is expected to work with async
operations. This way we can provide stronger guarantees that an async
IO trait object will behave in a reasonable way.

This CL also purges the cros_async -> base and io_uring -> base
references, and provides the base types needed to add new async
primitives to base.

BUG=none
TEST=builds

Change-Id: I0b0ce6ca7938b22ae8e8fb4e604439f0292678f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2504481
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-11-10 11:40:50 +00:00
David Staessens
290d5c49ce crosvm: Fix wrong value used when configuring bitrate.
This CL fixes the wrong value being used when configuring a bitrate
using the V4L2_CID_MPEG_VIDEO_BITRATE control. Rather than using the
requested value, the original value was wrongly being used.

BUG=b:162804477
TEST=tast run DUT arc.VideoEncodeAccel.h264_1080p_i420_vm

Change-Id: I1381277c324eff035643b5f65c1e03832085e3f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2522772
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Staessens <dstaessens@chromium.org>
Commit-Queue: David Staessens <dstaessens@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
2020-11-10 06:45:07 +00:00
Michael Hoyle
cd23bc2581 base: keep_fds -> keep_rds rename
Along with this rename comes updating all usages to the
appropriate RawDescriptor traits. As per usual it touches
many files, but makes no significant changes.

The only remaining instance of "keep_fds" is to call out to
3p lib adhd.

BUG=b:162363783
TEST=./build_test

Change-Id: I6d292cc6404a9f84ffa5bf1320b6545a28842afa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2488071
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Tested-by: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-10 05:57:52 +00:00
Chia-I Wu
dd9c48cf60 virtio: gpu: set PCI class to DisplayController
Without this, non-root X fails with

[     7.544] (EE) modeset(0): drmSetMaster failed: Permission denied

because of the fallback

[     7.367] (II) systemd-logind: took control of session /org/freedesktop/login1/session/_31
[     7.368] (II) xfree86: Adding drm device (/dev/dri/card0)
[     7.368] (II) Platform probe for /sys/devices/pci0000:00/0000:00:06.0/virtio5/drm/card0
[     7.368] (II) systemd-logind: got fd for /dev/dri/card0 226:0 fd 10 paused 0
[     7.369] (II) no primary bus or device found
[     7.369]	falling back to /sys/devices/pci0000:00/0000:00:06.0/virtio5/drm/card0

BUG=None
TEST=Arch Linux guest

Change-Id: I4921fbd22b77d43d190b7adeb0399fc77fcec908
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2518656
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chia-I Wu <olv@google.com>
2020-11-07 00:58:57 +00:00
Michael Hoyle
e47a500f52 crosvm: Rename linux mod to platform.
Very small renaming to generify the mod.

BUG=b:159741216
TEST=./build_test

Change-Id: Iba156b36ba0a1b2da9518eae4af6cd9cb7ba71ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477735
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-11-06 23:44:50 +00:00
Victor Hsieh
c7ae4b7890 fuse: implement a worker to work with /dev/fuse
BUG=b:168305155
TEST=./build_test

Change-Id: Ibeef30a69a1ebd8813f4bf35027a1f8be4e573cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2500945
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2020-11-05 18:50:17 +00:00
Daniel Verkamp
c26d20b6e6 Fix new clippy warning for potential matches! uses
Replace uses of match where the branches just return true or false
depending on a single match with the matches! macro, as checked by
clippy:
https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

BUG=None
TEST=bin/clippy # with cargo 1.47.0 / clippy 0.0.212

Change-Id: I9f18ef8ccb45dacc2c4e2a113afd0b5a2d2e3580
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2519842
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-05 06:27:17 +00:00
Daniel Verkamp
34167b153c docker: update platform2 commit for p9 API change
BUG=None
TEST=docker/build_crosvm_base.sh && docker/wrapped_smoke_test.sh

Change-Id: I64f33db10ea13c077baeaa1c5f81232b233c90ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2519839
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-05 04:29:32 +00:00
Alexandre Courbot
27b9b91450 devices/video/decoder: remove session map
A decoder session is always associated to a given context ; therefore
our session map ends up having the same keys as the context map, with
the only difference that sessions are created a bit later.

Move the DecoderSession into the Context struct so we don't need to do
this double-lookup and to maintain consistency between the two maps. Since
the context can lack an associated session until the first output buffer
is queued, put the session behind an Option<>.

BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: I0511e51d422700a161457bb796ced3f2ef4732e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2484064
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-11-05 04:24:23 +00:00
Alexandre Courbot
c4712744c8 devices/video/decoder: fix clippy warning
Clippy is not happy because this method uses too many arguments. Since
we just happened to introduce a Rect type, use it to reduce them to an
acceptable number.

BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: I88fd0af5be75e3ddf3d3e2c03593aa492a18830e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2484063
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-11-05 04:24:22 +00:00
Alexandre Courbot
b922486164 devices/video/decoder: use generic events in DecoderDevice
Introduce our own event type to avoid using the libvda one in the
DecoderDevice interface. The current type is a 1:1 mapping from the
libvda event type, but we may simplify it in the future.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: Ic0fa1276ffe33c510f8a36ff26a69ece4e271974
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477407
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-11-05 04:24:21 +00:00
Alexandre Courbot
babfae73fd devices/video/decoder: use generic plane struct in DecoderInterface
Introduce our own plane type to avoid using the libvda one in the
DecoderDevice interface.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: I59e7dd0003a4fd5cb5cc10501f8167d8434addc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477406
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
2020-11-05 04:24:21 +00:00
Alexandre Courbot
2b9bf44f78 devices/video/decoder: use decoder pixel format type in DecoderDevice
Use the decoder's own pixel format type to avoid using the libvda one in
the DecoderDevice interface.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: I85589c25d337a517e4d98c55e8fb4e968c0c3e46
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477405
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
2020-11-05 04:24:20 +00:00
Alexandre Courbot
828150b5d4 devices/video/decoder: use decoder format type in DecoderDevice
Replace the libvda profile type by the more generic crosvm format type
to make this part of the interface portable.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: Ia0eb210278e4e4d945a4caa304c072ce68771440
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477404
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
2020-11-05 04:24:19 +00:00
Alexandre Courbot
3bb00ba75e devices/video/decoder: return VideoResult from DecoderDevice
Replace libvda::Result by the more generic VideoResult in the
DecoderDevice interface. Since all callers of the interface ended up
converting libvda errors into VideoErrors anyway, this turns out to be a
better fit.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: Idc3be76ab312c95b9d234550270adef44ea86f3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477403
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-11-05 04:24:18 +00:00
Alexandre Courbot
673b9cea79 devices/video/decoder: introduce DecoderBackend interface
The virtio video decoder was working directly with libvda to
provide the video decoding service to the guest. In the future we may
want to add other ways of providing decoding support, like
software-based decoding (useful for testing the virtio device and the
guest support), or direct decoding using the host's native capabilities.

Introduce a DecoderBackend interface that the decoder will use to
perform the actual decoding, and start moving the libvda-related code as
an implementation of it. At the moment the interface still uses libvda
types for parameters and return values for the purpose of keeping the
change simple, but we will replace them in the subsequent changes.

BUG=b:169295147
BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: I9d47cc934d34a0c706c2112831e827b6b1aa5d0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2460526
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-11-05 04:24:17 +00:00
Steven Richman
ce33acefff hypervisor: add vcpu methods: id, nmi, window off
New Vcpu methods get the vcpu ID for a vcpu and the current thread.
A new VcpuX86_64 method injects NMIs. request_interrupt_window now
takes a bool parameter, so the request window flag can be turned off.

These methods are to support the userspace irqchip. The thread-local
vcpu ID will help route MMIO requests to the appropriate APIC. Clearing
the interrupt window request is needed because KVM won't clear the
flag if the kernel APIC is disabled.

BUG=chromium:1077058
TEST=boots with KVM kernel irqchip, KVM split irqchip

Change-Id: I2a08988e71663f0d2a63985f3239568c7a9befea
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2419673
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-11-05 03:24:36 +00:00
Chirantan Ekbote
75ba87522b p9: Support ascii casefolding
Enable ascii casefold support for the 9p server when requested on the
command line.  Needed by arcvm.

BUG=b:162388795
TEST=`stat foo.txt` and `stat FoO.TXt` return identical results even
     though only foo.txt exists

Cq-Depend: chromium:2498170
Change-Id: Icf507ac0d8413e7794fdd643296d507781897039
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2501545
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-11-04 14:37:45 +00:00
Chirantan Ekbote
2449288cc8 devices: p9: Update for API change
The p9 crate API changed so that the new() function now returns a
result.  Update the caller to match.

Additionally, the implementation also changed to use different syscalls
so update the seccomp filters to match.

BUG=b:162388795
TEST=Start a vm with a 9p mount and test the changed operations to make
     sure they still work.

Cq-Depend: chromium:2494169
Change-Id: I7c4e1fd2fb192206402e895b09e519c3e769ae3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2494328
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-11-04 14:37:23 +00:00
Jason Macnak
046ed143a7 devices: gpu: gfxstream: Add ANGLE flag for Gfxstream
... to allow configuring Gfxstream host renderer based
on whether or not the guest Android is using ANGLE as
its native OpenGL driver.

BUG=b:165022040
TEST=launch_cvd --gpu_mode=gfxstream

Change-Id: I566ed1e7590f7f3db99960440421fd65bba08f7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2466604
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Jason Macnak <natsu@google.com>
2020-11-04 06:13:49 +00:00
David Staessens
0c4bba741a crosvm: Increase maximum resolution in virtio video encoder.
This CL increases the maximum resolution in the virtio video encoder
from 1920x1080 to 4096x4096. While devices are typically not able to do
realtime encoding in huge resolutions, they are usually still supported
by the HW encoder.

BUG=b:168262411
TEST=Record using Camera test app in 1600x1200 resolution on hatch

Change-Id: I62bdead25861dd3384d7c9d8ad1a8877e5af3215
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2508094
Reviewed-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: David Staessens <dstaessens@chromium.org>
Commit-Queue: David Staessens <dstaessens@chromium.org>
2020-11-04 05:53:11 +00:00
Dennis Kempin
336a9ef925 pl030: Add simple tests
This CL justs adds two very simple tests to improve overall test coverage.

Not sure what the best practices would be for mocking out the system
time, so I have skipped that functionality for now.

BUG=b:171750410
TEST=No change in functionality, just an added test.

Change-Id: I7a4e99c9d11203c5569ff28d2a5477bf8fd1b3a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2500948
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2020-11-04 00:28:11 +00:00
Steven Richman
0c47e9441e devices: irqchip: register events in IOAPIC
Previously the caller of ioapic::new was responsible for calling
register_irq_event on the IOAPIC's outgoing events.  The MSI IrqRoutes
for these outgoing events used the same GSIs < 24 as the incoming
PIC/IOAPIC routes.

This worked for the split irqchip, because PIC/IOAPIC events are handled
in userspace and MSI events in the kernel, so there was no confusion
about which route an event should use.  But with the userspace irqchip,
the routes have to be differentiated, otherwise incoming and outgoing
IOAPIC events with the same GSI trigger each other in a loop.  Also,
registering all outgoing IOAPIC events upfront increased the number of
irq event tokens by 24, even though only a few outgoing events are used.

Now the IOAPIC is responsible for registering outgoing events and it
allocates new GSIs >= 24 for its MSI routes.  An event and route are
only set up when a redirection table entry is configured with non-zero
MSI data.

BUG=chromium:1077058
TES=boots with split irqchip

Change-Id: I87c1df6150d50205810759ef152e1c9b33bcfe4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2419672
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-11-03 21:15:14 +00:00
Colin Downs-Razouk
bd5327620d devices: irqchip: handle multiple events per irq
There were some assumptions built into the hypervisor abstraction
implementations that we would only ever be registering a single Event
for any irq number, but that is no longer the case since 1d0f160. So
this change updates the hypervisor abstraction trait functions to allow
callers of irq_event_tokens to distinguish between multiple events that
refer to the same irq number using an IrqEventIndex. This index is then
used when calling service_irq_event.

Also, if register_irq_event would add a new irq event that the main
thread should wait on, register_irq_event will return the associated
IrqEventIndex. This change also updates linux.rs to use these changes.

The --split-irqchip mode may work even without this fix, depending on
which devices are sharing irqs. If the devices using shared irqs are all
virtio pci devices they may switch to MSIx mode and then not need their
original interrupt event.

BUG=chromium:1077058
TEST=disabled MSI mode on pci devices, forced additional irq sharing,
  and verified that --split-irqchip mode still works + cargo test -p
  devices

Change-Id: I4feb2817b6c477284ad463c0221d1f156813b6ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2405300
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-11-03 21:15:13 +00:00
Colin Downs-Razouk
e5774c3a8b hypervisor: userspace ioevent changes
For hypervisors that do not handle ioevents in-kernel, we need to make
some minor adjustments to the hypervisor abstraction api:
  - register/unregister_ioevents needs &mut self instead of &self
  - move handle_io_events from Vcpu to Vm, because the ioevents are
  registered on the Vm not the Vcpu.

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

Change-Id: Iddd61502a716143e117c454e64a9c9bd2578148d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2405299
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-11-03 21:15:11 +00:00
Daniel Verkamp
6c987cf924 fuzz: block_fuzzer: remove use of AsRawFd
The Event API has changed so that it exposes only RawDescriptor, not
RawFd, so the block fuzzer's use of as_raw_fd() no longer worked.

The actual intent of the code using as_raw_fd() was to clone the Event,
so just use the existing Event::try_clone function which achieves the
same result without using platform-specific code.

BUG=chromium:1144535
TEST=`FEATURES=test USE='asan fuzzer' emerge-amd64-generic crosvm`

Change-Id: I64689dde1b1351997aa2f11ed440416e3d226815
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2514901
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-03 03:32:24 +00:00
Victor Hsieh
fe8a4ba74b fuse: Replace split_at in the Writer trait with write_at
This simplies the complexity to deal with ownership and mutability,
while considering both the virtio-fs and regular FUSE use cases.

BUG=b:168305155
TEST=./build_test

Change-Id: Ic77d8e0b922e74a5733b99eeff41946177666c8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2500944
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2020-11-03 00:14:08 +00:00
Michael Hoyle
4694cd31c6 base: Remove AsRawFd from SharedMemory
Just another small step towards AsRawDescriptor universal
usage.

BUG=b:162363783
TEST=./build_test

Change-Id: I370f6dbeec10b9e4df75e5e4a5258c4d00a0ac9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2488724
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-10-31 07:12:34 +00:00
Michael Hoyle
6a0960a4a7 base: First steps towards universal RawDescriptor
This involves removing RawFd trait implementations from
Event and Timer, and resolving the echoing dependencies from
there.

Ultimately, this results mostly in changes across ioctl
(new thin layer in base), kvm, msg_on_socket, and a few other
areas. As usual, most changes are negligible.

BUG=b:162363783
TEST=./build_test

Change-Id: I47dec94666bc3430fed627b4767919c9cb4fce6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2462330
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-31 07:12:34 +00:00
Michael Hoyle
e392c46953 base: Add WaitContext
This is a layer above PollContext with a more generic interface.
As PollContext is used so widely, this is quite a large change
in order to accomodate the interface update, especially with the
use of RawDescriptor. In some cases this has caused an echo
of updates to RawDescriptor, which is fine because of our eventual
goal to move the whole codebase to it regardless.

Note there are a few instances of forcing the RawDescriptor update
chain to stop, ex. ioctl. This is to keep the scope of this CL
concentrated and avoid changing entire other areas.

Note that this CL leaves out a few additional pieces of work:
 - The sole usage of EpollContext over PollContext (event_loop),
which poses a bigger challenge for interface changes
 - Full PollToken renaming, which is a tiny change turned difficult
due to the unavailability of type aliases for traits.
 - Renaming certain methods which have been updated to use
RawDescriptor such as keep_fds. Some have enough dependencies that
they are worth avoiding to keep this CL pointed, but will be
addressed in future CLs to make sure the whole codebase is on the
fd->descriptor train

BUG=b:162363783
TEST=./build_test

Change-Id: Iff2cfe8f90dea55f1388f8e91bdc698e121a8e43
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2455726
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-31 07:12:30 +00:00
Daniel Verkamp
0b0dd364ff fuzz: block_fuzzer: add new base_features arg
virtio::base_features() now takes an argument to indicate whether the
protected VM feature is enabled; update the block fuzzer to match.

BUG=chromium:1142959
TEST=`FEATURES=test USE='asan fuzzer' emerge-amd64-generic crosvm`

Change-Id: I79de47d2bfff8705a4d35c6d978c1d08b36d0db7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2508468
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-10-30 20:15:47 +00:00
Alexandre Courbot
23be1ee5f8 msg_socket: use is_empty() instead of testing for zero-length
This makes clippy happy and compilation goes without warning.

BUG=None
TEST=crosvm builds.

Change-Id: Iacfca0615f055ce333baf135900b3bd04bcd29f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2505274
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-10-29 19:25:03 +00:00
Chih-Yu Huang
bd27bd0eac virtio: video: Only clear output resource after ProvidePictureBuffers()
At CL:2494322, we moved the clearing output resources logic from
handle_provide_picture_buffers() to clear_queue(). That CL only
considered the resolution change case, but didn't handle the flush
case correctly.

When the userspace flush the decoding, it streamoff the output queue.
But VDA doesn't request new set of buffers, ProvidePictureBuffers()
won't be called. In this case, crosvm shouldn't clear the output
resources. Crosvm only needs to clear the set of queued resource ids.

Also, when VDA sends ProvidePictureBuffers() the first time, V4L2
output queue at the userspace is not streaming. So the userspace won't
streamoff the output queue. In this case, we also don't need to clear
the output resources.

BUG=b:171860073
TEST=pass android.media.cts.MediaCodecTest#testDecodeAfterFlush
TEST=pass android.media.cts.AdaptivePlaybackTest

Change-Id: I2a425c1fd9e61322d92dc54930dd88242c964de3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2505284
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
2020-10-29 12:56:30 +00:00
Noah Gold
d4ca29b5d9 Restore default virtio features for virtio-input.
A prior CL (@81d5adbad7) removed VIRTIO_F_VERSION_1 from the features on
virtio-input, which causes boot failures on VMs that require those input
devices. This CL pipes protected-vm down to virtio-input & restores the
features.

BUG=none
TEST=builds

Change-Id: Ic54c7135c3ed4abf4c9d0a2c6969a0abaef7e7b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2503486
Auto-Submit: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Will Deacon <willdeacon@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-28 06:50:55 +00:00
Colin Downs-Razouk
b428fa1c15 hypervisor: allow shared MemSlotOrd
Move MemSlotOrd out of the kvm hypervisor implementation so other
implementations can share the same struct.

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

Change-Id: I9d992699defab53e32517bb40e29192e31c45983
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2405301
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2020-10-28 05:37:33 +00:00
Daniel Verkamp
4060eb5cd4 resources: add allocator sets for mixed low/high
This will allow allocating an MMIO region that can be in the high (>4G)
address space, but prefers to be in the low region if possible.

BUG=b:169430664
TEST=Boot Crostini with GPU

Change-Id: If90c0d90c95b0dcb3cb451eb7f573eede5ea3b2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2436370
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-10-28 05:01:46 +00:00
Daniel Verkamp
59865d4af4 arch: allocate all IO BARs before device BARs
This will allow IO BARs that need to be in the low (32-bit) memory
region to be allocated first, followed by device BARs, allowing device
BARs to be allocated in the low 32 bits of address space when possible.

BUG=b:169430664
TEST=Boot Crostini with GPU enabled

Change-Id: I5387b1e00ed6d5cbcff7b25e10f6115ff797c85b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2436369
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-28 05:01:44 +00:00
Victor Hsieh
bae88f4f65 fuse: extract FUSE as a crate from virtio/fs
The current crate still require some work to be really reusable as a
regular FUSE, i.e. with a new reader/writer against /dev/fuse. This
change intends to focus on creating the crate, without trying to find
the optimal interface, and still keep virtio/fs working.

BUG=b:168305155
TEST=./build_test
TEST=USE='asan fuzzer' emerge-hatch crosvm

Change-Id: I8b623c9262221113b720c10125a6770763f14dc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2466484
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
2020-10-27 16:18:51 +00:00
Dennis Kempin
a5262a177f acpi_tables: Add test case for reading SDT data from files
Seemed like an easy test to add.

BUG=b:171082843
TEST=This is a test

Change-Id: I2a10c0965be2952cd3150965e4127a27a3ec6dff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2495844
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
2020-10-27 05:22:34 +00:00
Dennis Kempin
831b11e869 Add scripts to run code coverage
One script to run coverage for the whole smoke test suite,
the resulting file can be uploaded to codecov.io for consumption:
https://codecov.io/gh/denniskempin/crosvm

Another script to run tests + coverage for a single crate,
which is useful during development to keep track of coverage
while adding tests (IDEs can display the generated lcov.info file)

BUG=b:171082843
TEST=Manual testing of both scripts

Change-Id: I52384762400a146cb0e7deb3d54dccf59b6134db
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2492914
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
2020-10-27 05:22:32 +00:00
Chih-Yu Huang
8ba5fc9819 virtio: video: clear output resources when the output queue is cleared
Originally, we clear all the output resources when getting
ProvidePictureBuffers command from VDA. At this point only VDA
discards the output buffers. crosvm should keep the output resources
until the output queue is cleared.

Note that at crrev.com/c/2494602, GAVDA will ignore the output buffers
after calling ProvidePictureBuffers(). So it's safe that crosvm passes
the output buffers after getting ProvidePictureBuffers command.

BUG=b:171442927
TEST=pass android.media.cts.AdaptivePlaybackTest#testVP9_adaptiveDrc

Change-Id: I54dd364e7509c18fb3a3cd193da97dd107ceec44
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2494322
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-26 06:34:08 +00:00
Fergus Dall
efb2186785 crosvm: Suppress useless error messages when creating serial device
When creating a serial device of type UnixSocket crosvm will race with
vmlog_forwarder to bind a socket to the address. This is expected to
fail in most cases, so don't log an error message if it does unless
the reason was unexpected.

BUG=none
TEST=Booted termina and checked for logs about failing to bind sockets

Disallow-Recycled-Builds: test-failures
Change-Id: I446dd803662de57221b501a6f87957035c4593de
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2494321
Tested-by: Fergus Dall <sidereal@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Fergus Dall <sidereal@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-10-24 01:47:39 +00:00
Daniel Verkamp
55ef29aaa3 disk: qcow: fix write_zeroes with backing file
The qcow disk format implemented the discard and write zeroes requests
by deallocating the underlying cluster when possible, with the
assumption that a deallocated cluster would return all zeroes if it is
read until it is written again.

Add an alternate implementation of write_zeroes that is used when a
backing file is present that uses the straightforward approach of
allocating all clusters and zeroing them out in the raw file rather than
using deallocation.

BUG=b:171230599
TEST=BLKZEROOUT test case
TEST=cargo test -p disk

Change-Id: I745f6dc7aa411ec9b1be0150ba1bc96c011ada9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2490605
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-10-23 21:26:10 +00:00
Alex Lau
e29e95e9b2 devices: virtio: video: Implement video encoder device
BUG=b:140082257
TEST=emerge-$BOARD crosvm
TEST=v4l2-encoder-sample
TEST=tast run DUT arc.VideoEncodeAccel.h264_192p_i420_vm after crrev.com/c/2256525 (on hatch and eve)

Change-Id: I7f1c1bb6a8ba192ab7a598227e59fc9ec307ad8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2167311
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
2020-10-23 08:47:44 +00:00
Noah Gold
7cc7c233a7 Simplify read_u64 for UringSource.
When using uring, we can just call `read_to_vec` rather than having to
call `libc::read`. Unfortunately, PollSource cannot do the same without
hitting an illegal seek (e.g. with eventfds), so we still have to keep
the read_u64 method around.

BUG=None
TEST=`cargo test` in `cros_async`.

Change-Id: I2c61468bec4a3f130c153eccf2875c047c61a2a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2482430
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-10-22 07:39:10 +00:00
Alexandre Courbot
11376b0959 devices/video/decoder: remove unneeded reference to session key
The argument passed to get() and get_mut() is already a reference, so we
don't need to add another redirection to it.

BUG=b:161774071
TEST=Youtube video playback works on kukui-arc-r.
TEST=Youtube video playback works on hatch-arc-r.

Change-Id: I0d299c284c00b68160676332dcf5387aed078b7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2484062
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2020-10-22 07:21:43 +00:00
Noah Gold
abf9f6e969 Remove unneeded type parameter on async traits.
The compiler & clippy weirdly didn't flag these type parameters &
constraints as unused. This CL removes them.

BUG=None
TEST=builds

Change-Id: I435f73957e7243628d7a0b0e73c1d543f410bb98
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2488846
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-10-22 07:08:22 +00:00