Commit graph

1203 commits

Author SHA1 Message Date
Daniel Verkamp
6eadef77a3 sys_util: add WriteZeroesAt trait
Add a variant of WriteZeroes that allows the caller to specify the
offset explicitly instead of using the file's cursor.  This gets rid of
one of the last bits of shared state between disk file users, which will
help in implementing multi-queue support.

Additionally, modify the WriteZeroes trait to use a generic
implementation based on WriteZeroesAt + Seek when possible.

BUG=chromium:858815
TEST=Boot Termina in crosvm

Change-Id: If710159771aeeb55f4f7746dd4354b6c042144e8
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913519
2019-11-27 21:22:37 +00:00
Xiong Zhang
3064a7164a Setup vcpu's MTRR
When vfio pass-through is enabled, guest will be very slow. The root
casue is gfn is uncachable in EPT.

From the comments in kernel vmx_get_mt_mask(vcpu, gfn, is_mmio)
function, EPT memory type with VT-d, VT-d without snooping control
feature: can't guarantee the result, try to trust guest through
kvm_mtrr_get_guest_memory_type(vcpu, gfn).

But crosvm doesn't set mtrr, so host kernel will set uncachable for all
gfn in ept.

This patch set the default cache type as WB, and set mmio cache type as
UC, so the guest ram is WB.

BUG=chromium:992270
TEST=crosvm --vfio /sys/devices/pci0000:00/0000:00:02.0, pass through
host igd into linux guest, the guest runs smoothly and guest desktop
could be shown on physical local display.

Change-Id: I151aae7835910cfbc9e38464ee901e5da281de1e
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1813458
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-11-27 09:04:26 +00:00
Chirantan Ekbote
3ea11281eb io_jail: Use rlim64_t for minijail_rlimit
The libminijail API defines rlim_t as an alias for rlim64_t.  Change the
FFI bindings to use rlim64_t.

BUG=none
TEST=`tast run kevin vm.Virtiofs`

Change-Id: I21ece499bcef187b358574bca0918b39f5971586
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1933612
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>
2019-11-27 08:45:56 +00:00
Zach Reizner
2b0bc61ea7 gpu_display: amend GpuDisplay to import and attach EventDevices
This change also includes stubs for the wayland and x11 impls.

TEST=compiles
BUG=chromium:1023975

Change-Id: Ia2bcb5c2ed75ea47071dd77e149e60901a56595c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930407
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-11-26 21:05:44 +00:00
Zach Reizner
6f8823abb5 gpu_display: add EventDevice to bridge gpu_display to a virtual input device
The EventDevice is a data structure that allows a generic gpu display to
send and receive input events in evdev's format to a generic input
device, such as virtio-input.

BUG=chromium:1023975
TEST=None

Change-Id: Ic663cc8c7a3031aee929e09620c5430c27a25190
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930406
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-11-26 21:05:44 +00:00
Zach Reizner
e3f1271842 sys_util: poll: add iter_writable to set of methods for PollEvents
There were already methods for the readable and hungup events, so this
completes the set.

TEST=None
BUG=chromium:1023975

Change-Id: Ie9cd1459893cc8b6ba7a52e638e164095ddbcba5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930404
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-11-26 21:05:42 +00:00
Chirantan Ekbote
1a2683b90d linux.rs: Remove references to chronos
Even when run on Chrome OS, the crosvm process does not have enough
privilege to add the chronos user/group to the {u,g}idmap of the 9p
device process.  This was never cleaned up because we don't use the 9p
device in crostini VMs (seneschal spawns 9s servers in a separate
process tree).

Remove all references to the chronos user/group and just do what the
other devices do: use the crosvm user/group if it exists or fall back to
the current euid/egid.

BUG=chromium:1028442
TEST=Add `--shared-dir` to the command line flags of a termina VM and
     see that it starts properly

Change-Id: Iad4927d37c35709aee6e15f79b316eb88483458f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1935581
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>
2019-11-26 20:20:02 +00:00
Daniel Verkamp
bdd708edd2 disk: fix composite unit test build
This was unintentionally broken when changing ReadWriteVolatile to
ReadWriteVolatileAt (the composite unit tests aren't built or run by
default since they are behind a feature flag).

BUG=None
TEST=cargo test --features=composite-disk -p disk

