Commit graph

482 commits

Author SHA1 Message Date
Yunlian Jiang
31c20fdcce crosvm: add getpid and prlimit to seccomp
This is needed to make sure seccomp work with glibc 2.27

BUG=chromium:897477
TEST=None

Change-Id: I101aa07bffd8db2b449be1a697dafcd7d6f1cb58
Reviewed-on: https://chromium-review.googlesource.com/1294729
Commit-Ready: Yunlian Jiang <yunlian@chromium.org>
Tested-by: Yunlian Jiang <yunlian@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2018-10-23 02:55:29 -07:00
Zach Reizner
15503e236e gpu_display: use syslog for display_wl
Change-Id: I8275d0f3f7ed31b9f53a533c0d2fbda62977a1b7
Reviewed-on: https://chromium-review.googlesource.com/1292756
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
2018-10-22 17:38:06 -07:00
Yunlian Jiang
a70445aa3b crosvm: add openat to seccomp
This adds openat to a seccomp policy file if open is already there.
We need this because glibc 2.25 changed it system call for open().

BUG=chromium:894614
TEST=None

Change-Id: Ie5b45d858e8d9ea081fd7bfda81709bda048d965
Reviewed-on: https://chromium-review.googlesource.com/1292129
Commit-Ready: Yunlian Jiang <yunlian@chromium.org>
Tested-by: Yunlian Jiang <yunlian@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2018-10-21 05:25:01 -07:00
Daniel Verkamp
8eceba31c0 devices: make PCI work in --disable-sandbox mode
Make the Minijail part of the PCI device tuple optional so that an empty
jail is not created for --disable-sandbox.

BUG=None
TEST=Boot crosvm in both --multiprocess and --disable-sandbox modes

Change-Id: Ibb3f2dbf33ca19910ee7448ea823b2772e09ecc5
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1290289
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-19 15:07:43 -07:00
Daniel Verkamp
f02fdd1f66 main: autodetect disk image type
Make --disk and --rwdisk automatically distinguish between qcow2 and raw
disk images.  --qcow and --rwqcow are kept as aliases for compatibility.

BUG=chromium:893380
TEST=Boot crosvm with both raw and qcow2 disk images.

Change-Id: I5b572626ca5ab894c78454f59355f27d552cbf7d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1275185
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-19 12:19:52 -07:00
Daniel Verkamp
de198cc9be devices: virtio: block: ignore Discard failures
Our branch of the 3.18 kernel has FALLOC_FL_PUNCH_HOLE disabled for the
ext4 filesystem, which means that systems running that kernel always
take the fallback path of writing buffers full of zeroes.  This is not
necessary for the Discard command, since it is just a hint and is not
required to actually zero the blocks.

Split the WriteZeroes trait up into a new PunchHole trait, which
corresponds to fallocate() with FALLOC_FL_PUNCH_HOLE, and use the new
trait to implement the virtio block Discard command.

BUG=chromium:896314
TEST=`mkfs.btrfs /dev/vdb` and verify the desired fallocate() is used
     and no write() calls are issued when inducing a failure

Change-Id: I67fd9a132758d8d766531ccca8358c7fe67b0460
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1286224
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-19 12:19:41 -07:00
Daniel Verkamp
7f9b9ea344 qcow: add convert API and export it in qcow_utils
This will be used in vm_concierge's ExportDiskImage function in order to
allow a minimal qcow2 image to be written on the fly (containing only
the required clusters in a tightly-packed image file). It also allows
future flexibility to change the underlying disk image file format while
still exporting qcow2 images (e.g. via `vmc export`).

For testing, add a qcow_img `convert` command, which can convert
between raw and qcow2 as both source and destination.

BUG=None
TEST=Use qcow_img to convert a raw image to qcow2 and back and verify
     its contents are the same as the original.

Change-Id: I74167aca9a9c857d892e24adf5ee17afc0f6e6b5
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1272060
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-18 19:01:06 -07:00
Daniel Verkamp
2167ae9535 sys_util: add SeekHole trait
Allow seeking to the next hole or data region in File and QcowFile.

BUG=None
TEST=None

Change-Id: I16e77e4791aa85b4cc96f38327026cd93f02b7e1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1274147
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-18 19:01:06 -07:00
Daniel Verkamp
c1f08277f9 cargo fmt aarch64 and kvm
A few non-rustfmt changes slipped in since the tree-wide formatting
pass.

