Commit graph

1659 commits

Author SHA1 Message Date
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
46d61ba80d linux: add disk path to open error message
Previously, if a disk could not be opened, the error message did not
include the path of the disk, e.g.:

  The architecture failed to build the vm: error creating devices:
  failed to load disk image: Read-only file system (os error 30)

To make debugging easier, add the path to Error::Disk.

BUG=b:150181514
TEST=crosvm run --rwdisk ro.img vm_kernel

Change-Id: I7b319c419b889334ecadbb0497dc4b3dc5115aa6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2070844
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:24:14 +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
Chuanxiao Dong
91e8403ddf acpi_tables: Add initial ACPI tables support
The basic ACPI table support for creating XSDT.

It refers to the implementation of the Cloud-hypervisor's ACPI
commit:
 - Cloud-hypervisor: acpi_tables: Add initial ACPI tables support

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

Change-Id: Ia3b597936fef214fcb92fce28c91152dfa03bec9
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035350
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-27 05:07:01 +00:00
Matt Delco
ec8aacb134 sys_util: cleanup shared mem file after test
Running "build_test" fails if it's been previously run using sudo.
The failure is:
thread 'main' panicked at 'error creating shared memory;'
and errno is 17, so apparently the shared memory name is left
behind.

BUG=None
TEST=Verified that "sudo build_teat" followed by "build_test" results in
a failure, while with this change it reports success.

Change-Id: I09748b9c0b89ac953e054de852277d819ad85287
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1876662
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Matt Delco <delco@chromium.org>
2020-02-26 06:45:16 +00:00
Dylan Reid
72ccaefe0f msg_socket: Add async receiving of messages
Add a member to MsgSocket that effectively returns an async iterator
over messages received on the socket. This is done by setting the socket
as non-blocking and registering with the async infrastructure when the
socket would block.

This feature will be used by devices that wish to handle messages in an
async fn context.

Change-Id: I47c6e83922068820cd19ffd9ef604ed8a16b755e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1997243
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-02-26 06:20:39 +00:00
A. Cody Schuffelen
dfd0139d7c Better errors on missing composite disk components.
When there is an error opening one of the composite disk components now,
it gives the message `failed to open component file: "No such file or
directory (os error 2)"` without specifying the file path it tried to
use. Exposing the file path will make it faster to act on errors, rather
than trying to examine the composite disk file for paths.

TEST=n/a
BUG=b:150150052

Change-Id: I9341b330e7e6dcd517d5bfb5262b1657a2da46fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2072738
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-02-26 02:23:10 +00:00
A. Cody Schuffelen
f1f20f59be Support the Android Sparse disk format
Android defines its own "sparse disk" format, which its images are
usually published in. Cuttlefish has special-cased this to build raw
images in the android build system, but it still causes a performance
hit when downloading and extracting the image zip files. Experimentally,
running bsdtar on the zip file of raw images is about 50 seconds slower
than bsdtar on the equivalent zip file of android sparse images.

These disks can only be opened as read-only, as the Android Sparse
format is designed around writing once then interpreting the contents
while flashing a physical device through e.g. fastboot.

TEST=Run with aosp/1184800 on cuttlefish, unit tests
BUG=b:145841395
Change-Id: I13337b042e92841bd3cba88dc8b231fde88c091e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1956487
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-02-25 20:28:09 +00:00
A. Cody Schuffelen
5ad3bc3459 Initialize qcow clusters off the backing file when present
This preserves any data that the backing file had on a cluster when
doing a write to a subset of that cluster. These writes cause a
performance penalty on creating new clusters if a backing file is
present.

TEST=unit tests
BUG=b:140069322
Change-Id: I724990225617c05e5f2dea39e39ce84c940328fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982832
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-25 20:28:07 +00:00
Daniel Verkamp
0275efb3a0 x86_64: use __cpuid intrinsic
Use the Rust __cpuid and __cpuid_count intrinsics to replace the C
implementation in host_cpuid.c.

These are defined in core, but they are also re-exported in std, despite
being undocumented there due to technical reasons:
https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549

Use the std version for consistency (we don't currently use anything
from core anywhere else in crosvm).

BUG=None
TEST=cargo test -p x86_64
TEST=Boot crosvm on x86_64

Change-Id: Ic7a1094d1b804304a2944f8ee1fe55c5e2db23e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2067159
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-22 08:41:29 +00:00
Chirantan Ekbote
f84c2298e9 linux.rs: Don't pivot_root when using host's root directory
pivot_root(2) will fail with EBUSY if we try to pivot_root to "/".
Check for this case and skip the pivot_root if necessary.