Change-Id: I864d7063bd27a401c3d878fcd22b52e2357fde8d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913960
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-25 06:36:36 +00:00
Daniel Verkamp
e7d7728701 Cargo.lock: add sync to libcras dependencies
libcras now depends on crosvm's sync crate; add it to Cargo.lock to
satsify non-portage builds of crosvm with cargo (otherwise cargo updates
Cargo.lock itself).

The dependency was added here:
https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/1871758

The pinned commit for adhd used in the Docker build is also upgraded to
the current master so that it matches.

BUG=None
TEST=`cargo build; git diff` and verify Cargo.lock was not modified

Change-Id: I53526ae2448b95c287528596099a804ec28a16d1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1924784
2019-11-23 01:04:45 +00:00
Chuanxiao Dong
c81d5fcad8 x86_64: fix the incorrect parameter for disabling ACPI
noacpi is not used by the current guest linux kernel to disable ACPI.
Instead, acpi=off is the right parameter to be used.

BUG=chromium:1026497
TEST=launch crosvm linux guest and ACPI is disabled

Change-Id: I9c9001146abb57ea9dbc078ee6188b8c60cb056e
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1925999
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-22 13:46:19 +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
Chirantan Ekbote
220605a5fd io_jail: Replace rlim_t with rlim64_t
rlim_t is defined as an unsigned long but importantly, it is defined as
what the _kernel_ thinks is an unsigned long.  This means that when you
have a 32-bit userspace and a 64-bit kernel (like we do for arm64
chromebooks), rlim_t is 64 bits.

This isn't really a problem for C and C++ code because they use the
headers from the kernel where rlim_t is properly sized but it doesn't
really work for rust.  The libc crate defines rlim_t as an alias for
::std::os::raw::c_ulong, which leads to the rust compiler thinking that
it has a 32 bit width.

Hilarity ensues when you attempt to cross the rust -> C FFI barrier with
these conflicting definitions. The rust compiler thinks the parameters
can fit in 32 bit registers so it puts the `cur` parameter in r2 and the
`max` parameter in r3. On the other hand, the C code knows that the
parameters are 64-bit values and combines r2/r3 to create the 64-bit
`cur` value and uses the first 8 bytes on the stack as the `max` value.
This leads to a `cur` value that is way too large and a nonsensical
`max` value that depends on whatever happened to be on the stack at the
time.

Fix this by changing the library bindings to u64 and the
Minijail::set_rlimit parameters to rlim64_t.  Once we add a method to
minijail that accepts rlim64_t's we can switch the library bindings to
use that as well.

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

Change-Id: I8f58923c4768ecfe827d2a5d73c72dc778fe419c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1916560
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-11-22 05:54:01 +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
Chirantan Ekbote
b0ac00745a Enable seccomp for virtio-fs
Add x86_64 and arm seccomp policy files for the virtio-fs device.

BUG=b:136128319
TEST=Run a vm with a sandboxed virtio-fs device

Change-Id: I8ea7c5d3e90696077f0c2b1f942cb286a0b36cf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1916559
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2019-11-19 17:59:49 +00:00
Chirantan Ekbote
bd4723b218 Add fs device to --shared-dir
Expand the `--shared-dir` option to allow callers to select between 9p
and virtio-fs for sharing directories.

BUG=b:136128319
TEST=start a VM with a virtio-fs based shared directory

Change-Id: Ie8afc1965b693805dd6000f0157786317aab060d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1705656
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2019-11-19 17:59:47 +00:00
Daniel Verkamp
9093c002fe fuzz: block_fuzzer: add sparse param to Block::new
Fix the block_fuzzer build after CL:1906750, which added a new parameter
to the Block::new() function without updating the fuzzer.

This change passes `true` for sparse in order to keep previous behavior
and maximize the available commands for fuzzing.

BUG=chromium:1025757
TEST=`USE='asan fuzzer' emerge-nami crosvm`

Change-Id: I29ed9945077936aee9636ddee20b59729eb78c85
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1922065
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-11-19 03:10: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
Daniel Verkamp
1de388ae02 Revert "devices: virtio: disable MSI-X for block and net"
Re-enable MSI-X for virtio-blk and virtio-net now that the underlying
issue causing hangs at startup has been fixed (CL:1917495).

BUG=chromium:1019986
TEST=Boot Termina on nami

This reverts commit 85858f580e.

