Commit graph

164 commits

Author SHA1 Message Date
Richard
1b0f01be24 devices: Enable mods that already build or had a trivial fix
BUG=b:213149155
TEST=built and presubmits

Change-Id: I42065bb583aed2ed3ad85b2c4189cb5d86aacfd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3736924
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2022-07-02 00:00:29 +00:00
Daniel Verkamp
98fcb96d6b Cargo: bump all rand dependencies to 0.8
The previous configuration made us pull in three different versions of
rand, and depending on "*" is a recipe for API incompatibility.

crosvm-fuzz needs to match its rand version to the rand_core used in
common/cros_fuzz, so that will be upgraded separately.

BUG=b:236978141
TEST=cargo build
TEST=emerge-hatch crosvm

Change-Id: I655ed3f156e4ac43afa3122596f62e9caa43b4f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3722184
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-30 23:22:37 +00:00
Daniel Verkamp
e5c6e65731 devices: pit: remove clock_gettime() usage
The original Pit code encoded the start value of a timer into the
count_load_time field as a number of nanoseconds since the start of
the host's monotonic time value. Instead, we can use the PitCounter's
creation_time as the epoch. This makes the math look a bit more sensible
and removes the use of the non-portable clock_gettime() function.

Before
======

get_channel_state():
    count_load_time = get_monotonic_time() - start.elapsed()
=== count_load_time = now() - (now() - start)
=== count_load_time = start

set_channel_state():
    start = now() - (get_monotonic_time() - count_load_time)
=== start = now() - now() + count_load_time
=== start = count_load_time

After
=====

get_channel_state():
    count_load_time = start - creation_time

set_channel_state():
    start = creation_time + count_load_time

BUG=chromium:908689
BUG=b:213149155
TEST=cargo test -p devices pit
TEST=tools/run_tests --target=host --arch=win64

Change-Id: I5468d1d964a04b1ce96979ed583b729d139e1005
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723804
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-29 22:08:44 +00:00
Alex Gimenez
ed071b6edd crosvm: implement lock-guest-memory feature.
This CL adds a command-line flag to crosm that locks the entire guest
memory, per http://go/host-assisted-vm-swap.
The change relies on existing balloon device code that punches holes
within the guest memory region upon "inflate".

BUG=b:236210703

TEST=manual startup, roblox+instagram and various chrome sessions

Change-Id: I11e0e5b0b0cb6450f47124a6a8b6c4befd9de6ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3725731
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Marciano Gimenez <raging@google.com>
Auto-Submit: Alexandre Marciano Gimenez <raging@google.com>
2022-06-28 10:08:44 +00:00
David Stevens
8b9fc10192 vm_control: use Protection in mapping requests
Switch VmMemoryRequest and FsMappingRequest to use base::Protection to
express permissions, in preparation for unifying the APIs.

BUG=b:201745804
TEST=boot ARCVM and crostini

Change-Id: Id001abbd2dde19aa14fcf1643f25abafdd66a2e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716337
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-27 00:51:20 +00:00
Clarissa Garvey
e12a9aad61 base: Upstream stream_channel
The cvt crate dependency was removed and replaced with a manual
check of the returned value in StreamChannel::inner_read.

Bug: b:231641496
Upstream-Crate: base/src/sys/unix
Change-Id: Ie4cfa14b4b4821923828a97546d6c2a767b9356f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707390
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-24 21:13:03 +00:00
Noah Gold
2bb4f97051 base: add nanoseconds to log timestamps.
We accidentally removed nanosecond precision at some point (likely when
I redid the formatter). This CL fixes that.

BUG=b:237004396
TEST=tested format string in the playground

Change-Id: Iaa502c13c34c9cc8f4b7be05821a63c8f10cb360
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3722782
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-24 19:09:49 +00:00
Alexandre Courbot
8297d745c6 devices: virtio: console: use ReadNotifier trait for polling
AsRawDescriptor is a very generic trait and some of the types we want to
use as input sources already implement it for other purposes.
ReadNotifier makes the purpose of the returned descriptor obvious (wait
for some data), so use it instead.

BUG=b:228912920
TEST=console device works in both regular and vhost-user modes.