BUG=b:147258662
TEST=`tast run <dut> vm.Virtiofs`

Change-Id: I1d7645844e183222a561578677fc5f59c080d58c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2067823
Auto-Submit: 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-02-22 06:20:21 +00:00
A. Cody Schuffelen
d8144a56e2 Read from the backing file if present on read miss
Reads to qcow files with backing files will fall through to the backing
file if there is no allocated cluster. As of this change, a write will
still trash the cluster and hide any data already present.

TEST=unit tests
BUG=b:140069322
Change-Id: Iba353fa1e7c25bb6267eb96b30b8f5a6ac61d423
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982831
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-21 21:52:56 +00:00
A. Cody Schuffelen
9ca6039b03 Support generating and opening backing files
The new functionality can be invoked through
"crosvm create_qcow2 --backing_file=backing new_file".

The old behavior of creating a qcow image with a particular size is
still available with its original syntax.

This is relevant to implement as by default something like qemu-img will
create a new image that assumes the backing file is raw or qcow, while
crosvm can use its knowledge of other formats (such as composite disk,
and later android sparse) to determine the true size of the backing
file.

TEST=unit tests
BUG=b:140069322
Change-Id: I22de6a79c6d8566a9fcb0bc8124e2d74fea9ca55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982833
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-21 21:52:53 +00:00
Matt Delco
4f48eab602 build_test.py: set env vars for cross compile
Now that minijail-sys is added a simple run of ./build_test fails with
messages like:

error: failed to run custom build command for `minijail-sys v0.0.11
(/mnt/host/source/src/aosp/external/minijail)`

thread 'main' panicked at 'called `Result::unwrap()` on an `Err`
value: CrossCompilation', src/libcore/result.rs:1165:5

This change adds various environment variables to address the problem.

BUG=None
TEST=./build_test.py --arm-sysroot /build/cheza/ --aarch64-sysroot /build/kevin64/

Change-Id: Iba15ceafa35ba3ab2d08dc5827af3cb8ee07530c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2064821
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Matt Delco <delco@chromium.org>
2020-02-21 13:58:52 +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
Chirantan Ekbote
c6b73e30c8 linux.rs: Refactor 9p device jail
Give the 9p device the same jail as the fs device.  In particular it
needs a higher max open file limit and should map the current euid/egid
in its user namespace rather than always using the crosvm user.

BUG=b:147258662
TEST=`tast run <dut> vm.Blogbench.p9`

Change-Id: I12e7ba7b651da4bae1435e0598b62fe2c35ff1bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2065254
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-02-21 05:55:24 +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
Matt Delco
e73414db48 crosvm: add ability to enable caps on vcpu
This change primarily adds functionality to allow kvm features to be
enabled on a vcpu (most of the current infra only supporst the ioctl for
the vm fd).

BUG=b:144746965
TEST=ran 'build_test' and verified that the added tests passed.

Change-Id: I30c00b6f462377c21d477602ceba5853df953b37
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2055883
Tested-by: Matt Delco <delco@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Matt Delco <delco@chromium.org>
2020-02-20 02:12:03 +00:00
Matt Delco
c469580e6c crosvm: support kvm's hyper-v cpuid ioctl
Kvm can emulate the hyper-v paravirt interface.  Newer versions of kvm
can advertise the features they support via an ioctl() that reports the
cpuid leafs for this interface.  This change adds some support for the
ioctl() and plumbs it through the plugin interface so that plugins can
determine the level of support available in kvm.

BUG=b:144746965
TEST=Ran build_test on kernel that supports the ioctl.  Added temporary
code to print the cpuid leafs and verified that the output is as
expected.  Instrumented failure as expected from older kernels and
verified that results still passed.

Change-Id: I6cd7dade1793e4edb52b331d5b960685541f7ba3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2037919
Tested-by: Matt Delco <delco@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Matt Delco <delco@chromium.org>
2020-02-20 02:12:01 +00:00
Matt Delco
ce03437d56 tests: avoid internal error in pause test
When running plugin tests it's not uncommon to see:

vcpu 0 has internal error

Though the tests don't actually fail on this problem. This seems
to occur as a side effect of the plugin_vcpu_pause.c calling
crosvm_destory_memory() before the test VM has actually finished
running.

The main thread will call read() on the 'kill' eventfd 5 times for:
init, pause, unpause, unpause, kill

The vcpu thread will call write() on the eventfd up to 8 times:

