Commit graph

637 commits

Author SHA1 Message Date
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
Chirantan Ekbote
220eaf5d2d devices: fs: Report "." and ".." entries
BUG=b:153677176
TEST=vm.Virtiofs and manually check that the "." and ".." entries appear
     in a VM when you run `ls -al`

Change-Id: I75045fd5bced67ff13045088e6f198fa61cb2d4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2142847
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-04-14 14:12:50 +00:00
paulhsia
4ee9bffbd5 ac97: Set CRAS_CLIENT_TYPE_CROSVM for crosvm
Set client type for debug log and ucm.

BUG=b:140401362
TEST=Build, deploy and run `aplay -f dat /dev/zeros`
     and check `cras_test_client --dump_a` results

Change-Id: I2b040ddaaafe0b7d6e7c3a6f3973598d0a79ff82
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2142836
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
2020-04-10 06:19:45 +00:00
Daniel Verkamp
e1980a9c36 devices: pmem: implement flush using msync()
Previously, writable pmem devices implemented the flush command using
fsync(); however, this does not guarantee synchronization of memory
mappings via mmap() to the file on disk.  What we actually need is
msync() on the pmem file mapping, but we don't have access to that
mapping in the pmem child process, and it isn't trivial to pass it along
since it is owned by the Vm object once it has been added as a
mmap_arena.

In order to call msync() on the mapping, add a new VmControl socket so
that the pmem device can request that the main process issues an msync()
on the MemoryMappingArena identified by its slot number.

BUG=chromium:1007535
TEST=mount filesystem on /dev/pmem0 and sync; verify msync in strace

Change-Id: Id0484757c422cf81d454fd54012a12dbcc1baaf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2044365
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-04-08 06:09:25 +00:00
Dylan Reid
252d5b3cf3 handle mmap of large offsets on 32 bit systems
While only 32 bits of address can be mapped, that 32 bits can be offset
by further than 32 bits in to a large file. As chirantan points out, the
try_mmap call was already casting the usize to u64 on all architectures.

Convert the usize offset in mmap to u64 and address users of the API as
well.

Change-Id: I67aed928ea521049fb51eb7aa61ea4de8b4d096c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124879
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-04-05 21:32:17 +00:00
Xiong Zhang
773c70740e Virtio-net: Let queue-num could configurable
Virtio-net multi queue feature need multi queue pairs, this patch change
queue-num configurable instead of static. --net-vq-pairs parameter could
config virtio net device virtual queue pairs.

BUG=chromium:1064482
TEST=Test virtio net function in guest with --net-vq-pairs=1 and
--net-vq-pairs=2

Change-Id: I75202c8ae52a83b8087b52149ec6d2138d8831cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2120312
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-04-04 19:52:11 +00:00
David Stevens
11e71a1838 virtio-gpu: add support for exporting virtgpu resources
BUG=b:136269340
TEST=boot ARCVM and launch play store

Change-Id: I2d78ffb15dcf2dc0f245916485f5ebb636ef6e78
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2014680
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-04-04 13:49:16 +00:00
Xiong Zhang
4cbcc26f5c Virtio-net: Add multi queues in multi threads
In order to support 2 vq pairs for virtio-net, this patch create 2
sockets in one tap interface,  2 vq pairs(rx/tx) and 2 threads in
device model, So one vq pair has one thread and one socket in tap
corresponding.

On my SkyLake desktop with crosvm and ubuntu 18.04 guest:
If run one iperf server on host and one iperf client in guest, 2 vq
pairs has the same netwrok bandwidth as 1 vq pair, the bandwidth is
5.99Gbits/sec

If run two iperf server on host and two iperf client in guest,
In 1 vq pair mode, two iperf cliens bandwidth are 3.19Gbits/sec and
3.18Gbits/sec.
In 2 vq pairs mode, two iperf clients bandwidth are 4.87Gbits/sec and
4.86Gbits/sec.
So 2 vq pairs improve net bandwidth 52.7% compared with 1 vq pair in
this case.

BUG=chromium:1064482
TEST=Run iperf test in guest

Change-Id: I1fa14d7e24085552dc828a89a883d4a2ada34789
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2099754
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-04-04 05:57:05 +00:00
Charles William Dick
664cc3ca49 crosvm virtio balloon stats
Introduces the ability to request BalloonStats from a
BalloonControlCommand.

BUG=b:147334004
TEST=tast run <DUT> arc.Boot.vm, and the balance available changes based
on this.

Change-Id: I808c4024f8c644c9cc4e30cc455ceda5f477bff3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2061517
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Charles Dueck <cwd@chromium.org>
2020-03-31 05:59:32 +00:00
Chirantan Ekbote
c6f1380932 devices: fs: Replace RwLock with Mutex
The RwLock implementation on linux has a tendency to starve writers.
Since the fs device workload has a roughly evenly distributed number of
reads and writes, using a Mutex should give us better performance.

BUG=b:150264042
TEST=vm.Blogbbench.virtiofs

Change-Id: I85ec4053bf03d19bb21b420c0aa506720e666708
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2103604
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-03-27 20:07:34 +00:00
Chirantan Ekbote
d74bb77a3e devices: fs: Use l{get,set,list,remove}xattr
Using the `open_inode` method on an fd for a symlink results in the
kernel returning -ELOOP.  Since there are no `*at` methods for extended
attributes, manually read the path for the file and then use the
l{get,set,list,remove}xattr method on the returned path.

BUG=b:136128512
TEST=boot arcvm with virtio-fs and selinux enabled

Change-Id: I2fde57db8a075838a3a877309f6cf89059f19258
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2120763
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-03-27 00:44:06 +00:00
Chirantan Ekbote
9e8aa131d3 devices: fs: Add missing & in copy_file_range
`offset_dst` is supposed to be a pointer.

BUG=none
TEST=none

Change-Id: I033501ba5a57a130625e68be88457b15ad1484ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2120762
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-03-26 17:32:29 +00:00
Lingfeng Yang
22964eab88 gfxstream: fix build
API for export_resource changed

Bug: b/146066070
Change-Id: I614880704658bbe7aae2f7ad8b10c76555d99c1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2102760
Tested-by: Lingfeng Yang <lfy@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-03-26 02:52:58 +00:00
Chuanxiao Dong
45a94bedae vhost-net: implement direct msix irq fd
The current vhost-net msix irq injection flow is from vhost-kernel
to crosvm vhost-net, then to the KVM for irq injection. It still need
crosvm vhost-net to trigger irq, which is because the set_vring_call
is not directly using the msix irq fd.

To optimize this flow to be from vhost-kernel to KVM directly, need:
1. if the msix is enabled and unmasked, use the misx irq fd for the
vring_call directly so that all the misx injection can directly to
KVM from vhost-kernel.
2. if the msix is disabled or masked, use the indirect vhost_interrupt
fd to let the crosvm to control the irq injection.

BUG=None
TEST=cargo test -p devices
TEST=start crosvm with vhost-net, and run the iperf3 on the network
without any issue

Change-Id: Idb3427f69f23b728305ed63d88973156a03e7c6b
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2046452
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-03-25 17:41:42 +00:00
Chuanxiao Dong
57b8201eeb vhost: pass response_socket to activate thread
Pass the Option of the response socket should be used by the
activate thread, to communicate with its device model.

BUG=None
TEST=cargo test -p devices

Change-Id: I929f4c901468e920116f2a744ec73571d91080e3
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2046451
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-03-25 01:33:59 +00:00
Chuanxiao Dong
02f58e6d74 vhost-net: add control socket basic support
Add a pair of control socket for vhost net. This pair can be
used for the vhost-net device model to control and
communicate with its activate thread.

