summary refs log tree commit diff
path: root/devices/src
Commit message (Collapse)AuthorAge
* devices: pci: replace byteorder with from_le_bytes()Daniel Verkamp2019-08-26
| | | | | | | | | | | | | | Use the standardized from_le_bytes() functions rather than the byteorder crate. BUG=None TEST=./build_test Change-Id: I07a062bf63c5d3ae1e25f403713bf9a1677e8cba Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761155 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: virtio: replace byteorder with {to,from}_le_bytes()Daniel Verkamp2019-08-26
| | | | | | | | | | | | | | | Use the stabilized standard to_le_bytes() and from_le_bytes() functions rather than the byteorder crate. BUG=None TEST=./build_test TEST=cargo test -p devices virtio_pci_common_config Change-Id: I4106a41484760b9e7e586de07135874238bcadb0 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761154 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: vsock: replace byteorder with from_le_bytes()Daniel Verkamp2019-08-26
| | | | | | | | | | | BUG=None TEST=cargo test -p devices vsock Change-Id: I9da35f894898198413737f9caa29a7f772e4f720 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761153 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* usb: clean up clippy unit_arg warningDaniel Verkamp2019-08-26
| | | | | | | | | | | | | | | | | | | Fix the last instance of this clippy warning: warning: passing a unit value to a function ... and remove this warning from the "To be resolved" list in bin/clippy. BUG=None TEST=bin/clippy passes without warnings Change-Id: Ic1d558e935366d80eeadb96bf1ff951ce50edd5b Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1766623 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: set zero length mmio eventfd for VQ notification addressZide Chen2019-08-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By registering the notify address with Datamatch::AnyLength, KVM is able to take advantage of KVM_FAST_MMIO_BUS to accelerate eventfd handling. Seems this doesn't violate the virtio spec because "writing the 16-bit virtqueue index" refers to the implementation of front-end driver, for example, Linux's vp_notify() function. While how to handle the VQ index write in VMM is not covererd by virtio spec. Here Crosvm ensures that every VQ has dedicated notify address and KVM implements the notification by eventfd, which should be fine with the spec. On eve Pixelbook (R77 host kernel 4.4.185), in 5000 samples, on average the MMIO write vmexit takes 0.96us with fast_mmio enabled, while it takes 3.36us without fast_mmio. without fast_mmio: 232812.822491: kvm_exit: reason EPT_MISCONFIG rip 0xffffffff986f18ef info 0 0 232812.822492: kvm_emulate_insn: 0:ffffffff986f18ef:66 89 3e (prot64) 232812.822493: vcpu_match_mmio: gva 0xffffb0f4803a1004 gpa 0xe000f004 Write GPA 232812.822493: kvm_mmio: mmio write len 2 gpa 0xe000f004 val 0x1 232812.822495: kvm_entry: vcpu 1 with fast_mmio: 230585.034396: kvm_exit: reason EPT_MISCONFIG rip 0xffffffff9a6f18ef info 0 0 230585.034397: kvm_fast_mmio: fast mmio at gpa 0xe000f004 230585.034397: kvm_entry: vcpu 1 BUG=chromium:993488 TEST=Boot Crostini on eve and run iperf benchmark TEST=Analysis kernel trace for vmexit handling time Change-Id: Id1dac22b37490f7026b6c119c85ca9d104a8a3f4 Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com> Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1762282 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* devices: gpu: remove BackedBuffer/GpuRendererResource distinctionGurchetan Singh2019-08-20
| | | | | | | | | | | | | | | | | | | | | | | | | | We always advertise VIRTIO_GPU_F_VIRGL and don't activate the worker thread if Renderer::init fails. We're unlikely to encounter an platform where we can initialize a GBM device, but can't initialize virglrenderer. Since our virtio-gpu implementation depends on virglrenderer, we can pipe 2D hypercalls to virglrenderer (QEMU does this too, when built with the --enable-virglrenderer option). Also remove virgl_renderer_resource_info since it's unlikely to work with non-Mesa drivers. BUG=chromium:906811 TEST=kmscube renders correctly (though there's a prior bug in closing the rendering window -- see chromium:991830) Change-Id: I7851cd0837fd226f523f81c5b4a3389dc85f3e4f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1743219 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
* gpu_renderer: remove EGL related functionsGurchetan Singh2019-08-20
| | | | | | | | | | | | | | | | Now that we're not creating EGL images anymore, we can remove EGL logic. BUG=chromium:906811 TEST=freecad works without any local Mesa patches Change-Id: I09db1c828ae1a331eaeae7c66653a49fe42a04bf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1725451 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* gpu_renderer: use GBM inside virglrendererGurchetan Singh2019-08-20
| | | | | | | | | | | | | | | | | | | | | | With YUV support + modifier support coming up, it makes sense to move GBM allocation inside virglrenderer so we can upstream our use cases. In addition, this allows us to use gbm_bo_map(..) for the freecad issue, which would otherwise be resolved through local patches in our graphics drivers. BUG=chromium:906811 TEST=freecad works without Mesa patches Change-Id: I61db5c58a5bc5a79fda3cec8ad6c322fae6acc9e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1725450 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
* ac97: remove duplicated codeFletcher Woodruff2019-08-20
| | | | | | | | | | | | | | | | Crosvm's AC97 device had code that was duplicated between playback and capture stream creation. Abstract that code out so it can be shared. BUG=chromium:968724 TEST=aplay /dev/urandom within container Change-Id: If2fb50a0655656726dd9c6255bc84493e91c04e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749948 Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
* devices: virtio: add copy_config() helper functionDaniel Verkamp2019-08-16
| | | | | | | | | | | | | | | | | | | | | | | Add a new virtio configuration copying function to replace all of the slightly varying read_config() and write_config() implementations in our virtio devices. This replaces a lot of tricky bounds-checking code with a single central implementation, simplifying the devices to a single call to copy_config() in most cases. The balloon device is also changed to represent its config space as a DataInit struct to match most other devices and remove several unwrap() calls. BUG=None TEST=./build_test TEST=Boot vm_kernel+vm_rootfs in crosvm TEST=Start Crostini on nami Change-Id: Ia49bd6dbe609d17455b9562086bc0b24f327be3f Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749562 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: use libc::exit instead of process::exitStephen Barber2019-08-14
| | | | | | | | | | | | | | | | | | | | We don't always shut down the worker threads cleanly, which can lead to a race when crosvm is exiting. Worker threads that attempt logging to stderr may fail an expect(), panic, and then panic again trying to write to stderr causing SIGILL. Work around this issue for now by using libc's exit, which won't run any rust-specific cleanup. BUG=chromium:978319,chromium:992494 TEST=crosvm shuts down without SIGILL/core dumps Change-Id: I8a99ce8a34220afdf503402d44721a9bea5ec460 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1746830 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* devices: virtio: block: use descriptor chain utilsDaniel Verkamp2019-08-13
| | | | | | | | | | | | | | | | | | | Rewrite the virtio block device to use the descriptor Reader/Writer interfaces - this greatly simplifes the block device code. This also lets the block device handle arbitrary descriptor layouts, since the descriptor reader/writer handles that transparently for us. BUG=chromium:990546 TEST=./build_test TEST=Boot crosvm with vm_kernel+vm_rootfs on workstation TEST=Boot full Crostini environment on nami Change-Id: Ie9a2ba70a6c7ed0ae731660fd991fb88242e275f Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721371 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* devices: virtio: make create_descriptor_chain pubDaniel Verkamp2019-08-13
| | | | | | | | | | | | | | Allow use of this helper function in other virtio devices that want to write virtio descriptor chains as part of their tests. BUG=chromium:990546 TEST=./build_test Change-Id: Ib986646dc36b6406c88f20950586e1c665adf167 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1732851 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: virtio: add volatile read/write for desc chainsDaniel Verkamp2019-08-13
| | | | | | | | | | | | | | This will allow streaming data between a FileReadWriteVolatile and the descriptor chain Reader/Writer types. BUG=chromium:990546 TEST=./build_test Change-Id: Idc97ce99dd1cc340444298f705df4f12e339095d Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721370 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: virtio: add seek() for descriptor chainsDaniel Verkamp2019-08-13
| | | | | | | | | | | | | | This allows moving the read/write cursor around within a chain of descriptors through the standard io::Seek interface. BUG=chromium:990546 TEST=./build_test Change-Id: I26ed368d3c7592188241a343dfeb922f3423d935 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721369 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: virtio: add Error type for descriptorsDaniel Verkamp2019-08-13
| | | | | | | | | | | | | | | | Add an error type to describe descriptor Errors in more detail. This lets us return a more accurate error in a later CL in this chain by adding a VolatileMemoryError variant. BUG=chromium:990546 TEST=./build_test Change-Id: I08680d0cb64bfc3667bac7b2ad8a8bc0e78e8058 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1733988 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* Fix compiling warnings in test codeJianxun Zhang2019-08-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change fixes two small warnings in smoke test: Compiling crosvm_plugin v0.17.0 (/platform/crosvm/crosvm_plugin) warning: unused import: `std::mem::size_of` --> devices/src/virtio/input/event_source.rs:292:9 | 292 | use std::mem::size_of; | ^^^^^^^^^^^^^^^^^ | = note: #[warn(unused_imports)] on by default warning: variable does not need to be mutable --> devices/src/virtio/input/event_source.rs:385:13 | 385 | let mut evt_opt = source.pop_available_event(); | ----^^^^^^^ | | | help: remove this `mut` | = note: #[warn(unused_mut)] on by default Compiling arch v0.1.0 (/platform/crosvm/arch) BUG=None TEST=./wrapped_smoke_test.sh Pass smoke test. The 2 warnings disappear in the output. Change-Id: Ib4de48e9586e80087e30411e225265554d5e7a11 Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1742921 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* crosvm: add x-display argument for choosing the X11 gpu displayZach Reizner2019-08-08
| | | | | | | | | | | | TEST=cargo run -- run --gpu --x-display :0 BUG=None Change-Id: I76b4b33a6b14cb6fad322ffa95f00cce976f81a3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670550 Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* usb: handle transfer errors after port is detachedTomasz Jeznach2019-08-07
| | | | | | | | | | | | | | | | | | When USB device is detached from kernel driver there might be multiple pending USB transfers enqued, each completing with TransferStatus::NoDevice. Once backend device is detached from system it's ok to ignore subsequent detach request errors in transfer completion handler. BUG=chromium:987500 TEST=ADB USB device attach/detach cycles with active adb service. Change-Id: I4026e68df860c483973f51f9787bf3d48d2716b3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1737471 Tested-by: Tomasz Jeznach <tjeznach@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* devices: fix virtio-queue range checkJorge E. Moreira2019-08-07
| | | | | | | | | | | | | | | | | The check for validity of a DescriptorChain needs to ensure that self.len bytes starting from self.addr are valid valid guest memory addresses. The last byte of that range (assuming self.len > 0) is self.addr + self.len - 1. BUG=b/138459777 TEST=run cuttlefish locally with 4.19 kernel Change-Id: I2eb6e70e099b3849ac1f6cdd0dfeed092c2a2b02 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1728481 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jorge Moreira Broche <jemoreira@google.com> Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
* Allow to connect standard input to a serial port other than the guest consoleJorge E. Moreira2019-08-03
| | | | | | | | | | | | | | | | | | | | | Before this change, setting console=true on a serial port caused that port to be the one connected to the crosvm process' standard input. By adding an extra 'stdin' argument to the serial parameters it's possible to make those concepts independent. Just as with the console argument, stdin defaults to serial port 1 (ttyS0) when not provided and it's possible to set no serial port connected to stdin (or set as the console) by defining the first serial port without the stdin (console) argument. BUG=b/138616941 TEST=boot debian guest in debian host, boot cuttlefish in debian host Change-Id: I7273e6860218521073df93a4ad71e31c7da522a5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1731139 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Auto-Submit: Jorge Moreira Broche <jemoreira@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org>
* ac97: Fix device real time priority issuepaulhsia2019-08-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | - Add allow sched_setscheduler call in seccomp policy - Change the real time priority constant AUDIO_THREAD_RTPRIO to 10 to match all other clients' priority. Run the following commands to test 1. ulimit -r 10 2. crosvm run -r ./vm_rootfs.img -c 1 -m 1024 -s /run --cid 5 --host_ip \ 100.115.92.25 --netmask 255.255.255.252 --cras-audio \ --params="snd_intel8x0.inside_vm=1 snd_intel8x0.ac97_clock=48000" \ --mac d2:47:f7:c5:9e:53 ./vm_kernel 3. aplay -Dhw:0,0 -f dat /dev/zero 4. ps -AT -o comm,rtprio | grep crosvm should see a thread running with rtprio=10 BUG=chromium:983533 BUG=b:138262556 TEST=Test with eve (x86_64) and bob (arm) Change-Id: Idc3711d03d716741f7cefd9a89b14ae4c20c2033 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1729089 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Chih-Yang Hsia <paulhsia@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Chih-Yang Hsia <paulhsia@chromium.org>
* gpu_display: add X11 backendZach Reizner2019-07-25
| | | | | | | | | | | | | | This change adds an X11 backend to the gpu_display crate. With this addition, the virtio-gpu device can display to traditional linux desktops that only have X11 output. Change-Id: I86c80cac91ca5bdc97588194a44040273ae69385 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591572 Reviewed-by: Stéphane Marchesin <marcheu@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Zach Reizner <zachr@chromium.org>
* tree-wide: use PollContext::build_with where possibleZach Reizner2019-07-24
| | | | | | | | | | | | | | | | | | The old method of creating a PollContext and calling `add` inside of `and_then` chains was an ugly way handle the Results that can crop up after each call. The `build_with` function is equivalent but operates on a slice which has way less boilerplate. TEST=./build_test BUG=None Change-Id: I8b0d6532680e04c501187397bd211014a2363c25 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715581 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org>
* tree-wide: Use new trait object syntaxDylan Reid2019-07-24
| | | | | | | | | | | A few places were using the old syntax without `dyn`. Nightly compilers have started warning more aggressively, so fix up the last of those. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I4df49b4a27a62acfd8c542cec903e4c5b31bedcc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715576 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* tree-wide: update to new inclusive range syntaxDylan Reid2019-07-24
| | | | | | | | | | | 1.38 nightly started warning about using `...` vs `..=`, update to avoid the warning. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Ibc3d24c5410b6eed9a1207db21e529ec6a763376 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715575 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* Refactor input devices interactions with buffers in guest memoryJorge E. Moreira2019-07-17
| | | | | | | | | | | | | | | Input devices were using GuestMemory's read_to_memory and write_from_memory under the (incorrect) assumption that these function used the io::Read and io::Write traits, when they in fact use AsRawFd. BUG=b/137138116 TEST=ran cuttlefish in workstation Change-Id: I7ab1e2d0ab685dd25dcc91e794766c2f210665f7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1700418 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
* Don't call UNGRAB IOCTL on a socketJorge E. Moreira2019-07-17
| | | | | | | | | | | | | | | That IOCTL only makes sense on devices from /dev/input BUG=none TEST=ran cuttlefish in workstation Change-Id: I1aa1eea1a10db9a4d67337546782e118fceb14ee Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1703209 Tested-by: Jorge Moreira Broche <jemoreira@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jorge Moreira Broche <jemoreira@google.com> Auto-Submit: Jorge Moreira Broche <jemoreira@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* devices: gpu: advertise support for capset 3Gurchetan Singh2019-07-16
| | | | | | | | | | | | | | | Useful for prototyping new features. BUG=chromium:924405 TEST=compile Change-Id: Ibdc4a70761493939ca96b92540b9e0cca88c17a8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650290 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
* tempfile: Unify the two tempdir implementationsDavid Tolnay2019-07-11
| | | | | | | | | | | | | | | | | | | | | | Looks like we ended up with two totally different tempdir implementations: one from CL:520706 and the other from CL:1409705. This CL consolidates them into one implementation. BUG=chromium:974059 TEST=tempfile: cargo test TEST=crosvm: cargo check --all-features TEST=devices: cargo check --tests TEST=sys_util: cargo check --tests TEST=local kokoro TEST=./build_test Cq-Depend: chromium:1574668 Change-Id: Id70e963c9986ed2fc5f160819c4a7f9f16092b3b Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1573227 Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
* devices: silence unused code warning in PCIDaniel Verkamp2019-07-10
| | | | | | | | | | | | | | | | Now that nothing uses the PCI-to-PCI bridge device type, the compiler warns that it is never constructed. Mark the PciHeaderType enum to allow this, since the enum is public and could be constructed outside this file. BUG=None TEST=./build_test Change-Id: I6832996c4e00a33cc1ba88d97fede65b226cbfc5 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691239 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* devices: remove use of mem::uninitializedDaniel Verkamp2019-07-09
| | | | | | | | | | | | | | | mem::uninitialized is unsafe, and we already replaced most instances of it with alternate implementations; however, another one slipped in since then. Replace it with Default::default() as a safe alterantive. BUG=None TEST=./build_test Change-Id: Idacdcb0ebe197cc93fba4b15c3dda774bb56e73e Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691233 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* pci: Let device could trap pci config read/writeXiong Zhang2019-07-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently device impliments PciDevice trait, it will return config register to bus trait at pci cfg r/w, then BusDevice trait on behave of device to do actual pci config r/w. But vfio device need to handle the pci config r/w by itself, as vfio device need to transfer this request to kernel. For pci config read, this patch delete PciDevice->config_registers(), and add PciDevice->read_config_register(), then BusDevice-> config_register_read() call PciDevice->read_config_register(), finally Device could trap the PciConfig Read. For pci config write, it is similiar with pci config read. But the common code is moved into PciConfiguration. BUG=none TEST=none Change-Id: Ie6bd3a8c94f523d6fb1ef3d1e97d087bb0407d9f Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1580457 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* virtio-gpu: Allocate buffers with shared bind flag using gbm.David Riley2019-07-03
| | | | | | | | | | | BUG=chromium:972237 TEST=eglgears_wayland Change-Id: If5a09c1ad95dfdbd47e7810c466c127c53413f21 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1657291 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: David Riley <davidriley@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
* usb: switch to new libusb_wrap_sys_device APIDaniel Verkamp2019-06-27
| | | | | | | | | | | | | | | | | | | | Replace use of our custom, patched libusb APIs with the new libusb_wrap_sys_device() function, which has been submitted to libusb upstream. This allows us to drop the bindings for the custom APIs (and will also allow us to drop the libusb patch that introduces them). For now, keep this path behind the sandboxed-libusb feature to allow crosvm to build against older libusb versions that do not have the new API. This should be cleaned up eventually once we are comfortable with raising the minimum libusb version required. BUG=b:133773289 TEST=Attach Android device to Linux VM; deploy app via adb Change-Id: Ie249c6f3f3b4c63210dd163ca7ad03e2de8a8872 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1676601 Tested-by: kokoro <noreply+kokoro@google.com>
* devices: pci: preserve read-only bits in write_regDaniel Verkamp2019-06-25
| | | | | | | | | | | | | | | | | | The 32-bit write_reg() function for PCI configuration space masked off non-writable (read-only) bits from the incoming value, but it did not preserve the original bits from the register; this results in writes to read-only registers to clear all read-only bits to 0 instead. Preserve the original value of the read-only bits and add a test to verify that this works. BUG=None TEST=./build_test Change-Id: Icc67b429f17d519ec4e9090f8e0ce48aaff76491 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660204 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* devices: pci: check BAR address alignmentDaniel Verkamp2019-06-25
| | | | | | | | | | | | | | | Each PCI BAR address must be aligned to at least its own size to allow the BAR sizing mechanism to work properly. Add a check in add_pci_bar() to enforce this. BUG=None TEST=Boot vm_kernel in crosvm Change-Id: Iee9d866c4982bd79935337682bd50b9205b95024 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660203 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: pci: allocate BARs with correct alignmentDaniel Verkamp2019-06-25
| | | | | | | | | | | | | | | | | | Each PCI BAR must be aligned to at least its own size to allow the BAR sizing mechanism to work. Change all BAR allocations to use allocate_with_align(), specifying the size as the alignment. In particular, this fixes the alignment of the XHCI BAR, whose size is larger than a page (the default MMIO allocator alignment). BUG=None TEST=Boot vm_kernel in crosvm Change-Id: Icba03771a896b9b4feae608efdb7685fe24f8b98 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660202 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* devices: pci: Change host brige into IntelXiong Zhang2019-06-25
| | | | | | | | | | | | | | | | For kvmgt linux guest, intel graphic driver i915 need intel host bridge located at 0000:00.0, so this patch change the vendor id of 0000:00.0 device to intel. BUG=none TEST=none Change-Id: I52f2341d25859f2b7d4a3837f4f0c8a4b2443525 Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581139 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* devices: pci: use header type 0 for host bridgeDaniel Verkamp2019-06-25
| | | | | | | | | | | | | | | | | | | Previously, we were using header type 1 (which is meant to be used only for PCI-to-PCI bridges), which upsets the Linux PCI probing code: pci 0000:00:00.0: ignoring class 0x060000 (doesn't match header type 01) Switch to the standard type 0 header instead, which makes the kernel happy and matches what real hardware uses. BUG=None TEST=Boot vm_kernel (Linux 4.19) in crosvm Change-Id: I33d10bda39edf6d949827963cebbfe66c9147ea2 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660892 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* gpu_renderer: make Box3 less error prone with constructorZach Reizner2019-06-24
| | | | | | | | | | | | | | | | | | | The argument order of the new_2d constructor was very odd. That has been changed to the ordinary x,y,w,h order. Also, each Box3 is checked by is_empty() before being used, which prevents some degenerate operations on zero area boxes. TEST=cargo run -- run --gpu BUG=None Change-Id: I6954fa4846f20353517fe81028058b639752d8ea Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670549 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org>
* devices: Use Reader/Writer interfaces in virtio-net.Jakub Staron2019-06-24
| | | | | | | | | | | | | BUG=chromium:966258 TEST=tast run ${IP} vm.CrostiniStartEverything TEST=tast run ${IP} vm.CrostiniNetworkPerf Change-Id: I99c5b9e564c219b76593d729fb934722fc8a3431 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1658980 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* gpu: Allow more than one resource bridge socketChirantan Ekbote2019-06-24
| | | | | | | | | | | | | | | | | | | | | | | | Currently the wayland device accesses buffers allocated by the gpu device via a dedicated socket connection. Upcoming virtual devices like vdec and camera will also need access to these buffers. Modify the gpu device so that it can process requests on multiple resource_bridge sockets. Each future device that needs access to gpu device buffers should create a new resource bridge socket pair and add it to the list of sockets that the gpu device monitors. The actual interface between the devices is unchanged. BUG=b:133381367 TEST=run glxgears in a crostini container with and without gpu enabled Change-Id: I58693881945965071a53653bf4f86681725267d0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1652876 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
* crosvm: Implement Reader/Writer interface over DescriptorChain.Jakub Staron2019-06-21
| | | | | | | | | | | | | | | | | | | This change adds a convinient interface over DescriptorChain. It hides the complexity of DescriptorChain and allows to treat it as a pair of read-only and write-only buffers. In the future, it will also allow to easily support indirect descriptors. BUG=chromium:966258 TEST=cargo test --package devices descriptor_utils TEST=run crosvm without sandbox, share a directory, compare checksum of shared file between host and guest Change-Id: I9fb722ee2024c8d7d40f560571ec7d7c454bfc2b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1647370 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jakub Staroń <jstaron@google.com>
* crosvm: Ensure slices are the same size when copying.Jorge E. Moreira2019-06-21
| | | | | | | | | | | | | Bug=b/135190799 TEST=run cuttlefish in debian host Change-Id: I7f9343dd202da2a163b3e8aeb8fbde5eb4cfb1d3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1659144 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Cody Schuffelen <schuffelen@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Jorge Moreira Broche <jemoreira@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* crosvm: fix clippy warningsJakub Staron2019-06-08
| | | | | | | | | | | | | | | | | | | Resolve a couple of minor clippy warnings: - unneeded return statement - use `if let` instead of `match` for single pattern destruction - use `values()` function to iterate over map values - supress warning about `ptr::null()` as expressed by the comment BUG=None TEST=./bin/clippy TEST=cargo build Change-Id: Ic4cea94cd3a25a9edf6ef38119de8c46dcfec563 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1646739 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Jakub Staroń <jstaron@google.com>
* serial: fix clippy warningsJakub Staron2019-06-08
| | | | | | | | | | | | | | | | Resolve couple of minor clippy warnings: - unneeded return statement in last expression of the function - redundant closure BUG=None TEST=./bin/clippy TEST=cargo build Change-Id: I602e56289315cb88779c0029d400b24a8180b899 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1646738 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Jakub Staroń <jstaron@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* usb: reset backend device on port resetDaniel Verkamp2019-06-05
| | | | | | | | | | | | | | | | | | | | | | | | This enables the full firmware update/reset/use device in application mode sequence for Edge TPU USB Accelerator. There is a bit of a UI hiccup: once the firmware update and reset is complete, the device re-enumerates with a different VID/PID, and the "Connect to Linux" prompt shows up again. The user must re-affirm that the device should be connected to Linux to proceed with using the Edge TPU. This may be unavoidable - I'm not sure if we can tell the difference between a newly-inserted device and a reset one. Allowing USBDEVFS_DISCONNECT_CLAIM should be safe, since it can only operate on file descriptors passed into the xhci device jail. BUG=chromium:831850 TEST=Run Edge TPU Accelerator demo and verify that it can update FW Change-Id: I3d61c7bd914830ce25448b1ae4d60e1c16f10aed Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1599881 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* crosvm: virtio-pmem deviceJakub Staron2019-06-05
| | | | | | | | | | | | | | | | | | | | Adds support for virtio-pmem device as an alternative for virtio-blk. Exposing disk image to guest as virtio-blk device results in both guest and host independently caching the disk I/O. Using virtio-pmem device allows to mount disk image as direct access (DAX) in the guest and thus bypass the guest cache. This will reduce memory foodprint of the VMs. BUG=None TEST=cargo test TEST=Boot patched termina kernel in crosvm; mount virtio-pmem device as DAX and run xfstests. Change-Id: I935fc8fc7527f79e5169f07ec7927e4ea4fa6027 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1605517 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Jakub Staroń <jstaron@google.com>
* eliminate mut from non-mut referencesZach Reizner2019-06-04
| | | | | | | | | | | | | | | | | | | | | | | This manifested itself in a couple places that were turning shared memory buffers into slices for the purposes of passing these slices to `Read` and `Write` trait methods. However, this required the removal of the methods that took `Read` and `Write` instances. This was a convenient interface but impossible to implement safely because making slices from raw pointers without enforcing safety guarantees causes undefined behaviour in Rust. It turns out lots of code in crosvm was using these interfaces indirectly, which explains why this CL touches so much. TEST=crosvm run BUG=chromium:938767 Change-Id: I4ff40c98da6ed08a4a42f4c31f0717f81b1c5863 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1636685 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Zach Reizner <zachr@chromium.org>