Commit graph

339 commits

Author SHA1 Message Date
Frederick Mayle
dc3a9018e8 base: handle EINTR in Tube recv methods
`peek_size` blocks until there is data available, so it is actually more
likely to see an EINTR than the `recv_with_fds` call that follows it.

Before, the following command failed had 5 flakes, 3 of which were
clearly caused by EINTR when recving on a tube. After, I saw no flakes.

    ./tools/run_tests --dut=vm --filter-expr="test(boot_test_vm_uring)" --repetitions 100

BUG=b:293463612

Change-Id: Ie0471a46be11d67f38d4d0a5a4793e5ca2fc1633
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4727022
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-07-28 01:30:27 +00:00
Daniel Verkamp
2b67ccffeb base: unix: adjust shm test for SEAL_EXEC
Due to MFD_NOEXEC_SEAL being applied by SharedMemory::new() on newer
kernels, the set of seals may not be 0 after shm creation. Tweak the
test to validate that only the F_SEAL_SEAL flag is clear before we
intentionally set it so the test can pass on both old and new kernels.

BUG=b:282221246
TEST=tools/dev_container tools/presubmit # on Linux 6.3.11 kernel

Fixes: 5b7cdc1eb0 ("base: use MFD_NOEXEC_SEAL if available when creating memfds")
Change-Id: I60e3886bf0401f037b3ca03ba1b43186adcec5bb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4718767
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-07-25 22:39:23 +00:00
Junichi Uekawa
8d83d0d1c1 crosvm: Rename to open_file_or_duplicate.
open_file does not always open_file. It reuses given fd when it points
to a special path /proc/self/fd/XX.

BUG=b:291832160
TEST=build

Change-Id: If821834e3adbc457616c71e5b8425962286245e7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4706830
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2023-07-24 01:30:27 +00:00
Dennis Kempin
7ea17ea685 base_event_token_derive: Move entry point to standard location
For bazel migration we will require lib entry points to be in their
standard location at src/lib.rs

BUG=b:289258700
TEST=CQ

Change-Id: I2346260212532716c5954ba65d6264afc7e55a68
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4691163
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-07-17 18:47:27 +00:00
Daniel Verkamp
ce5a78e83b clippy fixes for Rust 1.70 and 1.71
Change-Id: If86c6cd531b854293a93208de5254664f5ee6bec
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4637612
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-07-13 20:29:05 +00:00
Daniel Verkamp
587d5fab3d vm_control: move send_recv_event test to base
This test is unrelated to vm_control; it is testing base::Event and
base::Tube functionality, so move it next to the existing Tube tests.

The test module was also in the middle of the file for some reason,
which caused clippy warnings in Rust 1.71.

Change-Id: I52858e71df8aa3e092b3b7d12e1232454b61c4d4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4684827
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-07-13 19:59:28 +00:00
James Ye
ea7d75a6c2 base: change syslog output buffers to Vec<u8>
The internal buffer is changed from String to Vec<u8>. This avoids
breaking incomplete UTF-8 sequences during string parsing, which would
result in replacement characters in the output.

BUG=b:289736895
TEST=Check syslog for "…" when running a Debian VM on Linux
TEST=tools/presubmit

Change-Id: I9316e728d39aad2980946a5e90239d466e082d75
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4666847
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: James Ye <jamesye@google.com>
2023-07-07 03:54:16 +00:00
David Stevens
5b031ce8b0 base: Introduce TimerTrait
Introduce a TimerTrait that is implemented by both Timer and FakeTimer.
This trait can be used to write testable code without needing to
condition use statements on cfg(test).

BUG=None
TEST=CQ