BUG=None
TEST=cargo test -p devices

Change-Id: I8bacdb9132787dc499ef00eea1df26ff3b35028d
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2046450
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-03-25 01:33:57 +00:00
Daniel Verkamp
0dcbfa1176 usb: avoid setting configuration when unnecessary
On devices with only one configuration, skip the code that attempts to
change the device's active configuration, since it must always be the
single available configuration.

This works around an issue observed with some USB devices (e.g. Servo
Micro) where the initial Get Configuration control request fails with
-EPIPE.

BUG=chromium:1061382
BUG=b:151408644
TEST=Attach servo micro, see /dev/ttyUSB[012], screen /dev/ttyUSB0

Change-Id: Ic3333e1d70a0c57b090de64e4d3b7932ce2cf81d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2108871
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: George Engelbrecht <engeg@google.com>
Commit-Queue: George Engelbrecht <engeg@google.com>
2020-03-24 11:29:57 +00:00
Gurchetan Singh
83fc5c49ba devices: gpu: complete resource V2 rebase
* Remove RESOURCE_V2_UNREF
* Add RESOURCE_MAP/RESOURCE_UNMAP to enable resources without guest
  storage that don't need to be mapped directly either

BUG=chromium:924405
TEST=compile and test

Change-Id: I10d6cd120d86131fa7ed8917ddad25cdb99ae50c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015587
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-03-23 20:37:12 +00:00
Gurchetan Singh
151af70ac9 devices: gpu: modify resource v2
Rebase of zero-copy virtio-gpu flow:

    * Removes guest_memory_type/guest_caching_type in favor of a bitmask
    * Removes ALLOCATION_METADATA, since ideally we'd just read from
      guest memory to get guest responses
    * Renames HOST_COHERENT to HOST_VISIBLE
    * Adds a few more feature flags

BUG=chromium:924405
TEST=compile

Change-Id: I0d5a84b66cfa6d09f7e2d07ed8e761e7ba850284
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2013767
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-03-23 20:37:11 +00:00
Judy Hsiao
d5c1e968c9 audio: Create AC97 device with --ac97 option
1. Replace --cras-audio, --cras-capture, null-audio options by --ac97
option to create audio devices.
2. "--ac97 backend=BACKEND\
[capture=true,capture_effect=EFFECT]" is comma
separated key=value pairs for setting up Ac97 devices.
It can be given more than once to create multiple devices. Possible
key values are:
backend=(null, cras) - Where to route the audio device.
`null` for /dev/null, and  cras for CRAS server.
capture=true - Enable audio capture.
capture_effects - | separated effects to be enabled
for recording. The only supported effect value now is EchoCancellation
or aec.

BUG=b:140866281
TEST=1.crosvm run -r ./vm_rootfs.img -c 4 -m 1024 -s /run --cid 5 --host_ip\
100.115.92.25 --netmask 255.255.255.252 --ac97\
backend=cras,capture=true,capture_effect=aec\
--mac d2:47:f7:c5:9e:53 ./vm_kernel
2. Record with the vm by:
arecord -D hw:0,0 -d5 -fS16_LE -c2 -r48000 /tmp/test.mp3
3. Verify that AEC is enabled within the recording stream by
cras_test_cleint.

Cq-Depend: chromium:2053654
Cq-Depend: chromium:2095644
Cq-Depend: chromium:2038221
Change-Id: Ia9e0e7cda1671a4842ec77a354efaa4a2dc745eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2038413
Tested-by: Judy Hsiao <judyhsiao@chromium.org>
Commit-Queue: Judy Hsiao <judyhsiao@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Auto-Submit: Judy Hsiao <judyhsiao@chromium.org>
2020-03-20 15:26:02 +00:00
Daniel Verkamp
e5113047d5 devices: virtio: add virtio-console device
This is a virtio device that provides a serial console.  It has
constructors matching the existing Serial device (new_in_out, new_out,
and new_sink) that take generic io::Read and io::Write streams.

This change just adds the device code; additional changes are required
to add the console device to the command-line parsing and device setup
code.

BUG=chromium:1059924
TEST=boot linux with console=hvc0

Change-Id: I917157d5ecb5160c9b00b499eabe6fb08486776c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2095534
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-03-19 19:47:10 +00:00
Chirantan Ekbote
5b2447ceaf devices: fs: Bump fuse minor version to 31
Add new definitions and constants to support fuse minor version 31.
These include the FUSE_SETUPMAPPING and FUSE_REMOVEMAPPING opcodes used
by the virtio-fs driver for implementing DAX support.

BUG=b:147341783
TEST=vm.Virtiofs

Change-Id: Ie59ec1a44e555910f2ee2c5ba7afccb8bd435db9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105823
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
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-03-19 08:13:32 +00:00
Chirantan Ekbote
6dfa1e4ce5 devices: fs: Implement copy_file_range
BUG=none
TEST=vm.Virtiofs

Change-Id: I2ed7137a901e6e506e6b1562b77fdb042bdc58ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105822
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-19 08:13:31 +00:00
Chirantan Ekbote
93a9877057 devices: fs: Support FOPEN_CACHE_DIR
Add support for FOPEN_CACHE_DIR so that the guest can cache directory
entries for longer.

BUG=b:150264964
TEST=vm.Virtiofs

Change-Id: Iade67b54084ed72378afa70af9e9e0f7f0bc03e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105821
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-19 08:13:30 +00:00
Chirantan Ekbote
a07d84ad68 devices: fs: Add support for fuse minor version 28
BUG=b:150264964
TEST=vm.Virtiofs

Change-Id: I544329b63352956647d07aefdfce3118947d0821
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105820
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-19 08:13:29 +00:00
Dylan Reid
8476d79a3c Fix warnings added in rust 1.42
rustc now warns about return statements that have an extra set of
parenthesis. Remove such instances so that the code is warning free.

TEST=cargo build completes without warnings

Change-Id: I55148f8aceca8ba90f6bead2b6929e2c843351aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2104767
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-03-17 00:05:44 +00:00
Chirantan Ekbote
752f9c2870 devices: Ignore O_DIRECT in 9p and fs devices
Specifying O_DIRECT in the 9p device doesn't actually work correctly and
leads to an error.  O_DIRECT handling in the fs device works correctly
but also makes it look much worse in disk I/O benchmarks because the
block device gets the benefit of the host cache while the fs device
depends on the performance of the actual storage device.

BUG=none
TEST=`tast run vm.Fio.*`

Change-Id: I738e4032081e331ef956c9d4c33616607e403d86
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2093967
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-03-16 15:12:52 +00:00
Jorge E. Moreira
cba39f2fef Allow all serial port types to read from stdin
Bug=b/148677254

Change-Id: I1fa38bc95ca303c7a2c38dbe4b938a6042c910c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2093800
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@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: Jorge Moreira Broche <jemoreira@google.com>
2020-03-11 20:52:10 +00:00
Chirantan Ekbote
265967bcda descriptor_utils: Add iter method
Add an `iter` method to the `Reader` struct so that callers can iterate
over the objects in place rather than having to store them in a separate
collection.

BUG=none
TEST=unit tests

Change-Id: I29671910a4244a8d7786ca2eb241416ae72b8c9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2093966
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-03-10 03:35:05 +00:00
Keiichi Watanabe
9515b05c08 devices: virtio: resource_bridge: Transfer plane metadata
Transfer plane offsets and strides for exported GPU resource over resource
bridge as well as a resource itself.
These metadata will be required by virtio-video decoder and encoder.