Change-Id: I68a4ce05be449e07ea71e7cb472e8cda00e9d84d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671059
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-06-24 03:19:46 +00:00
Clarissa Garvey
3b2d0d6cfc base: Add safety comments in net.rs
Bug: b:231641496
Change-Id: If743749735190ebe41f889d781dc396e6d840b21
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3722779
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-23 23:37:02 +00:00
Noah Gold
972ed6d094 base: log with local timestamps instead of UTC
00068bc0a2f02bd79235ff50b9d6f81a6133986f caused the timestamps on
crosvm logs to switch to UTC (ISO 8601). The 8601 part is great,
but the UTC time is a little annoying for local debugging.

Thanks to auradkar@ for coming up with the new formatter code.

BUG=b:236004673
TEST=ran downstream crosvm & verified logs appear w/ local timestamps.

Change-Id: I715f68b7f4ba545e3eadbfd1b9be9abba69d8258
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3712544
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-06-23 17:04:25 +00:00
Daniel Verkamp
19fc097eb8 crosvm: replace lazy_static with once_cell
We depend on both lazy_static and once_cell, which do basically the same
thing.

The once_cell crate has a few advantages:
- once_cell is on track to be included into libstd.
  (https://github.com/rust-lang/rust/issues/74465)
- once_cell doesn't require macro magic.

Replace the uses of lazy_static with their once_cell equivalents so we
don't need to pull in both crates.

BUG=b:236191006
TEST=tools/presubmit --all
TEST=tools/run_tests --target=host --arch=win64 --build-only
TEST=cargo test --features=plugin

Change-Id: I7cabcd837ef4878e8e8ae635bb4f235a58e4cae3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707624
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-21 23:40:55 +00:00
Daniel Verkamp
b33353cc46 base: remove use of cvt crate
cvt isn't used anywhere else in the base crate, and it isn't included in
the ChromeOS crosvm ebuild, so this breaks the CrOS build. Just check
the result and return an error the same way we do elsewhere in base.

BUG=b:231641496
TEST=cargo build
TEST=emerge-hatch crosvm

Fixes: 21445b1b83 ("base: Upstream unix net set_nonblocking fn")
Change-Id: Iba8beee21810210e50e0c715a1b84de29278625a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3716851
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-21 22:04:32 +00:00
Clarissa Garvey
21445b1b83 base: Upstream unix net set_nonblocking fn
Bug: b:231641496
Upstream-Crate: base/src/sys/unix
Change-Id: I62b07f2fc3f7a02c1b72da735ac41d6dc73416f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708762
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
2022-06-21 18:58:53 +00:00
Frederick Mayle
e0b3fe3845 base: Delete unused rand crate
BUG=b:228881485
TEST=cargo build && cargo check --tests

Change-Id: I492d564872873953fa30b1b15ccc8e62f3c5bc23
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3710853
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-16 23:46:15 +00:00
Allen Webb
b1475abeb0 base: Remove unused scoped_path.
scoped path is not exported and isn't used in crosvm, so delete it (and
move it to libchromeos-rs).

BUG=b:229016539
TEST=crosvm presubmit passes

Change-Id: I661c253db909874aec356538a687e99f3aa95e3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706096
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Allen Webb <allenwebb@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-06-15 17:23:57 +00:00
Allen Webb
efdcf90a42 base: Minor Cargo.toml changes for ChromeOS support.
Add 'provided by ebuild' in necessary places to install crosvm's base
crate on ChromeOS as crosvm_base. Also fix dependency ordering and add a
missing version attribute.

BUG=b:229016539
TEST=FEATURES=test emerge-${BOARD} crosvm_base

Change-Id: Ie09e16819e7e27664b5897afd8c6a40e19cc87ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3703158
Auto-Submit: Allen Webb <allenwebb@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
2022-06-13 23:16:13 +00:00
Daniel Verkamp
9315d0a741 Use 4-space indent in cfg_if treewide
A few of the cfg_if blocks got misaligned somewhere along the line, and
cargo fmt won't rewrite code inside macro invocations, so we have to fix
them manually.

BUG=None
TEST=stare at whitespace

