Commit graph

1547 commits

Author SHA1 Message Date
Dylan Reid
1160f456a4 sys_util: timerfd: Methods don't need to me mut
Because TimerFd is a wrapper around a 'File' that is never modified
there isn't a need for a mutable borrow. The kernel already handles the
interior mutability of the underlying file descriptor.

Change-Id: I7ae068cc54050b0021d00620b561335b2ae0ba16
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2161625
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@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-23 19:50:08 +00:00
Daniel Verkamp
a7b6a1c897 arch, main: add virtio-console parsing and creation
This allows the creation of virtio-console devices using the new
hardware=virtio-console parameter to the --serial option.

Also add support for the serial earlycon option, which allows using
virtio-console as the main console device with a traditional serial
device as the early console.  This allows logging during early boot
before PCI device discovery (when virtio-console devices are set up).

BUG=chromium:1059924
TEST=crosvm run -r vm_rootfs.img \
        --serial hardware=serial,type=stdout,console=false,earlycon=true \
        --serial hardware=virtio-console,type=stdout,console=true,stdin=true \
        vm_kernel

Change-Id: Iff48800272b154d49b1da00f3914799089268afe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2127322
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-04-23 07:17:59 +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
e538d5216f arch: serial: simplify device creation
Factor out the call to Serial::new so it isn't repeated for each output
type.

BUG=chromium:1059924
TEST=cargo build

Change-Id: Ie0ad65b4315173a3f2a7c2bf04f041ad3b2157f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2127320
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:57 +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
Daniel Verkamp
043aaea79b docker: update to rust 1.42 and rustup 1.21.1
Update to the latest rustup release, which (since 1.20.0) installs
rustfmt and clippy by default:
https://blog.rust-lang.org/2019/10/15/Rustup-1.20.0.html

Also update the Rust toolchain version to 1.42.0 to match the version in
the CrOS build environment.

Additionally, add workarounds for sysroot of cargo clippy.

BUG=None
TEST=docker/build_crosvm_base.sh && docker/wrapped_smoke_test.sh
TEST=bin/clippy on workstation

Change-Id: I7ac4db92f4e5f277d77a77fa3c4ffa880f2ae116
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2150988
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-04-18 12:01:32 +00:00
Daniel Verkamp
fcf078c38a disk: resolve iter_nth_zero clippy warning
Replace .nth(0) with .next() to resolve this:

  error: called `.nth(0)` on a `std::iter::Iterator`

BUG=None
TEST=bin/clippy

Change-Id: I103e8b44b1564708d92d096aaf044db7f67d1ba8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2151147
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-04-18 12:01:29 +00:00
Keiichi Watanabe
d8d9556184 docker: Put libvda.pc under /pkgconfig/
Put a dummy pc file for libvda under /docker/pkgconfig/ instead of generating
at the runtime.

This is a fix for CL:2133987, but shouldn't change any behavior.

BUG=none
TEST=build_crosvm_base.sh && build_crosvm.sh with CL:1973973

Change-Id: Ifd7677abf14346ca2e7a9bc48b5ebb6c519b78aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145533
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-04-17 20:53:07 +00:00
Zach Reizner
5cf5af601e seccomp: allow kcmp on x86_64 gpu device
A mesa change to the amdgpu driver "winsys/amdgpu: Re-use
amdgpu_screen_winsys when possible" causes kcmp to be called with the
following simplified stacktrace.

SYS_kcmp
os_same_file_description
amdgpu_winsys_create
radeonsi_screen_create
<snip>
eglInitialize
virgl_egl_init
virgl_renderer_init

The use of this syscall caused the gpu device process to be killed with
SIGSYS. This change fixes that by allowing kcmp in that process, which
should be secure given the sandboxing in place and the level of
permissions required by kernel to succesfully use the kcmp syscall.

BUG=chromium:1070805
TEST=crostini.GPUEnabled.artifact_gpu_unstable

Change-Id: Ica0e5c6ebc01cbc33ac62fea001949798ca4446e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2151145
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Drew Davenport <ddavenport@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Lepton Wu <lepton@chromium.org>
Reviewed-by: Victor Hsieh <victorhsieh@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-04-16 19:05:15 +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
Keiichi Watanabe
40af8ee748 crosvm: Enable cargo clippy in smoke_test
Enable cargo clippy in the smoke test script for kokoro with many whitelisted rules
to be resolved. This check will reject compile warnings as well.

Also, this CL removes cargo check in Docker.crosvm as cargo clippy is a superset of
cargo check.

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

Change-Id: Iaa546fc0166e3d9762c5e91144d036725d38b0f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145538
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-04-15 18:01:34 +00:00
Keiichi Watanabe
05489a7637 crosvm: Fix clippy::correctness error
Fix a style problem categorized into `clippy::correctness`, which causes
an error by default.

BUG=chromium:908640
TEST=cargo clippy --all-features --all-targets -- -D clippy:correctness

