Commit graph

428 commits

Author SHA1 Message Date
Zach Reizner
a1422e6bca fix warning and bit rotted tests uncovered by kokoro
TEST=run kokoro presubmit
BUG=None

Change-Id: I301551f8f58263f1a8b7a8276867881cb17517ab
Reviewed-on: https://chromium-review.googlesource.com/1236889
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-09-22 01:43:11 -07:00
Chirantan Ekbote
0a4f280e3a seccomp: Update 9p policy
Add newfstatat for x86 and fstatat64 for arm to the seccomp policy file
for the 9p device and server program.

BUG=chromium:886535
TEST=`vmc share termina foo` and then `ls /mnt/shared` inside the VM
     works

Change-Id: I6871f54ae885e080dca0ea5751987d59c55a59d6
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1232556
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-09-21 19:50:12 -07:00
Stephen Barber
5abdc78c82 kokoro: add initial presubmit script and config
BUG=b:73822503
TEST=run kokoro presubmit

Change-Id: Id128de2300a76f8a359521c83b371e9b743bc71b
Reviewed-on: https://chromium-review.googlesource.com/964601
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-21 00:51:21 -07:00
Daniel Verkamp
a40cbb4a94 devices: block: enforce read-only in execute()
To fully meet the requirements laid out by the virtio specification, we
need to fail write commands for devices that expose VIRTIO_BLK_F_RO with
a specific error code of VIRTIO_BLK_S_IOERR.  Pipe the read_only status
down into the worker and the request execute function so that it can be
checked and return the correct error code.

BUG=chromium:872973
TEST=Attempt to write to read-only /dev/vda in termina

Change-Id: I98c8ad17fde497e5a529d9e65096fb4ef022fd65
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1211062
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-09-21 00:51:15 -07:00
Daniel Verkamp
a0408258e0 seccomp: whitelist connect for wl_device
The path to the wayland socket changed, so the previous whitelist based
on the connect() arg2 sockaddr_un size now fails.

BUG=None
TEST=Verify that release build of crosvm starts again on chromebook

Change-Id: I3c30977e7c1487b937d69e1dbce4b7fd87136978
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1234827
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-20 15:00:24 -07:00
Daniel Verkamp
713dd60491 devices: block: clear flush timer once it fires
Otherwise, the flush timer case of the PollContext continues to fire
repeatedly, since the timerfd remains readable.

BUG=None
TEST=Verify that crosvm virtio_blk thread no longer pins the CPU after
     writes are done

Change-Id: I693346c078e07b97e30083f34d00be75fa93841d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1232295
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-19 15:40:06 -07:00
Daniel Verkamp
616a093d91 devices: block: allow timerfd syscalls in seccomp
"devices: block: Flush a minute after a write" introduced new timerfd_
syscalls into the block device but did not add them to the seccomp
whitelist.

BUG=chromium:885238
TEST=Run crosvm in multiprocess mode and verify that it boots

Change-Id: I1568946c64d86ab7dba535a430a8cbe235f64454
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1231513
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-19 15:40:06 -07:00
Dylan Reid
cd9f86b299 qcow: Add a utility program for qcow analysis
This program makes figuring out the state of a qcow file easier.

Change-Id: If297eb0cd835a86d8f284d3aef3d7e962e095726
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1207455
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-09-19 15:40:06 -07:00
Dylan Reid
39401ff269 qcow: Add accessors for more file state
Being able to access the state of the qcow file makes debugging easier.
These functions will be used from a helper program in the following
commit.

Change-Id: I1db7ddaeaff1c83363513a2c55c44a1825833634
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1207454
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-09-19 15:40:05 -07:00
Zach Reizner
579bd2cf0e linux: bind wayland directory in virtio-wayland sandbox
For example, if the wayland socket is given as /run/wayland-0, the
entire /run/ directory will be bind mounted into the sandbox as
/wayland/. The wayland device will then be told to open the socket at
/wayland/wayland-0. If the /run/wayland-0 file is removed and a new
socket is opened in its place, as in a chrome crash, the
/wayland/wayland-0 socket will open the new socket rather than the one
belonging to the expire process.