BUG=None
TEST=Re-run `cargo fmt` and verify that it makes no further changes.

Change-Id: Ic5afb20dabc1087e5d6f54862e6b8b47c5f5608d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1287369
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-18 14:53:32 -07:00
Zach Reizner
f6b58e4cf2 enable integer overflow checks on release profile
This will harden crosvm against potential integer overflow leading to
unsafe behavior in unsafe blocks.

TEST=cargo test --release
BUG=None

Change-Id: Ie750906d04c6ef8cb9400b976827c2abeab2ab56
Reviewed-on: https://chromium-review.googlesource.com/1282064
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-16 02:57:36 -07:00
Daniel Verkamp
6b28917b83 qcow: create BufWriter with exact capacity
Rather than using the default BufWriter capacity (currently 8K),
calculate the exact size required to contain the table.  This further
consolidates the write() system calls to the minimum required.

BUG=chromium:891335
TEST=Manually verify expected write() calls with strace

Change-Id: I9ade77024e60a92d30b65beb07c2385e5dacc167
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1250035
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-13 14:55:25 -07:00
Daniel Verkamp
abbe0c8cf0 sys_util: use PUNCH_HOLE to implement write_zeroes
Some filesystems do not support FALLOC_FL_ZERO_RANGE; in particular,
encrypted files on ext4 fail this request with -EOPNOTSUPP.  Use
fallocate with FALLOC_FL_PUNCH_HOLE instead, which is more widely
supported.

BUG=None
TEST=strace crosvm using qcow files on encrypted ext4 and verify that
     fallocate(FALLOC_FL_PUNCH_HOLE) is issued when required.

Change-Id: Idffabc75ea0e1153efbb13cec8b4a25570427235
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1250022
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-13 14:55:24 -07:00
Daniel Verkamp
6c765fd2ac aarch64: remove reboot=k kernel cmdline option
The "reboot" option is specific to x86 (reboot=k forces use of the i8042
keyboard controller to initiate a reset).  Remove the unnecessary option
from the aarch64 command line.

BUG=None
TEST=Stop and restart VM on Kevin

Change-Id: Ic91c9a03491a6620d6f88ea0ada12f637f402840
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1279268
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-10-12 23:07:17 -07:00
Daniel Verkamp
56f283b297 Revert "Revert "linux: Convert all virtio devices to PCI""
This reverts commit c8986f14a8.

Re-land the virtio PCI conversion after the preceding fixes.

BUG=chromium:854766
TEST=Boot crosvm on nami and kevin

Change-Id: I3699e3ed1a45cecc99c51e352d0cf0c32bc4116f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1265862
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-12 23:07:16 -07:00
Zach Reizner
ed31137fd0 kvm: fix clippy error about mis-aligned pointer casts
BUG=None
TEST=cargo test -p kvm

Change-Id: I43321d01a02821495fb8a8f0f03df21eacc688ee
Reviewed-on: https://chromium-review.googlesource.com/1277873
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-12 23:07:10 -07:00
Zach Reizner
7c78a3c948 kvm: fix clippy error about multiple mut references
TEST=cargo test -p kvm
BUG=None

Change-Id: I2d4552b693f253f8411199ecf4583553c80e37a6
Reviewed-on: https://chromium-review.googlesource.com/1277874
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-12 23:07:10 -07:00
Stephen Barber
73a40e37a3 kokoro: add continuous config
BUG=none
TEST=run kokoro CI

Change-Id: If231d30581d511807a1d7a03119d3243bb0078b1
Reviewed-on: https://chromium-review.googlesource.com/1277882
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-12 18:55:03 -07:00
Zach Reizner
029fc665a1 sys_util: use checked arithmetic and alignment in sock_ctrl_msg
Change-Id: I45125fc3a6af83e7f7ec791a2f9c5daef723ec89
Reviewed-on: https://chromium-review.googlesource.com/1277872
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-12 18:54:59 -07:00
Sonny Rao
c7af4b1e68 aarch64: add arm serial input support
Wire up the serial device interrupt on aarch64 so stdin works.

BUG=chromium:890956
TEST=Verify serial console works on kevin