Change-Id: I85f54c9b031a1628127041e85678c88f1c72d4df
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145535
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-04-15 18:01:33 +00:00
Keiichi Watanabe
275c1ef45d crosvm: Apply cargo fix for some clippy errors
Executed the following command to fix trivial style problems automatically.
$ rustup run nightly cargo fix -Z unstable-options --clippy \
  --all-features --all-targets

BUG=chromium:908640
TEST=build

Change-Id: I8a42806dc573b25d4ca918112e7b420793261d37
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145537
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-04-15 18:01:32 +00:00
Keiichi Watanabe
6eb0ca94ac crosvm: Fix compile warnings
BUG=none
TEST=cargo check --all-targets --all-features

Change-Id: I266350f9cf7ce6c89fd25106a1a3e43361672dbb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145536
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-04-15 18:01:31 +00:00
Zach Reizner
297ae77887 msg_socket: add specialized error for zero sized recv
Receiving no data can be considered a special case for MsgOnSocket. It
doesn't necessarily indicate EOF because usually messages are sent over
a datagram channel and some fixed sized messages are actually zero
sized. This change handles this by adding a specific result for
receiving no data when at least some was expected. This will also
simplify some error handling that had to unpack the `BadRecvSize`
variant.

TEST=cargo test -p msg_socket
BUG=None

Change-Id: I16feeabc1481de93a2b189989d095434b5b417b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2079178
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-04-14 23:56:49 +00:00
Zach Reizner
e4cbef4caf tests: enable logging for boot test
The logs are important for diagnosing errors for the boot integration
testing. This change enables those logs.

TEST=cargo test -- boot
BUG=None

Change-Id: I1cc64fecacb0334118fec748f5382bc16c301e14
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2079177
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2020-04-14 23:56:47 +00:00
Chuanxiao Dong
1d6af551b9 msg_socket: allow Enum with no variant filed types
This is to allow the Enum which doesn't have filed type for all its variants
to derive the MsgOnSocket.

BUG=None
TEST=cargo test -p msg_socket

Change-Id: Iab9edda777f42e25af40e4ec0e5870401c17572b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2143572
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
2020-04-14 18:50:44 +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
Charles William Dick
ed22f6b611 crosvm balloon_stats command
In preparation for moving balloon sizing logic from crosvm to concierge,
expose a balloon_stats command in crosvm. This will allow concierge to
query the actual balloon size and available memory of VMs.

BUG=b:153134684
TEST=(chroot)$ tast run <DUT> arc.Boot.vm; (vm)$ crosvm balloon_stats
<pipe>; See stats are reported.

Change-Id: I1f544526ee728a085d842035754a0c17cf41ed3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2141752
Tested-by: Charles Dueck <cwd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Charles Dueck <cwd@chromium.org>
2020-04-13 02:59:02 +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
Dylan Reid
03164ca9d8 io_uring: allocate iovecs based on returned count from the kernel
The kernel is allowed to not only limit the number of requested entries,
but also provide more than is requested. If a non-power-of-2 is
requested, it will be rounded up to the next power of 2.

Ensure that there are enough iovecs by allocating them based on the
number returned from io_uring_setup instead of the number of entries
requested.

TEST=cargo test read_parallel

Change-Id: If92e0a31858d1af53b99af8415002a4f26b48230
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2140915
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-04-10 00:13:08 +00:00
Dylan Reid
23a2b7b8a2 io_uring: add reading and writing iovecs
Let the user of the io_uring interface specify a slice of iovecs to read
from or write to when queueing an operation to the ring.

These ops can be used by block that has a Vec of iovecs from the
descriptor chain already.

Change-Id: Ia91e03e441cdae03e4fdba33bb601de006ef53ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2140914
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-04-10 00:13:08 +00:00
Dylan Reid
40d0e01de6 io_uring: operation results are unsigned
Switch from returning an i32 to a u32. This will make handling the
number easier for users, as they can assume it is >= 0.

Any value < 0 would not be returned as Ok(value) anyways as ret < 0 is
used for error conditions.

Change-Id: I609ce55d3c6be6e28f4d7aadf7148b2ac3b18878
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2140913
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-04-10 00:13:06 +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
A. Cody Schuffelen
f3081b120e Fix performance problem on Android Sparse images
This was adding ~11 minutes to the boot time with sparse images.

BUG=b:151981838
TEST=launch cuttlefish with sparse images.

Change-Id: I707258566aee338f742a3a5fe94d0bad8302c447
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2111117
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-04-07 23:03:40 +00:00
Charles William Dick
0bf8a5590f crosvm balance available memory
Poll available memory from the host and guest every second. Resize the
balloon so that available memory in the guest is the same as in the
host.

balancemem_timer adds a Token::BalanceMemory to poll_ctx every second
which creates a balloon stats request.
When the stats results come back from the guest, we compute how much the
balloon should change to balance available memory between the guest and
host. If this new balloon size is > 5% different than the current
balloon size, we make a BalloonControlCommand::Adjust to resize the
balloon.