BUG=b:120456557
TEST=Start ARCVM on atlas

Change-Id: Iaf539857c0f8525bd5be294521e75ad32cae05e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1787032
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-03-06 13:27:50 +00:00
Mattias Nissler
3f3c0a3f6a ac97: Mark pci::ac97_bus_master::test::start_playback ignored
The test is flaky and causes continuous build failures.

BUG=chromium:1058881
TEST=Tests run, offending test is listed as ignored.

Exempt-From-Owner-Approval: Sheriff action to silence flakes on builders

Change-Id: I204e6ef548e6f203b0c15b0d01fde3b88660bd44
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2090414
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Commit-Queue: Mattias Nissler <mnissler@chromium.org>
Tested-by: Mattias Nissler <mnissler@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-03-06 10:58:08 +00:00
Xiong Zhang
aee33b5862 virtio: Add VIRTIO_RING_F_EVENT_IDX test case
VIRTIO_RING_F_EVENT_IDX use Wrapping(u16) for irq suppressing, this
test case to avoid some corner case for Wrapping.

BUG=None
TEST=Run build_test.py

Change-Id: I47d377056fefcc36739bb197e30319deafb0faf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2073902
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-03-06 07:28:23 +00:00
Xiong Zhang
ea6cf66ab5 Vfio: multi vfio group support
current one container contains one group only, but one container could
contain multi groups actually. The main gap that current code to
support multi groups is that container will be initialized multi times
when multi groups exist, as each group will initialize container one time.

This patch extracts the code which should run one time only on a
container, so when the first group is added into container, this
container initialize code will run once. The container once initialize
code contains:
a. Set iommu driver type as VfioType1V2
b. Setup Iommu table on each guest memory region
c. create vfio_kvm device, so kernel kvm and vfio is associated.

BUG=chromium:992270
TEST=passthrough two/three vfio devices into guest, these devices belong
to different vfio groups, then check these devices function in guest.

Change-Id: I94c9c86f70f49957a5e5c1dfd2c7d823ad042320
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2078970
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-03-06 01:50:11 +00:00
Noah Gold
dc7f52bdb7 Use simple virtio_input_events where possible.
Previously, all input events in CrosVM were required to be linux
input_events, which have a timestamp field that is actually unused by
when we send/receive from the guest which are of type
virtio_input_event. This CL allows CrosVM to understand both types of input
events in a first class manner. It is a follow up on
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930405.

This CL also addresses some bugs with window driven input:
1. attach_event_device was being called before the surface was
created, so the devices were never attached.
2. The default touchpad size was not being set to the display window
size.

Additionally, it removes the unused event "filter" feature on event
sources.

Breaking change: from this point forward, CrosVM will treat input events sent
via a socket (e.g. SocketEventSource) to be virtio_input_events.

BUG=None
TEST=builds + manual

Change-Id: I7fec07c582e5a071a6f116975ba70d6e621bb483
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034046
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2020-03-06 01:00:39 +00:00
Zhuocheng Ding
b9f4c9bca3 crosvm: Add plumbing for split-irqchip interrupts
Devices use irqfd to inject interrupts, we listen to them in the main
thread and activate userspace pic/ioapic accordingly.

BUG=chromium:908689
TEST=lanuch linux guest with `--split-irqchip` flag

Change-Id: If30d17ce7ec9e26dba782c89cc1b9b2ff897a70d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945798
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2020-03-05 13:12:23 +00:00
Xiong Zhang
2f7dabbd6a Virtio: Add blk VIRTIO_RING_F_EVENT_IDX feature
Previous interrupt suppress patch only supply crude interrupt suppress,
VIRTIO_RING_F_EVENT_IDX feature supply a more performant alternative:
1) where the driver specifies how far the device can progress before a
notification is required
2) where the device specifies how far the driver can progress before a
interrrupt is required.

This patch add this feature into blk.
For gpu and network, this could be added also, but gpu and network
performance don't get better.

BUG=None
TEST=run benchmark for blk in guest

Change-Id: I73fe3f8b72a9e88fd6073890bc6ab2bee891d51d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2008341
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-03-05 09:03:33 +00:00
Zhuocheng Ding
db4c70d215 devices: PIC: implement interrupt injection
TODO: Route irqfd to PIC, and use signal to kick vCPU thread when
interrupt is triggered.

BUG=chromium:908689
TEST=Unit tests in file.

Change-Id: I9a87502da57e725d3bb26d746a337d0ba44ef337
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945797
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2020-03-05 01:02:49 +00:00
Zhuocheng Ding
f2e90bf0b0 Add logic to setup PIC/IOAPIC.
TODO: Route irqfd to PIC/IOAPIC to make them fully work.

BUG=chromium:908689
TEST=None

Change-Id: I301287b1cf32cfccffce6c52ebbb5e123931178e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945796
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2020-03-05 01:02:48 +00:00
Xiong Zhang
80fb0753b3 Virtio: Add queue ack_features() interface
Virtio spec define some features like VIRTIO_F_RING_INDIRECT_DESC,
VIRTIO_F_RING_EVENT_IDX, VIRTIO_F_RING_PACKED. If one feature is enabled
in guest, device's queue will have corresponding behavior for this
feature. Queue's ack_features() interface let queue know which features
is enabled in guest.

BUG=None
TEST=build_test

Change-Id: I865f93940a1f4db8ca6da8829136127353cc1c6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2008340
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-03-01 05:09:59 +00:00
Fletcher Woodruff
7eae7735ee ac97: switch to ShmStreamSource
Convert playback and capture for the AC97 device to use the zero-copy
ShmStreamSource instead of the old StreamSource.

In the process, rework start_playback and start_capture unit tests so
they rely less on sleep statements.

BUG=chromium:968724
BUG=chromium:1006035
TEST="sox -n -r 48000 -b 16 output.raw synth 5 sine 330 &&
     aplay -f dat output.raw" within a VM, check that sine wave is played
     accurately.

Change-Id: Ie9cddbc5285a9505872c9951a8a1da01de70eb88
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749950
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
2020-02-28 01:07:56 +00:00
Chuanxiao Dong
020fbf04c2 x86_64: generate ACPI tables
Add acpi_rsdp_addr in boot_params to allow crosvm to pass
a physicall address of RSDP to the Linux guest kernel, so
that the linux guest kernel can parse the constructed ACPI
tables and enable the ACPI.

Although there is ACPI tables but as we still have "acpi=off"
in command line parameter, there is still no ACPI in guest kernel.

The ACPI construction refers to the implementation of the
Cloud-hypervisor commit:
- arch: x86_64: Generate basic ACPI tables

BUG=chromium:1018674
TEST=None

Change-Id: Ibcb2ae98c43da8ef8c07a07eda9213f61570d14c
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035351
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
2020-02-28 00:11:19 +00:00
Daniel Verkamp
7673338200 devices: block: let resize convert to non-sparse
Change the behavior of the resize operation on virtio-block devices so
that it causes a disk to become fully allocated (non-sparse) even if it
had previously been sparse.

This means that we could have a disk that was previously sparse and is
now non-sparse, so treat discard requests for sparse disks as a no-op
instead of an error.  This is acceptable since discard is a hint and
doing nothing is a valid implementation.

BUG=chromium:858815
TEST=`crosvm disk resize` a sparse disk

Change-Id: I8b79e460e5432cc71bed98172527fe1cd2e726ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2070846
Reviewed-by: David Munro <davidmunro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-27 22:22:26 +00:00
Daniel Verkamp
1f9c1bb88b devices: pci: add error handling for msix_enable
This more gracefully handles failure of msix_enable; in particular, if
it fails, the self.enabled state is returned to false so that future
device operations won't try to access uninitialized parts of
self.irq_vec.