Change-Id: Ifcafecb10d443f0100f047d0a2ec545c24e718af
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1115728
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-10-12 15:16:54 -07:00
Zach Reizner
06a7779e67 sys_util: simplify format string for Display impl for Priority
Change-Id: I2c08c707b0e5c8d576aeade94265434f126c6927
Reviewed-on: https://chromium-review.googlesource.com/1277870
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-12 11:43:28 -07:00
Daniel Verkamp
1232debf1d devices: virtio: pci: reset ISR status on read
The virtio PCI spec (4.1.4.5.1 Device Requirements: ISR status
capability) says:

  "The device MUST reset ISR status to 0 on driver read."

BUG=chromium:854766
TEST=None

Change-Id: I92a1ddccfc8e44bed7f4a16e3cfd11b946629e22
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1260252
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-11 17:33:55 -07:00
Daniel Verkamp
cf2e00e982 arch: add virtio-pci eventfds with exact match
The virtio PCI spec (4.1.5.2 Notifying The Device) says:

  "The driver notifies the device by writing the 16-bit virtqueue index
  of this virtqueue to the Queue Notify address."

We were previously registering the notify address specifying
NoDatamatch; switch this to a 16-bit match of the queue index to follow
the specification.

BUG=chromium:854766
TEST=Boot crosvm with virtio devices converted to PCI

Change-Id: Ic950a8c7751268f7fcc21d5c37b0afc859f1e6d0
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1265861
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-11 13:25:38 -07:00
Daniel Verkamp
db6edff22f kvm: refactor ioeventfd datamatch interface
This allows the caller to specify the full range of datamatch options
defined in the KVM ioeventfd API, including matching accesses of a
particular size with or without matching a specific data value.

BUG=None
TEST=cargo test -p kvm

Change-Id: I28b543f7c0b35eb2a6d47a14a33145ea00d09d1d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1271836
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-11 13:25:38 -07:00
Daniel Verkamp
9357ceab6a mptable: mark PCI interrupts as edge triggered
BUG=chromium:854766
TEST=Boot crosvm on an x86_64 platform (nami)

Change-Id: Id55975a443a54e8b9c25616cd842507c57802af0
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1265047
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-10 17:07:55 -07:00
Daniel Verkamp
c968aa995a README: update rustfmt guidance to format all code
BUG=None
TEST=`cargo fmt` and make sure nothing changes

Change-Id: Ic5a832710074d13a40f1ca0c28e9f5124fb2a5a3
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1273689
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-10 17:07:52 -07:00
Daniel Verkamp
310b308166 rustfmt wire_format_derive and poll_token_derive
BUG=None
TEST=cargo test

Change-Id: I62f00a71ed3693352de648bb8ee576335b32019f
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1273688
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-10 17:07:51 -07:00
Jingkui Wang
f5d565d693 crosvm: add msg_sock.
MsgSock wraps UnixDatagram and provides simple macro to define Messages
that could be send through sock easily.

TEST=cargo test
BUG=None

Change-Id: I296fabc41893ad6a3ec42ef82dd29c3b752be8b8
Reviewed-on: https://chromium-review.googlesource.com/1255548
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-10-09 21:14:12 -07:00
Zach Reizner
3655a633b2 gpu_renderer: cargo fmt epoxy_egl.rs, which is huge
The formatting of epoxy_egl.rs was separated from the rest because it is
an order of magnitude larger than any other file and seriously slows
down tools interacting with git.

TEST=cargo test
BUG=None

Change-Id: I3b407078b85e585dc7d1d518bf85a8cfcb07dd58
Reviewed-on: https://chromium-review.googlesource.com/1259288
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
2018-10-09 21:14:06 -07:00
Zach Reizner
55a9e504be cargo fmt all source code
Now that cargo fmt has landed, run it over everything at once to bring
rust source to the standard formatting.

TEST=cargo test
BUG=None

Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b
Reviewed-on: https://chromium-review.googlesource.com/1259287
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-10-09 21:14:05 -07:00
Gurchetan Singh
046df60760 virtio-gpu: use the newest caps
capset2 has many new features. We currently hardcode num_capsets
to 1, however our Mesa/guest kernel/virglrenderer are new enough
to support caps v2.