Change-Id: I5a5e197243a16aee2b2aaf3145a1180749b097b2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1918261
Reviewed-by: Zide Chen <zide.chen@intel.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-18 07:44:13 +00:00
Daniel Verkamp
2a9e620f9a devices: virtio: remove unused VirtioPciDevice functions
The queue_evts() and interrupt_evt() functions were public, but nothing
was calling them.  Remove them to clean up the unused code.

BUG=None
TEST=./build_test

Change-Id: Id36e78343869746c733bba04383ab93c9d377601
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898270
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-11-18 07:43:05 +00:00
Daniel Verkamp
5eca937941 devices: virtio: use signal helper for config changes
Add handling of the virtio device MSI-X configuration change vector by
using the signal function that was previously factored out.

BUG=chromium:854765
TEST=./build_test
TEST=trigger disk config change with `crosvm disk resize ...`

Change-Id: I462c23e10d152f896586bb70b95634a53088d480
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898269
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-11-18 07:43:04 +00:00
Daniel Verkamp
24eeed2b6f devices: virtio: pass Interrupt to activate()
Factor out the common creation of struct Interrupt.

No functional change.

BUG=chromium:854765
TEST=./build_test

Change-Id: Idf8804771ba1af5181818f643e15e1b42918258a
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1898268
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-18 07:43:03 +00:00
Daniel Verkamp
e7c46cad41 devices: virtio: block: refactor status_writer setup
This consolidates the status byte manipulation in process_one_request()
instead of requiring both that function and execute_request() to deal
with it.

The tests are modified to run the full process_one_request() function
instead of just execute_request() to exercise the full descriptor
parsing logic, and they are adapted to read the status of the request
from the status byte in the buffer from the descriptor since
process_one_request() returns successfully as long as the descriptor
parsing succeeded, even if the requested I/O failed.

BUG=None
TEST=./build_test

Change-Id: I17affabc2d3c30c810643ce260152cf34893b772
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1918479
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-18 07:39:54 +00:00
Chuanxiao Dong
917b90e2a3 devices: update the msix route table regardless msix mask status
The msix entries might be changed by guest during msix maksed. The
current implementation won't update the MSIX route table in this case
which can cause KVM still inject the IRQ according to the old routing.

To fix this, we should update the msix route regardless the msix mask
status.

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

Change-Id: Ifa356b3834ff454ecfca1dbdd97a7ca940d1f2b6
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1911721
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-18 03:46:37 +00:00
Daniel Verkamp
8ec87d6d33 devices: pci: make get_bar_addr work for all BAR types
Previously, PciConfiguration::get_bar_addr would only correctly return
the value of a 32-bit memory region; implement support for the other
valid BAR types as well.

BUG=None
TEST=cargo test -p devices

Change-Id: I221187dfb96b31d7fead73eccf605a0886021d8b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1880164
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-17 22:34:22 +00:00
Zide Chen
8958407dcb main: remove EPOLLHUP epoll item from host kernel synchronously
control_sockets.swap_remove() could cause host kernel to invoke
ep_remove() to remove the epoll item.

But it's called from the task work, and it could be deferred after
next poll_ctx.wait() which could unexpectedly pick up epoll events
from the already closed fd.

BUG=chromium:1019986
TEST=launch Crosvm guest from heavy loaded Linux host

Change-Id: I474a7a47a484e3acfae4383d61601e1553bd674f
Signed-off-by: Zide Chen <zide.chen@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1917495
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-17 00:22:43 +00:00
Zach Reizner
f35d8904b8 devices: virtio: add missing virtio type IDs
TEST=./build_test
BUG=None

Change-Id: I52dd8ca64287a93eb89c045cb0418aefc9e9ba23
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1912777
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2019-11-16 22:22:02 +00:00
Gurchetan Singh
f829a93b62 guest_memory: remove optional memfd
Builders should all have memfd support now.

BUG=chromium:942183
TEST=compile and run, CQ will also test

Cq-Depend: chromium:1901871, chromium:1907541
Change-Id: I0cd4ec43a51e9995def2e105d68e12a703168365
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1834701
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2019-11-16 11:07:22 +00:00
Matt Delco
2da6132389 io_jail: add additional apis
This change adds additional APIs that are present in the libminijail
header file but not in the rust thunk.  In particular it adds the API
that allows pre-compiled bpf files to be used as a policy file.  The
native API lacks an API to specify a filename (it only provides an API
to provide the contents of the file).

BUG=None
TEST=Local run of build_test to confirm that both .bpf and .policy files
work in a subsequent change.