TEST=vmc start termina; chrome://inducebrowsercrashforrealz;
    vsh termina; start wayland application
BUG=chromium:884398

Change-Id: I259eb2f7e29ee6b61836133ec1c3a110c5575957
Reviewed-on: https://chromium-review.googlesource.com/1227063
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-09-17 21:35:02 -07:00
Zach Reizner
a99954cb7c sys_util: remove Scm struct and sock_ctrl_msg C library
The Scm object was made to reduce the number of heap allocations in
the hot paths of poll loops, at the cost of some code complexity. As it
turns out, the number of file descriptors being sent or received is
usually just one or limited to a fixed amount that can easily be covered
with a fixed size stack allocated buffer.

This change implements that solution, with heap allocation as a backup
in the rare case that many file descriptors must be sent or received.

This change also moves the msg and cmsg manipulation code out of C and
into pure Rust. The move was necessary to allocate the correct amount
of buffer space at compile time. It also improves safety by reducing the
scope of unsafe code. Deleting the code for building the C library is
also a nice bonus.

Finally, the removal of the commonly used Scm struct required
transitioning existing usage to the ScmSocket trait based methods. This
includes all those changes.

TEST=cargo test
BUG=None

Change-Id: If27ba297f5416dd9b8bc686ce740866912fa0aa0
Reviewed-on: https://chromium-review.googlesource.com/1186146
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-17 21:34:50 -07:00
Dylan Reid
4a55609f50 devices: block: Flush a minute after a write
If the guest doesn't issue a flush command after a write, insert one.
This will mainly help qcow backed files. However, it is a good idea for
block devices as well, it narrows the window for data loss.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I1d6eaeda6fd5038ec994ed882e870ae025e3c151
Reviewed-on: https://chromium-review.googlesource.com/1211126
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-09-17 21:34:43 -07:00
Dylan Reid
407c3151d8 sys_util: timerfd: Add ability to check if the timer is armed
This allows users to only arm timers if not already armed.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I8d7c6a7643a2ae2ce4b5679107bfd2be6e4adf3a
Reviewed-on: https://chromium-review.googlesource.com/1214442
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-09-17 21:34:42 -07:00
Dylan Reid
32e17bc0b7 qcow: Cache address and refcount tables
Cache the address lookup and refcount tables in RAM. This removes an
absurd number of system calls required for accessing the qcow image as
previously each lookup required reading from at least three locations on
disk. Now the disk will only be accessed when there is a cache miss or
when the structure of the disk need to be updated; when a cluster is
added or removed.

The L1 address lookup table and the refcount table are both read at
creation time and kept in memory. For now all caches are committed to
disk only when the file is flushed. Later a timer will be added to
periodically flush the caches to disk so there is less window for data
loss.

The L2 and refcount blocks are cached as full clusters. Those clusters
are kept in the cache until a flush or they need to be evicted to make
room for a new entry. The eviction is currently very simple, writing
back the first entry in the cache in whatever order a hashmap iterator
uses. This can be improved, but the speedup is already enough that it
seems acceptable to start.

Change-Id: Ifcc55f243961d54eb1c6255b975a1529e2e987af
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1207453
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-09-17 21:34:42 -07:00
David Riley
b22b6137aa gpu: add sandboxing via minijail for virtio gpu device.
Sandboxing only works when started as chronos via concierge client.  If
started directly via crosvm as root, the jail will not have proper group
permissions to access the Wayland socket.

BUG=chromium:837073
TEST=build with --features=gpu; null_platform_test without --disable-sandbox
CQ-DEPEND=CL:1213779

