Commit graph

504 commits

Author SHA1 Message Date
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
Jingkui Wang
8cad751ce0 crosvm: Add bit_field_derive
Support macro derive(BitField) to make life easier.

BUG=None.
TEST=local build and run test.

Change-Id: I582620de250017fb7c0b601f9ad4fbcbbc2fe02a
Reviewed-on: https://chromium-review.googlesource.com/1069331
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-03 22:14:45 -07:00
Dylan Reid
f11e6ed8e8 linux: Allow running without chromeos-low_mem
Keep desktop builds running by making the cros-specific low memory
device optional.

BUG=none
TEST=Boot a kernel with crosvm on ubuntu desktop

Change-Id: I3c90a40e877fee8ed6763de027b0e25deec36373
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1157198
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-08-01 19:35:29 -07:00
Dmitry Torokhov
658357638c plugin: allow retrieving list of supported MSRs
Add crossvm plugin API to allow fetching list of supported MSRs.

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

Change-Id: I178c7bc33d606bef10422faac6bb9afb3fe0a014
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1152229
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-31 16:37:06 -07:00
Dmitry Torokhov
c017a764d7 kvm: plumb accessor for KVM_GET_MSR_INDEX_LIST
Plumb in KVM_GET_MSR_INDEX_LIST to allow clients to figure out what MSRs
are supported.

BUG=b:111083877
TEST=cargo test -p kvm

Change-Id: I69deba32a21fb9360f8cd53001d717338523fb71
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1152228
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-31 16:37:06 -07:00
Dylan Reid
0ed91abecd linux: Create stuct to hold runnable state
In future changes this state will be generated by the architecture, so
make it easier to pass around than 11 variable individually.

Change-Id: If2c5f15b429ef7b651f88bfa50aabcf47757c02b
Reviewed-on: https://chromium-review.googlesource.com/1099855
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-07-31 12:07:32 -07:00
Dylan Reid
625866b8bb x86_64: Enable pci on the command line.
Change-Id: I73f77dfbd1d76ed94e6ae9645fa7c0a6fab0337a
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1085250
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-07-31 12:07:31 -07:00
David Riley
c9ce2da943 gpu: add force_ctx_0 calls prior to each gpu command
BUG=None
TEST=build with --features=gpu; null_platform_test

Change-Id: Ib7aab8b2f0d7e1523df49360ab99677b59ce6052
Reviewed-on: https://chromium-review.googlesource.com/1073960
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-30 23:08:05 -07:00
David Riley
f89e0b50e2 gpu: add support for fences
BUG=None
TEST=build with --features=gpu; null_platform_test

Change-Id: Ib863c8ef3e85aa0f345c1f20be414979808b6a17
Reviewed-on: https://chromium-review.googlesource.com/1073959
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-30 23:08:04 -07:00
David Riley
ba7c6035f8 gpu: hold image with resource
Ensure eglImage is not destroyed until the referencing resource is dropped.

BUG=None
TEST=build with --features=gpu; null_platform_test

Change-Id: I55c33344f46b08f846e094451516fcd16c9d16ae
Reviewed-on: https://chromium-review.googlesource.com/1073958
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-30 23:08:04 -07:00
David Riley
4cbaeb7eaa gpu: make process_descriptor return Option
In preparation of adding fence support, allow process_descriptor to
defer returning the descriptor until later by returning None.

BUG=None
TEST=build with --features=gpu; null_platform_test

Change-Id: I57e4dc438e7f5a925c870e0bd596f89a2ed4e083
Reviewed-on: https://chromium-review.googlesource.com/1073957
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-30 23:08:03 -07:00
David Riley
af9d7edfb7 gpu: import buffers for rendering from minigbm
BUG=None
TEST=build with --features=gpu; null_platform_test (has tearing)

Change-Id: Ic53ac703971bfdafcff2a4df55ddc4cf382144f1
Reviewed-on: https://chromium-review.googlesource.com/1050989
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-30 23:08:03 -07:00
David Riley
150daf94c2 gpu_renderer: update virglrenderer bindings
BUG=None
TEST=None