In addition, the AddMsiRoute response is now checked (previously, it was
just ignored), and errors are bubbled up via MsixError rather than just
printing a message.

BUG=chromium:1041351
TEST=Boot Crostini on nami

Change-Id: I9999f149817bc9f49176487446b52e74fb8be9a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2067964
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-27 21:50:51 +00:00
Xiong Zhang
2647a1916d Vfio: Disable msix bar's mmap
If vfio device's bar is mmappable, vcpu could access it directly through
ept without trapping. But msix's table and pba exist on pci bar, they must
be trapped and emulated by crosvm, so these bars mmappable must be
disabled.

BUG=chromium:992270
TEST=pass through a device with msix cap to guest, then test device
function in guest.

Change-Id: If7504a924902c940e00cc759c1ca64a116bbca17
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987815
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-21 11:45:16 +00:00
Zhuocheng Ding
04b44e3df0 devices: IOAPIC: implement interrupt routing
This change implements MSI routing and injection, so that service_irq
can actually inject an interrupt into guest.

BUG=chromium:908689
TEST=Unit tests in file.

Change-Id: I2db4f00f569db56f5765c707faaa87c64fd3da9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945795
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
2020-02-21 09:33:19 +00:00
Xiong Zhang
521646a401 Vfio: Emulate MSI-x
When VFIO device have msix capability, vfio kernel doesn't emulate msix,
so all the msix emulation are handled by crosvm. This include
msix capability register read/write, msix table read/write, msix pba
table read/write.

BUG=chromium:992270
TEST=passthrough a device with msix capabilty to guest, and check device
msix function in guest

Change-Id: Ic39737662a5051ac6b9e29aad227d3d4946190a8
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987814
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-20 06:42:13 +00:00
Xiong Zhang
de92ad05c7 Vfio: Enable multi vectors in irq_enable()
When msix is enabled, msix will have multi vectors, this patch enable
mutlti vectors in vfio_device.irq_enable() function.

BUG=chromium:992270
TEST=passthrough a device with msix capability to guest, and check
device msix function in guest

Change-Id: I5f8265e7badec8551ff9a974462f08425ee93ab2
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987813
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-19 19:31:56 +00:00
Xiong Zhang
9f7e38de57 Virtio: Add virtio block irq suppress
The flag in avail descriptor supplies irq suppress, it could reduce irq
injection from device, so many redundant interrupts could be removed
from guest, then improve guest performance.

BUG=None
TEST=run fio read and fio write in guest

Change-Id: I68789d8ca24d0e84d0b446db65057f4da2fac56f
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2008339
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-19 17:31:39 +00:00
Chuanxiao Dong
546f01cb96 acpipm: implement suspend and resume mechanism
For suspend request from VM, will write suspend event and notify
crosvm main process to pause VCPUs.

For resume request, it is not from VM itself but by the resume
command through crosvm socket. Resume request will notify the PM
device to fill its wakeup registers with wakeup event so that
when VCPUs start to run, VM can know there is wakeup from outside.

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

Change-Id: I4724ffee10150065a62bf520076c16cbc70b7749
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035169
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2020-02-19 10:38:04 +00:00
Charles William Dick
80a8d52fac devices: virtio: Implement Reader::collect() and Writer::consume()
Adds a method Reader::collect() to read a collection of DataInit types,
and a method Writer::consume() to write a collection of DataInit types.

BUG=b:147334004
TEST=cargo test -p devices

Change-Id: Ib5947d30b44b74dc6cf0474e5b87778aad6f08a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2061516
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
2020-02-19 10:25:23 +00:00
Lingfeng Yang
ddbe8b7e8e virtio-gpu: gfxstream backend
Adds a new backend type, gfxstream, that calls out to a C library
implementing the actual rendering.

The purpose is to allow the Cuttlefish and Android Studio Emulator teams
to use crosvm with the current API-forwarding style of rendering
employed in the Android Studio Emulator.

Also, introduces a new key to the --gpu command line interface,
backend=, which selects from different backends. Note that the previous
behavior is now deprecated and will be removed after some time
(when all clients switch over to backend=).

The gfxstream backend itself implements a subset of 3d-related resource
and context creation/transfer/execbuffer commands. Their meaning is
specific to the way in which they are interpreted in the backend
library.

To interface with display, gfx stream backend takes a callback that is
run on guest vsync. The callback is responsible for repainting the
display's contents. gfx stream provides a callback, get_pixels, that can
be used asynchronously. The asyncness is not taken advantage of
currently but will be useful for cases where the client attached to the
VMM might want to update at a different rate than guest vsync.

The guts of the stream backend library is currently defined here:

https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/android-qemu2-glue/emulation/virtio-goldfish-pipe.cpp

The linking of the library is controlled via the feature "gfxstream".
If the feature is turned off, we use a default do-nothing stub impl.

Next steps:
- integrate virtio-gpu-next so as to have host coherent memory for
vulkan
- Figure out low latency command submit/response with SUBMIT_CMD_3DV2

BUG=b:146066070

Change-Id: If647381c15e5459cec85e2325f97e2f0a963b083
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2033305
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Lingfeng Yang <lfy@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-02-19 06:18:37 +00:00
Xiong Zhang
79f10170da virtio: Inject virtio-blk interrupt quickly
Current blk interrupt is injected into guest after device handle a
batch of requests. While this patch injects interrupt at the end of each
request. So guest block will get much more interrupts and could handle
request more quickly.

With this patch, the guest fio read test improves 13%, while fio write
doesn't get better.

BUG=none
TEST=run fio_read and fio_write in guest

Change-Id: Ib0bd23e624dfc5d940d6cc124468b898d8ba128e
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2008338
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-19 06:09:41 +00:00
Chuanxiao Dong
ed6c972994 devices: add acpi device emulation code in devices
Add ACPI PM resource emulation code in devices, so that it can support
the ACPI PM requestion from guest OS.

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

Change-Id: I7b82b1c3a6f609136e493b55420b947afd1d5cfc
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035168
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2020-02-17 04:57:26 +00:00
Keiichi Watanabe
7c43b32a36 crosvm: virtio: Use larger IDs for crosvm-specific devices
Stop using 30 and 31 as device IDs of virtio-wl and
virtio-tpm, as these numbers were reserved for virtio-video devices
in the upstream [1].

Instead, use integers from 63, which is the largest
number we can use for a virtio device ID.

Note that this CL must be merged after kernels with CL:2024135 landed.

[1]: https://github.com/oasis-tcs/virtio-spec/issues/67

BUG=chromium:1031512
TEST=Check if /dev/wl0 exists on ARCVM with CL:2024135

Change-Id: I267c7702d3c28642492f560170a0d1d9d6523c31
Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2025127
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Fergus Dall <sidereal@google.com>
2020-02-15 09:18:09 +00:00
Kaiyi Li
bccb4ebb85 Use display size as the default size for single touch
When the user specifies the display size through the gpu argument but
not specifies the size of the single touch device, the display size
will be used as the size of these touch devices.

Use default() to initialize the GpuParameters. Allow initialize the
GpuParameters dynamically in the future.

Change-Id: I9fa04f8ff479732370514fbaeb062d737adba319
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2043072
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-02-12 19:01:12 +00:00
Xiong Zhang
c13648b444 Vfio: Create Msix capability for vfio device
Loop vfio device config register, then find out the msi and msix
pci capability.