Change-Id: I1ccf7aff7c7827a2687ab5fa50cc192c79d6400b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3691968
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-07 17:36:51 +00:00
Daniel Verkamp
4c0de58cbf base: unix: rename PollContext to EventContext
We already exported PollContext as EventContext for use in the portable
WaitContext wrapper, so this makes no difference to callers.

A few remaining references to PollContext in documentation and errors
are fixed up as well to avoid confusion.

BUG=None
TEST=cargo build

Change-Id: I89943d4d9e135a0da7dd0fbff470b6a14efd669a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3687059
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-06 17:07:35 +00:00
Daniel Verkamp
25f08902ff base: unix: remove unused IntoRawDescriptor for PollContext
PollContext is wrapped by the platform-agnostic WaitContext, which does
not support IntoRawDescriptor, so nobody should be using this.

BUG=None
TEST=cargo build

Change-Id: I5d931d20cb3d0a8f42cc1e625d35df4047e45c7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3687058
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-06 17:07:34 +00:00
Daniel Verkamp
f0f10c4209 base: remove WatchingEvents in favor of EventType
Migrate the last few users of WatchingEvents to the equivalent EventType
values so we can remove the unix-specific WatchingEvents type.

BUG=b:213153157
TEST=cargo build

Change-Id: I215127309591125c4c64ff2963e7d2b8e1914cf3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3687057
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-06 17:07:33 +00:00
Peter Collingbourne
4f7d84e5b9 Fix some clippy warnings on aarch64.
Change-Id: Iac9a9540c585a08374c966a1014c6746fbba0554
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3687061
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Peter Collingbourne <pcc@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-06 16:58:32 +00:00
Noah Gold
b803f10fa2 base: add unix no op impl of enable_high_res_timers.
This is needed by broker_ipc (next crate in the chain).

BUG=232318124
TEST=builds

Change-Id: I7d71b9208123dd055b7150fd3ae6703cdc21bf6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3685809
Commit-Queue: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2022-06-03 22:00:10 +00:00
Daniel Verkamp
d4505a7f1c base: replace PollToken with EventToken tree-wide
Pull the declaration of the `EventToken` enum up to the top level of the
base crate, replacing the identical implementations inside sys/windows
and sys/unix.

Use the `EventToken` name consistently throughout the tree to remove the
unix-flavored "poll" nomenclature.

BUG=b:213153157
TEST=tools/dev_container tools/presubmit --all

Change-Id: I0ba42037b533b796797a7a3f6d8d7e71a5592aba
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3642673
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-02 22:30:38 +00:00
Daniel Verkamp
3e8054ee7c base: unix: merge EpollContext into PollContext
The main distinction between PollContext and EpollContext was that the
latter was safe to use from multiple threads. This was not true of the
more widely-used PollContext for two reasons:

1. The `events` array was stored inside the `PollContext` structure,
   whereas `EpollContext` required the caller to pass their own storage
   for events.
2. `PollContext` had a hangup detection feature used to debug busy
   looping cases that result from a failure to remove hungup file
   descriptors from the context.

Point 1 is resolved by returning a `SmallVec` of events that avoids
allocation for the normal case (and in fact it should avoid allocation
in all cases on Linux, where the maximum number of events returned from
a single `epoll_wait()` call is limited to the same size as the
preallocated `SmallVec`). This simplifies the API and also means that
there is no need for per-context storage.

Point 2 can't easily be resolved, since it would require the `wait` call
to mutate shared state (this could be done by adding a mutex around the
shared data, but that seems like too much overhead for the value of the
feature). Instead, this patch just removes the hangup detection code.

BUG=b:213153157
TEST=tools/dev_container tools/presubmit --all

Change-Id: Ia48c46de96976da27cb5387e3e5e8fcf92d0e85b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3633111
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-02 21:44:39 +00:00
Noah Gold
1977979fbb net_util: upstream Windows support
Adds the libslirp interface code, as well as the Windows pseudo-tap
device.

BUG=b:213151463

TEST=bots (unix + windows)

Change-Id: I975b27a76c82e25037d4061587fec0c31222a159
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3598234
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-06-02 03:00:36 +00:00
Vaibhav Nagarnaik
65806f5213 base: Introduce number_of_logical_cores()
This crossplatform API returns the number of logical cores on the
system.