Change-Id: I48f6dcf4c176fe4d9bcbaae94bf2319a9063b0a8
Reviewed-on: https://chromium-review.googlesource.com/1073955
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-30 23:08:02 -07:00
Jingkui Wang
c1ce54a9dd pci: Add serial bus subclass
Add serial bus subclass

BUG=chromium:831850
TEST=cargo test

Change-Id: Iffd7a27b5cb423c928f0108b16fb58558cf7bcd4
Reviewed-on: https://chromium-review.googlesource.com/1152212
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-07-27 19:11:15 -07:00
Chirantan Ekbote
448516e3f9 balloon: Implement device policy
Implement a policy for the balloon device so that it starts taking
memory away from the VM when the system is under low memory conditions.
There are a few pieces here:

* Change the madvise call in MemoryMapping::dont_need_range to use
  MADV_REMOVE instead of MADV_DONTNEED.  The latter does nothing when
  the memory mapping is shared across multiple processes while the
  former immediately gives the pages in the specified range back to the
  kernel.  Subsequent accesses to memory in that range returns zero
  pages.
* Change the protocol between the balloon device process and the main
  crosvm process.  Previously, the device process expected the main
  process to send it increments in the amount of memory consumed by the
  balloon device.  Now, it instead just expects the absolute value of
  the memory that should be consumed.  To properly implement the policy
  the main process needs to keep track of the total memory consumed by
  the balloon device so this makes it easier to handle all the policy in
  one place.
* Add a policy for dealing with low memory situations.  When the VM
  starts up, we determine the maximum amount of memory that the balloon
  device should consume:

    * If the VM has more than 1.5GB of memory, the balloon device max is
      the size of the VM memory minus 1GB.
    * Otherwise, if the VM has at least 500MB, the balloon device max is
      50% of the size of the VM memory.
    * Otherwise, the max is 0.

  The increment used to change the size of the balloon is defined as
  1/16 of the max memory that the balloon device will consume.  When the
  crosvm main process detects that the system is low on memory, it
  immediately increases the balloon size by the increment (unless it has
  already reached the max).  It then starts 2 timers: one to check for
  low memory conditions again in 1 seconds (+ jitter) and another to
  check if the system is no longer low on memory in 1 minute (+ jitter)
  with a subsequent interval of 30 seconds (+ jitter).

  Under persistent low memory conditions the balloon device will consume
  the maximum memory after 16 seconds.  Once there is enough available
  memory the balloon size will shrink back down to 0 after at most 9
  minutes.

BUG=chromium:866193
TEST=manual
Start 2 VMs and write out a large file (size > system RAM) in each.
Observe /sys/kernel/mm/chromeos-low_mem/available and see that the
available memory steadily decreases until it goes under the low memory
margin at which point the available memory bounces back up as crosvm
frees up pages.
CQ-DEPEND=CL:1152214

Change-Id: I2046729683aa081c9d7ed039d902ad11737c1d52
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1149155
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-07-27 15:29:07 -07:00
David Riley
1187595da3 gpu: fix parsing of third descriptor in chain
Descriptor chains of three descriptors were not having the last
descriptor parsed correctly which resulted in some commands not
properly being responded to.

BUG=None
TEST=build with --features=gpu; null_platform_test

Change-Id: Ia77c7ca485ded7cdcb71fd62e8f6be5c226df1bf
Reviewed-on: https://chromium-review.googlesource.com/1073956
Commit-Ready: David Riley <davidriley@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-25 19:45:39 -07:00
Zach Reizner
e9717c4b7b gpu_buffer: fix reading and writing to GPU buffers
The original methods for reading and writing to GPU buffers naively
assumed that the mappings returned by GBM were to the first byte in the
buffer. In fact, the returned mapping is to the first pixel of the
mapped rectangle. This would lead to segaults when the copy routine
would breeze past the end of the mapping into segault territory.

This change fixes the read and write algorithms and adds lots more guard
rails in to prevent future undefined behavior (hopefully).

TEST=boot kernel with VT and VIRTIO_GPU
BUG=None

Change-Id: Ia7c968b6dd274551b6d218e2f0b255af6e55bd35
Reviewed-on: https://chromium-review.googlesource.com/1102110
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-07-25 00:14:24 -07:00
Dylan Reid
940259c548 main: Fix help for create_qcow2
The size is specified in bytes, correct the help messages.