both msi and msix need IrqRequestSocket for adding its routing info
into kvm routing table, but vfio device has one IrqRequestSocket only,
and only msi or msix is enabled at runtime, so Arc is used to let msi
and msix share one device IrqRequestSocket.

BUG=chromium:992270
TEST=pass a device with msix capability to guest, and check device msix
function in guest

Change-Id: I008ccd0e98507dc4d587418fbe00aa23029bdbad
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1987812
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-12 14:16:39 +00:00
Xiong Zhang
5c51e05282 Virtio: Add fence(Acquire) after avail_index read
Driver use virtio_wmb() before avail_index updating, here fence() is
compared with it, this guarantee that the descriptor_index is read after
avail_index.

BUG=none
TEST=run fio_read and fio_write in guest

Change-Id: I6a5e1bc7c915effd433b05aca246302c5a3e313c
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035079
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-07 15:27:25 +00:00
Chuanxiao Dong
c65a406abd vhost-net: implement the reset method
Vhost-net reset method can stop the activate thread and let it to
return the ownership of eventfds and tap back to the device, so that
it is possible to be activated again.

BUG=None
TEST=launch Crosvm guest with vhost-net. It works fine with iperf test.
TEST=cargo test -p devices

Change-Id: I8f3cb6939595b4dffa0e95bcffbf9fcc8fcf71ba
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009665
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-06 14:34:57 +00:00
Chuanxiao Dong
fab42c86ed virtio-input: implement the reset method
the event_source needs to be returned through the reset method to allow
the virtio-input device model reactivated again.

BUG=None
TEST=cargo test -p devices

Change-Id: I07a4add40b1c233e1ed328ccef1a1abd453ea0f7
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2032351
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-06 12:31:56 +00:00
Chuanxiao Dong
3eb7927bcd vhost: put kill eventfd to Worker
worker.run might encounter error when running but we still need it
to give the ownerships of the kill eventfd back so that it
can have a second round activate. And Worker structure also contains
several other eventfds which will be needed for a second round activate
so change to put this eventfd into Worker as well.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them work fine.
TEST=cargo test -p devices

Change-Id: I34477cfa3de23d7ab849f741d0ffb098c720a629
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009664
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
2020-02-06 03:25:33 +00:00
Daniel Verkamp
f054de59b3 devices: pci: fix writable_bits for 64-bit BARs
The high 32 bits of writable_bits was set incorrectly when adding 64-bit
memory BARs to PciConfiguration: it would effectively always be all
zeroes (no writable bits) instead of all ones (all writable bits).

The writable_bits field is used to determine which bits to force to 0
when reading the BAR, which is used by the guest to determine the size
of a BAR: write an all-ones value to the BAR, read it back, and the
resulting value has only the writable bits still set.  Since PCI BARs
must be a power of two in size, the effective size of the BAR is the
bitwise inverse of the resulting value plus one.

For 64-bit BARs, this process is the same, except that two contiguous
32-bit registers are combined, so for a 4096-byte 64-bit BAR, the
writable_bits field should be 0xFFFFFFFF_FFFFF000; however, with the
previous (buggy) code, it was 0x00000000_FFFFF000.

Add checks to the unit tests to verify that the writable_bits field is
correctly calculated as well.

BUG=None
TEST=cargo test -p devices pci_configuration
TEST=Boot Linux 4.19 kernel in crosvm

Change-Id: Ib97aa5dccf9bf042328c0fc9defe1797fc67bb05
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2033620
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-05 09:18:36 +00:00
Daniel Verkamp
df2bfe30f3 devices: xhci: support TRB Immediate Data bit
Transfer TRBs have a flag that indicates that data is transferred within
the TRB itself instead of as a separate buffer.  Add support for this
type of transfer in the ScatterGatherBuffer implementation.

This fixes USB support when using Linux 5.1+ as the guest kernel, since
it now uses immediate data transfers.

BUG=chromium:1046564
TEST=`adb root` to connected phone on Linux 5.4 guest kernel

Change-Id: I6c37db422ac8e65d10e1a91807b15e903ad614de
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2026262
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-03 18:12:01 +00:00
Keiichi Watanabe
392b73cdbc devices: virtio: Add a function to get a FD via resource_bridge
Add a function to get a resource FD via resource_bridge by extracting code from
the wayland device implementation.
This function will be used by virtio-video devices.

BUG=b:147465619
TEST=Run ARCVM and check that a window is displayed

Change-Id: I7b064c9a04bd082e30dd488d0b14731228e6047d
Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2014520
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-02-03 12:33:52 +00:00
Jason Macnak
327fc2454c virtio-gpu: implement 2D GPU Backend
... which does not require virglrenderer (or any renderer).

This will allow the Cuttlefish team to use minigbm as its gralloc
implementation when both hardware acceleration is available and
unavailable.

Adds a GPU `Backend` trait with all of the existing methods of the
current backend and converts the existing `Backend` into
`Virtio3DBackend` which implements the new trait.

Adds a `Virtio2DBackend` which creates resources with byte vectors on
the host and implements transfers via the old code from
gpu_buffer/src/lib.rs.

Adds a runtime flag to select between 2D and 3D mode with 3D mode as
the default.

Moves the process_resource_bridge() function to the `Frontend` and
instead expose a export_resource() function on the `Backend` to avoid
some code duplication.

BUG=b:123764798
TEST=build + launch cuttlefish w/ 2D mode (minigbm + custom hwcomposer)
TEST=built + launch cuttlefish w/ 2D mode (minigbm + drm_hwcomposer)
TEST=built + launch cuttlefish w/ 3D mode (minigbm + drm_hwcomposer)

Change-Id: Ie5b7a6f80f7e0da72a910644ba42d2f34b246be8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1993913
Commit-Queue: Jason Macnak <natsu@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Lingfeng Yang <lfy@google.com>
2020-02-03 11:14:22 +00:00
Chuanxiao Dong
bc499ec278 vhost-net: set backend to null when activate fn quit
Set the backend with null fd can reset the vq in vhost, which
can allow the activate fn to run again.

BUG=None
TEST=launch Crosvm guest with vhost-net. It works fine with iperf test.
TEST=cargo test -p devices

Change-Id: Ida952409147fd6fbd1d8f69b3a88a7ef03051d65
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2009523
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-03 09:47:41 +00:00
Gurchetan Singh
8b8c01e1ad devices: virtio/gpu: support PCI shared mem cap
The plan is to use shared mem cap for virtio-gpu.

BUG=chromium:924405
TEST=build

Change-Id: Id2829c2cd9883aca19641eff625c65a8db335e7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963334
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-01-25 02:28:10 +00:00
Daniel Verkamp
3c62aac88f devices: virtio: block: keep disk allocated on resize
When a non-sparse disk is resized, we should allocate storage for the
newly-expanded space when the disk is grown to maintain the
non-sparseness.  To accomplish this, add a call to allocate in the
resize function in the block device.

BUG=chromium:858815
TEST=`crosvm disk resize ...` and verify disk image is fully allocated

Change-Id: If263aa2b5c9da11b8bfc0586e4ac1575f2bd7084
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015829
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2020-01-24 20:22:49 +00:00
Daniel Verkamp
e43d300aef devices: xhci: use get_bar_addr() to find BAR 0
Don't store the BAR value, as it can potentially be updated by the
guest. (This is not supported by our PCI device model just yet, but this
is still the correct thing to do and matches other crosvm PCI devices.)

BUG=None
TEST=Add USB device on nami

