Commit graph

312 commits

Author SHA1 Message Date
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
Daniel Verkamp
875a1d7d30 base: net: use tempfile::tempdir() in tests
Avoid the possibility of tests reusing the same socket path by using a
known unique directory from tempfile::tempdir().

BUG=b:274145919
TEST=tools/dev_container tools/presubmit

Change-Id: I883e223617fb465cdfbff5a45509098487b62b3b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4348699
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-03-17 20:02:44 +00:00
Daniel Verkamp
7e803c87ca base: use SafeDescriptor in unix socket wrappers
The SafeDescriptor type manages the lifetime of the file descriptor,
which simplifies the socket wrappers (each wrapper no longer needs to
manually implement Drop to close the descriptor, for example).

Also remove unneeded RawFd-related functions, replacing them with
RawDescriptor and SafeDescriptor equivalents.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: I634a19922ec24d06071b21247c79761cfc21a79a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4322266
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2023-03-17 18:12:49 +00:00
Elliot Berman
d88d67c39b base: Move BlockedSignal to base sys
Move generic implementation of BlockedSignal to base sys.

Change-Id: I459ca424a633dc3fc2a5dec625dde8e5878132c0
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
(cherry picked from commit 5f51fa4ae3b979972d273dff4c224c1999b6e641)
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4346950
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-03-16 18:16:28 +00:00
Elliot Berman
e3d71786c2 sys_util: Cast ioctl_expr inputs to IoctlNr
If the input to ioctl_expr is a u8, it cannot be implicitly upcast to
u32. Cast the inputs, not the output, to IoctlNr.

Change-Id: I2bce639bd13f49c92fadedb146ef09171b7128ef
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
(cherry picked from commit 585dbff782e96d0531734d37ec2dae958f6ff6c1)
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4346949
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-03-16 18:16:28 +00:00
Steven Moreland
d86a1ff9c7 Revert "base: Cast ioctl_expr inputs to IoctlNr"
This reverts commit 3216994fd6.

Change-Id: I0109a3270e492be0feb6dd1430c159be2bbeb4ff
(cherry picked from commit deb06d8a71b17b83e382e998c77674cfd0d7428f)
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4346934
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-03-16 18:16:28 +00:00
Steven Moreland
6a524c08b0 Revert "base: Move BlockedSignal to base sys"
This reverts commit 92ffa564c4.

Change-Id: I98ce7763a5dba804ebbe17a78a9a0af35daca52e
(cherry picked from commit 8558a5dfaee0ef5f683cf932f5abcb197afd730d)
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4346933
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-03-16 18:16:28 +00:00
Isaac Bosompem
59ee40f04c crosvm: Add vGPU/vGPUserver cgroup support
Adds command line options to move the vGPU threads housed within crosvm
and the vGPUserver threads housed externally into separate cgroups.

This will give us the ability to perform some tweaks/experiments
with the affinity masks of these threads as a group.

BUG=b:269139377
TEST=Launch Borealis VM, ensure command line options work as expected.

Change-Id: I558673e616e0344bae2407db1ff693902816daac
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4304743
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Isaac Bosompem <mrisaacb@google.com>
2023-03-15 16:25:49 +00:00
Zihan Chen
abd53b6a1f crosvm: Trace seccomp filter usage precisely by filename
Add multiple log points to dump minijail's internal data structure
address, this allowes precise tracking of which minijail seccomp
filter is applied to which process/pid.

TESTED=CROSVM_CARGO_TEST_E2E_WRAPPER_CMD="strace -ff --output=/workspace/stracetest" CROSVM_CARGO_TEST_LOG_LEVEL_DEBUG=1 CROSVM_CARGO_TEST_LOG_FILE=/workspace/logtest.log ./tools/bench boot

BUG=b:258316090

Change-Id: Ibc2b66bf18b8af004bb30fd53523161bc9ca1ec4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4316958
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-14 23:18:39 +00:00
Daniel Verkamp
0d069fc1e6 base: remove unsafe Tube FromRawDescriptor impl
Nothing calls this code, so it should be okay to remove it.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: I5f079dc9e6e15178506b801b7266d8bd0351ddbb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4321329
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-03-14 20:17:25 +00:00
Noah Gold
7e22d900e0 base: fix unsafe overlapped read/write marked safe.
The overlapped wrappers on PipeConnection are unsafe, but they were
marked as safe. There are no actual unsafe production uses of them
because the conventions for overlapped IO generally make that hard to
do. That being said, these wrappers MUST be marked unsafe. This CL does
so and updates the callers with safety statements.

BUG=b:272812234
TEST=presubmit

Change-Id: I0def7056431d5b3b70eb4ce7c6ac8b44aef0a4cc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4330490
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
2023-03-14 18:42:38 +00:00
Noah Gold
29e018652f base: move read/write wrappers to their own module.
In the future we'll be using read/write wrappers in multiple places,
but the wrapping code currently lives in the named pipe implementation.
This CL pulls it out to its own module. It also brings in some other
code in win_util that wasn't upstreamed.