init, pause #1, unpause #1, pause #2, unpause #2, pause #3,
unpause #3, kill

The main thread's third pause request might occur before the second
pause request has been processed, in which case the vcpu thread will
only be paused twice (thus there will only be 6 calls to write()).
Given the unpredictable # of events I've opted to split the
init/pause/unpause events to a separate eventfd and keep the 'kill'
eventfd solely for its intended purpose.

BUG=None
TEST=ran ./build_test several times and observed no failures in the
pause plugin test.

Change-Id: Ie0817a4419ae6199fcc5c53496360b2bd81556e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2012788
Reviewed-by: Matt Delco <delco@chromium.org>
Commit-Queue: Matt Delco <delco@chromium.org>
Tested-by: Matt Delco <delco@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-19 23:05:34 +00:00
Matt Delco
c24ad78624 linux.rs: unify jail creation
This change unifies two substantially similiar segments of code used to
create a jail.

BUG=none
TEST=Ran 'build_test'.  Local build, deployed to DUT, and verified that
termina VM could still be used.

Change-Id: Ib1f2f9bc5cfe1e6c9f3633af7e23f52e5eafe3c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2057744
Tested-by: Matt Delco <delco@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Matt Delco <delco@chromium.org>
2020-02-19 22:37:59 +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
Daniel Verkamp
2dae56768c docker: check out minijail in expected location
Move the minijail source checkout location in the Dockerfile so that it
is in the expected place relative to the crosvm checkout so that Docker
(and kokoro) can successfully find it.

Also update Cargo.lock for the new minijail-sys dependency; this fixes
"read-only filesystem" errors from cargo running inside Docker when it
tries to write the updated Cargo.lock.

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

Change-Id: Ic399030004c2c4891a03a60474348b0bed9f01d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2062675
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-19 01:05:34 +00:00
Daniel Verkamp
1ba620d821 qcow_utils: use DiskFile trait from disk crate
Drop the local DiskFile trait definition from qcow_utils and use the one
defined by the disk crate, since qcow_utils already depends on disk.

In order to make the switch, use the DiskGetLen::get_len function
instead of seeking to the end of the file to get the current file size.

BUG=None
TEST=emerge-nami crosvm
TEST=cargo build -p qcow_utils

Change-Id: Ie4b3b8ee0fb11ef02fbc322c5b0f9e22b0345bb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2056991
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-19 00:46:39 +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
Stephen Boyd
a0742bb58e arch64: Support rng-seed to seed the kernel's rng
Having this property in the chosen node in conjuction with
CONFIG_RANDOM_TRUST_BOOTLOADER lets us seed the kernel's random number
generator with some truly random numbers. This is useful to get a better
stack canary than the default build time one and it means that you
should see a message like:

   random: get_random_bytes called from start_kernel+0x1e8/0x39c with crng_init=1

instead of a message like

   random: get_random_bytes called from start_kernel+0x1e8/0x39c with crng_init=0

in the kernel logs. We seed 256 bytes here because that seems good
enough to kick start the rng.

BUG=None
TEST=Boot vm, see crng_init=1 when guest kernel has
CONFIG_RANDOM_TRUST_BOOTLOADER=y

Change-Id: If3689f56cc17204a16410cf368e8413de160646c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2055526
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Hsin-Yi Wang <hsinyi@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Boyd <swboyd@chromium.org>
Commit-Queue: Stephen Boyd <swboyd@chromium.org>
2020-02-15 16:48:15 +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
Stephen Barber
a2d845a569 io_jail: use minijail-sys crate
BUG=chromium:1032360
TEST=cargo build outside of chroot; emerge-board crosvm

Cq-Depend: chromium:2055725
Change-Id: I2493f563b07aeaff4627c8b8c4b578901393dc58
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1959449
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2020-02-15 07:46:04 +00:00
Daniel Verkamp
c0cbedd8d2 docker: upgrade rustc to 1.41.0
BUG=chromium:1050853
TEST=docker/build_crosvm_base.sh && docker/wrapped_smoke_test.sh

Change-Id: Id98a05c6ca01c9220e692cefc1a2c1d9eca50834
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2049243
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-13 05:37:28 +00:00
Dylan Reid
62d95045e1 README: Add IRC info
Copy the IRC text from the chromium docs, giving users a place to go ask
questions.