Change-Id: Ie42d08429e7ff124178c818877b4cee83003d66f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1924782
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-01-23 20:11:06 +00:00
Noah Gold
90878fb30e Remove warning for VIRTIO_INPUT_CFG_UNSET.
As indicated in the comments, it seems that this warning is unnecessary.
We've added explicit handling for the UNSET case, and left the warning
intact to handle any out of range values.

BUG=chromium:1041054
TEST=builds.

Change-Id: I2d41159f2d4ccbb4d75d2a8f4bab54586ec65442
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1995308
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Auto-Submit: Noah Gold <nkgold@google.com>
2020-01-21 17:16:59 +00:00
Chuanxiao Dong
1375c284b7 vhost: impl on_device_sandboxed for virtio device
vhost set_owner fn only needs to be called once. Put it in activate
fn will block the vhost devices to be activated again in future.
on_device_sandboxed is a good place to put the set_owner as it only
run once. So put it there.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them can work
TEST=cargo test -p devices

Change-Id: I45308e26b026c9141e4426d8b1bbe1944612a915
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954173
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-19 09:24:42 +00:00
Chuanxiao Dong
92ee1489ce vhost: add cleanup_vqs to do some cleanup stuff
Activate_vqs is used to do the queue preparation before really
running. The virtio-vhost device might need to do some cleanup
to allow a second round activate in the future. How to do the
cleanup is depending on how the vhost virtio devices.

Just add an interface called cleanup_vqs to allow the vhost virtio
devices to do their own cleanup stuff.

BUG=None
TEST=launch Crosvm guest with vhost-net and vsock. Both of them can work
TEST=cargo test -p devices

Change-Id: I2472e79a8b63c9336f886cde55ffef6a78008ad8
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954172
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-19 09:24:40 +00:00
Jason Macnak
60eb1fbe89 gpu_display: implement stub display
Adds a stub display that emulates a display without actually
displaying contents anywhere.

This is needed for transitioning Cuttlefish to always using minigbm
as its gralloc implementation. Cuttlefish currently uses a custom
gralloc and hwcomposer implementation when running without hardware
acceleration. The Cuttlefish team would like to start with removing
our custom gralloc implementation and use minigbm. For this, we need
to add a virtio 2D backend to crosvm. Our hwcomposer implementation
currenlly sends framebuffers from the guest to the host via sockets.
The gpu backend still requires a display so we need a stub display
to use with the 2D backend for the period of time while we are
either still using our hwcomposer implementation or until our
hwcomposer implementation is updated to use the virtio backend for
display.

BUG=b:123764798
BUG=chromium:1033787
TEST=built and launched with Cuttlefish locally

Change-Id: I1a7e259d914a53252200c59589c4142e76c6b96b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1993947
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2020-01-14 00:31:00 +00:00
Chuanxiao Dong
81c804cc7a virtio: resolve some new introduced clippy warnings
BUG=None
TEST=./bin/clippy
TEST=cargo test -p devices

Change-Id: Ic5183ef887a85bc14357fd29bc7ea70caded61a8
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1988704
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-10 06:10:22 +00:00
Zach Reizner
19ad1f3d3a devices: remove user_command from proxy device
The only device that used user_command was Serial. This change makes
Serial device use a thread to read from its input instead of using
user_command.

BUG=chromium:1033787
TEST=./build_test
     run crosvm with stdio serial with and without sandbox

Change-Id: Ia0f2ee83d94ad2fee3f1f4f89aa734b976e33507
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1966435
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-01-09 07:53:57 +00:00
Stephen Barber
58df38b615 devices: net: add control queue for enabling/disabling offloads
Add a control queue for virtio_net, and implement the command to set
available networking offloads.

Set offloads initially when acking features from the guest. We previously set
offloads on unconditionally.

Add TUNSETOFFLOAD to the allowed ioctls for virtio_net.

BUG=chromium:1031413
TEST=boot 5.4 guest, check vmtap offloads enabled with ethtool
TEST=enable ip_forward in guest, check vmtap offloads disabled with ethtool

Change-Id: I4129aa03419798906bd95cf65a6a4ab63069f50b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1968200
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-08 23:10:13 +00:00
Gurchetan Singh
5c1208d128 devices: gpu: log hung-up display
This could be useful for debugging feedback reports.

BUG=chromium:1027379
TEST=compile

Change-Id: I520dedb0d0639f27cd5c2f81b09271bc4a243850
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1986298
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-01-08 20:18:04 +00:00
Ryo Hashimoto
0b788defc6 devices: virtio: wl: Support multiple sockets
Guest can specify which socket it wants to connect by passing a
parameter to VIRTWL_IOCTL_NEW_CTX_NAMED.

Even after this CL, only the unnamed wayland socket is used for composition.
Additional sockets are used for IPC purpose (e.g. camera).

BUG=b:146100044
TEST=Camera works

Cq-Depend: chromium:1962108
Change-Id: Ibd8efbae1b2177cc0381d88d151643183c31b519
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963412
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-01-07 07:59:06 +00:00
Xiong Zhang
3ec8cc4f52 Vfio: Ignore vfio device's multifunction flag
PciRoot doesn't support multifunciion which forward pci config r/w
from function > 0 to function 0, so if the vfio device have multifunction
flag, guest will find the existence of all the other functions, actually it
is from the function 0. In order to fix these extra functions, this
patch clear the multifunction flag, so guest won't probe the other
functions.

BUG=chromium:992270
TEST=pass through a device with multifunction into guest

Change-Id: I395636411e0d7d2a3729de16e638d7f6b2dde552
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954221
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-07 05:58:48 +00:00
Xiong Zhang
5c6bf3e32d Vfio: Add igd Opregion support
igd opregion is used by igd driver to get vbt info and exhange info
between bios and driver, but it isn't a standard pci resource, host
bios allocate, reserve its memory, and report the memory base address
through cfg_register 0xFC on native.

As crosvm doesn't have bios, it is hard to allocate and reserve opregion
for guest. Here opregion is faked as mmio memory, and let crosvm
allocate guest memory from mmio space, report its base to cfg_register
0xFC also.

guest driver read cfg_register 0xFC to get opregion base address, then rw
it throgh this address. Read is forwarded to vfio kernel and write is
ignored.

BUG=chromium:992270
TEST=crosvm --vfio /sys/devices/pci0000:00/0000:00:02.0, pass through
host igd into linux guest, the physical local display lightup and show linux desktop.

Change-Id: I1cc3618e99313fc1f88b96dcbc635f090b19340c
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1688689
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-07 05:58:46 +00:00
Noah Gold
7898b80860 gpu_display: add X11 input bindings.
Adds bindings to the X11 display window to capture keyboard & mouse
input & send it to the guest via an EventDevice.

Original implementation by zachr@chromium.org.

BUG=chromium:1023975
TEST=None

Change-Id: I33156a8ca0b8c610a2080e3b6891cca2a865734b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971121
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-01-03 20:03:53 +00:00
Chuanxiao Dong
313f64127f virtio: implement reset for balloon/rng/blk/net
The reset method will be called when guest virtio driver is
resetting the device. Currently the balloon/Rng/block/net
virtio drivers will re-configure the virt queue during the
reset so they required to be re-activated for using the new
virt queue configurations. To support this, need these device
models to return back the moved ownership of the important
variables so that they can do the re-activate.

BUG=chromium:1030609
TEST=Launch linux guest and follow the reproduce steps in BUG#1030609 to check
if balloon/Rng/block/net driver still complain failure.