Remove the older `get_vcpu_count()` that was mis-named and replace its
use with `number_of_logical_cores()`.

TEST=Compiled

Change-Id: I4c46deb35e8354ad2313230d26c94c0f7558e06f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3684930
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
2022-06-02 00:05:07 +00:00
David Stevens
569a58490e base: clarify SharedMemory API
When creating shared memory, 'name' can have one of two meanings. It
could either be a debugging tag with no semantic meaning, or it could
uniquely identify a shared memory object within some namespace. Linux
memfd uses name in the first meaning, whereas Windows (and Linux shm)
uses it in the second meaning.

Currently, crosvm has no use cases for the named shared memory of the
second type, so it is not supported. Make it clear that the SharedMemory
APIs treats name as a debugging-only name. Remove the "anon" and "named"
constructors, since they had no semantic meaning. Also require a name
when constructing a SharedMemory, since there's no reason not to provide
one to make debugging easier.

The only semantic change is setting the name of GuestMemory's underlying
shmem to "crosvm_guest", which it was until recently. This fixes some
ManaTEE tests which use the name to determine CrOS guest memory usage.

BUG=None
TEST=compiles

Change-Id: I78d5046df04d6f19640abbbc67af6bd433a177b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3676695
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-01 03:55:47 +00:00
Alexandre Courbot
aa2e59d82f base: improve documentation of Descriptor and AsRawDescriptor
Although it can be useful for some limited cases, the Descriptor wrapper
class should ideally be eschewed and an alternative based on
implementing AsRawDescriptor on the right type be preferred. Make sure
its documentation reflects that.

The reason for avoiding Descriptor is that it encourages storing raw
descriptors that can possibly be closed before the user expects it. A
reasonable alternative to doing this is to call as_raw_descriptor() at
the exact moment the descriptor is needed, and never storing the result
- this ensures that the providing object (and underlying descriptor)
remain alive for long enough. Update the documentation of
AsRawDescriptor to explain and hopefully encourage this practice.

BUG=233968702
TEST=cargo build

Change-Id: I91c2ef11152b3b6adcc25f40d6de0a0f131700dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3670101
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-05-28 07:29:03 +00:00
Alexandre Courbot
c9b84cf570 base: fix cargo doc warnings
Fix a few link-related (either dead links or typos) in the base crate.

BUG=None
TEST=cargo doc

Change-Id: I520dd2fbfc16de72fcf19ecdd90943a7a963103c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3671057
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-05-27 05:29:02 +00:00
Alexandre Courbot
738adc7072 devices: serial: introduce SerialInput trait
Introduce a new dedicated trait for types that can be used as serial
input. This trait adds the requirement that the type must implement
`AsRawDescriptor`, which will allow us to use the input as a poll source
instead of having to spin a dedicated thread to call `read()` on it.

BUG=b:228912920
TEST=cargo build

Change-Id: Ib07f7b4e63545fa0f27940553ad6124796f5b3cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600167
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-26 10:09:52 +00:00
Anton Romanov
86939a1337 crosvm: fix logging for commands other than run, add ability to disable syslog output
BUG=b:231388464
TEST=tested manually

Change-Id: I3d0504e28b9fe9e791b801a3d58ff3ba5beef2cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3661922
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-05-24 18:18:25 +00:00
Colin Cross
1136e3b115 Fix compiling crosvm against x86_64-unknown-linux-musl
Fix some compatibility issues in crosvm to allow it compile against
musl libc:

- Ioctl numbers are ints like bionic, not unsigned long like glibc.
- The sched_param struct has extra fields that must be initialized, zero
  initialize the whole struct.
- libc::pthread_t is void* and doesn't match std::os::unix:🧵:RawPthread,
  it needs a cast.
- Some msghdr and cmsghdr fields are u32 instead of usize.
- cmsghdr has an extra __pad1 fields that must be initialized, zero initialize
  the whole struct.
- msghdr has private __pad1 and __pad2 fields that cannot be initialized,
  zero initialize the whole struct.