Change-Id: I6331f7ae1f5b99d31ad44cf158f72337294771f0
Reviewed-on: https://chromium-review.googlesource.com/1181168
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-17 13:18:06 -07:00
Dylan Reid
9fbac2cf59 Add basic rustfmt config
Enable two optional features:
- Swapping try for '?'
- Shortening "name = name," to "name," in member initialization.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I8e29eb01f10451cd2a549a699de07f651cc4af0f
Reviewed-on: https://chromium-review.googlesource.com/1226224
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-15 20:58:19 -07:00
Dylan Reid
5e8406549f qcow: Add refcounting helper
The refcounting helper breaks out management of the refcounts and
caching the refcount blocks.

Change-Id: I6e75fbe0eb47277ccf7a93af026b5020089875db
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1207452
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-09-15 20:58:18 -07:00
Dylan Reid
62d21839e6 qcow: Add vec_cache
The `VecCache` struct will be used to represent the file clusters in
caches. It ties a vector to a state of dirty or clean.

Change-Id: I474eb67d2ad9f086da638ecc385ccce74737d3b9
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1207451
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-09-15 20:58:17 -07:00
Dylan Reid
8b952c2faf qcow: Add raw file struct
The raw file struct will be used to hold enough state for basic
operations. This will allow mutating the file without taking a mutable
reference to an entire QcowFile.

Change-Id: Ia0a86537915da039274923df2f85c22d191b9969
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1207450
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-09-13 18:59:02 -07:00
Dylan Reid
96c4a6df2d devices: pci: add subsystem vendor and device ID
The virtio PCI specification places requirements on the PCI subsystem
IDs, so allow PCI devices to specify them in PciConfiguration.

Change-Id: I70bc6ad4333ba3601db2831fef03483bcaea70ff
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1208156
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-13 18:58:44 -07:00
Dylan Reid
11809f60ab devices: pci: fix capability mask in status reg
The status register is actually the high 16 bits of register index
STATUS_REG (1).  Adjust the STATUS_REG_CAPABILITIES_USED_MASK value
accordingly so it is bit 4 within the high 16 bits.

Change-Id: I3fb695a577bae754eda5640224ef335c44b119eb
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1208152
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-10 17:17:36 -07:00
Dylan Reid
bc8d9059ab resources: fix allocator doc tests
Change-Id: I5a9b7460fc798d9abf1ad1f452233fe76c449b29
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1208151
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-10 17:17:36 -07:00
Dylan Reid
67afe44f80 devices: Move VirtioDevice to its own file
Currently VirtioDevice was only used by MmioDevice. Move it to a
separate file to allow it to be used by a PCI implementation in the
following commits.

Change-Id: Ie2de92d8876fdaa31d71341714681212d52a618c
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1208690
Commit-Ready: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-10 17:17:35 -07:00
Dylan Reid
059a188d0d Arch: Big refactor and add an empty PCI bus
When setting up IO, accept an optional PciRoot device to put on the IO
bus.

For aarch64, it's currently ignored. For x86_64, it will be added at
0xcf8.

 break up mmio device creation and registration

Moving forward registration will be handled by the architecture specific
code. However, creation will be handled by the common code. To make that
easier split up the two steps so a list of devices is created, then each
is registered later.

Start moving to a model where the configuration generates a set of
components that are passed to the architecture. The architecture will
crate a VM from the components.

Break up the big run_config function and move architecture specific
parts to the various architectures.

This doesn't refactor the function calls each architecture makes, but
moves the setup flow in to the arch impls so that they can diverge in
the future.

Change-Id: I5b10d092896606796dc0c9afc5e34a1b288b867b
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1099860
Commit-Ready: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2018-09-10 17:17:35 -07:00
Daniel Verkamp
7621d910f5 devices: block: implement discard and write zeroes
Discard and Write Zeroes commands have been added to the virtio block
specification:
88c8553838

Implement both commands using the WriteZeroes trait.

BUG=chromium:850998
TEST=fstrim within termina on a writable qcow image

Change-Id: I33e54e303202328c10f7f2d6e69ab19f419f3998
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1188680
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-10 13:33:46 -07:00
Daniel Verkamp
ed2b3e0349 pci: add tests for add_capability()
Also fix the misleading add_capability() comment.  The standard PCI
capability header is just two bytes (capability type and next pointer);
the length byte is only part of the vendor-specific capability (09h).