Change-Id: I5b40fd303ea334484c590982e3e0874ea4e854ee
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971097
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-03 11:12:04 +00:00
Chuanxiao Dong
572ca0cca2 virtio: call virtio device reset method for reset
It refers to the implementation of the Cloud-hypervisor
commit:
- vm-virtio: Reset underlying device on driver request

If the driver triggers a reset by writing zero into the status register
then reset the underlying device if supported. A device reset also
requires resetting various aspects of the queue.

The reset method of a virtio device might return false if it is failed
to reset the device or it is not implemented. In this case, we don't
reset the queues. Otherwise the queues will also be reset together with
a successful device reset.

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

Change-Id: Iad2be38149e423a79d8366dc72e570a1d6eb297c
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1971096
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-01-03 11:12:01 +00:00
Dylan Reid
691a619926 devices: fix warning about extra parens
rust 1.40 has a new warning when there are extra parens, soRemove them.

Change-Id: Ibb565cac41ba8d72879f4cb8b949f2be30e55167
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1978140
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2019-12-23 21:20:13 +00:00
Gurchetan Singh
78f6d4b134 devices: gpu: remove hung display from PollEvents
This display isn't typically used when the virt-wl device is
available and it can lead to hung fds during plug/unplug with
external displays and docks.

BUG=chromium:1027379, chromium:1027447
TEST=
Tested five times each on R79-12607.47.0 sarien:
  => without patch --> CPU usage goes to 100% after unplug
  => with patch --> CPU usages remains normal

Change-Id: Iea57f05002acc661f36b180e9e88c37b1f1b9047
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1977100
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2019-12-20 23:45:39 +00:00
Xiong Zhang
5aef647486 vfio: Disable igd stolen memory
igd stolen memory isn't a standard pci resource, so guest couldn't
access it. Once guest i915 driver see its size is zero, i915 won't use
it. Here sotlen memory's size register PciCfg 0x51 is forced to zero.

BUG=chromium:992270
TEST=crosvm run --vfio=/sys/devices/pci0000:00/0000:00:02.0, pass
through host igd into linux guest. The physical local display lightup and show linux desktop.

Change-Id: I1a0a6edda5d92d32307ea8025ef96677ca62c125
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1688368
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-12-17 10:25:05 +00:00
Daniel Prilik
afa30327f8 devices: virtio: add support for VIRTIO_PCI_CAP_SHARED_MEMORY_CFG
Could be used by virtio-fs and virtio-gpu.

(cherry picked from crrev.com/c/1493014)
[took out PCI portions and modified commit message -- @gsingh]

BUG=chromium:924405
TEST=build and run

Change-Id: I47fd4482aa7c11e08bfb4f6c990221ae7a11a11d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1963333
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2019-12-12 10:28:34 +00:00
Jason Macnak
bf19558be5 Makes gpu renderer flags configurable via command line
BUG=b:134086390
TEST=built crosvm and booted cuttlefish locally with gpu

Change-Id: I4d816ddb52a2eadd06088d204d95118289a3f587
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927873
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2019-12-11 16:58:39 +00:00
paulhsia
8d3f9ba350 ac97: bus_master: Check pi_info before warm reset
According to ac97 spec, warm reset is specified to no-op when the device
is running. We should ignore it while the device is recording audio as
well.

BUG=chromium:1026538
TEST=Build

Change-Id: I64be922149c90be9a7a8669ef6d56591e6de632b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1960058
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
2019-12-11 16:09:36 +00:00
Fletcher Woodruff
65588b2535 ac97: extract moving to next buffer into function
Create a function move_to_next_buffer which handles incrementing civ and
piv properly.

Set the PICB register when that function is called, not when we read a
guest buffer.

BUG=chromium:968724
TEST=playback on-device

Change-Id: Ib384efceeac4be0e056c20591d93fe32b7305db6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954207
Reviewed-by: Fletcher Woodruff <fletcherw@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-11 01:04:46 +00:00
Gurchetan Singh
bf433ea9f6 crosvm: move vec_with_array_field to data_model
Move it to the newly created flexible array file.

BUG=chromium:892806
TEST=compiles

Change-Id: I6c423a885cec17e376b0da87a4adbd17c71ff6f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1325510
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-11 00:34:36 +00:00
Zach Reizner
65b98f1ccc utilize EventDevices to make virtio-input devices
BUG=chromium:1023975
TEST=./build_test

Change-Id: I10267e535d4d1dae90b2b5f30db046c388791a16
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930409
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-11 00:25:55 +00:00
Daniel Verkamp
2767223fdb devices: block: add block_size option for disks
This allows overriding the default logical block size (512 bytes) with
other values, such as 4096 for 4K block size disks.

BUG=chromium:942700
TEST=crosvm run -r vm_rootfs,block_size=4096 vm_kernel
TEST=verify block size with lsblk --output-all

Change-Id: Ia6db05f369a76557a2afb8b48b5cc2b66cf84b01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954220
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-12-10 23:33:56 +00:00
Zhuocheng Ding
7434c00020 crosvm: PIT: use full address and avoid conflict
The PIT implementation has the assumption that addresses are I/O port
numbers, so we should use full address mode. i8042 is also changed to
full address mode to avoid the conflict on port 0x61.

BUG=chromium:908689
TEST=None

Change-Id: Ibbb851e3a46ac7fc71576990a1618196de92e33c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945794
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-10 05:08:11 +00:00
Zhuocheng Ding
0e8c11e354 devices: IOAPIC: ignore interrupt polarity
Interrupt polarity is ignored by kvm since 3.15, and the irqfd interface
does not support polarity. We should not consider polarity either.

BUG=chromium:908689
TEST=Unit tests in file. Integration testing is blocked on rest of
split-irqchip being implemented.

Change-Id: Ibae23b81274f867bbf56009854611628dbb4c154
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945793
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-12-10 05:08:08 +00:00
Jason Macnak
cc7070b284 Support configurable screen sizes
This change enables Cuttlefish to run with a user specified display size on top
of virtio gpu accelerated graphics rendering.

This change makes the width and height an argument/flag and adds the necessary
plumbing to pass this width and height through the gpu backend.

BUG=b:134086390
TEST=built crosvm and booted cuttlefish locally

Change-Id: Idabf7ef083b2377e3ebf3b50dd0296f4bf7e8ddc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927872
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Jason Macnak <natsu@google.com>
2019-12-10 04:24:26 +00:00
Chirantan Ekbote
4f9f5c7479 devices: fs: Support fs crypto ioctls
Add support for FS_IOC_{GET,SET}_ENCRYPTION_POLICY.  Unfortunately,
since the I/O direction is encoded backwards in the ioctl definitions,
these will only work with on a kernel that's compiled with a patch to
mark them as unrestricted FUSE ioctls.

BUG=b:136127632
TEST=Compile and run the vfs_crypto.c program on a virtio-fs mount
     inside a VM

Change-Id: I124c5a943111b453dd44921a079a2baa1036dfd4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1952570
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>
2019-12-10 03:10:57 +00:00
Chuanxiao Dong
39087b289a devices: clone the EventFds before activate
The interrupt_evt/interrupt_resample_evt/queue_evts were move to activate
so the reset method has to return them back (although there is no virtio
device implemented the reset method yet).

Instead of move, another way is just clone these EventFds so that they
don't need needed to be returned.

The advantage of doing this can avoid changing every virtio device reset
method (again, currently there is no virtio device implemented the reset
method yet, but this method is going to used when needs to support the
reset of a virtio device) for returning them, which can simplify the code.
And reset method just needs to take care their own specific resources.