Bug: 216192129
Test: m USE_HOST_MUSL=true crosvm
Change-Id: I0652148e09b9a4d167801b002036ec5a575d3bb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3651504
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-23 21:47:12 +00:00
Anton Romanov
9453959c4c crosvm: rework logging
Motivation:
    * simplify and unify, align more with standard log facade
    * code reduction
    * remove hardcoded platform-specific things
    * a little more flexibility
    * easily allow lov level/filtering config as cli argument

Note that there is more code removal than simply loc as updating tests
added few loc

Change-Id: I7beb4b2c28c3462553c6663b234ee38df79f59f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3657053
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-23 21:11:49 +00:00
Vineeth Pillai
d823be68e0 base: remove ScopedEvent
Now that we do not need ScopedEvent after moving to directional tubes
for VM events, remove the dead code.

BUG=None.
TEST=None

Change-Id: I37b1f7614afa9dc0a9ea1d742ec4872cadedbe2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3655288
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vineeth Pillai <vineethrp@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-20 18:30:34 +00:00
Vineeth Pillai
81b5e616d6 crosvm: vm_events: consolidate vm events into one framework.
crosvm waits on events like exit, reset, crash, guest panic etc and
uses eventfd to wait on these events. As of now, we have 4 eventfds
and may increase.

This is an attempt to consolidate all Vm events into one framework.
Use Tube instead of Event to get consistent behavior between OSes.
Implement a wrapper over Tube to have a consistent API for events.

BUG=None.
TEST=Built crosvm. Ran a minimal vm to panic and verified that crosvm
received the panic event. cargo test on devices.

Change-Id: I313d428de5e3ce3b879982f913918ec0a4a72c35
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3480577
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vineeth Pillai <vineethrp@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-05-20 18:04:21 +00:00
Daniel Verkamp
ddbb57d355 base: unix: timer: factor out timerfd_settime call
Deduplicate the unsafe block and the update of interval into a helper
function so that reset() and clear() can be greatly simplified.

BUG=None
TEST=tools/presubmit --all

Change-Id: Ic0210bc3dd2239b575d47f718709333bce842509
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3653256
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-18 17:47:05 +00:00
Daniel Verkamp
6fd2272510 base: unix: remove unsafe in duration_to_timespec()
This function just initializes a simple struct with two elements; it
does not need to use `unsafe`.

BUG=None
TEST=cargo test -p base

Change-Id: I6f7db5df29cb8a181d2f69ea4cede1ad8be12234
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652894
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Anton Romanov <romanton@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-18 17:47:05 +00:00
Daniel Verkamp
515694f155 base: unix: timer: use duration_to_timespec()
Replace the duplicated Duration to timespec conversion code with calls
to the existing helper function.

BUG=None
TEST=cargo test -p base timer -- --include-ignored

Change-Id: I99d9e77c2056c760c37fd014ca99363276a473d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652892
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-18 17:47:05 +00:00
Daniel Verkamp
f3be99cd03 base: unix: timer: use mark_waited() in wait_for()
Remove some duplicated code that called read() on the timerfd in an
almost identical way in two functions by reusing mark_waited() within
wait_for().

BUG=None
TEST=cargo test -p base timer -- --include-ignored

Change-Id: I3bf4a6eb3c777aa9314c408281e4d60ff218fd2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652891
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Anton Romanov <romanton@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-18 17:47:05 +00:00
Daniel Verkamp
1e8aae8b8d base: improve Timer wait/wait_for documentation
wait() blocks indefinitely, and it does not take a timeout argument, so
remove the wording about `timeout`.

wait_for() can return because of either timeout or timer expiration;
clarify which return value means what.

BUG=None
TEST=tools/cargo-doc

Change-Id: I84ee01d3595510c36a4651d36424883e5bb3c9d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652890
Reviewed-by: Anton Romanov <romanton@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-05-18 17:47:05 +00:00
Vaibhav Nagarnaik
bb30f23ce0 hypervisor: Upstream traits changes for Vm
Add to the `trait Vm` 2 new methods that allow more control for
hypervisors when dealing with memory (un)mapping. This is intended for
dealing with expanding and releasing memory from `virtio-balloon`.

For windows based hypervisors, balloon expansion triggers OS interaction
with reclaiming memory pages, which is automatically managed in KVM.
Similarly, a balloon deflation will cause OS interaction for releasing
memory back to the OS.