Change-Id: I874ffe19fafe73e5c17fd5bb689e5b571e9f5b12
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4664188
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-07-05 01:12:35 +00:00
Daniel Verkamp
a376c39b7d base: windows: move MultiProcessMutex into a new file
This cleans up the final windows/win/* file, so the import is removed.

BUG=b:263815124
TEST=tools/run_tests --platform=mingw64

Change-Id: I705d4789982284739a81694fbb0d15bd07cfa77f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126573
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-06-16 19:04:56 +00:00
Daniel Verkamp
da39885e8d base: windows: make platform_timer_utils internal
Move platform_timer_utils.rs to src/sys/windows (out of win/) and do not
export its functions from base. These are only used internally and are
not cross-platform APIs, so they should not be public.

BUG=b:263815124
TEST=tools/run_tests --platform=mingw64

Change-Id: Id82065d15d7b2fabd33b3ba1784a6a8a243f1db0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126572
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-06-16 19:04:56 +00:00
Zihan Chen
19e215aa39 crosvm: Remove DataInit from windows components
TEST=CQ
TEST=turn on building for perfetto, and rust-analyzer doesn't
complain about things I changed.

BUG=b:204409584

Change-Id: I4c290304028ecd155069d6194f776360d48b4220
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4618952
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-06-15 21:30:12 +00:00
Daniel Verkamp
5b7cdc1eb0 base: use MFD_NOEXEC_SEAL if available when creating memfds
The new MFD_NOEXEC_SEAL flag allows creating memfds that don't have the
execute file mode. Add a function to detect whether this feature is
available on the currently running kernel so we can make the guest
memory memfd a non-executable file if the feature is available.

BUG=b:282221246
TEST=run crosvm on a ChromeOS kernel with MFD_NOEXEC patch
TEST=stat -L /proc/<crosvm pid>/fd/<crosvm memfd>; observe no x
TEST=run crosvm on an older vanilla Linux kernel without MFD_NOEXEC

Change-Id: I5d60cfe4b90eb23f79ecbc04d6bde9e1f46eeb8e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4528584
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Jeff Xu <jeffxu@google.com>
2023-06-14 21:31:28 +00:00
Noah Gold
16625da26a base: unify TubeError::Send & TubeError::SendIo.
After recent refactoring, these variants are identical.

BUG=b:284057368
TEST=clippy

Change-Id: I10947eac1720cbe7c10010d2a647bc38c1704267
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4596526
Reviewed-by: Shin Kawamura <kawasin@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Auto-Submit: Noah Gold <nkgold@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-06-09 17:16:05 +00:00
Lepton Wu
5092bd0ad1 base: syslog: Use UTC timesamp
This avoid opening timezone files from jailed process under unix.

BUG=b:280298742
TEST=manual - run crosvm with logging from battery device.

Change-Id: I1869ce5a79bdd0ace678e4e90ea1f9df2e90fd8a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4574297
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Lepton Wu <lepton@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-06-01 20:24:57 +00:00
Dennis Kempin
4cd4043fd1 Upgrade to 1.68.2: Fix clippy nits
The new rust toolchain comes with improved clippy warnings that
catch more unnecessary casts than before.
Some cases have to be whitelisted since libc types have varying size
based on the architecture we are compiling for.

BUG=None
TEST=presubmit

Change-Id: Ia473b0bfe6e74bdb7b0d4ca15d2c9fb410fc353e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4568144
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-25 18:28:14 +00:00
Noah Gold
2516507e92 base: make Tubes return a Disconnect error.
Detecting if a Tube is disconnected used to be a little painful since
we'd have to extract the underlying io::Error and check for BrokenPipe.
On unix it wasn't ever this hard since Error::Disconnected exists for
the Tube Error type. On Windows it looks like we just forgot to
implement this.

This CL makes all broken pipes on Tube read/write return Disconnected
instead of a generic IO error.

BUG=b:276361599
TEST=manual run of VM.

Change-Id: I422951b770fd966d6d5e9618c3b756bb2ab5ef7d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4558305
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
2023-05-23 22:53:30 +00:00
Noah Gold
3a46037613 base: fix StreamChannel broken pipe bug.
StreamChannel notifications were not properly handling broken pipes
when fetching the number of bytes available during the notification
sync. This is because the PeekNamedPipe call comes after the final read
call that drains the named pipe, and at this point the pipe is broken.
This CL fixes the problem by treating the byte count as zero if the
pipe is broken, which is technically true (it has no data).

BUG=b:279840868
TEST=manual

Change-Id: Ib563c7e5e426524f666ff191ec3774a4b40f59a0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4556842
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
2023-05-23 22:04:40 +00:00
Noah Gold
70e9e588d1 base: relax thread::spawn_with_timeout trait reqs.
base:🧵:spawn_with_timeout was stricter than
std:🧵:spawn, which wasn't really helpful.
(In prod code we use std:🧵:spawn, so being
stricter than that isn't useful or safer in a meaningful
way.)

BUG=b:276361599
TEST=builds

Change-Id: I4197d3ac082af4077f82d7d70a11869b0a886238
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4556841
Reviewed-by: Richard Zhang <rizhang@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2023-05-23 21:41:06 +00:00
Noah Gold
738220a623 base: new Tube APIs (split, PipeTube, FlushOnDrop).
* Sometimes we want to split a Tube end into a reader & writer so
those responsibilities can be handled separately. This is what
`split_to_send_recv` does.
* On Windows, making a Tube directly attached to a named pipe will be
  needed for the control client. This is what `PipeTube` implements.
  Just like a raw named pipe, it has no notification support, and so it
  hides those elements of the Tube API.
* On Windows, we need a way to ensure a Tube is flushed before it is
  dropped so that a disconnecting client can ensure the server has read
  its messages before the pipe is dropped / EPIPE happens.
  Paradoxically, the "flush" can only be implemented on the server end
  of a pipe, so in CrosVM, our "clients" are actually the server end of
  pipes.

BUG=b:276361599
TEST=tested in future CL in the chain.

Change-Id: I70a7badc92461d49b9f08a5f997157b0698cff24
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4556840
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
2023-05-23 21:36:56 +00:00
Noah Gold
a6169ea5b1 base: fix ERROR_MORE_DATA being a read failure.
In our overlapped read helper API, ERROR_MORE_DATA was considered to be
a fatal error (if returned from the initial call to ReadFile). It looks
like this might only happen for message mode pipes, which probably
weren't used with this function until an upcoming CL. This error would
cause us to return early and leave the OverlappedWrapper in use. Leaving
the wrapper in use is still possible, so that's a bug (b/279459822).

BUG=b:276361599
TEST=future CLs in the chain.

Change-Id: Icc8dff9b83542365336664ee1219654cb3ec1eef
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4556839
Reviewed-by: Richard Zhang <rizhang@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2023-05-23 21:31:49 +00:00
Noah Gold
448e796868 base: add interruptable ConnectNamedPipe for pipes.
Similar to our other overlapped utility functions for read, this CL adds
one for the named pipe equivalent of accept (ConnectNamedPipe).

BUG=b:276361599
TEST=unit tests

Change-Id: I30780fbfea6ff57aaf4bb3176f400f5b5e5fb9de
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4556838
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
2023-05-23 21:31:49 +00:00
Shintaro Kawamura
f35834e243 base: tube: handle EINTR on Tube
According to man 7 signal:

> On Linux, even in the absence of signal handlers, certain blocking
> interfaces can fail with the error EINTR after the process is stopped
> by one  of the stop signals and then resumed via SIGCONT.  This
> behavior is not sanctioned by POSIX.1, and doesn't occur on other
> systems.
>
> The Linux interfaces that display this behavior are:
>
> •  "Input"  socket  interfaces,  when  a  timeout  (SO_RCVTIMEO)  has
>    been set on the socket using setsockopt(2): accept(2), recv(2),
>    recvfrom(2), recvmmsg(2) (also with a non-NULL timeout argument),
>    and recvmsg(2).
> •  "Output" socket interfaces, when a timeout (SO_RCVTIMEO) has been
>    set on the socket using setsockopt(2):  connect(2),  send(2),
>    sendto(2),  and sendmsg(2), if a send timeout (SO_SNDTIMEO) has
>    been set.

The swap feature sends SIGSTOP and SIGCONT to crosvm processes. The
balloon command tube and the proxy devices fall into this category.

BUG=b:259621330
TEST=tools/dev_container tools/run_tests2

Change-Id: I34535430d6fcde4eaf3d2b21acf9ee444baad42c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4547741
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-05-23 10:29:53 +00:00
Shintaro Kawamura
ded8ec392e base: tube: send/recv for srteam socket to use io::Result
It is confusing that `Tube::recv()` may return `Error::Send`. This was
because `TubeError::Recv` accepts `std::io::Error` only while socket
related raw function in base crate returns `base::Error`.
`TubeError::Recv` and `Tube::Send` should accept either of `base::Error`
or `std::io::Error` but the same one.

`std::io::Error` is preferred because send/recv on `ScmSocket` are I/O.

`std::io::Error::raw_os_error()` always returns `Some` if the error was
constructed via `std::io::Error::last_os_error()`.

BUG=b:276384648
TEST=tools/dev_container tools/run_tests2

Change-Id: I73509c7173b4b0e5e7ed939ef20e36db2f16ade3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4546494
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Shin Kawamura <kawasin@google.com>
2023-05-23 10:29:53 +00:00
Vikram Auradkar
bc604656c9 clippy: Disallow nmodule_inception
BUG=b:283512997
TEST=none

Change-Id: I5cacef1d485d2f25e5377e285a47442da766bac2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4549998
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-05-22 21:21:43 +00:00
Vikram Auradkar
0e1c85f293 clippy: Disallow new_without_default
BUG=b:283512997
TEST=none

Change-Id: If10b73f0cd686ff1a1a17e4aa3260f01e1ee8db5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4546662
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-05-22 21:14:06 +00:00
Daniel Verkamp
a37829eadd base: windows: move file_utils to sys/windows
BUG=b:263815124
TEST=tools/run_tests --platform=mingw64

Change-Id: Iffa9e8137465d5427f0fdea2b36783ae99ec37c9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126571
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-05-19 19:58:45 +00:00
Daniel Verkamp
380359295e base: windows: merge win/syslog.rs into syslog.rs
BUG=b:263815124
TEST=tools/run_tests --platform=mingw64

Change-Id: I619d86bfc10aae5083eeb771cd77e8a7748cdfba
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126570
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-05-19 19:52:38 +00:00
Daniel Verkamp
b13262f48f base: windows: move give_foregrounding_permission to a new file
Move the AllowSetForegroundWindow() wrapper out of windows/win.

BUG=b:263815124
TEST=tools/run_tests --platform=mingw64

Change-Id: I401eb5098ce9d2d02c1f5d8651743d99c19a037f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126567
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-05-19 19:52:38 +00:00
Daniel Verkamp
7806484161 win_util: move SYSTEM_INFO helpers to base
These helper functions for getting system information are only used to
implement the equivalent base functions, so move the implementation into
base itself.

This also cleans up the initialization of the cached system information
so that it is contained in a single once_cell::sync::Lazy. The relevant
data is retrieved once and stored in an internal struct SystemInfo to
avoid problems with storing SYSTEM_INFO itself (the Win32 structure
contains pointers, so it is not Sync and can't be stored directly in a
sync::Lazy).

BUG=b:263815124
TEST=tools/run_tests --platform=mingw64

Change-Id: I94d029ef165764f976fd34d846fab60b8754cfb1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126566
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-05-17 19:25:32 +00:00
maciek swiech
39bdd50ed7 tube: create a ProtoTube wrapper
as part of stabilizing/formalizing the messages that will be sent on
optional registered event listening sockets, introduces a ProtoTube
wrapper around Tube, largely mirroring the functionality of the same
from Windows tubes.

BUG=b/278117550
TEST=unit test

Change-Id: Ib2a722ad9ccd8a454d2ebccbcaadec2a147efe40
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4510027
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: maciek swiech <drmasquatch@google.com>
2023-05-16 14:50:44 +00:00
Richard Zhang
84ab00303e e2e_tests: snapshot vhost user tests
This test will spin up block and net vhost user device processes. This
test will be used as a smoke test and won't run during presubmits

Also refactor functions that can be shared into the fixture crate.

BUG=b:281115884
TEST=ran test. Also verified messages get sent to vhost user devices

Change-Id: Ic7e78a8ed71290fd3c42f9e15bf59a238623c49e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4519650
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2023-05-15 21:11:42 +00:00
Takaya Saeki
7781380f01 devices: virtio: block: use fdatasync for FLUSH
Currently, virtio-blk translates a FLUSH request to fsync system call.
However, fsync always updates the metadata of a file, which causes extra
journaling for metadata update. Since virtio-blk cares only the data of
the given block image file, we should avoid updating extra metadata.

After this change, virtio-blk now calls fdatasync for a FLUSH request.
If a write operation wrote to a data block that is already allocated
before, fdatasync can avoid triggering jdb2 journaling on an ext4 file
system.

Note there are structs which fall back to fsync for fdatasync. In
addition, io_uring executor does not implement fdatasync yet.

We observed statistically significant play_store_shown_time improvement
on trogdor-arc-r by -1.614% with this change. Including non
statistically significant data, we observed the following improvements.

|         Name          |  delta  | Count |
|-----------------------|---------|-------|
| trogdor-arc-r (lazor) | -1.614% |  170  |
| brya-arc-t (primus)   | -1.478% |  200  |
| octopus-arc-t (apel)  | -0.887% |  190  |
| kukui-arc-r (kakadu)  | -0.451% |  170  |

BUG=b:281609112
TEST=run a vm with block and confirmed fdatasync is called by strace

Change-Id: Idc94a3ec169e9a5e04394079967f6d79ff4c32db
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4523029
Commit-Queue: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-12 18:15:54 +00:00
Colin Cross
2b1953cd4d Fix building sock_ctrL_msg.rs against musl libc
Musl libc uses u32 for cmsg_len, cast it to usize when calling
the new CMSG_ALIGN const fn.

Bug: 216192129
Test: m USE_HOST_MUSL=true crosvm
Change-Id: Ida9f09f6a44f6db5f109513618dcf745cf547a5f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4521472
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Colin Cross <ccross@google.com>
2023-05-12 18:01:18 +00:00
David Dai
e9426a6ace aarch64: devices: Add a virtual cpufreq device
Introduce support for a virtual CPU frequency device
to improve guest task placement behaviour along with performance
and power usage of workloads within VMs[1]. This device adds MMIO regions
that enables the guest to:

- Query for the frequency of the physical CPU that the current
vCPU is affined to.
- Send frequency requests that can be used as hint for the
host to schedule vCPU threads and choose physical CPU frequency.

Add a config option "--virt-cpufreq" that enables the virtual cpu device
and populates the frequencies of vCPUs through devicetree, which can
be used by a guest kernel cpufreq driver[2].

[1] https://lore.kernel.org/all/20230330224348.1006691-1-davidai@google.com/
[2] https://android-review.git.corp.google.com/c/kernel/common/+/2239182

Bug: None
Test: ./tools/presubmit
Change-Id: I03983c5e4a3fa288ca19504aa093ad1f7f9f7e51
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4504738
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-11 21:13:57 +00:00
Dennis Kempin
fcce3f2c0c Move base::syslog::tests into an integration test
These tests require initialization of the syslogger via
`openlog_and_get_socket` which requires no other threads in the
process to prevent conflicting file descriptors.

BUG=b:280331266
TEST=run_tests --dut=host
TEST=cargo test -p base --test syslog
TEST=cargo test -p base --lib

Change-Id: I3d83ecb80770d94914fc23b2d5760c7a54f6380f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4499660
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-05-02 18:29:55 +00:00
Daniel Verkamp
b018c19e23 base: unix: reimplement CMSG_* macros as const fns
These macros are no longer necessary, as we can replace them with const
fn implementations instead.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: If64cfa8fe08f113ead7236d11bb5a8b0fd51c290
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4484512
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-05-01 19:34:03 +00:00
Daniel Verkamp
a360baa819 Cargo.toml: upgrade protobuf 2.x -> 3.x
system_api bindings have been regenerated with protobuf 3.2; this should
be okay to land before the full ChromeOS system_api migration, since
crosvm always uses its own copy of the bindings rather than the ones
provided by the dev-rust/system_api package.

The protoc-rust crate is replaced with protobuf_codegen in 3.x.

BUG=b:277243607
BUG=b:279834784
TEST=tools/dev_container tools/presubmit

Change-Id: I6aad45ded2639d7506a7238800584bebab196455
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4405309
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-04-28 19:32:01 +00:00
Daniel Verkamp
6eec4b7768 Fix cargo doc warnings from Rust 1.68
Some type parameters in <> were being mis-parsed as HTML tags.

BUG=b:276487055
TEST=tools/cargo-doc # with rust 1.68.2

Change-Id: Iaa9ec6cf94a6084cfdf323bb04c643396a320889
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4485758
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2023-04-28 17:22:01 +00:00
Elie Kheirallah
8afa6096aa base: add casts for support on Android
Add cast to support Android. Libc Android has different types for some
variables than Libc Linux. This leads to casts required. Added skips on
clippy for these casts as they would be redundant on a platform while
required on another.

The same change is also applied to fuse:.

BUG=N/A
Test=presubmit

Change-Id: I994af922cf3ccc56438f2642fef9af91f6af5118
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4485518
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-04-28 00:59:45 +00:00
Idan Raiter
8831cf5560 audio: Windows: Fix realtime priority not being set
Both single and multi process did not have realtime priority, due to us
dropping the multimedia trick handle in set_audio_thread_priority where
we should be holding it until the thread is finished.

BUG=b:276698085
TEST=Process explorer -> properties -> threads -> base priority
increases from 8 to 24

Change-Id: Ia9199f4816e087046b8718e85c60abc9479ec0f3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4416757
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Idan Raiter <idanr@google.com>
2023-04-27 18:52:14 +00:00
Daniel Verkamp
99e8506da6 base: remove redundant &format!() reference
Fixes clippy lint in Rust 1.68

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: I6754dc4f93c7c2fadfa03f240cae3e2e4a86e225
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4391103
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-17 21:20:57 +00:00
Daniel Verkamp
87134857f0 base: clean up redundant casts
Some `as usize` casts are necessary on non-glibc C libraries, since the
type of `cmsg_len` and `msg_controllen` may not be usize in the libc
bindings, so these warnings are suppressed instead of removing the
casts.

BUG=b:276487055
TEST=tools/clippy # with Rust 1.68

Change-Id: I30d9a16d37710b1356cffc183a03f8c8f6f35680
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4391102
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-17 21:20:57 +00:00
Elie Kheirallah
6eff774b01 base: add deserialize seq to array in custom serde
Add method to deserialize sequences to arrays in custom serde.
This allows for a simpler conversation, avoiding more code for each
conversation, while bypassing the serde limitation on array deserialization
of sizes larger than 32.

BUG=N/A
TEST=tools/presubmit

Change-Id: I89e4d7599cdde2c9781117f2a8e53fc9c50aa909
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4385874
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Elie Kheirallah <khei@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-07 22:12:14 +00:00
Junichi Uekawa
d03c99fc0c crosvm: Uprev uuid > 1
Uprev to version available in Debian.

This seem to end up doing uprev to 1.3 now.

BUG=b:265082456
BUG=b:229895468
TEST=build

Change-Id: I550778acb675c9034b9cfcea77f4ae847e2d2ea1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4364559
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-04-04 23:56:13 +00:00
Daniel Verkamp
658902eede base: windows: de-macro-ify File trait impls
The volatile_impl! and volatile_at_impl! macros were only used to
implement the traits for the File type, and they don't make sense for
any other type on Win32 anyway, so it is simpler to replace the macro
invocations with the actual implementation.

BUG=b:263815124
TEST=tools/run_tests --platform=mingw64

Change-Id: I695fdfdefa87fe267927ae15dc914a55b779021f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126569
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-04-04 21:14:25 +00:00
Shintaro Kawamura
018e8caf99 swap: add trim command
"crosvm swap trim <socket_path>" command for trimming 2 types of pages
in the staging memory before swapping out to reduce the disk I/O.

* clean pages
* zero pages

The doc comment of TrimContext explains the page types.

BUG=b:265592787
TEST=cargo test -p swap

Change-Id: I5c33149f7d0bfd712f07fd11eb9aa07c1a8b0e7a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4357224
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
2023-03-29 01:22:02 +00:00
Daniel Verkamp
083dcf75f4 tree-wide: apply nightly rustfmt
BUG=None
TEST=tools/fmt --nightly

Change-Id: Ifb08dd55ccf2a74ef739d7517a64970d24a82405
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4375640
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-03-27 21:30:45 +00:00
Elie Kheirallah
9d214c1843 hypervisor: Add snapshot to vCPU x86_64
Add snapshot to vCPU for x86 and x86_64 arch.

BUG=b:266515147
BUG=b:232437513
Test=crosvm run && crosvm snapshot take img_name socket

Change-Id: I65d059a7537c713e9ef6c1456a7aeae2b6bc4728
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237759
Auto-Submit: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
2023-03-23 17:15:47 +00:00
Shintaro Kawamura
2914297216 swap: prefetch pages in swap file to page cache while swap in
Pre-populating page cache improves the latency of swap-in which I/O wait
mostly have taken up. This was because page cache populations were
triggered on page fault basis. Since swap-in operation moves pages
sequentially, pre-populating has a benefit on the latency.

MADV_WILLNEED causes the kernel to asynchronously start populating the
pages, and MLOCK_ONFAULT ensures that the data remains in the page cache
until it is UFFD_COPYed. mlock(2) without MLOCK_ONFAULT is not
applicable because it blocks the calling thread until populated.

MADV_DONTNEED is also important in terms of the swap-in latency. It
frees the page cache which is already UFFD_COPYed to be reused for later
readaheading swap file. Otherwise the memory pressure from the swap file
page cache population triggers system-wide page frame collection which
is heavy.

Pre-populating page cache alone is actually not enough to improve the
swap-in latency without swapping in on a background thread
(https://crrev.com/c/4317028).

BUG=b:265606668
TEST=cargo test -p swap

Change-Id: I2069c1260d0cf45499298999a71621e563f28f30
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4314186
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-22 06:01:44 +00:00
Zihan Chen
96b24f0ccc crosvm: Convert DataInit to zerocopy 9/n
This CL introduced a negligible amount of overhead as some read
operations on some tiny data strucutres (acpi netlink events) are
converted from zerocopy to single copy.

Also fixed a naming mistake around PCI MSI and manually added
padding to allow AsBytes to be derived.

TEST=CQ

BUG=b:204409584

Change-Id: Ibafe4c413fbed50e61c54433d495ff024fe60da4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4348712
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-03-20 22:17:26 +00:00