The disadvantage is that, the clone of an EventFd is try_clone which might
return error code (although this shouldn't happen). If in such case, the virtio
device won't be activated.

BUG=None
TEST=launch crosvm guest with virtio devices(rng/balloon/blk/net).

Change-Id: I6e55782c3ecc46bfa878aff24b85a58a7ed66365
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925682
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-09 03:06:47 +00:00
Xiong Zhang
85abeff27f vfio: Implement bar mappable
if device bar is mappable, map bar's gpa to hpa in EPT, guest vcpu
could access this bar directly through EPT without trapping. This
could improve performance.

vm.add_mmio_memory could help do this, here vfio_pci send
RegisterMmapMemory request through vm_control socket to do this.

BUG=chromium:992270
TEST=none

Change-Id: I3b4274372f7dcd32e18084d55f037b6fe45ed422
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581147
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-12-06 08:47:29 +00:00
Daniel Verkamp
c0a1f5318e devices: use File rather than shm in tests
Two virtio descriptor_utils tests were using SharedMemory to stand in
for I/o targets with a fixed size; replace these with File to avoid
needing the FileReadWriteVolatile impl for SharedMemory, which isn't
used anywhere else in the crosvm code base.

This slightly changes the behavior under test in the reader_failing_io
test, since it was previously using the SharedMemory seal functionality
to make the region ungrowable; this is an unusual corner case, and (as
mentioned in the comment that was previously at the end of the test) it
is testing implementation details of write() on shared memory on Linux.
Instead, just use a read-only file so that write() to it will fail and
cause the same observable result.

BUG=None
TEST=./build_test.py

Change-Id: I6d62cd70791f1dec625b750ecd01cc51e307f971
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1939783
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-06 04:28:37 +00:00
Daniel Verkamp
bb712d649f devices: virtio: enable MSI-X for all devices
All virtio devices can use the same generic calculation for number of
MSI-X vectors required: number of queues plus one for configuration
changes.  Move this calculation to the VirtioPciDevice implementation
and remove the Option to unconditionally enable MSI-X support for all
PCI virtio devices.

BUG=chromium:854765
TEST=Verify all virtio interrupts in /proc/interrupts are PCI-MSI

Change-Id: I5905ab52840e7617b0b342ec6ca3f75dccd16e4d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925169
Reviewed-by: Zide Chen <zide.chen@intel.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-12-06 01:45:44 +00:00
Fletcher Woodruff
277ea5f4b4 ac97: combine PlaybackError and CaptureError
PlaybackError and CaptureError encode the same error cases. Combine the
two into one Error type, AudioError.

BUG=None
TEST=builds

Change-Id: I44259227d67a0284c9a11c4aafd86fafe1006f8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925727
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
2019-12-04 18:02:49 +00:00
Daniel Verkamp
4cc280bcff disk: add get_len() to eliminate need for Seek
This new trait allows DiskFile implementors to provide the length of the
file directly rather than using SeekFrom::End with seek().

BUG=None
TEST=./build_test
TEST=Boot Termina in crosvm

Change-Id: I9447ebb43dbd5fbb32a3a6b6d2fc969b9406cdbc
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913961
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-27 21:22:41 +00:00
Daniel Verkamp
624c51bee3 disk: switch from WriteZeroes to WriteZeroesAt
This eliminates an extra seek per guest write zeroes request.

Additionally, it allows us to stop depending on the file cursor and pass
the offset directly, making multi-queue implementation easier.

BUG=chromium:858815
TEST=Boot Termina in crosvm

Change-Id: I8b15a39752a1b68597a2b1e1fd72382a484a3cb2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913521
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-27 21:22:40 +00:00
Chirantan Ekbote
37bd738b78 devices: fs: Use 32-bit uid/gid values on arm
The setres{u,g}id and the gete{u,g}id system calls on arm use 16 bit
values for uid_t and gid_t. This causes the kernel to interpret a
uid/gid of 65535 as -1, which means do nothing.

Use the 32-bit variants of these system calls instead so that we can use
32-bit values. Normally, libc would take care of hiding these kinds of
implementation details but since we can't use the libc wrappers for
these system calls, we have to do it ourselves.

BUG=b:136128319
TEST=`tast run vm.Virtiofs` on kevin

Change-Id: I6c0fda42c131e059139000828b3a53d4a73f340c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1923569
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-11-22 05:54:03 +00:00
Chirantan Ekbote
6576091e56 devices: fs: Only resample interrupts on one thread
Having more than one thread watch the interrupt resample event meant
that the threads would race to acknowledge the event: if thread B called
epoll_wait after thread A got a readable event for the resample eventfd
but before thread A called `read()` on the eventfd, then thread B would
also get a readable event for that eventfd. Both threads would then
attempt to acknowledge the event but only one would succeed. This would
leave the other thread blocked on the `read()` call until the resample
event became readable again.

Fix this by having only one worker watch the resample event.

BUG=b:136128319
TEST=`tast run vm.Virtiofs` on kevin

Change-Id: I5cd781a9c79ac718207a944433ea20a967735237
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1923568
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-11-22 05:54:03 +00:00
paulhsia
5277958078 ac97: bus_master: Sync SR_CELV with civ == lvi
From ac97 spec, SR_CELV should be synced with civ == lvi in bus_master.
intel8x0 is not using the bit but some other driver or system might be
using it.

Remove checking if new_sr equals to old_sr since update_sr will do
nothing if the input value equals to the old sr value.

Add unit tests steps to test the expected results.

BUG=chromium:1026538
TEST=Unit tests

Change-Id: I3dc9f42e2beed8e635a65dbefba44677c73fcc5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925917
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-21 23:45:13 +00:00
paulhsia
c61d4d05ec ac97: bus_master: CR: Clean up reset registers opt
In bus_master control register (CR), reset registers (RR) operation is
refactored by:
- Don't call stop_audio(), since the bus master should always be in stop
  state while getting this control. (From AC'97 spec: Setting it when the
  Run bit is set will cause undefined consequences."). And the driver
  will always disable the audio first by setting 0 to CR_RPBM bit.
- While doing the registers reset, clean up sr by using update_sr since
  assigning 0 to sr directly won't unset the interrupt bit in global
  status register and the driver might go into snd_intel8x0_update()
  with a stopped substream.
- Introduce helper function - reset_func_regs()

Add steps in unit tests which
- Start the bus masters with "Interrupt on Completion Enable" (CR_IOCE) bit.
- Verify if the interrupt bit in global status register is set / unset.

BUG=chromium:1026538
TEST=Unit tests

Change-Id: Ie90ca4c82cc3c867992ecaeb61ef4b3e9dd0d079
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925916
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2019-11-21 23:45:12 +00:00
Daniel Verkamp
e73c80f355 devices: block: add option to control sparseness
Extend the --disk option and other related options to allow a particular
disk to have the sparse operations (virtio-blk's discard command)
enabled or disabled.

By default, the sparse flag will be enabled for virtio-blk devices,
matching current behavior.

BUG=chromium:858815
TEST=Run `crosvm with --rwdisk file.img,sparse=false` and try to discard

Change-Id: Ib72c949711fbe869a3f444d7f929a80d0e039f72
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1906750
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-11-18 09:30:58 +00:00
Xiong Zhang
40a721b434 vfio: Don't exit at get_region_info failure
At vfio device initialization, it will probe all the defined regions,
most device don't have vga region, then when crosvm probe vga region info,
kernel vfio will return -EINVAL. So when error happens, it should continue
getting the next region info, instead of exit.

BUG=None
TEST=passthrough non graphic device into guest

Change-Id: If4d2f723df45f58ccd733e03c854cdcef3530bdb
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1918486
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-18 07:58:33 +00:00