BUG=b:147334004
TEST=tast run <DUT> arc.MemoryChomeOSPerf*, .vm shows memory use similar
to the base arc test. tast run <DUT> arc.MemoryShiftingPerf.vm, both
chromeos and android counters report high numbers. Switch
LOWMEM_AVAILABLE constant to non-existing file, check the ARCVM reports
not running in ChromeOS, but still boots.

Change-Id: I8a581f86bf4881541d2f5f26dc541b35b862d244
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2061518
Reviewed-by: Lepton Wu <lepton@chromium.org>
Reviewed-by: Charles Dueck <cwd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Charles Dueck <cwd@chromium.org>
2020-04-06 05:27:09 +00:00
Dylan Reid
a9a1d02277 Add io_uring interfaces
Provide a low-level interface to operating the new io_uring interface.

This is an unsafe interface with the basic operations of setting up the
ring, adding to it, removing from it, and polling it.

This will be followed by a safe interface layer on top of this code,
then by additions to the asynchronous executor that allow for
asynchronously doing multiple operations to files from one context.

Change-Id: I71f7ffb04ce8cb4da470deda9aee768ab95d3d98
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124009
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@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:20 +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
Zach Reizner
146450b456 msg_socket: support dynamically sized types
This change is a major shift in how the MsgOnSocket trait works to allow
`self` to be used to determine the result `msg_size()`. This is to
support data structures with `Vec` or other dynamically sized type.

TEST=./build_test
     cargo test -p msg_socket
     tast run <DUT> crostini.CopyPaste.*
BUG=None

Cq-Depend: chromium:2025907
Change-Id: Ibdb51b377b2a2a77892f6c75e1a9f30b2f8b0240
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2029930
Tested-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-04-05 15:10:47 +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
Keiichi Watanabe
c56bc98966 docker: Add setup for libvda
Add the following setup for libvda, which will be used by video features
introduced by CL:1973973:

* Pull down platform2 as /platform2
* Create a dummpy libvda.pc file

Note that we don't build libvda.so.

BUG=b:147465619
TEST=build_crosvm.sh

Change-Id: I1f61df57244a13b7df1b7a373d955b6cfe91e188
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2133987
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-04-04 13:49:20 +00:00
Keiichi Watanabe
abf8dabae9 docker: Run cargo check with all features enabled
The current Dockerfile builds crosvm only with some selected features.
To cover all of crosvm code, this CL adds 'cargo check' command.

BUG=none
TEST=./build_crosvm_base.sh && ./build_crosvm.sh

Change-Id: I6e1efa8f68476912c9cec46188f096d430df663c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2134003
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-04-04 13:49:19 +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
Dylan Reid
31deb9fd45 sys_util: Allow pre-populating mmaps
io_uring would like to pre-fault the ring pages as they are likely to be
accessed regularly. Allow mmap users to specify the MAP_POPULATE flag
through a new API.

Change-Id: I5fefc13443280fe832c9601fe5a497b572127f0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124008
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-03-29 08:58:42 +00:00
Dylan Reid
d32100205f syscall_defines: add new/updated syscalls
io_uring is needed so update the syscall defines to match 5.6-rc5.

There was a slight refactor in arm upstream which changed some syscall
names to better reflect their 32 vs 64 bit variants. See kernel commit:
00bf25d6: y2038: use time32 syscall names on 32-bit

TEST=samus,  kukui, and kevin64 build.

Change-Id: Idcceb4bba313a3f826556e90ffde94f166de0a05
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124007
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
2020-03-28 21:09:03 +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
Daniel Verkamp
bbb82287c1 devices: usb: temporarily disable resets
This is a workaround for a bug encountered with newer Android phones -
when connected to the Linux VM, resetting the USB device via
USBDEVFS_RESET causes the device to disconnect from the host, preventing
its use in the VM.

This works around the issue by removing both paths that can cause a
USB device reset (initial reset at device insertion plus reset when
requested by the guest kernel).  Both of these must be removed to
restore functionality; if either is still in place, the failure is still
observed.

The workaround specifically exempts Edge TPU devices, which need a reset
for firmware update; these devices will still issue a reset on connect
and when requested by the guest.

BUG=chromium:1058059
TEST=Connect Pixel 3 to eve, adb logcat

Change-Id: I7a689da1120e1fb772d95e41a0d4debe64f7d6a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2105814
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-03-27 03:58:37 +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
928a8395e0 docker: update ADHD commit to fix kokoro build
Update the audio_streams dependency to fix a build failure introduced in
https://crrev.com/c/2038413.

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

Change-Id: I99b26c925a8bc5bb6f77575eb64c0972a5a5e0ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2116274
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: George Engelbrecht <engeg@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-03-24 20:59:23 +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