Change-Id: I386b329123bbfc9dfdaf073eb345c4554ade4982
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1145763
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2018-07-23 21:05:07 -07:00
Dylan Reid
a697d31fc6 mptable: Add ability to allocate pci interrupts
PCI devices will require interrupts, allow this by passing a vector of
IRQs to the mptable so the guest kernel can find the IRQs.

Change-Id: I9fa8a2ed0a34089e631441570521082ffde9c4ef
Reviewed-on: https://chromium-review.googlesource.com/1072578
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-07-23 21:05:03 -07:00
Sonny Rao
b847858e66 seccomp: rename aarch64 -> arm
These policies are not for aarch64 but use the 32-bit system calls.
We call it aarch64 support because that's what we're targetting for
the guest kernel, but it doesn't really make any sense to call the
seccomp policies aarch64 when we're building a 32-bit binary.
We can add real aarch64 seccomp policies when we start building a
aarch64 crosvm binary.

BUG=chromium:866197
TEST=emerge-kevin crosvm, run vm_CrosVmStart
CQ-DEPEND=CL:1145903

Change-Id: I7c5e70fbc127e4209ed392cfcf10ea36a6dd4b2c
Reviewed-on: https://chromium-review.googlesource.com/1145909
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-23 21:04:38 -07:00
Zach Reizner
98ca995c39 wl: add pipe2 and fcntl64 to wl_device.policy
These syscalls were added to the x86 policy when vfd pipe support was
added, but they were never added to the arm version, for whatever
reason. This is needed to keep crosvm from getting killed by SIGSYS
whenver the user copies to or from guest applications.

BUG=chromium:864218
TEST=on kevin, copy/paste to/from gedit

Change-Id: Ibe385d50e367c362e911badd640bab2c98e07030
Reviewed-on: https://chromium-review.googlesource.com/1145876
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-23 21:04:37 -07:00
Zach Reizner
cd2d4fe45e data_model: add offset, copy_to_volatile_slice, Copy to VolatileSlice
These methods are convenient for safely doing complex copies between
`VolatileSlice`s.

TEST=cargo test -p data_model
BUG=None

Change-Id: I02f446953c24ef5cbb2cebd306344b1e13556bd7
Reviewed-on: https://chromium-review.googlesource.com/1102153
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-07-20 05:30:56 -07:00
Zach Reizner
59caefa5ab gpu_buffer: add bytes_per_pixel method to Format
TEST=cargo test -p gpu_buffer
BUG=None

Change-Id: I39f825065b6dd2904d81ae3baf76b3552c739691
Reviewed-on: https://chromium-review.googlesource.com/1102111
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: David Reveman <reveman@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-07-20 05:30:55 -07:00
Zach Reizner
3a8100adc7 gpu: implement virtio-gpu
Basic 2D and 3D support is there. The drm_cursor_test and
null_platform_test in drm-tests should run to completion.

The extra device is hidden behind both a build time feature called 'gpu'
and the device is only added to a VM if the  '--gpu' flag is given.

TEST=build with --features=gpu;
     drm_cursor_test && null_platform_test
BUG=chromium:837073

Change-Id: Ic91acaaebbee395599d7e1ba41c24c9ed2d84169
Reviewed-on: https://chromium-review.googlesource.com/1036862
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-20 05:30:54 -07:00
Zach Reizner
f40bb190ec gpu_renderer: add virglrenderer bindings
These bindings are needed for virtio-gpu 3D capabilities.

All the rust files under gpu_renderer/src/generated are generated via
the gpu_renderer/src/generated/generate script.

The gpu_renderer/src/lib.rs file contains the Renderer and Context
structs, which are the main interfaces to virglrenderer. They
encapsulate the global state of virglrenderer (Renderer) and each
context ID (Context).

The command_buffer module is included only for basic testing and is not
intended for production use.

The pipe_format_fourcc module is provided for the conversion of
virglrenderer specifc formats to standard fourcc formats.

BUG=chromium:837073
TEST=cargo build -p gpu_renderer
CQ-DEPEND=CL:1144406

Change-Id: Iad153390f618309bf493e92e76432c0b1c4a8a93
Reviewed-on: https://chromium-review.googlesource.com/1043447
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-07-20 05:30:54 -07:00