Change-Id: I15510ffa857b501512f3f9905882545f407bcd78
Signed-off-by: Matt Delco <delco@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1914415
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-16 10:29:04 +00:00
Stephen Barber
8865c5b195 devices: net: remove rx_buf from receive path
Performance-wise this about breaks even, but greatly simplifies the
virtio-net handling for processing received frames.

BUG=chromium:753630
TEST=crostini.NetworkPerf

Change-Id: Ie7b576020ecfe2a6cc41b7f72bd7143795a9a457
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1906996
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-11-16 09:47:43 +00:00
Chirantan Ekbote
961461350c devices: fs: Allow running as users other than root
Don't assume the file system is running as the root user when changing
credentials.  Instead keep track of the thread euid/egid and use those
when restoring thread credentials.

BUG=b:136128319
TEST=`tast run vm.VirtioFs`

Change-Id: I37d59def99cd71de68aa7f94941031a86df54329
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1890584
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-11-12 06:31:52 +00:00
Daniel Verkamp
6cf8651dc3 devices: virtio: ensure all block data is transferred
Add _exact/_all variants of the FileReadWriteAtVolatile functions on
descriptor Reader/Writer, and use them in the block device to replace
the short read/short write error cases.  This ensures all data is
read/written even if the underlying implementation (in particular,
qcow2) does not transfer the full amount of data in one
read_vectored_at_volatile/write_vectored_at_volatile call.

BUG=chromium:1023422
TEST=`mkfs.btrfs /dev/vdb` with a qcow2 disk

Change-Id: Ia37a333947f6f63faf3d4a06cfcc297309d5aff6
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1907443
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-11-11 22:02:33 +00:00
Xiong Zhang
62fd776c5c Vfio: Suitably allocate bar for vfio device
Use 64bit flag in vfio device's bar to get correct mmio allocator.

BUG=chromium:992270
TEST=none

Change-Id: I8f3dab48eb6dc0b92071803aa3526cadda8034c7
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581143
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-11-11 09:46:44 +00:00
Xiong Zhang
d9a54c222e kvm: Allow low mmio added into kvm
gpa > guest_mem.end_addr() is used to avoid gpa fall into guest ram,
but low mmio maybe below guest_mem.end_addr(), this condition is false,
then low mmio couldn't be added. Since low mmio could be added into kvm
also, this condition is wrong.

This patch iterate all the guest memory reginos, and check whether it
overlap with any of them.

BUG=chromium:992270
TEST=bulld_test

Change-Id: I9560db43f9836f85d0ff927e7eeb92447774568c
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895235
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-11-11 09:46:43 +00:00
Chirantan Ekbote
3f8599aea9 io_jail: Add minijail_rlimit
The virtio-fs server opens a lot of fds and needs to have it's open file
limit increased.

BUG=b:136128319
TEST=run pjdfstests

Change-Id: I9ccc9e0753f990788c9cef2540b3a1aab5f5d15d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1890583
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-11-11 03:13:51 +00:00
Xiong Zhang
383b3b520a resource: Rename device memory to mmio
Since unified allocator is used to allocate mmio, this patch remove the
device memory name, and rename device to mmio.

BUG=chromium:992270
TEST=this patch doesn't change function, run build_test

Change-Id: I234b0db4b3c5de8cfee372ace5212a980564d0c7
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895234
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-11-10 06:39:34 +00:00
Xiong Zhang
87a3b44d9e Resource: Unify mmio allocator
Current mmio and device two allocators exist, the purpose to define
two allocator is:
Accessing to gpa from mmio allocator cause vm exit, while gpa from
device allocator doesn't cause vm exit.

Whether vm exits exist or not, dependency on whether
vm->add_device_memory() is called with gpa from allocator or not.Even
if gpa is from mmio alloator, and vm->add_device_memory() is called
with this gpa, accessing this gpa won't cause vm exit. So mmio allocator
and device allocator couldn't guarantee the original purpose.

This patch unify mmio allocator and device allocator into one mmio
allocator.

BUG=chromium:992270
TEST=this patch doesn't change function, so just run build_test

Change-Id: If87d5c2838eb122ef627fa45c394b1b3ccfafeb0
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895233
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-11-10 06:39:31 +00:00
Daniel Verkamp
279248255f devices: virtio: add peek operation to queue
This allows the caller to grab a buffer without committing to using it,
which can be used in the case where two resources (a virtio buffer plus
some other resource) need to be acquired simultaneously.