BUG=b:272614458
TEST=presubmit

Change-Id: I6871f3db6991336f42706652b69935755bf2fbc3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4326942
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-14 18:24:44 +00:00
Vikram Auradkar
948735a289 base: upstream overlapped send recv message functions
Upstreams blocking overlapped read/write commmands to base.
These funtions will be used by the broker to forward messages exchanged
between main and service.

Bug: 269191436
Test: none
Change-Id: I029e8c440bb6b8234fe2d1ca3b1dd5ddb408d814
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4329913
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-03-10 23:01:40 +00:00
Maciek Swiech
d7bfa2dc54 crosvm: reland socket control mechanism
crrev.com/v/4237140 was reverted in crrev.com/c/4310064 due to the
generated header file not defining the RegisteredEvent type. along with
re-reverting the original cl (and corresponding bugfix cl) this patch
introduces a RegisteredEventFfi type which mirrors the original
RegisteredEvent type but should be exposed in the generated header file.

BUG=b:269609274
TEST=sidecar process (patch: crrev.com/c/4276642)
TEST=cargo build, header file inspection

Change-Id: I4a17163e36eb466a540a72d2bb4356419739c974
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4311831
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
2023-03-10 18:49:13 +00:00
Shin Kawamura
0ce2557fc5 Revert "balloon: add event registration mechanism for sidecar processes."
This reverts commit 2404c5ed44.

Reason for revert: This fails to build crosvm C interface and blocking ChromeOS CQ.

Original change's description:
> balloon: add event registration mechanism for sidecar processes.
>
> this patch introduces a mechanism for so-called 'sidecar processes' to
> register as event listeners, consuming events that are generated in
> various parts of crosvm. in this patch we focus on events that enable
> roziere cooperative ballooning, but lay the groundwork for a more
> general framework.
>
> the general idea is that a sidecar process would open a listening socket
> and register the path with crosvm for a specific event. crosvm will pass
> along a handle to a registered event tube to the appropriate device (or
> other internal component) which would then be responsible for passing
> along events. once events arrive back in the crosvm control loop, an
> attempt is made to dispatch the events to any registered sockets.
>
> BUG=b:269609274
> TEST=sidecar program that performs registration and receives events
>
> Change-Id: Iaff41aad8f862ed99a104c75623caaabc53e9e88
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237140
> Commit-Queue: Maciek Swiech <drmasquatch@google.com>
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>

Bug: b:269609274
Change-Id: I135e0d55bb296cf591548b7bd4feffc7ff9f3447
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4310064
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2023-03-06 06:51:35 +00:00
Maciek Swiech
2404c5ed44 balloon: add event registration mechanism for sidecar processes.
this patch introduces a mechanism for so-called 'sidecar processes' to
register as event listeners, consuming events that are generated in
various parts of crosvm. in this patch we focus on events that enable
roziere cooperative ballooning, but lay the groundwork for a more
general framework.

the general idea is that a sidecar process would open a listening socket
and register the path with crosvm for a specific event. crosvm will pass
along a handle to a registered event tube to the appropriate device (or
other internal component) which would then be responsible for passing
along events. once events arrive back in the crosvm control loop, an
attempt is made to dispatch the events to any registered sockets.

BUG=b:269609274
TEST=sidecar program that performs registration and receives events

Change-Id: Iaff41aad8f862ed99a104c75623caaabc53e9e88
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237140
Commit-Queue: Maciek Swiech <drmasquatch@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-02 20:50:18 +00:00
Daniel Verkamp
05dea3bb70 base: syslog: do not attempt to reconnect socket
The device process sandbox does not allow connect(), so if the syslog
connection is closed for any reason and then a device tries to log
something, calling connect() in the retry loop would kill the process
since connect is not allowed in the seccomp policy.

BUG=b:259860758
TEST=kill -9 $(pgrep rsyslogd); resize disk to get a log

Change-Id: Ic3d44543edbc6ab63e41f4589f77630620b4eca5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4245440
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Nicholas Verne <nverne@chromium.org>
2023-03-02 00:04:47 +00:00
Dennis Kempin
b67eaca468 Use custom test harness for tests using fork
forking a process with multiple threads will lead to
undefined behavior. Unfortunately, newer versions of
libtest will spawn multiple threads even when running
a with --test-threads=1.

This change implements a custom, test harness using
libtest-mimic. It mimics the libtest CLI but enforces
a single threaded test process.

BUG=b:270167741
BUG=b:268496046
TEST=tools/run_tests --dut=host

Change-Id: Icef6a1b65bab7f5cd5021c01fbd94487fa0ca5fb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4295157
Reviewed-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-03-01 21:46:16 +00:00
Zihan Chen
e670159c2e crosvm: Add seccomp_trace feature
Add a minijail's mode of operation where an always-allow seccomp
filter is attached to forked device processes. This facilitates
capturing seccomp filters used by each device process separately.