We could attempt to do negotiation (see virtio_gpu_virgl_get_num_capset
in QEMU), but virtio::gpu::Gpu::get_config actually comes before
virtio::gpu::Gpu::activate. To support older Mesa/guest kernel/virglrenderer
configurations, this must be refactored.

BUG=none
TEST=get a gles31 context on tatl

Change-Id: I8d9ed54774a63da2ec5a4ba86187330521785566
Reviewed-on: https://chromium-review.googlesource.com/1258323
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2018-10-05 15:43:20 -07:00
Daniel Verkamp
b1570f2672 qcow: track deallocated clusters as unreferenced
In deallocate_cluster(), we call set_cluster_refcount() to unref the
cluster that is being deallocated, but we never actually added the
deallocated cluster to the unref_clusters list.  Add clusters whose
refcounts reach 0 to the unref_clusters list as well.

Also add mremap() to the seccomp whitelist for the block device, since
this is being triggered by libc realloc() and other devices already
include it in the whitelist.

BUG=chromium:850998
TEST=cargo test -p qcow; test crosvm on nami and verify that qcow file
     size stays bounded when creating a 1 GB file and deleting it
     repeatedly

Change-Id: I1bdd96b2176dc13069417e0ac77f0768f9f26012
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1259404
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-05 07:54:49 -07:00
Daniel Verkamp
c8986f14a8 Revert "linux: Convert all virtio devices to PCI"
This reverts commit d635acbaf3.

This commit seems to be responsible for introducing hung tasks in tests,
so let's revert it for now to get the tests green and debug it offline.

BUG=chromium:891806
TEST=None

Change-Id: I83504058baeae00909d9fb4f4bb704a144a0dfaf
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1259408
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-04 00:37:22 -07:00
Daniel Verkamp
d635acbaf3 linux: Convert all virtio devices to PCI
Change the main create_virtio_devs() function to create virtio devices
using the PCI transport rather than MMIO.

BUG=chromium:854766
TEST=Boot crosvm and verify that all virtio devices still work

Change-Id: I9a6e60b21edea1e5ac2b3ae5c91793d45cf5063a
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1241541
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-02 09:17:25 -07:00
Dylan Reid
a158e31038 devices: Implement virtio PCI transport
Change-Id: Ieaa83205ba4e3f029f6d183a1b93799352551299
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1237364
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:05 -07:00
Daniel Verkamp
948b5f7bc1 aarch64: add generic PCI host controller
Implement the generic PCI host as supported by Linux and described in
Documentation/devicetree/bindings/pci/host-generic-pci.txt in the kernel
source tree.

Also increase the ARM64 MMIO region size from 0x10000 to 0x100000 to
allow enough space for several virtio PCI devices.

Change-Id: I2f0a9b04356cce912874a06e62b4f3a59cbb08f1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1244398
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-10-01 11:30:05 -07:00
Daniel Verkamp
8102525958 x86_64: increase size of MMIO range
VirtioPci uses 0x4000 bytes of MMIO space per device, so the existing
allocation of 0x10000 was only enough for 4 devices; extend the MMIO
region to allow for more devices.

Change-Id: I0cc44edacc5f435510ab8ae9b38a925a0ee5d008
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1240654
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:04 -07:00
Daniel Verkamp
4a33cd5b18 virtio: set default queue size to maximum
The virtio PCI transport requires that the queue_size configuration
value returns the maximum supported queue size on reset; it uses 0 to
indicate an unavailable queue.

Queue::size is write-only via the existing MmioDevice (the driver must
always write a queue size during initialization), so there should be no
difference in behavior when using MMIO virtio devices.

Change-Id: I5b77e0d84f0bc7b854e33aaeb34ff011af226103
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1237363
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:04 -07:00
Daniel Verkamp
f3a3a870b1 devices: pci: add MMIO config access mechanism
This will be used on ARM.

Change-Id: I61206b761f49f963f0cce706268379ceae1a0239
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1241540
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:04 -07:00
Daniel Verkamp
28a671a95f devices: pci: refactor config access mechanism
The current PciRoot is only workable for the legacy I/O port 0xCF8
access mechanism; factor out the config access mechanism part of PciRoot
into PciConfigIo so that we can add a MMIO-based access mechanism for
ARM.