Update the error return for `remove_mapping` when `madvise` call fails.

BUG=b:213150327
TEST=compiled.

Change-Id: I6ac04d27ac06ea97825f4d22e36543b5dde5b032
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3640424
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vaibhav Nagarnaik <vnagarnaik@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-13 00:30:09 +00:00
Daniel Verkamp
96e50eb795 base: return SmallVec directly from platform wait impls
On Windows, this changes the EventContext::wait() return type from Vec
to SmallVec; this removes an extra conversion step, since the only
caller, WaitContext::wait(), constructed a SmallVec from the return
value anyway.

On Linux, this lets us get rid of the PollEventsOwned structure, since
the SmallVec contains the events and does not need to point back at a
separate type for storage.

BUG=b:213153157
TEST=tools/dev_container tools/presubmit --all

Change-Id: I7857a306ad71be020af309d4186d9e3e651fcc05
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3633110
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-12 20:37:30 +00:00
Shao-Chuan Lee
c3c170f780 Revert "base: Add CloseNotifier support to Linux"
This reverts commit b10fa49a6f.

Reason for revert: made ARCVM unresponsive during CTS tests

Original change's description:
> base: Add CloseNotifier support to Linux
>
> This is necessary for its cross-platform usage in metrics.
>
> BUG=b:213152497
> TEST=build
>
> Change-Id: I6618777679349d1f6298f79e1f93fe4e9a3ecf7a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3622798
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Michael Hoyle <mikehoyle@google.com>

BUG=b:213152497,b:232316549
TEST=CtsAccessibilityServiceTestCases

Change-Id: If27d2ad016878896a261d6d80c4ea3e252ddd08e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3641219
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Shao-Chuan Lee <shaochuan@chromium.org>
2022-05-12 16:31:52 +00:00
Vikram Auradkar
151a573acc base: catch-up with downstream windows changes
- Updates changes to named-pipe.
- Adds high resolution timer support.

BUG=b:213153157
TEST=presubmit

Change-Id: I08615d343aaa0f6576f3e8df884310adf3ade087
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3639144
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-12 00:21:59 +00:00
Daniel Verkamp
b5f8224312 base: windows: use sync::Mutex to avoid unwrap()
Switch the uses of std::sync::Mutex to our custom sync::Mutex, which
panics internally if lock() fails. This helps to reduce the instances of
unwrap(), making it easier to review and understand the code.

BUG=b:213153157
TEST=tools/dev_container tools/run_tests --target=host --arch=win64

Change-Id: I99bfc85967152f50045e64293104de788a5d3829
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3633108
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-11 17:56:27 +00:00
Vikram Auradkar
8212e88f83 base: add generate_uuid function
This function will be used by crash reporter to associate a unique id
to a session.

BUG=b:213153157
TEST=presubmit

Change-Id: I5f17e023f8895a75062d80773d1aac6315ce4dcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3639685
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-11 15:43:25 +00:00
Vikram Auradkar
878a53ea57 base: remove wildcard exports
Also exports few more windows symbols.

The current exports are not well grouped/organized yet. We will get to
that in another patch.

BUG=b:213153157
TEST=presubmit

Change-Id: I902ec0f9f572ac7889bd7703365dad472fc8d930
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3636274
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-05-10 21:04:22 +00:00
mikehoyle
b10fa49a6f base: Add CloseNotifier support to Linux
This is necessary for its cross-platform usage in metrics.

BUG=b:213152497
TEST=build

Change-Id: I6618777679349d1f6298f79e1f93fe4e9a3ecf7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3622798
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2022-05-10 03:52:11 +00:00
Vikram Auradkar
209c8e774d base: add few more windows specific Event functions
BUG=b:213153157
TEST=presubmit

Change-Id: Ie0fa96e4b84199323bd03000f9be25cf6c3b7723
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3636273
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-10 02:19:24 +00:00
Vikram Auradkar
c57fcc8ef2 base: add clear() to WaitContext as a platform specific extension
BUG=b:213153157
TEST=presubmit

Change-Id: I9f7c958834e9727acaba860600aecfbdc98fcdc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3631414
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-09 17:06:19 +00:00