More importantly, the current implementation of add_capability() already
inserts the two-byte standard header, so the caller should not provide
it as part of cap_data.

BUG=None
TEST=cargo test -p devices

Change-Id: Id3517d021bfe29d08ff664d66455b15cf07af1d1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1197069
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-05 21:04:23 -07:00
Daniel Verkamp
8a4a13d48d virtio-gpu: fix reporting of VIRTIO_F_VERSION_1
The virtio 1.0 feature flag is defined as a shift count, not a mask.

While we're at it, change the virtio gpu features() function to the
avail_features style used in other devices for consistency.

BUG=None
TEST=None

Change-Id: I704d9676cfe5f13d9a2f83eb9160937e94070d1e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1198224
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-05 01:25:54 -07:00
Daniel Verkamp
9c7cd86325 qcow: deallocate clusters in write_zeroes
When a write_zeroes call covers a whole cluster, we can deallocate the
storage for that cluster rather than writing zeroes.

This is currently implemented by removing the cluster allocation from
the mapping tables, then attempting to release the backing storage using
fallocate() with FALLOC_FL_PUNCH_HOLE.

BUG=chromium:850998
TEST=cargo test -p qcow

Change-Id: Ie4edb2e02bfaa1df9a19919b77eeb3c58c112d1c
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1187019
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-05 01:25:50 -07:00
Daniel Verkamp
95a8868aef qcow: implement WriteZeroes for QcowFile
Add a simple implementation of WriteZeroes for QcowFile that just
writes zeroes to allocated clusters and skips clusters that are already
unallocated (since they already read back as zeroes).

BUG=chromium:850998
TEST=cargo test -p qcow

Change-Id: I8f26c8cc4016c129850aaf08c7188dfe08d6dacb
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1187018
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-05 01:25:50 -07:00
Daniel Verkamp
a3d11edaa6 sys_util: add WriteZeroes trait and impl for File
BUG=chromium:850998
TEST=cargo test -p sys_util write_zeroes

Change-Id: I90f670fffed055f39e141b26819d56948b1bf30d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1187017
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-09-05 01:25:49 -07:00
Daniel Verkamp
0e8f6fa96e sys_util: add safe wrapper for fallocate()
BUG=chromium:850998
TEST=None

Change-Id: I1b6864f7d508cf7f24248a8cc9783af2d8b00891
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1187016
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-09-05 01:25:49 -07:00
Dmitry Torokhov
caa2e5a4ac plugin: do not fail crosvm_vcpu_get_msrs() if we failed to fetch some
KVM_GET_MSRS may return less MSRs that were requested; do not fail but
instead let callers to know how many were fetched.

BUG=None
TEST=cargo test --features plugin

Change-Id: Ie14a3d38b66bfe34f5279543bea9c6c78423527e
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1192232
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-08-31 05:22:52 -07:00
Dmitry Torokhov
9dec40e242 kvm: fix get_msrs() to handle case where KVM does not fetch all MSRs
KVM may not return all MSRs that were requested in KVM_GET_MSRS call and
instead stop early. We should handle this case.

BUG=None
TEST=cargo test -p kvm

Change-Id: I18402c0a07b1d0c7657c171873d521fd2f223611
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1192231
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-08-31 05:22:52 -07:00
Dmitry Torokhov
45e6c843bb kvm: fix set_gsi_routing() test
We have to create irqchip in kernel before we are allowed to set up
routing.

BUG=None
TEST=cargo test -p kvm

Change-Id: Icee680ce3cc16af9cf4492c048f0b9b3cbe98d09
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1192230
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-08-31 05:22:51 -07:00
Jorge Lucangeli Obes
f4afa06ac6 Fix typo in libminijail.rs.
While fixing an unrelated bug in mosys' copy of this file, I found this
typo.