TESTED=./tools/build_release -- --features seccomp_trace && strace -ff crosvm --log-level debug run <args>

BUG=b:258316090

Change-Id: Ic4d3f5178e6a2dcbd748d101db43574f3224ff78
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4289510
Commit-Queue: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-03-01 19:18:12 +00:00
Shintaro Kawamura
99900d234a devices: use fork_process() from ProxyDevice::new()
This is a refactoring of ProxyDevice and fork_process().

ProxyDevice did not have `ExitGuard`, but it should have it.

BUG=none
TEST=manual test

Change-Id: I19020b7ce1704638b16e544f0c4863a35c652d47
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4230551
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-02-27 02:46:48 +00:00
Shintaro Kawamura
fc3e5c9b80 disk: add PunchHoleMut trait
PunchHole should be originally immutable method since the
file_punch_hole() for both unix and windows are immutable function which
do not change the underlining file offset.

QcowFile is the only object which requires mutability to punch a hole to
its file.

This commit introduce a new PunchHoleMut and the existing PunchHole
traits and make PunchHole trait immutable. This unblocks b/269981962
which tries to punch a hole to non-mut reference File.

This also remove useless top level defined functions in base crate.

BUG=b:269981962
TEST=cargo build --feature=qcow
TEST=./tools/run_test2

Change-Id: I8333d13f4adc6dff319c0ddababe400d5e995141
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4269718
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-02-22 01:53:38 +00:00
Daniel Verkamp
4a61fb87bb base: add WorkerThread abstraction
WorkerThread provides a mechanism to start a thread that can be stopped
by sending an event from another thread. It also handles automatically
stopping the thread if the WorkerThread object is dropped.

BUG=b:269187468
TEST=tools/presubmit --all

Change-Id: Ifeef3f34f75fcd0496e87e038b60fa9e5e60a681
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237530
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-02-17 22:47:37 +00:00
Frederick Mayle
85eda99bd4 vm_memory: option to set MADV_DONTFORK on guest memory
This is admittedly an odd feature with a narrow use case. It will lower
the risk of crash analysis tools accidentally trying to read guest
memory that has been unshared from the host (i.e. in a protected VM).

Hoperfully we'll eventually have a better solution, where we only mmap
the memory regions that are shared with the host. There is no hypervisor
support for that yet.

BUG=b:238324526

Change-Id: Iac7ed38aa52778a43ac5ba22bab5a3df7a554ee6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4251719
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-02-16 18:23:47 +00:00
Daniel Verkamp
232406ee94 base: windows: implement terminal raw mode
This roughly matches the unix::terminal interface and can be used
to configure the terminal for use with a serial console (no line
buffering, interpret ANSI escapes, and so on).

BUG=b:264428954
TEST=tools/presubmit --all

Change-Id: I7efa8c405b44dadec55e08993b5f7a4c0236cf69
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4200971
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-02-15 18:14:46 +00:00
Clarissa Garvey
4b0a3d88f7 base/src: Fix and update mmap.rs doctests
Prior to this CL, the doctest for write_obj_volatile() was failing on
a Windows device, and the doctest for read_obj_volatile() called
read_obj() rather than read_obj_volatile(), not testing the correct
function. After this CL, both tests pass on Linux and Windows, and the
doctest for read_obj_volatile() correctly tests the volatile version of
the function.

TEST=cargo test --doc in base/src, CQ

Change-Id: I4d3fd77a7ededed12231c980899187d747b61234
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4247139
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
2023-02-13 23:42:21 +00:00
Zihan Chen
4acc0186ad devices: Clean up DataInit (7/n)
With the previous CLs migrating many functions and types to use
zerocopy, finally we can do a big clean up of`unsafe impl DataInit`.
We are down to 93 instances now from 230 at 5th CL in this series.

Also fixes a bug introduced previously in this series where I set
the trait bound of a few write_at_addr unsafe functions to
`FromBytes` when `AsBytes` should also be required.

TEST=CQ

BUG=b:204409584

Change-Id: I6658dd246a8932493ef6a652054a23ecfde76198
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4237765
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-02-13 19:26:45 +00:00
Zihan Chen
7e346a6a91 x86_64: Convert all DataInit to zerocopy
TEST=CQ

BUG=b:204409584

Change-Id: Ic05209ebca76e97a0851b939083d73d5ad0a3f4b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4234064
Commit-Queue: Zihan Chen <zihanchen@google.com>
Reviewed-by: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-02-09 22:59:10 +00:00
George Burgess IV
64c178e9b7 crosvm: skip single-threaded tests
The Rust uprev breaks some assumptions these make. Sounds best from
discussion on the CL to temporarily disable them.

BUG=b:266817148, b:268496046
TEST=emerge-nocturne crosvm-base

Change-Id: If86eb23200b5af4be8221bacc42954b3dfc25aeb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4218895
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: George Burgess <gbiv@chromium.org>
2023-02-09 20:21:23 +00:00