summary refs log tree commit diff
path: root/sys_util/src
Commit message (Collapse)AuthorAge
* sys_util: make UnixSeqpacket::recv use libc::recv interguestAlyssa Ross2020-07-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's very surprising that a method called "recv" would end up calling read(). When UnixSeqpacket was introduced in 1d44223f9, the method was called "read", so this behaviour made more sense. It was renamed to "recv" in b7196e2a1, but the implementation was not changed to call libc::recv. In most cases, according to recv(2), the difference between read() and recv() doesn't matter: > The only difference between recv() and read(2) is the presence of > flags. With a zero flags argument, recv() is generally equivalent > to read(2) (but see NOTES). But the NOTES section explains that > If a zero-length datagram is pending, read(2) and recv() with a > flags argument of zero provide different behavior. In this > circumstance, read(2) has no effect (the datagram remains pending), > while recv() consumes the pending datagram. This means that, while we might expect UnixSeqpacket::recv(&mut []) to mirror the behaviour of recv() and discard a message despite the empty buffer, it would actually leave it there. This became relevant when I implemented the startup message queue in 5bd2e7f60, because I used an empty recv to drop the ready message from the socket, since it was only used for polling and I didn't care about the content. But, it turns out that my UnixSeqpacket::recv call did nothing, and left the message on the socket. This wasn't immediately noticeable, but it meant that when a message came through on the control socket later, it would actually get the ready message from UnixSeqpacket::recv, rather than the expected message on the control socket. For example, trying to use crosvm disk resize would print a message like the following: > [ERROR:vm_control/src/lib.rs:649] unexpected disk socket result: Ready > [ERROR:devices/src/virtio/block.rs:334] Attempted to resize read-only block device We can see that it does try to process the received message, but first it tries to do something with the Ready message, which should have been discarded by now. With this fix applied, we can see that it now receives and tries to process the correct message (but then fails because the VM I tested didn't support disk resizing!): > [ERROR:devices/src/virtio/block.rs:334] Attempted to resize read-only block device Fixes: b7196e2a1c1eb7123e7eace5418b7eb4a3e24dbe Fixes: 5bd2e7f606b726b598fdc26fe26a9b4029fab6d3 Cc: Cole Helbling <cole.e.helbling@outlook.com>
* Make lots of things DebugAlyssa Ross2020-07-02
|
* switch from poly_msg_socket to msg_socket2Alyssa Ross2020-06-15
|
* vm_control: make MaybeOwnedFd genericAlyssa Ross2020-06-15
| | | | | This will allow more easily sending types other than File over sockets, (e.g., UnixSeqpacket).
* hacky working out-of-process virtio_wlAlyssa Ross2020-06-15
|
* guest_memory: allow creating with an existing memfdAlyssa Ross2020-06-15
| | | | | This will allow creating GuestMemory structs representing memory of VMs being managed by other processes.
* Merge remote-tracking branch 'origin/master'Alyssa Ross2020-06-14
|\
| * hypervisor: add Vm user memory region functionsSteven Richman2020-06-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The separate Vm functions for MemoryMappings and MemoryMappingArenas have been combined and now use a MappedRegion trait that the mappings implement. msync_memory_region replaces the get_mmap_arena function, which is used by VmMsyncRequest. Since Vm uses mutexes for cloning, it can't return mem region references. BUG=chromium:1077058 TEST=cargo test, cargo test -p sys_util, cargo test -p hypervisor Change-Id: If257b16ee34d07820ae7ebdb9a3a598a41df013c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2202845 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
| * sys_util: Make ioctl number method a const fnChirantan Ekbote2020-06-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows us to define const variables that are the return value of the method, which we can then use in match statements. BUG=b:157189438 TEST=unit tests Change-Id: I2475c59bfd43ec9ec149a6b688bf680fa2361a0b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2214962 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* | Merge remote-tracking branch 'origin/master'Alyssa Ross2020-06-14
|\|
| * sys_util: Refactor IntoIovecChirantan Ekbote2020-05-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original stated purpose of this trait was to reduce memory allocations but having the `into_iovec` method return a Vec kind of defeats that purpose. Refactor the trait so that it can either convert a T into an iovec or convert a &[T] into a &[iovec]. Implement the trait for VolatileSlice, IoSlice, and IoSliceMut and update all the callers. BUG=none TEST=unit tests Cq-Depend: chromium:2210272 Change-Id: I9d0d617a23030d241d50411f4a5a16e7cba4bcee Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2208527 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Tested-by: Chirantan Ekbote <chirantan@chromium.org>
| * Make VolatileSlice ABI-compatible with iovecChirantan Ekbote2020-05-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change VolatileSlice so that it is ABI-compatible with iovec. This allows us to directly pass in a VolatileSlice for a C function that expects an iovec without having to create temporaries that convert from one to the other. Also change all the parameters from u64 to usize. It's not possible to address more memory than fits into a usize so having u64 here didn't really provide much benefit and led to a lot of tedious casting back and forth all over the place. BUG=none TEST=unit tests Cq-Depend: chromium:2206621 Change-Id: I258f9123c603d9a4c6c5e2d4d10eb4aedf74466d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2203998 Tested-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
* | Merge remote-tracking branch 'origin/master'Alyssa Ross2020-05-22
|\|
| * hypervisor: add KvmVm new and try_cloneSteven Richman2020-05-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Vms and Vcpus will be try_cloneable and Send, so we can configure on vcpu threads and so IrqChips can reference all Vcpus. To support cloning, collection fields in Vm have been moved into arc mutexes, and Vm and Vcpu are now Sized. Because this breaks object safety, all usage of the traits will be via static binding. Add impl AsRawFd for SafeDescriptor, to get the sys_util ioctl functions working with SafeDescriptor; eventually the functions will change to take SafeDescriptors. Copy set_user_memory_region helper from kvm crate. BUG=chromium:1077058 TEST=cargo test -p hypervisor Change-Id: I23de47c4472a77632006d0d45de9754394b400c2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197337 Reviewed-by: Udam Saini <udam@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Steven Richman <srichman@google.com>
* | Merge remote-tracking branch 'origin/master'Alyssa Ross2020-05-10
|\|
| * remove instantes of using IntoRawFd in unsafe blocksZach Reizner2020-05-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The trait IntoRawFd isn't marked unsafe, but its documentation says that an impl must return a uniquely owned RawFd. Some code blocks depended on that behavior to ensure safety with the unsafe File::from_raw_fd, but this leads to a soundness hole where a nominally safe impl of IntoRawFd can lead to unsafety in functions that had been left as safe. This change sidesteps the issue by not using IntoRawFd, and using only safe conversions instead. BUG=None TEST=cargo build --features='wl-dmabuf plugin' Change-Id: I9b357e5592be21189fb96e343823dd63000aac30 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2185580 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> Auto-Submit: Zach Reizner <zachr@chromium.org>
| * Adding hypervisor crate to abstract out Kvm implementationUdam Saini2020-05-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a separate hypervisor crate for interacting with Kvm in an abstract manner. The intention is to not leak the internals of kvm with its specific calls in various places in the codebase. Currently, this just creates an initial structure for adding various implementations over time. In addition, a SafeDescriptor class is added, that wraps a raw file descriptor safely, without needing to wrap it in the rust file class. The intention is to use this for non file raw descriptors. BUG=chromium:1077058 TEST=added a basic kvm test that creates a Kvm struct Change-Id: I4229203902e480b52435cde12bf0d25a322c71be Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2174756 Commit-Queue: Udam Saini <udam@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
| * Stop tracking sub-mappings in MemoryMappingArenaChirantan Ekbote2020-04-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The kernel already takes care of tracking all our memory mappings. Doing it again ourselves doesn't provide any benefit and also adds additional restrictions (like not being able to overlap with existing mappings or partially remove mappings). Additionally, the `MemoryMappingArena` will already unmap the entire memory mapped region so there is no need to individually unmap the sub-mappings. The kernel's mmap api doesn't have these restrictions and as far as I can tell there are no safety concerns with allowing this behavior so just stop tracking the sub-mappings. Safe use of MAP_FIXED only requires that the address is part of a previously mmaped region so allow any MemoryMapping to be converted into a MemoryMappedArena. BUG=b:147341783 TEST=unit tests Change-Id: Iaf944a971b8ba9333802aab73c1d184fe388af89 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2162542 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
| * Remove redundant single-component importsDaniel Verkamp2020-04-26
| | | | | | | | | | | | | | | | | | | | | | | | | | Fix clippy 1.43.0 clippy::single-component-path-imports warnings. BUG=None TEST=bin/clippy Change-Id: I3f4f54138bedce16dc1ca937bb8bc00a94594f69 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2163203 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
| * sys_util: timerfd: Methods don't need to me mutDylan Reid2020-04-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Because TimerFd is a wrapper around a 'File' that is never modified there isn't a need for a mutable borrow. The kernel already handles the interior mutability of the underlying file descriptor. Change-Id: I7ae068cc54050b0021d00620b561335b2ae0ba16 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2161625 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* | crosvm: collapse simple boolean matchesAlyssa Ross2020-04-11
| | | | | | | | | | Rust 1.42 introduces matches!(), which can be used to collapse simple match statements like these.
* | Merge remote-tracking branch 'origin/master'Alyssa Ross2020-04-10
|\|
| * handle mmap of large offsets on 32 bit systemsDylan Reid2020-04-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While only 32 bits of address can be mapped, that 32 bits can be offset by further than 32 bits in to a large file. As chirantan points out, the try_mmap call was already casting the usize to u64 on all architectures. Convert the usize offset in mmap to u64 and address users of the API as well. Change-Id: I67aed928ea521049fb51eb7aa61ea4de8b4d096c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124879 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org>
| * sys_util: Allow pre-populating mmapsDylan Reid2020-03-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | io_uring would like to pre-fault the ring pages as they are likely to be accessed regularly. Allow mmap users to specify the MAP_POPULATE flag through a new API. Change-Id: I5fefc13443280fe832c9601fe5a497b572127f0e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124008 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Dylan Reid <dgreid@chromium.org>
* | sys_util: EpollContext doc copy editsAlyssa Ross2020-04-10
| |
* | Merge remote-tracking branch 'origin/master' into masterAlyssa Ross2020-03-09
|\|
| * ac97: switch to ShmStreamSourceFletcher Woodruff2020-02-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert playback and capture for the AC97 device to use the zero-copy ShmStreamSource instead of the old StreamSource. In the process, rework start_playback and start_capture unit tests so they rely less on sleep statements. BUG=chromium:968724 BUG=chromium:1006035 TEST="sox -n -r 48000 -b 16 output.raw synth 5 sine 330 && aplay -f dat output.raw" within a VM, check that sine wave is played accurately. Change-Id: Ie9cddbc5285a9505872c9951a8a1da01de70eb88 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1749950 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
| * sys_util: cleanup shared mem file after testMatt Delco2020-02-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Running "build_test" fails if it's been previously run using sudo. The failure is: thread 'main' panicked at 'error creating shared memory;' and errno is 17, so apparently the shared memory name is left behind. BUG=None TEST=Verified that "sudo build_teat" followed by "build_test" results in a failure, while with this change it reports success. Change-Id: I09748b9c0b89ac953e054de852277d819ad85287 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1876662 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Matt Delco <delco@chromium.org>
* | sys_util::PollToken: fix typo in documentationAlyssa Ross2020-02-11
|/
* sys_util: recv entire UnixSeqpacket packets into VecZach Reizner2020-02-06
| | | | | | | | | | | | | | | | | | This change adds the `recv_*_vec` suite of methods for getting an entire packet into a `Vec` without needing to know the packet size through some other means. TEST=cargo test -p sys_util -p msg_socket BUG=None Change-Id: Ia4f931ccb91f6de6ee2103387fd95dfad3d3d38b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034025 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> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: add ScopedEvent to trigger and EventFd on DropZach Reizner2020-02-01
| | | | | | | | | | | | TEST=cargo test -p sys_util BUG=None Change-Id: I1190947835549f872c6df7616e05a0a7be06d51e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2029926 Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Zach Reizner <zachr@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org>
* sys_util: add FileAllocate traitDaniel Verkamp2020-01-24
| | | | | | | | | | | | | | | This trait provides a generic interface for allocating space on the filesystem within a given file. It is equivalent to the fallocate(2) system call with the default mode (mode = 0). BUG=chromium:858815 TEST=cargo build --features=composite-disk Change-Id: I2f4e8aceb4878790e8dec2e3d539071915efd205 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015828 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* guest_memory: add fn to get memfd offset of addrFletcher Woodruff2020-01-23
| | | | | | | | | | | | | | | | | | | Add a function offset_from_base() which, given a GuestAddress, determines the offset of that address within the backing memfd of the GuestMemory. In other words, this lets you convert a GuestAddress into an offset that can be understood by another process which has mapped the the memfd and would like to read from that address. BUG=chromium:968724 TEST=cargo test Change-Id: I5b033ad29dd38090f74577c068cc62ee9c6effb6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015835 Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
* sys_util: Fix unused trait warningDylan Reid2020-01-14
| | | | | | | | | | | | | Commit "d5aa99542: disk: use seek to determine file length" added these traits to sys_util but didn't use them. Change-Id: I0babbbc75450e20f9f7ae7d5f94dd6285c12a8bb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1999948 Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Dylan Reid <dgreid@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* disk: use seek to determine file lengthDaniel Verkamp2020-01-13
| | | | | | | | | | | | | | | | Add a new disk-specific DiskGetLen trait which uses io::Seek instead of File::metadata() to determine the length so that it works on raw block devices (e.g. /dev/sda) as well as regular files. BUG=b:146811529 TEST=`crosvm run --disk /dev/sda` and verify block device length Change-Id: I6936863490efaa479a3c8745c75c373748c800a1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1990855 Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Trent Begin <tbegin@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* devices: remove user_command from proxy deviceZach Reizner2020-01-09
| | | | | | | | | | | | | | | | | | The only device that used user_command was Serial. This change makes Serial device use a thread to read from its input instead of using user_command. BUG=chromium:1033787 TEST=./build_test run crosvm with stdio serial with and without sandbox Change-Id: Ia0f2ee83d94ad2fee3f1f4f89aa734b976e33507 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1966435 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Auto-Submit: Zach Reizner <zachr@chromium.org>
* sys_util: Expose setting FD flags as a pub fnDylan Reid2019-12-12
| | | | | | | | | | | | | Other users will want to set flags on FDs. Particularly asynchronous code that wants to set FDs as non-blocking. Add a helper that handles fetching and or-ing in the given flags so users don't have to handle that themselves. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Iabe438fbbb1ec305f693dbe1348930ef153edcf4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1955044 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* crosvm: move vec_with_array_field to data_modelGurchetan Singh2019-12-11
| | | | | | | | | | | | | | Move it to the newly created flexible array file. BUG=chromium:892806 TEST=compiles Change-Id: I6c423a885cec17e376b0da87a4adbd17c71ff6f0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1325510 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* sys_util: guest_memory: check u64 to usize conversionDaniel Verkamp2019-12-06
| | | | | | | | | | | | | | | Replace the unchecked conversion with a try_from() rather than just truncating without warning. This gives a more useful error message when a >4GB guest memory size is requested on a 32-bit platform. BUG=chromium:1028747 TEST=`crosvm run -m $((5 * 1024)) ...` on kevin Change-Id: Ib1fcf4019eefdc9ee8f93a5307802e6d6d43d01c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1937552 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: don't implement File*Volatile for SharedMemoryDaniel Verkamp2019-12-06
| | | | | | | | | | | | | | | | | | The implementations of FileReadWriteVolatile and FileReadWriteAtVolatile for SharedMemory are never used; SharedMemory is typically accessed as a memory mapping, not as a writable/readable file-like object. Remove the implementation of these traits for SharedMemory to simplify porting to other platforms where SharedMemory may not necessarily be backed by a file-like object. BUG=None TEST=./build_test.py Change-Id: I9c1e46ad2d3299b8676fad33151cde7c4b1c7b8e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1937555 Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* sys_util: Ignore struct_util doc commentDylan Reid2019-12-04
| | | | | | | | | | | | | The code in the doc comment didn't compile, fix the missing command. Ignore the snippet because it depends on arch::__IncompleteArrayField, and getting it to compile isn't worth adding a crate dependency. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Ibaee50d0d44fbfb9ca2862b1dda220a0a1e5696b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1944097 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* disk: add get_len() to eliminate need for SeekDaniel Verkamp2019-11-27
| | | | | | | | | | | | | | | This new trait allows DiskFile implementors to provide the length of the file directly rather than using SeekFrom::End with seek(). BUG=None TEST=./build_test TEST=Boot Termina in crosvm Change-Id: I9447ebb43dbd5fbb32a3a6b6d2fc969b9406cdbc Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913961 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: do not deallocate space in write_zeroesDaniel Verkamp2019-11-27
| | | | | | | | | | | | | | | | | | Replace the implementation of File write_zeroes with one that uses fallocate() with the FALLOC_FL_ZERO_RANGE flag instead of FALLOC_FL_PUNCH_HOLE. This means it will keep space allocated for the zeroed region instead of deallocating it. The PunchHole trait is available for this purpose instead, and the virtio-blk implementation already relies on these two traits for their differing behaviors. BUG=chromium:858815 TEST=cargo test -p sys_util write_zeroes Change-Id: I69ab06037f72dc219e6ea9409654f97eeaba32c3 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913520 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add WriteZeroesAt traitDaniel Verkamp2019-11-27
| | | | | | | | | | | | | | | | | Add a variant of WriteZeroes that allows the caller to specify the offset explicitly instead of using the file's cursor. This gets rid of one of the last bits of shared state between disk file users, which will help in implementing multi-queue support. Additionally, modify the WriteZeroes trait to use a generic implementation based on WriteZeroesAt + Seek when possible. BUG=chromium:858815 TEST=Boot Termina in crosvm Change-Id: If710159771aeeb55f4f7746dd4354b6c042144e8 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913519
* sys_util: poll: add iter_writable to set of methods for PollEventsZach Reizner2019-11-26
| | | | | | | | | | | | | | | | There were already methods for the readable and hungup events, so this completes the set. TEST=None BUG=chromium:1023975 Change-Id: Ie9cd1459893cc8b6ba7a52e638e164095ddbcba5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930404 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
* guest_memory: remove optional memfdGurchetan Singh2019-11-16
| | | | | | | | | | | | | | | | | Builders should all have memfd support now. BUG=chromium:942183 TEST=compile and run, CQ will also test Cq-Depend: chromium:1901871, chromium:1907541 Change-Id: I0cd4ec43a51e9995def2e105d68e12a703168365 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1834701 Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
* kvm: Allow low mmio added into kvmXiong Zhang2019-11-11
| | | | | | | | | | | | | | | | | | | gpa > guest_mem.end_addr() is used to avoid gpa fall into guest ram, but low mmio maybe below guest_mem.end_addr(), this condition is false, then low mmio couldn't be added. Since low mmio could be added into kvm also, this condition is wrong. This patch iterate all the guest memory reginos, and check whether it overlap with any of them. BUG=chromium:992270 TEST=bulld_test Change-Id: I9560db43f9836f85d0ff927e7eeb92447774568c Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895235 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* devices: virtio: block: advertise seg_maxDaniel Verkamp2019-11-08
| | | | | | | | | | | | | | | | | | | | | | The virtio-blk configuration space has a `seg_max` field that lets the device inform the driver of the maximum number of segments allowed within a single request. The Linux virtio block driver assumes that if the corresponding feature (VIRTIO_BLK_F_SEG_MAX) is not advertised, then only one segment can be used. Add a segment limit based on sysconf(_SC_IOV_MAX) to allow the Linux block stack to make use of multiple segments in a single request, which will get translated into a single readv/writev call in the crosvm block device. BUG=None TEST=strace crosvm virtio-blk process and note preadv with iov_cnt > 1 Change-Id: Ia14ebebb85daa21e2d43437bb74886f32e6e8187 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1876806 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
* sys_util: split volatile_impl macro into volatile_{,at_}implStephen Barber2019-11-05
| | | | | | | | | | | | | | | | | | Certain types of file descriptors, such as tap devices, aren't compatible with writing at offsets. Split the volatile_impl macro into two, one for FileReadWriteVolatile and another for FileReadWriteAtVolatile. Tweak the macros be usable from other crates. BUG=chromium:753630 TEST=cargo build Change-Id: I0671024e24e8b5eaedbde2c1da80e3ec684c06a1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1881417 Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Commit-Queue: Stephen Barber <smbarber@chromium.org>
* sys_util: make IntoIovec return an actual vectorDaniel Verkamp2019-11-05
| | | | | | | | | | | | | Allow IntoIovec to produce an iovec with more than one entry. BUG=None TEST=./build_test.py Change-Id: I21e8512f3edb06d9c0be4a1707432dde9fda6e9e Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1815316 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>