Change-Id: I9466cb3058823b6afd65ff2912b05d8a70d70229
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2052390
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Dylan Reid <dgreid@chromium.org>
2020-02-12 20:54:37 +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
Dylan Reid
17cdcf5dea async_core: fix formatting of use statement
Change-Id: I609da3eb581349315d1fb84a6a5fba233ec26b5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2048218
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-11 06:13:25 +00:00
Daniel Verkamp
c7d1d1659a Update audio_streams checkout and dependencies
Uprev the pinned commit and update Cargo.lock to match:
- libcras no longer depends directly on sync
- cras-sys now depends on audio_streams
- audio_streams now depends on sync and sys_util

BUG=None
TEST=`cargo build` and verify Cargo.lock is unchanged
TEST=docker/build_crosm_base.sh && docker/wrapped_smoke_test.sh

Change-Id: Iba1fba57284e1e233725e4086d5d98bb460f118c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2047492
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-02-11 03:41:10 +00:00
Daniel Verkamp
e5cab9d90a io_jail: remove unused c_long import
This is no longer used after the bindings were updated to use c_ulong
instead of c_long; remove it to fix a compiler warning.

BUG=None
TEST=cargo build

Change-Id: I813b06797ddc8b6cdfd8b777bd0a6efe6ec914a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2047643
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-11 01:03:57 +00:00
Stephen Boyd
8ce25cc1b4 aarch64: Support kaslr-seed to randomize kernel address
We're currently adding 'kaslr' to the chosen node, with a value of 0.
I'm not sure what that does, but we should probably add an actual random
value here. There is a 'kaslr-seed' property that can be written into
chosen and used to randomize the kernel address in memory. Let's
populate that property instead so we get some sort of random kernel
location in memory.

BUG=None
TEST=Boot up guest on cheza, hexdump kaslr-seed in
/sys/firmware/devicetree and see that it's been changed to 0

Change-Id: I3f7b1ac64174bcf2e9010df992c2b2553ff90979
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2040476
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Boyd <swboyd@chromium.org>
Commit-Queue: Stephen Boyd <swboyd@chromium.org>
2020-02-11 00:59:43 +00:00
Dylan Reid
eed7020fba Add async_core crate
This crate will provide asynchronous helpers wrapping primitives
provided by sys_util. To start EventFDs and MsgReceivers are provided.

Change-Id: Ia8862adafca995a3e3ab56582acc166a37fc8d2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1955046
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-02-10 23:46:12 +00:00
Dylan Reid
2cc138341d Add a cros_async crate.
This crate will house code using the new async/await features to be used
by other parts of crosvm.

Start the crate with a Future executor that runs tasks in a single
thread and allows futures that block on system file descriptors.

Change-Id: If77778ac056210dabbfc6e6e1e63df1c1b904a7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1955045
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-02-10 23:46:11 +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
Zach Reizner
bc7728f69b vm_control: fix double-close on VmIrqRequest::AllocateOneMsi
The EventFd that wraps the MaybeOwnedFd will close the fd, but so will
MaybeOwnedFd, causing a double-close.

BUG=None
TEST=strace crosvm run

Change-Id: I277386cd20eaa1a8187274cc16084b1936355012
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034026
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-06 21:56:39 +00:00
Zach Reizner
787c84b51b sys_util: recv entire UnixSeqpacket packets into Vec
This change adds the `recv_*_vec` suite of methods for getting an entire
packet into a `Vec` without needing to know the packet size through some
other means.

TEST=cargo test -p sys_util -p msg_socket
BUG=None

Change-Id: Ia4f931ccb91f6de6ee2103387fd95dfad3d3d38b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034025
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-02-06 21:56:37 +00:00
Matt Delco
4441c01124 seccomp: update/cleanup aarch64 rules
The build-time seccomp compiler for aarch64 complains that it doesn't
recognize open, epoll_wait, recv, mmap2, dup2, poll, mkdir, or stat.

I tried to propose a change to upstream minijail to make it aware of
these syscalls, but the calls are in various forms of deprecation
so upstream is doubting the sanity of the policy files.

I applied the following mapping: open->openat, epoll_wait->epoll_pwait,
recv->recvfrom, mmap2->mmap, dup2->dup3, poll->ppoll, mkdir->mkdirat,
and stat->statx.  In many cases the new syscall was already present so I
just deleted the old one.

BUG=None
TEST=Ran compile_seccomp_policy.py with an unmodified minijail until
it stopped complaining.  I don't have an arm device for runtime testing.
Wrote an app to emulate the execution of the first 400 syscall #s though
the bpf filter and verified that the list that matches the filter is the
same as the policy file.

Change-Id: I599aa549a1712b898eb6b73492872a9676e7215d
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2036218
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-02-06 17:35:36 +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