BUG=None
TEST=build_test.py

Change-Id: Icb61de99db807648ff02c41f95b3128ecce41501
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1904638
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-11-09 22:10:10 +00:00
Zach Reizner
aa7f102ef8 ensure libc crate is at least 0.2.44
BUG=None
TEST=emerge-${BOARD} crosvm

Change-Id: Ifc7e0b0d8dc42faf54e920533225fafc197e0b7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1906988
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-11-09 06:37:57 +00:00
Daniel Verkamp
2fc5c6cd95 devices: virtio: wl: use descriptor reader/writer
Convert the virtio wayland device to use the descriptor_util
Reader/Writer helpers to simplify the code and allow support
of arbitrary descriptor layouts.

BUG=chromium:966258
TEST=./build_test.py

Change-Id: Ic854b76d378be261db4f21cba475bd0abc4af80e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1815418
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 23:19:53 +00:00
Daniel Verkamp
32f22987c8 disk: replace into_iter() with equivalent iter()
Fixes clippy warning:

  warning: this .into_iter() call is equivalent to .iter() and will not
  move the slice

BUG=None
TEST=bin/clippy

Change-Id: I5361495f02609dd5e5313b7bc792e663841212ad
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896091
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 22:18:19 +00:00
Daniel Verkamp
87865b9580 kvm: replace unused Err with is_err() check
Fixes clippy warnings:

  warning: redundant pattern matching, consider using `is_err()`

BUG=None
TEST=bin/clippy

Change-Id: I745a74e89be9b547e8f42bd80b5401ce3b27c42a
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896090
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 22:18:19 +00:00
Daniel Verkamp
2ad6124eeb kvm: silence clippy warning about pointer alignment
Ignore the clippy warning about pointer alignment in casts in
set_thread_id(), matching the existing annotation for set_data().

run_mmap is sufficiently aligned, since it is a mmap-ed region with at
least page alignment.

Fixes this clippy error:

  casting from `*mut u8` to a more-strictly-aligned pointer (`*mut
  kvm_sys::x86::bindings::kvm_run`) (1 < 8 bytes)

BUG=None
TEST=bin/clippy

Change-Id: I4c33385d081d785002dda2d589eeb3ed10a92bfc
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896089
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 22:18:18 +00:00
Daniel Verkamp
a1bc67ffd7 Remove unneeded return statements
BUG=None
TEST=bin/clippy

Change-Id: I2cf3b961baefd21fedaa6b545c1c7ecfb25a9efc
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896088
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 22:18:17 +00:00
Daniel Verkamp
0124500a28 Remove unnecessary static str lifetimes
Const and static variables imply a static lifetime, so declaring it
isn't necessary.

Fixes clippy warnings of the form:

  Statics have by default a `'static` lifetime

BUG=None
TEST=bin/clippy

Change-Id: I99e63b435b6b2fd5fbce9ef617e89ec114587ad7
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896087
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 22:18:17 +00:00
Daniel Verkamp
6787ff3f0f Remove unnecessary ? when returning Err
Fixes warnings of the form "returning an `Err(_)` with the `?` operator"
from clippy.

BUG=None
TEST=bin/clippy

Change-Id: Ied9c0bfbd71ad825fe88c861160e59db491efdd3
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896086
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 22:18:16 +00:00
Daniel Verkamp
7a5a7fc44f arch: replace is_some + unwrap with if let
BUG=None
TEST=emerge-kevin crosvm

Change-Id: I78aa9f4fb4fb46de3394bb9bc2fa5a53e210fa0b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896085
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 22:18:14 +00:00
Daniel Verkamp
2b109386e7 devices: virtio: block: advertise seg_max
The virtio-blk configuration space has a `seg_max` field that lets the
device inform the driver of the maximum number of segments allowed
within a single request.  The Linux virtio block driver assumes that if
the corresponding feature (VIRTIO_BLK_F_SEG_MAX) is not advertised, then
only one segment can be used.

Add a segment limit based on sysconf(_SC_IOV_MAX) to allow the Linux
block stack to make use of multiple segments in a single request, which
will get translated into a single readv/writev call in the crosvm block
device.

BUG=None
TEST=strace crosvm virtio-blk process and note preadv with iov_cnt > 1

Change-Id: Ia14ebebb85daa21e2d43437bb74886f32e6e8187
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1876806
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 20:35:18 +00:00