Change-Id: I87756b0ab31070d8717c76d419957bf5ea5d75ad
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1241539
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:03 -07:00
Daniel Verkamp
aee0ac2d67 devices: pci: make more registers read only
Most of PCI configuration space should be read only; initialize the
writable_bits field accordingly.

Change-Id: I67f93d81cfbac6000db51663bdf76e54aeac08f3
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1240659
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:03 -07:00
Daniel Verkamp
b2d6ffac5e devices: pci: ignore writable_bits when adding caps
The add_capability() function was using the normal PCI configuration
write_byte() function, which enforces read-only regions.  This won't
work once the appropriate regions of config space are marked as read
only in the following commit, so add an internal-only helper function to
access bytes without applying writable_bits.

Change-Id: If61f79cd80950bf517d69c18aaf98c2e76841a56
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1240658
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:02 -07:00
Dylan Reid
9f2bbc8a91 devices: pci: fix registration of PCI IRQs
MPTABLE needs the PCI device number, not the IRQ; modify the information
passed via pci_irqs so that it contains a (device index, interrupt pin)
tuple.

Change-Id: Ia1dcb478cdab6654087925093ef9d1204edb21c9
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1237362
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:02 -07:00
Dylan Reid
90c6ad029f devices: pci: fix add_bar return value
Return the BAR number rather than the register offset within PCI config
space.

Change-Id: I6e965c5fe7218abe6986b461731f18abb34894c1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1240653
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:01 -07:00
Dylan Reid
aa12c74bff devices: pci: add ioeventfds to PciDevice trait
VirtioDevices and potentially others need to register ioeventfds that
will be triggered when guests write to certain addresses. Allow
PciDevices to return an array of ioeventfds that the VM can install.

Change-Id: I2524c4e8c04f75a8d7868cac998304aecbb29c40
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1237360
Commit-Ready: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2018-10-01 11:30:01 -07:00
Daniel Verkamp
c5a6762081 devices: pci: add keep_fds to PciDevice
PciDevice implementations will have file descriptors that need to be
preserved across the minijail fork.

Change-Id: I0b1f5b827b55c4d8960ffa95331b82f9c692f304
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1237359
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:00 -07:00
Daniel Verkamp
4f228cb203 devices: pci: add Programming Interface to device
PCI class codes are made up of three fields: class, subclass, and
programming interface.  Some class/subclass combinations do not define
any programming interfaces, so add an optional parameter to specify the
value and use 0 if it is not provided.

Change-Id: Ib4000eafe2d7d003ed5753d7b0ea05e16fd06130
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1237358
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:30:00 -07:00
Dylan Reid
0f579cb09c move pci root creation to arch
passing everything in to the pci code is getting annoying. Instead build
it up in arch which already has access to all the needed resources.
Change-Id: If42f994443c4f11152fca8da16f27fa4cd80580d
Reviewed-on: https://chromium-review.googlesource.com/1237357
Commit-Ready: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-10-01 11:29:59 -07:00
Daniel Verkamp
b605850bce devices: block: track flush timer armed state
Rather than querying the flush timerfd state repeatedly on every write,
just track the state in a variable.  This avoids an extra
timerfd_gettime() syscall on every write.

BUG=None
TEST=Verify that the flush timer still fires via strace

Change-Id: I5437d26570de466f05b496d3e0dce08a521c4fde
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1247443
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-27 19:44:09 -07:00
Daniel Verkamp
46f70e8c16 qcow: optimize sync_caches to avoid extra writes
Track the clean/dirty state of the L1 table and the refcount table to
avoid writing them out and doing an extra fsyncdata() if nothing has
changed.

BUG=None
TEST=Manually verify strace output contains only the expected fsyncs

Change-Id: I20bdd250024039a5b4142605462a8977ced1efcc
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1247442
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-27 19:44:09 -07:00
Daniel Verkamp
eaaf3e17e6 qcow: buffer reads and writes in QcowRawFile
When reading and writing refcount blocks and pointer tables, the
QcowRawFile implementation was performing many individual read() and
write() system calls (one per table entry), which is quite inefficient.
Use the read_*_into functions from ReadBytesExt for reads and BufWriter
for writes to buffer the I/O into larger chunks.

BUG=None
TEST=Manually verify larger reads/writes with strace

Change-Id: I276963db0a4e91b22335c26c799ae8fb55bf6ad3
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1247441
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-09-27 19:44:08 -07:00