BUG=None
TEST=PreCQ

Change-Id: Icbb48864ad890fcd4f83c28203d187fcfdc648cc
Reviewed-on: https://chromium-review.googlesource.com/1194599
Tested-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-08-30 13:57:58 +00:00
Dmitry Torokhov
641b28b692 plugin: return number of supported MSRS even if buffer is too small
Userspace is interested in number of supported MSRs even if supplied
buffer is too small, as then it can intelligently [re]allocate the
buffer and repeat the call instead of doing this blindly. So let's
always populate 'out_count'in crosvm_get_msr_index_list() call.
Obviously if there is hard error we will not be able to supply a
meaningful number, so 0 will be returned, but in case of E2BIG error we
can return the real number.

Also let's do the same for get_supported_cpuids() and
get_emulated_cpuids() calls.

BUG=b:111083877
TEST=cargo test -p kvm; cargo test --features=plugin

Change-Id: I37a8d719103fac44597b88ddecb6b8af2dd54ac8
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1185293
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-08-29 16:09:27 -07:00
Jingkui Wang
b47c6925fb Remove sync requirements of pci device trait
It's not needed.

BUG=chromium:831850
TEST=cargo test

Change-Id: I7e38590271ec14db422f5f3421302e98a2ca19ab
Reviewed-on: https://chromium-review.googlesource.com/1194317
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-08-29 11:16:14 -07:00
Stephen Barber
bce85fe345 seccomp: move 9s policy aarch64 -> arm
Seccomp policy for ARM hosts was recently moved from aarch64 to arm to
accurately match the ABI used on the host. Move 9s policy to match this.

BUG=none
TEST=vm.Webserver on kevin succeeds

Change-Id: I97daa524edcd411618561ce07525738bc65457cb
Reviewed-on: https://chromium-review.googlesource.com/1180470
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-08-20 17:12:17 -07:00
Daniel Verkamp
285b682d74 qcow: fix check for compressed cluster bit
The bit that indicates a compressed cluster in the qcow2 format is
stored in the L2 table entry (cluster descriptor), but the code was
checking for it in the L1 table entry.

Spotted by inspection based on the qcow2 format documentation (QEMU
docs/interop/qcow2.txt).

This has no impact in normal crosvm use cases, since crosvm never writes
compressed clusters; the only case where it could have any effect would
be when using a QEMU-created qcow2 image with compressed clusters, which
would have returned incorrect data from a read instead of failing the
read request as intended.

BUG=chromium:874699

Change-Id: Ic247490dcac5440fab8e4d34d24ffe6fe9ab3110
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1176733
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-08-17 11:18:12 -07:00
Daniel Verkamp
d0a0828b2e devices: block: define config space as a struct
Define a struct to represent the virtio block configuration as defined
in the current revision of the specification.  Only the capacity field
is set; all other fields are defaulted to 0, which should be safe, since
they are all controlled by feature flags that our device does not
advertise.

This is prep work for adding discard/write zeroes support to the block
device, since these commands require additional config fields that will
be added at the end of the config struct.

BUG=chromium:850998
TEST=cargo test -p devices; verify that container still boots and
reports the correct size

Change-Id: I8beb76195e446eb3dcbf1a99cc246ddd8cc8a7df
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1175235
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-08-15 20:36:11 -07:00
Daniel Verkamp
70589a0797 devices: block: add support for read-only feature
The virtio block specification defines the VIRTIO_BLK_F_RO feature bit
to indicate read-only block devices.  Plumb the read-only status of
block devices from the crosvm frontend into the virtio block device and
populate the flag when appropriate.

BUG=chromium:872973
TEST=Verify lsblk output in guest has the correct RO values

Change-Id: I23af87cce8020641cd702adca6e8ff9fdd2b8220
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1170306
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-08-13 21:58:42 -07:00
Daniel Verkamp
18fa20569f devices: block: store features as a u64
This matches other virtio device models (net, p9, vsock) and makes it
easier to add flags conditionally at device creation time.

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

Change-Id: I65b3f37c220fae44a3f6b397acc6c0eec2b70bf2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1170305
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-08-13 21:58:42 -07:00
Daniel Verkamp
de9ae03d52 main: replace block writable option with read_only
This is more consistent with the way it will be used in the virtio-blk
device model.

BUG=chromium:872973
TEST=cargo test

Change-Id: I28c5d007a7f3864ef6e18e9b343d263123302484
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1170304
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-08-13 14:25:11 -07:00
Daniel Verkamp
5f871eb8f4 devices: block: define features as shift counts
Convert the definition of VIRTIO_BLK_F_FLUSH to a shift count instead of
a bitmask.  This matches the way the features are defined in the virtio
spec and makes block consistent with other device models, such as p9.

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

Change-Id: Iece974c6f4d826b7bb76622973f08469a7936234
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1170303
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-08-13 14:25:11 -07:00
Dylan Reid
660a653d0f Add capabilities to PCI configuration space
Allow PCI devices to specify the capabilities they have.

Change-Id: I0730fb18dc71aa252da0903f4273e8d922ee2b8d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1157440
Reviewed-by: Jingkui Wang <jkwang@google.com>
2018-08-09 22:04:37 -07:00
Dylan Reid
2dd78797d7 x86_64: Don't allocate addrs in the 32 bit gap
Device allocations have to skip the gap so they don't collide with
things like the APIC.

BUG=863490
TEST=Resize a gedit window on APL for a minute and make sure there isn't
a crash.

Change-Id: Ia8185bcdbb6c18e13d02be317ae4d48c73288661
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1168400
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-08-09 02:21:31 -07:00
Chirantan Ekbote
ebd56813e1 virtio: Implement the 9P device
Implement a new virtio_9p device to be used for sharing directories with
the VM.

BUG=chromium:703939
TEST=mount inside a VM and run `bonnie++ -r 256`
Append the shared directory to the crosvm command line:
--shared-dir /path/to/dir:test_9p
Then mount in the guest:
mkdir /tmp/9p
mount -t 9p -o trans=virtio test_9p /tmp/9p -oversion=9p2000.L
Or for a 9p root:
run --shared-dir /mnt/vm_root:/dev/root -p 'root=/dev/root ro rootflags=ro,trans=virtio,version=9p2000.L,cache=loose rootfstype=9p' vmlinux.bin

CQ-DEPEND=CL:1065170

Change-Id: I41fc21306ab5fa318a271f172d7057b767b29f31
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1065173
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-08-08 13:45:44 -07:00
Chirantan Ekbote
a79073ad7d 9s: Server binary for the 9p file system
Add the 9s crate, which provides an executable that can serve the 9p
file system protocol.  It initially only supports connections over vsock
but can easily be extended to support network and unix domain socket
based connections.

BUG=chromium:703939
TEST=Run the server, have maitred connect to it over vsock, mount the
     9p file system in the guest kernel, share it with the penguin
     container, and run `bonnie++ -r 256 -s 512`
CQ-DEPEND=CL:1121550, CL:1166446

Change-Id: Ia0c72bcf29188bba4c07b6c0a2dd5a83d02339b5
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1112870
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-08-08 13:45:41 -07:00
Jingkui Wang
f226e28632 bitfield: Add fmt::Debug
implements fmt::Debug for bitfield

BUG=chromium:831850
TEST=cargo test

Change-Id: I58c2211a50726aaea0ea45164ae07c7b38eddea7
Reviewed-on: https://chromium-review.googlesource.com/1147111
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-08-07 01:51:08 -07:00
Jingkui Wang
eba6e7f9bd sys_util: enable custom events in pollcontext
Can specify events for epoll now.

BUG=chromium:831850
TEST=local build

Change-Id: Iad418b5e9570b38fd8033276bf02ee3eb96d0d77
Reviewed-on: https://chromium-review.googlesource.com/1125293
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-08-06 22:11:30 -07:00